View Javadoc

1   /**
2    * Copyright 2005-2006 the original author or authors.
3    *
4    * Licensed under the Gnu General Pubic License, Version 2.0 (the
5    * "License"); you may not use this file except in compliance with
6    * the License. You may obtain a copy of the License at
7    *
8    *      http://www.opensource.org/licenses/gpl-license.php
9    *
10   * This program is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13   * See the Gnu General Public License for more details.
14   */
15  package org.figure8.join.control.action;
16  
17  import org.figure8.join.control.JoinAction;
18  import org.figure8.join.control.form.LoginForm;
19  import org.figure8.join.view.UserView;
20  import org.figure8.join.util.LogUtil;
21  
22  import org.apache.commons.logging.Log;
23  import org.apache.struts.action.ActionForm;
24  import org.apache.struts.action.ActionForward;
25  import org.apache.struts.action.ActionMapping;
26  
27  import javax.servlet.http.HttpSession;
28  import javax.servlet.http.HttpServletRequest;
29  import javax.servlet.http.HttpServletResponse;
30  /**
31   * This action is called when a user wants to log out from the Join system.
32   * @author <a href="mailto:laurent.broudoux@free.fr">Laurent Broudoux</a>
33   * @version $Revision: 1.1 $
34   *
35   * @struts.action path="/logout" name="loginForm"
36   *                scope="request" validate="true"
37   *                input="/pages/validationfailurepage.jsp"
38   * @struts.action-forward name="Next" path="/jsp/logout.jsp"
39   */
40  public class LogoutAction extends JoinAction{
41  
42     // Static -------------------------------------------------------------------
43  
44     /** Get a commons logger. */
45     protected static Log log = LogUtil.getLog(LogoutAction.class);
46  
47  
48     // Override of JoinAction ---------------------------------------------------
49  
50     /**
51      *
52      * @param operation String representing the operation to invoke on Action
53      * @param mapping Mapping between forwards name and path for this action
54      * @param form The form object containing request parameters
55      * @param request The servlet container request wrapper
56      * @param response The servlet container response wrapper
57      * @return A forward to the next view to render and display
58      */
59     public ActionForward doExecute(String operation, ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
60             throws Exception{
61        // Trace operation to execute.
62        log.debug("doExecute() called for logging in");
63  
64        if (form instanceof LoginForm){
65           // Put user's identity into request to say goodbye ...
66           UserView user = getUserContainer(request).getView();
67           if (user != null)
68              request.setAttribute("user.name", user.getUser().getFirstname());
69  
70           // Invalidate the user's session.
71           HttpSession session = request.getSession();
72           if (session != null)
73              session.invalidate();
74  
75           // Forward to logout page.
76           return mapping.findForward("Next");
77        }
78        // This should not happen ...
79        return null;
80     }
81  }