* from the security service
*/
public void doPerform(RunData data)
throws TurbineException
{
Configuration conf = Turbine.getConfiguration();
// Pull user from session.
data.populate();
// The user may have not logged in, so create a "guest/anonymous" user.
if (data.getUser() == null)
{
log.debug("Fixing up empty User Object!");
data.setUser(TurbineSecurity.getAnonymousUser());
data.save();
}
// This is the secure sessionvalidator, so user must be logged in.
if (!data.getUser().hasLoggedIn())
{
log.debug("User is not logged in!");
// only set the message if nothing else has already set it
// (e.g. the LogoutUser action).
if (StringUtils.isEmpty(data.getMessage()))
{
data.setMessage(conf.getString(TurbineConstants.LOGIN_MESSAGE));
}
// Set the screen template to the login page.
String loginTemplate =
conf.getString(TurbineConstants.TEMPLATE_LOGIN);
log.debug("Sending User to the Login Screen ("
+ loginTemplate + ")");
data.getTemplateInfo().setScreenTemplate(loginTemplate);
// We're not doing any actions buddy! (except action.login which
// will have been performed already)
data.setAction(null);
}
log.debug("Login Check finished!");
// Make sure we have some way to return a response.
if (!data.hasScreen() && StringUtils.isEmpty(
data.getTemplateInfo().getScreenTemplate()))
{
String template = conf.getString(
TurbineConstants.TEMPLATE_HOMEPAGE);
if (StringUtils.isNotEmpty(template))
{
data.getTemplateInfo().setScreenTemplate(template);
}
else
{
data.setScreen(conf.getString(
TurbineConstants.SCREEN_HOMEPAGE));
}
}
// The session_access_counter can be placed as a hidden field in
// forms. This can be used to prevent a user from using the
// browsers back button and submitting stale data.
// FIXME!! a template needs to be written to use this with templates.
if (data.getParameters().containsKey("_session_access_counter")
&& !TurbineSecurity.isAnonymousUser(data.getUser()))
{
// See comments in screens.error.InvalidState.
if (data.getParameters().getInt("_session_access_counter")
< (((Integer) data.getUser().getTemp(
"_session_access_counter")).intValue() - 1))
{
if (data.getTemplateInfo().getScreenTemplate() != null)
{
data.getUser().setTemp("prev_template",
data.getTemplateInfo().getScreenTemplate()
.replace('/', ','));
data.getTemplateInfo().setScreenTemplate(conf.getString(
TurbineConstants.TEMPLATE_INVALID_STATE));
}
else
{
data.getUser().setTemp("prev_screen",
data.getScreen().replace('/', ','));
data.setScreen(conf.getString(
TurbineConstants.SCREEN_INVALID_STATE));
}
data.getUser().setTemp("prev_parameters", data.getParameters());
data.setAction("");
}