~ubuntu-branches/ubuntu/lucid/libstruts1.2-java/lucid

« back to all changes in this revision

Viewing changes to contrib/struts-faces/src/example2/org/apache/struts/webapp/example2/LogoffAction.java

  • Committer: Bazaar Package Importer
  • Author(s): Arnaud Vandyck
  • Date: 2006-04-24 12:14:23 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20060424121423-naev53qigqgks0sa
Tags: 1.2.9-1
New upstream  release Fixes  three security  problems: CVE-2006-1546,
CVE-2006-1547,  CVE-2006-1548  (closes:  #360551),  thanks  to  Moritz
Muehlenhoff.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright 1999-2001,2004 The Apache Software Foundation.
3
 
 * 
4
 
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 
 * you may not use this file except in compliance with the License.
6
 
 * You may obtain a copy of the License at
7
 
 * 
8
 
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 
 * 
10
 
 * Unless required by applicable law or agreed to in writing, software
11
 
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 
 * See the License for the specific language governing permissions and
14
 
 * limitations under the License.
15
 
 */
16
 
 
17
 
 
18
 
package org.apache.struts.webapp.example2;
19
 
 
20
 
 
21
 
import java.util.Locale;
22
 
import javax.servlet.http.HttpServletRequest;
23
 
import javax.servlet.http.HttpServletResponse;
24
 
import javax.servlet.http.HttpSession;
25
 
import org.apache.commons.logging.Log;
26
 
import org.apache.commons.logging.LogFactory;
27
 
import org.apache.struts.action.Action;
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.util.MessageResources;
32
 
 
33
 
 
34
 
/**
35
 
 * Implementation of <strong>Action</strong> that processes a
36
 
 * user logoff.
37
 
 *
38
 
 * @author Craig R. McClanahan
39
 
 * @version $Revision: 1.3 $ $Date: 2004/04/29 03:58:40 $
40
 
 */
41
 
 
42
 
public final class LogoffAction extends Action {
43
 
 
44
 
 
45
 
    // ----------------------------------------------------- Instance Variables
46
 
 
47
 
 
48
 
    /**
49
 
     * The <code>Log</code> instance for this application.
50
 
     */
51
 
    private Log log =
52
 
        LogFactory.getLog("org.apache.struts.webapp.Example");
53
 
 
54
 
 
55
 
    // --------------------------------------------------------- Public Methods
56
 
 
57
 
 
58
 
    /**
59
 
     * Process the specified HTTP request, and create the corresponding HTTP
60
 
     * response (or forward to another web component that will create it).
61
 
     * Return an <code>ActionForward</code> instance describing where and how
62
 
     * control should be forwarded, or <code>null</code> if the response has
63
 
     * already been completed.
64
 
     *
65
 
     * @param mapping The ActionMapping used to select this instance
66
 
     * @param actionForm The optional ActionForm bean for this request (if any)
67
 
     * @param request The HTTP request we are processing
68
 
     * @param response The HTTP response we are creating
69
 
     *
70
 
     * @exception Exception if business logic throws an exception
71
 
     */
72
 
    public ActionForward execute(ActionMapping mapping,
73
 
                                 ActionForm form,
74
 
                                 HttpServletRequest request,
75
 
                                 HttpServletResponse response)
76
 
        throws Exception {
77
 
 
78
 
        // Extract attributes we will need
79
 
        Locale locale = getLocale(request);
80
 
        MessageResources messages = getResources(request);
81
 
        HttpSession session = request.getSession();
82
 
        User user = (User) session.getAttribute(Constants.USER_KEY);
83
 
 
84
 
        // Process this user logoff
85
 
        if (user != null) {
86
 
            if (log.isDebugEnabled()) {
87
 
                log.debug("LogoffAction: User '" + user.getUsername() +
88
 
                          "' logged off in session " + session.getId());
89
 
            }
90
 
        } else {
91
 
            if (log.isDebugEnabled()) {
92
 
                log.debug("LogoffActon: User logged off in session " +
93
 
                          session.getId());
94
 
            }
95
 
        }
96
 
        session.removeAttribute(Constants.SUBSCRIPTION_KEY);
97
 
        session.removeAttribute(Constants.USER_KEY);
98
 
        session.invalidate();
99
 
 
100
 
        // Forward control to the specified success URI
101
 
        return (mapping.findForward("success"));
102
 
 
103
 
    }
104
 
 
105
 
 
106
 
}