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
24 import org.apache.commons.lang.StringUtils;
25
26 import org.apache.commons.logging.Log;
27 import org.apache.commons.logging.LogFactory;
28
29 import org.apache.turbine.Turbine;
30 import org.apache.turbine.TurbineConstants;
31
32 import org.apache.turbine.services.security.TurbineSecurity;
33
34 import org.apache.turbine.util.RunData;
35 import org.apache.turbine.util.TurbineException;
36
37 /***
38 * SessionValidator for use with the Template Service, the
39 * TemplateSessionValidator is virtually identical to the
40 * TemplateSecureValidator except that it does not transfer to the
41 * login page when it detects a null user (or a user not logged in).
42 *
43 * <p>The Template Service requires a different Session Validator
44 * because of the way it handles screens.
45 *
46 * <p>Note that you will need to set the template.login property to the
47 * login template.
48 *
49 * @see TemplateSecureSessionValidator
50 * @author <a href="mailto:john.mcnally@clearink.com">John D. McNally</a>
51 * @author <a href="mailto:mbryson@mont.mindspring.com">Dave Bryson</a>
52 * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
53 * @version $Id: TemplateSessionValidator.java 534527 2007-05-02 16:10:59Z tv $
54 */
55 public class TemplateSessionValidator
56 extends SessionValidator
57 {
58 /*** Logging */
59 private static Log log = LogFactory.getLog(TemplateSessionValidator.class);
60
61 /***
62 * Execute the action.
63 *
64 * @param data Turbine information.
65 * @exception TurbineException The anonymous user could not be obtained
66 * from the security service
67 */
68 public void doPerform(RunData data)
69 throws TurbineException
70 {
71 Configuration conf = Turbine.getConfiguration();
72
73
74 data.populate();
75
76
77 if (data.getUser() == null)
78 {
79 log.debug("Fixing up empty User Object!");
80 data.setUser(TurbineSecurity.getAnonymousUser());
81 data.save();
82 }
83
84
85 if (!data.hasScreen() && StringUtils.isEmpty(
86 data.getTemplateInfo().getScreenTemplate()))
87 {
88 String template = conf.getString(
89 TurbineConstants.TEMPLATE_HOMEPAGE);
90
91 if (StringUtils.isNotEmpty(template))
92 {
93 data.getTemplateInfo().setScreenTemplate(template);
94 }
95 else
96 {
97 data.setScreen(conf.getString(
98 TurbineConstants.SCREEN_HOMEPAGE));
99 }
100 }
101
102
103
104 else if (data.getParameters().containsKey("_session_access_counter")
105 && !TurbineSecurity.isAnonymousUser(data.getUser()))
106 {
107
108 if (data.getParameters().getInt("_session_access_counter")
109 < (((Integer) data.getUser().getTemp(
110 "_session_access_counter")).intValue() - 1))
111 {
112 if (data.getTemplateInfo().getScreenTemplate() != null)
113 {
114 data.getUser().setTemp("prev_template",
115 data.getTemplateInfo().getScreenTemplate()
116 .replace('/', ','));
117 data.getTemplateInfo().setScreenTemplate(conf.getString(
118 TurbineConstants.TEMPLATE_INVALID_STATE));
119 }
120 else
121 {
122 data.getUser().setTemp("prev_screen",
123 data.getScreen().replace('/', ','));
124 data.setScreen(conf.getString(
125 TurbineConstants.SCREEN_INVALID_STATE));
126 }
127 data.getUser().setTemp("prev_parameters", data.getParameters());
128 data.setAction("");
129 }
130 }
131
132
133
134 if (data.getTemplateInfo().getScreenTemplate() != null)
135 {
136 data.setScreen(null);
137 }
138 }
139 }