View Javadoc

1   /***
2    *  The contents of this file are subject to the Mozilla Public
3    *  License Version 1.1 (the "License"); you may not use this file
4    *  except in compliance with the License. You may obtain a copy of
5    *  the License at http://www.mozilla.org/MPL/
6    *
7    *  Software distributed under the License is distributed on an "AS
8    *  IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
9    *  implied. See the License for the specific language governing
10   *  rights and limitations under the License.
11   *
12   *  The Original Code is pow2ACL library.
13   *
14   *  The Initial Owner of the Original Code is Power Of Two S.R.L.
15   *  Portions created by Power Of Two S.R.L. are Copyright (C) Power Of Two S.R.L.
16   *  All Rights Reserved.
17   *
18   * Contributor(s):
19   */
20  package com.pow2.struts.actions;
21  
22  
23  import javax.servlet.http.*;
24  
25  import org.apache.struts.action.*;
26  
27  import com.pow2.struts.action.*;
28  import com.pow2.user.*;
29  
30  
31  /***
32   *  Logout Action class.
33   *  <br>
34   *  Remove the User object from the the Session context
35   *  and redirect to the login resource.
36   *
37   * @author     Luca Fossato
38   * @created    22 aprile 2002
39   */
40  public class LogoutAction extends DispatcherAction
41  {
42    /***
43     *  Remove and set a new guest User object into the the Session context;
44     *  then redirect to the login resource.
45     *  <br>
46     *  The login resource can be specified by:
47     *  <ul>
48     *    <li>
49     *      the <code>parameter</code> attribute of the action element
50     *      of the struts configuration file
51     *    </li>
52     *    <li>
53     *      the <code>fwd</code> request attribute; the <code>fwd</code>
54     *      attribute value specifies the forward name of the ActionForward object to
55     *      retrieve.
56     *      <br>
57     *      Action URL Example: <code>logout.do?fwd=indexPage</code>
58     *    </li>
59     *  </ul>
60     *
61     * @param  mapping   Description of the Parameter
62     * @param  form      Description of the Parameter
63     * @param  request   Description of the Parameter
64     * @param  response  Description of the Parameter
65     * @return           Description of the Return Value
66     */
67    public ActionForward execute(ActionMapping       mapping,
68                                 ActionForm          form,
69                                 HttpServletRequest  request,
70                                 HttpServletResponse response)
71      throws
72        java.io.IOException,
73        javax.servlet.ServletException
74    {
75      UserManager userManager = UserManager.instance();
76      userManager.deleteUser(request);
77  
78      // invalidate the session;
79      request.getSession().invalidate();
80      cat.info("::perform - session invalidated");
81  
82      // get the actionForward object retrieved by the dispatcher;
83      ActionForward fwd = super.execute(mapping, form, request, response);
84  
85      if ((fwd != null)  && cat.isDebugEnabled())
86        cat.debug("::perform - retrieved fwd name, path [" + fwd.getName() + ", " + fwd.getPath() + "]");
87  
88      return (fwd != null) ? fwd : loginForward(request, mapping);
89    }
90  }