1 /*
2 * $Id: LogoffAction.java 471754 2006-11-06 14:55:09Z husted $
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
23 package org.apache.struts.webapp.example;
24
25
26 import javax.servlet.http.HttpServletRequest;
27 import javax.servlet.http.HttpSession;
28 import javax.servlet.http.HttpServletResponse;
29 import org.apache.commons.logging.Log;
30 import org.apache.commons.logging.LogFactory;
31 import org.apache.struts.action.Action;
32 import org.apache.struts.action.ActionForm;
33 import org.apache.struts.action.ActionForward;
34 import org.apache.struts.action.ActionMapping;
35
36
37 /**
38 * Implementation of <strong>Action</strong> that processes a
39 * user logoff.
40 *
41 * @author Craig R. McClanahan
42 * @version $Rev: 471754 $ $Date: 2006-11-06 08:55:09 -0600 (Mon, 06 Nov 2006) $
43 */
44
45 public final class LogoffAction extends Action {
46
47
48 // ----------------------------------------------------- Instance Variables
49
50
51 /**
52 * The <code>Log</code> instance for this application.
53 */
54 private Log log =
55 LogFactory.getLog("org.apache.struts.webapp.Example");
56
57
58 // --------------------------------------------------------- Public Methods
59
60
61 /**
62 * Process the specified HTTP request, and create the corresponding HTTP
63 * response (or forward to another web component that will create it).
64 * Return an <code>ActionForward</code> instance describing where and how
65 * control should be forwarded, or <code>null</code> if the response has
66 * already been completed.
67 *
68 * @param mapping The ActionMapping used to select this instance
69 * @param form The optional ActionForm bean for this request (if any)
70 * @param request The HTTP request we are processing
71 * @param response The HTTP response we are creating
72 *
73 * @exception Exception if business logic throws an exception
74 */
75 public ActionForward execute(ActionMapping mapping,
76 ActionForm form,
77 HttpServletRequest request,
78 HttpServletResponse response)
79 throws Exception {
80
81 // Extract attributes we will need
82 HttpSession session = request.getSession();
83 User user = (User) session.getAttribute(Constants.USER_KEY);
84
85 // Process this user logoff
86 if (user != null) {
87 if (log.isDebugEnabled()) {
88 log.debug("LogoffAction: User '" + user.getUsername() +
89 "' logged off in session " + session.getId());
90 }
91 } else {
92 if (log.isDebugEnabled()) {
93 log.debug("LogoffActon: User logged off in session " +
94 session.getId());
95 }
96 }
97 session.removeAttribute(Constants.SUBSCRIPTION_KEY);
98 session.removeAttribute(Constants.USER_KEY);
99 session.invalidate();
100
101 // Forward control to the specified success URI
102 return (mapping.findForward("success"));
103
104 }
105
106
107 }