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 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 /***
35 * SessionValidator for use with the Template Service, the
36 * TemplateSessionValidator is virtually identical to the
37 * TemplateSecureValidator except that it does not transfer to the
38 * login page when it detects a null user (or a user not logged in).
39 *
40 * <p>The Template Service requires a different Session Validator
41 * because of the way it handles screens.
42 *
43 * <p>Note that you will need to set the template.login property to the
44 * login template.
45 *
46 * @see TemplateSecureSessionValidator
47 * @author <a href="mailto:john.mcnally@clearink.com">John D. McNally</a>
48 * @author <a href="mailto:mbryson@mont.mindspring.com">Dave Bryson</a>
49 * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
50 * @version $Id: TemplateSessionValidator.java 264148 2005-08-29 14:21:04Z henning $
51 */
52 public class TemplateSessionValidator
53 extends SessionValidator
54 {
55 /*** Logging */
56 private static Log log = LogFactory.getLog(TemplateSessionValidator.class);
57
58 /***
59 * Execute the action.
60 *
61 * @param data Turbine information.
62 * @exception TurbineException The anonymous user could not be obtained
63 * from the security service
64 */
65 public void doPerform(RunData data)
66 throws TurbineException
67 {
68 Configuration conf = Turbine.getConfiguration();
69
70
71 data.populate();
72
73
74 if (data.getUser() == null)
75 {
76 log.debug("Fixing up empty User Object!");
77 data.setUser(TurbineSecurity.getAnonymousUser());
78 data.save();
79 }
80
81
82 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
99
100
101 else if (data.getParameters().containsKey("_session_access_counter")
102 && !TurbineSecurity.isAnonymousUser(data.getUser()))
103 {
104
105 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
130
131 if (data.getTemplateInfo().getScreenTemplate() != null)
132 {
133 data.setScreen(null);
134 }
135 }
136 }