1 16 17 package org.apache.jetspeed.modules.actions; 18 19 import java.util.Locale ; 20 21 import org.apache.turbine.util.RunData; 22 import org.apache.turbine.services.resources.TurbineResources; 23 import org.apache.turbine.services.localization.LocalizationService; 24 import org.apache.turbine.TurbineConstants; 25 26 import org.apache.jetspeed.om.security.JetspeedUser; 27 import org.apache.jetspeed.services.logging.JetspeedLogFactoryService; 28 import org.apache.jetspeed.services.logging.JetspeedLogger; 29 import org.apache.jetspeed.services.JetspeedSecurity; 30 import org.apache.jetspeed.services.security.LoginException; 31 import org.apache.jetspeed.services.rundata.JetspeedRunData; 32 import org.apache.jetspeed.services.resources.JetspeedResources; 33 import org.apache.jetspeed.util.ServiceUtil; 34 import org.apache.jetspeed.services.customlocalization.CustomLocalizationService; 35 36 37 52 public class JetspeedSessionValidator extends TemplateSessionValidator 53 { 54 55 56 59 private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(JetspeedSessionValidator.class.getName()); 60 61 67 public void doPerform( RunData data ) throws Exception 68 { 69 try 75 { 76 super.doPerform(data); 77 } 78 catch (Throwable other) 79 { 80 data.setScreenTemplate(JetspeedResources.getString(TurbineConstants.TEMPLATE_ERROR)); 81 String message = other.getMessage() != null ? other.getMessage() : other.toString(); 82 data.setMessage(message); 83 data.setStackTrace(org.apache.turbine.util.StringUtils.stackTrace(other), other); 84 return; 85 } 86 87 JetspeedUser user = (JetspeedUser)data.getUser(); 88 89 if ( ( user==null || !user.hasLoggedIn() ) && JetspeedResources.getBoolean("automatic.logon.enable", false) ) { 91 if ( data.getRequest().getCookies() != null ) 93 { 94 String userName = data.getCookies().getString("username",""); 96 String loginCookieValue = data.getCookies().getString("logincookie",""); 97 98 if ( userName.length() > 0 && loginCookieValue.length() >0 ) 99 { 100 try { 101 user = JetspeedSecurity.getUser(userName); 102 if (user.getPerm("logincookie","").equals(loginCookieValue)) { 103 data.setUser(user); 105 user.setHasLoggedIn(new Boolean (true)); 106 user.updateLastLogin(); 107 data.save(); 108 } 109 } catch (LoginException noSuchUser) { 110 } catch (org.apache.jetspeed.services.security.UnknownUserException unknownUser) { 112 logger.warn("Username from the cookie was not found: " + userName); 114 } catch (Exception other){ 115 logger.error(other); 116 } 117 } 118 } 119 } 120 121 JetspeedRunData jdata = null; 124 125 try 126 { 127 jdata = (JetspeedRunData)data; 128 } 129 catch (ClassCastException e) 130 { 131 logger.error("The RunData object does not implement the expected interface, " 132 + "please verify the RunData factory settings", e); 133 return; 134 } 135 String language = (String ) data.getRequest().getParameter("js_language"); 136 137 if (null != language) 138 { 139 user.setPerm("language", language); 140 } 141 142 CustomLocalizationService locService = (CustomLocalizationService) ServiceUtil.getServiceByName( 144 LocalizationService.SERVICE_NAME); 145 Locale locale = locService.getLocale(data); 146 147 if (locale == null) { 148 locale = new Locale ( 149 TurbineResources.getString("locale.default.language", "en"), 150 TurbineResources.getString("locale.default.country", "US")); 151 } 152 153 data.getUser().setTemp("locale", locale); 154 155 String paramPortlet = jdata.getParameters().getString("js_peid"); 158 if (paramPortlet != null && paramPortlet.length() > 0) { 159 jdata.setJs_peid(paramPortlet); 160 } 161 162 } 163 164 166 public boolean requiresNewSession( RunData data ) 167 { 168 return false; 169 } 170 171 } 172 | Popular Tags |