View Javadoc

1   /*
2    * $Id: LogoffAction.java 360442 2005-12-31 20:10:04Z husted $
3    *
4    * Copyright 1999-2004 The Apache Software Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  package org.apache.struts.apps.mailreader.actions;
20  
21  import org.apache.struts.action.ActionForm;
22  import org.apache.struts.action.ActionForward;
23  import org.apache.struts.action.ActionMapping;
24  import org.apache.struts.apps.mailreader.Constants;
25  import org.apache.struts.apps.mailreader.dao.User;
26  
27  import javax.servlet.http.HttpServletRequest;
28  import javax.servlet.http.HttpServletResponse;
29  import javax.servlet.http.HttpSession;
30  
31  /***
32   * <p>
33   * Log user out of the current session.
34   * </p>
35   *
36   * @version $Rev: 360442 $ $Date: 2005-12-31 13:10:04 -0700 (Sat, 31 Dec 2005) $
37   */
38  public final class LogoffAction extends BaseAction {
39  
40      // See superclass for Javadoc
41      public ActionForward execute(
42              ActionMapping mapping,
43              ActionForm form,
44              HttpServletRequest request,
45              HttpServletResponse response)
46              throws Exception {
47  
48          // Log event
49          HttpSession session = request.getSession();
50          User user = doGetUser(session);
51          if (user != null) {
52              if (log.isDebugEnabled()) {
53                  log.debug(
54                          "LogoffAction: User '"
55                                  + user.getUsername()
56                                  + "' logged off in session "
57                                  + session.getId());
58              }
59          } else {
60              if (log.isDebugEnabled()) {
61                  log.debug(
62                          "LogoffActon: User logged off in session " +
63                                  session.getId());
64              }
65          }
66  
67          // Process user logoff by removing session attributes
68          session.removeAttribute(Constants.SUBSCRIPTION_KEY);
69          session.removeAttribute(Constants.USER_KEY);
70          session.invalidate();
71  
72          // Done
73          return doFindSuccess(mapping);
74  
75      }
76  
77  }