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 52 public class TemplateSessionValidator 53 extends SessionValidator 54 { 55 56 private static Log log = LogFactory.getLog(TemplateSessionValidator.class); 57 58 65 public void doPerform(RunData data) 66 throws TurbineException 67 { 68 Configuration conf = Turbine.getConfiguration(); 69 70 data.populate(); 72 73 if (data.getUser() == null) 75 { 76 log.debug("Fixing up empty User Object!"); 77 data.setUser(TurbineSecurity.getAnonymousUser()); 78 data.save(); 79 } 80 81 if (!data.hasScreen() && StringUtils.isEmpty( 83 data.getTemplateInfo().getScreenTemplate())) 84 { 85 String template = conf.getString( 86 TurbineConstants.TEMPLATE_HOMEPAGE); 87 88 if (StringUtils.isNotEmpty(template)) 89 { 90 data.getTemplateInfo().setScreenTemplate(template); 91 } 92 else 93 { 94 data.setScreen(conf.getString( 95 TurbineConstants.SCREEN_HOMEPAGE)); 96 } 97 } 98 else if (data.getParameters().containsKey("_session_access_counter") 102 && !TurbineSecurity.isAnonymousUser(data.getUser())) 103 { 104 if (data.getParameters().getInt("_session_access_counter") 106 < (((Integer ) data.getUser().getTemp( 107 "_session_access_counter")).intValue() - 1)) 108 { 109 if (data.getTemplateInfo().getScreenTemplate() != null) 110 { 111 data.getUser().setTemp("prev_template", 112 data.getTemplateInfo().getScreenTemplate() 113 .replace('/', ',')); 114 data.getTemplateInfo().setScreenTemplate(conf.getString( 115 TurbineConstants.TEMPLATE_INVALID_STATE)); 116 } 117 else 118 { 119 data.getUser().setTemp("prev_screen", 120 data.getScreen().replace('/', ',')); 121 data.setScreen(conf.getString( 122 TurbineConstants.SCREEN_INVALID_STATE)); 123 } 124 data.getUser().setTemp("prev_parameters", data.getParameters()); 125 data.setAction(""); 126 } 127 } 128 129 if (data.getTemplateInfo().getScreenTemplate() != null) 132 { 133 data.setScreen(null); 134 } 135 } 136 } 137 | Popular Tags |