KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > security > actions > LogoffAction


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.sslexplorer.security.actions;
21
22 import javax.servlet.http.HttpServletRequest JavaDoc;
23 import javax.servlet.http.HttpServletResponse JavaDoc;
24
25 import org.apache.commons.logging.Log;
26 import org.apache.commons.logging.LogFactory;
27 import org.apache.struts.action.ActionForm;
28 import org.apache.struts.action.ActionForward;
29 import org.apache.struts.action.ActionMapping;
30
31 import com.sslexplorer.agent.DefaultAgentManager;
32 import com.sslexplorer.core.actions.DefaultAction;
33 import com.sslexplorer.security.LogonControllerFactory;
34 import com.sslexplorer.security.SessionInfo;
35 import com.sslexplorer.vfs.VFSRepository;
36
37 /**
38  * Logs a user out of the SSL Explorer
39  *
40  * @author Brett Smith <a HREF="mailto: brett@3sp.com">&lt;brett@3sp.com&gt;</a>
41  * @author Lee David Painter <a HREF="mailto: lee@3sp.com">&lt;lee@3sp.com&gt;</a>
42  * @author Peter King <a HREF="mailto: lee@3sp.com">&lt;peter@3sp.com&gt;</a>
43  * @author James D Robinson <a HREF="mailto:james@3sp.com">&lt;james@3sp.com&gt;</a>
44  */

45 public class LogoffAction extends DefaultAction {
46
47     static Log log = LogFactory.getLog(LogoffAction.class);
48
49     /* (non-Javadoc)
50      * @see com.sslexplorer.core.actions.DefaultAction#execute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
51      */

52     public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
53                     throws Exception JavaDoc {
54
55         try {
56             SessionInfo session = LogonControllerFactory.getInstance().getSessionInfo(request);
57             if(session != null) {
58                 VFSRepository.removeRepository(session);
59                 
60                 if(DefaultAgentManager.getInstance().hasActiveAgent(session))
61                     DefaultAgentManager.getInstance().unregisterAgent(session);
62
63                 String JavaDoc username = LogonControllerFactory.getInstance().getUser(request).getPrincipalName();
64                 username += " [" + request.getRemoteHost() + "]";
65                 if (log.isInfoEnabled())
66                     log.info("Logging off " + username);
67     
68                 try {
69                     LogonControllerFactory.getInstance().logoffSession(request, response);
70     
71                     if (log.isInfoEnabled())
72                         log.info(username + " has logged off");
73                 } catch (Exception JavaDoc ex) {
74                     if (log.isInfoEnabled())
75                         log.info("Logoff failed for " + username, ex);
76                 }
77                 
78             }
79         } catch (SecurityException JavaDoc ite) {
80             // Dont care - session may have timed-out
81
}
82
83         getMessages(request).clear();
84         getErrors(request).clear();
85         return (mapping.findForward("success"));
86     }
87
88     /*
89      * (non-Javadoc)
90      *
91      * @see com.sslexplorer.core.actions.CoreAction#getNavigationContext(org.apache.struts.action.ActionMapping,
92      * org.apache.struts.action.ActionForm,
93      * javax.servlet.http.HttpServletRequest,
94      * javax.servlet.http.HttpServletResponse)
95      */

96     public int getNavigationContext(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) {
97         return SessionInfo.MANAGEMENT_CONSOLE_CONTEXT | SessionInfo.USER_CONSOLE_CONTEXT;
98     }
99 }
Popular Tags