1 16 17 package org.apache.jetspeed.modules.actions; 18 19 20 22 import javax.servlet.http.Cookie ; 23 24 import org.apache.turbine.modules.ActionEvent; 26 import org.apache.turbine.util.RunData; 27 import org.apache.turbine.TurbineConstants; 28 29 import org.apache.jetspeed.services.logging.JetspeedLogFactoryService; 31 import org.apache.jetspeed.services.logging.JetspeedLogger; 32 import org.apache.jetspeed.services.resources.JetspeedResources; 33 import org.apache.jetspeed.services.JetspeedSecurity; 34 import org.apache.jetspeed.util.template.JetspeedLink; 35 import org.apache.jetspeed.util.template.JetspeedLinkFactory; 36 import org.apache.jetspeed.om.security.JetspeedUser; 37 38 39 40 43 public class JLogoutUser extends ActionEvent 44 { 45 46 49 private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(JLogoutUser.class.getName()); 50 51 public void doPerform( RunData data ) throws Exception 52 { 53 logger.info("Entering action JLogoutUser"); 54 55 if ( JetspeedResources.getBoolean("automatic.logon.enable", false) ) 57 { 58 Cookie userName = new Cookie ("username",""); 60 Cookie loginCookie = new Cookie ("logincookie",""); 61 62 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","/"); 65 66 if (domain == null) 67 { 68 String server = data.getServerName(); 69 domain = "." + server; 70 } 71 72 userName.setMaxAge(0); 73 userName.setComment(comment); 74 userName.setDomain(domain); 75 userName.setPath(path); 76 77 loginCookie.setMaxAge(0); 78 loginCookie.setComment(comment); 79 loginCookie.setDomain(domain); 80 loginCookie.setPath(path); 81 82 data.getResponse().addCookie(userName); 83 data.getResponse().addCookie(loginCookie); 84 85 86 if ( data.getRequest().getCookies() != null) 88 { 89 data.getCookies().remove("logincookie"); 90 data.getCookies().remove("username"); 91 } 92 } 93 94 if ( JetspeedResources.getBoolean("automatic.logout.save", false) ) 96 { 97 JetspeedSecurity.saveUser((JetspeedUser)data.getUserFromSession()); 98 } 99 100 JetspeedSecurity.logout(); 101 102 data.setMessage(JetspeedResources.getString( 103 TurbineConstants.LOGOUT_MESSAGE)); 104 105 JetspeedLink jsLink = null; 106 107 data.setScreen(JetspeedResources.getString( 108 TurbineConstants.SCREEN_HOMEPAGE)); 109 110 try 111 { 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 } 121 122 } 123 | Popular Tags |