1/*2 * Copyright 2000-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 at7 * 8 * http://www.apache.org/licenses/LICENSE-2.09 * 10 * Unless required by applicable law or agreed to in writing, software11 * 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 and14 * limitations under the License.15 */1617packageorg.apache.jetspeed.modules.actions;
181920// Java Core Classes2122import javax.servlet.http.Cookie;
2324// Turbine Modules25import org.apache.turbine.modules.ActionEvent;
26import org.apache.turbine.util.RunData;
27import org.apache.turbine.TurbineConstants;
2829// Jetspeed Stuff30import org.apache.jetspeed.services.logging.JetspeedLogFactoryService;
31import org.apache.jetspeed.services.logging.JetspeedLogger;
32import org.apache.jetspeed.services.resources.JetspeedResources;
33import org.apache.jetspeed.services.JetspeedSecurity;
34import org.apache.jetspeed.util.template.JetspeedLink;
35import org.apache.jetspeed.util.template.JetspeedLinkFactory;
36import org.apache.jetspeed.om.security.JetspeedUser;
37383940/***41 This class is responsible for logging a user out of the system.42*/43publicclassJLogoutUserextends ActionEvent
44 {
4546/***47 * Static initialization of the logger for this class48 */49privatestaticfinalJetspeedLogger logger = JetspeedLogFactoryService.getLogger(JLogoutUser.class.getName());
5051publicvoid doPerform( RunData data ) throws Exception
52 {
53 logger.info("Entering action JLogoutUser");
5455// if automatic login is enabled, then remove cookies when user logs out56if ( JetspeedResources.getBoolean("automatic.logon.enable", false) )
57 {
58// remove cookies by re-adding them with zero MaxAge, which deletes them59 Cookie userName = new Cookie("username","");
60 Cookie loginCookie = new Cookie("logincookie","");
6162 String comment = JetspeedResources.getString("automatic.logon.cookie.comment","");
63 String domain = JetspeedResources.getString("automatic.logon.cookie.domain");
64 String path = JetspeedResources.getString("automatic.logon.cookie.path","/");
6566if (domain == null)
67 {
68 String server = data.getServerName();
69 domain = "." + server;
70 }
7172 userName.setMaxAge(0);
73 userName.setComment(comment);
74 userName.setDomain(domain);
75 userName.setPath(path);
7677 loginCookie.setMaxAge(0);
78 loginCookie.setComment(comment);
79 loginCookie.setDomain(domain);
80 loginCookie.setPath(path);
8182 data.getResponse().addCookie(userName);
83 data.getResponse().addCookie(loginCookie);
848586// also need to remove the cookies from the current request - otherwise the session validator will log user in again87if ( data.getRequest().getCookies() != null)
88 {
89 data.getCookies().remove("logincookie");
90 data.getCookies().remove("username");
91 }
92 }
9394// use the standard turbine logout facility95if ( JetspeedResources.getBoolean("automatic.logout.save", false) )
96 {
97 JetspeedSecurity.saveUser((JetspeedUser)data.getUserFromSession());
98 }
99100 JetspeedSecurity.logout();
101102 data.setMessage(JetspeedResources.getString(
103 TurbineConstants.LOGOUT_MESSAGE));
104105JetspeedLink jsLink = null;
106107 data.setScreen(JetspeedResources.getString(
108 TurbineConstants.SCREEN_HOMEPAGE));
109110try111 {
112 jsLink = JetspeedLinkFactory.getInstance(data);
113 } catch (Exception e)
114 {
115 logger.error("Error getting jsLink", e);
116 }
117 data.setRedirectURI(jsLink.getHomePage().toString());
118 JetspeedLinkFactory.putInstance(jsLink);
119 jsLink = null;
120 }
121122 }