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