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
55
56
57
58
59 public class TemplateSecureSessionValidator
60 extends SessionValidator
61 {
62
63 private static Log log = LogFactory.getLog(
64 TemplateSecureSessionValidator.class);
65
66 @TurbineService
67 private SecurityService security;
68
69 @TurbineConfiguration
70 private Configuration conf;
71
72
73
74
75
76
77
78
79
80
81
82
83
84 @Override
85 public void doPerform(PipelineData pipelineData)
86 throws Exception
87 {
88 RunData data = getRunData(pipelineData);
89
90 data.populate();
91
92
93 if (data.getUser() == null)
94 {
95 log.debug("Fixing up empty User Object!");
96 User anonymousUser = security.getAnonymousUser();
97 data.setUser(anonymousUser);
98 data.save();
99 }
100
101
102 if (!data.getUser().hasLoggedIn())
103 {
104 log.debug("User is not logged in!");
105
106
107
108 if (StringUtils.isEmpty(data.getMessage()))
109 {
110 data.setMessage(conf.getString(TurbineConstants.LOGIN_MESSAGE));
111 }
112
113
114 String loginTemplate =
115 conf.getString(TurbineConstants.TEMPLATE_LOGIN);
116
117 log.debug("Sending User to the Login Screen ("
118 + loginTemplate + ")");
119 data.getTemplateInfo().setScreenTemplate(loginTemplate);
120
121
122
123 data.setAction(null);
124 }
125
126 log.debug("Login Check finished!");
127
128
129 if (!data.hasScreen() && StringUtils.isEmpty(
130 data.getTemplateInfo().getScreenTemplate()))
131 {
132 String template = conf.getString(
133 TurbineConstants.TEMPLATE_HOMEPAGE);
134
135 if (StringUtils.isNotEmpty(template))
136 {
137 data.getTemplateInfo().setScreenTemplate(template);
138 }
139 else
140 {
141 data.setScreen(conf.getString(
142 TurbineConstants.SCREEN_HOMEPAGE));
143 }
144 }
145
146
147
148
149
150
151 if (data.getParameters().containsKey("_session_access_counter")
152 && !security.isAnonymousUser(data.getUser()))
153 {
154
155 if (data.getParameters().getInt("_session_access_counter")
156 < (((Integer) data.getUser().getTemp(
157 "_session_access_counter")).intValue() - 1))
158 {
159 if (data.getTemplateInfo().getScreenTemplate() != null)
160 {
161 data.getUser().setTemp("prev_template",
162 data.getTemplateInfo().getScreenTemplate()
163 .replace('/', ','));
164 data.getTemplateInfo().setScreenTemplate(conf.getString(
165 TurbineConstants.TEMPLATE_INVALID_STATE));
166 }
167 else
168 {
169 data.getUser().setTemp("prev_screen",
170 data.getScreen().replace('/', ','));
171 data.setScreen(conf.getString(
172 TurbineConstants.SCREEN_INVALID_STATE));
173 }
174 data.getUser().setTemp("prev_parameters", data.getParameters());
175 data.setAction("");
176 }
177 }
178
179
180
181 if (data.getTemplateInfo().getScreenTemplate() != null)
182 {
183 data.setScreen(null);
184 }
185
186
187 pipelineData.get(Turbine.class).put(User.class, data.getUser());
188 }
189 }