1 package org.apache.turbine.modules.actions.sessionvalidator; 2 3 18 19 import org.apache.commons.configuration.Configuration; 20 21 import org.apache.commons.lang.StringUtils; 22 23 import org.apache.commons.logging.Log; 24 import org.apache.commons.logging.LogFactory; 25 26 import org.apache.turbine.Turbine; 27 import org.apache.turbine.TurbineConstants; 28 29 import org.apache.turbine.services.security.TurbineSecurity; 30 31 import org.apache.turbine.util.RunData; 32 import org.apache.turbine.util.TurbineException; 33 34 57 public class TemplateSecureSessionValidator 58 extends SessionValidator 59 { 60 61 private static Log log = LogFactory.getLog( 62 TemplateSecureSessionValidator.class); 63 64 76 public void doPerform(RunData data) 77 throws TurbineException 78 { 79 Configuration conf = Turbine.getConfiguration(); 80 81 data.populate(); 83 84 if (data.getUser() == null) 86 { 87 log.debug("Fixing up empty User Object!"); 88 data.setUser(TurbineSecurity.getAnonymousUser()); 89 data.save(); 90 } 91 92 if (!data.getUser().hasLoggedIn()) 94 { 95 log.debug("User is not logged in!"); 96 97 if (StringUtils.isEmpty(data.getMessage())) 100 { 101 data.setMessage(conf.getString(TurbineConstants.LOGIN_MESSAGE)); 102 } 103 104 String loginTemplate = 106 conf.getString(TurbineConstants.TEMPLATE_LOGIN); 107 108 log.debug("Sending User to the Login Screen (" 109 + loginTemplate + ")"); 110 data.getTemplateInfo().setScreenTemplate(loginTemplate); 111 112 data.setAction(null); 115 } 116 117 log.debug("Login Check finished!"); 118 119 if (!data.hasScreen() && StringUtils.isEmpty( 121 data.getTemplateInfo().getScreenTemplate())) 122 { 123 String template = conf.getString( 124 TurbineConstants.TEMPLATE_HOMEPAGE); 125 126 if (StringUtils.isNotEmpty(template)) 127 { 128 data.getTemplateInfo().setScreenTemplate(template); 129 } 130 else 131 { 132 data.setScreen(conf.getString( 133 TurbineConstants.SCREEN_HOMEPAGE)); 134 } 135 } 136 137 142 if (data.getParameters().containsKey("_session_access_counter") 143 && !TurbineSecurity.isAnonymousUser(data.getUser())) 144 { 145 if (data.getParameters().getInt("_session_access_counter") 147 < (((Integer ) data.getUser().getTemp( 148 "_session_access_counter")).intValue() - 1)) 149 { 150 if (data.getTemplateInfo().getScreenTemplate() != null) 151 { 152 data.getUser().setTemp("prev_template", 153 data.getTemplateInfo().getScreenTemplate() 154 .replace('/', ',')); 155 data.getTemplateInfo().setScreenTemplate(conf.getString( 156 TurbineConstants.TEMPLATE_INVALID_STATE)); 157 } 158 else 159 { 160 data.getUser().setTemp("prev_screen", 161 data.getScreen().replace('/', ',')); 162 data.setScreen(conf.getString( 163 TurbineConstants.SCREEN_INVALID_STATE)); 164 } 165 data.getUser().setTemp("prev_parameters", data.getParameters()); 166 data.setAction(""); 167 } 168 } 169 170 if (data.getTemplateInfo().getScreenTemplate() != null) 173 { 174 data.setScreen(null); 175 } 176 } 177 } 178 | Popular Tags |