1 package org.apache.turbine.modules.actions.sessionvalidator;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.commons.configuration.Configuration;
23 import org.apache.commons.lang.StringUtils;
24 import org.apache.commons.logging.Log;
25 import org.apache.commons.logging.LogFactory;
26 import org.apache.turbine.Turbine;
27 import org.apache.turbine.TurbineConstants;
28 import org.apache.turbine.annotation.TurbineConfiguration;
29 import org.apache.turbine.annotation.TurbineService;
30 import org.apache.turbine.om.security.User;
31 import org.apache.turbine.pipeline.PipelineData;
32 import org.apache.turbine.services.security.SecurityService;
33 import org.apache.turbine.util.RunData;
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54 public class TemplateSessionValidator
55 extends SessionValidator
56 {
57
58 private static Log log = LogFactory.getLog(TemplateSessionValidator.class);
59
60 @TurbineService
61 private SecurityService security;
62
63 @TurbineConfiguration
64 private Configuration conf;
65
66
67
68
69
70
71
72
73 @Override
74 public void doPerform(PipelineData pipelineData) throws Exception
75 {
76 RunData data = getRunData(pipelineData);
77
78 data.populate();
79
80
81 if (data.getUser() == null)
82 {
83 log.debug("Fixing up empty User Object!");
84 User anonymousUser = security.getAnonymousUser();
85 data.setUser(anonymousUser);
86 data.save();
87 }
88
89
90 if (!data.hasScreen() && StringUtils.isEmpty(
91 data.getTemplateInfo().getScreenTemplate()))
92 {
93 String template = conf.getString(
94 TurbineConstants.TEMPLATE_HOMEPAGE);
95
96 if (StringUtils.isNotEmpty(template))
97 {
98 data.getTemplateInfo().setScreenTemplate(template);
99 }
100 else
101 {
102 data.setScreen(conf.getString(
103 TurbineConstants.SCREEN_HOMEPAGE));
104 }
105 }
106
107
108
109 else if (data.getParameters().containsKey("_session_access_counter")
110 && !security.isAnonymousUser(data.getUser()))
111 {
112
113 if (data.getParameters().getInt("_session_access_counter")
114 < (((Integer) data.getUser().getTemp(
115 "_session_access_counter")).intValue() - 1))
116 {
117 if (data.getTemplateInfo().getScreenTemplate() != null)
118 {
119 data.getUser().setTemp("prev_template",
120 data.getTemplateInfo().getScreenTemplate()
121 .replace('/', ','));
122 data.getTemplateInfo().setScreenTemplate(conf.getString(
123 TurbineConstants.TEMPLATE_INVALID_STATE));
124 }
125 else
126 {
127 data.getUser().setTemp("prev_screen",
128 data.getScreen().replace('/', ','));
129 data.setScreen(conf.getString(
130 TurbineConstants.SCREEN_INVALID_STATE));
131 }
132 data.getUser().setTemp("prev_parameters", data.getParameters());
133 data.setAction("");
134 }
135 }
136
137
138
139 if (data.getTemplateInfo().getScreenTemplate() != null)
140 {
141 data.setScreen(null);
142 }
143
144
145 pipelineData.get(Turbine.class).put(User.class, data.getUser());
146 }
147 }