View Javadoc

1   /*
2    * @version $Revision$ $Date$
3    */
4   package org.sourceforge.vlibrary.security.actions;
5   
6   import java.util.ArrayList;
7   import javax.servlet.http.HttpServletRequest;
8   import javax.servlet.http.HttpServletResponse;
9   import javax.servlet.http.HttpSession;
10  import org.apache.struts.action.ActionForm;
11  import org.apache.struts.action.ActionForward;
12  import org.apache.struts.action.ActionMapping;
13  import org.apache.struts.util.MessageResources;
14  import org.apache.log4j.Logger;
15  import org.sourceforge.vlibrary.exceptions.LibraryException;
16  import org.sourceforge.vlibrary.user.actions.LibraryAction;
17  
18  /**
19   * Logoff action
20   *
21   * @version $Revision$ $Date$
22   */
23  
24  public class LogoffAction extends LibraryAction {
25      /** log4j Logger */
26      private static Logger logger =
27       Logger.getLogger(LogoffAction.class.getName());
28      
29      /**
30       * Logoff Action for form-based login -- invalidates session
31       *
32       * @param mapping  ActionMapping used to select this instance
33       * @param form  TransactionForm associated with this requewst
34       * @param request  HTTP request
35       * @param response  HTTP response* @param messages message resources
36       *
37       * @exception Exception
38       */
39      public ActionForward executeAction(ActionMapping mapping, ActionForm form,
40       HttpServletRequest request, HttpServletResponse response,
41       MessageResources messages) throws Exception {
42          
43          ArrayList errors = new ArrayList();
44          
45          try {
46              HttpSession session = request.getSession();
47              
48              session.invalidate();
49              
50              if (logger.isInfoEnabled()) {
51                  logger.info(messages.getMessage("logout", request
52                   .getRemoteUser()));
53              }
54          } catch (Throwable t) {
55              String errString = messages.getMessage("error.logoff");
56              logger.error(errString, t);
57              errors.add(new LibraryException(errString, t));
58          }
59          
60          return standardForward(mapping, request, errors);
61      }
62  }