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