You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by he...@apache.org on 2003/02/28 14:38:38 UTC
cvs commit: jakarta-turbine-2/src/java/org/apache/turbine/modules/actions/sessionvalidator DefaultSessionValidator.java TemplateSecureSessionValidator.java TemplateSessionValidator.java
henning 2003/02/28 05:38:38
Modified: src/java/org/apache/turbine/modules/actions/sessionvalidator
DefaultSessionValidator.java
TemplateSecureSessionValidator.java
TemplateSessionValidator.java
Log:
Removed TurbineResources from the Session Validators. Cleaned up the
Code so that TurbineSecurity is used to pull the anonymous user
object.
Revision Changes Path
1.8 +20 -14 jakarta-turbine-2/src/java/org/apache/turbine/modules/actions/sessionvalidator/DefaultSessionValidator.java
Index: DefaultSessionValidator.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/modules/actions/sessionvalidator/DefaultSessionValidator.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- DefaultSessionValidator.java 12 Feb 2003 17:52:17 -0000 1.7
+++ DefaultSessionValidator.java 28 Feb 2003 13:38:38 -0000 1.8
@@ -54,8 +54,11 @@
* <http://www.apache.org/>.
*/
+import org.apache.commons.configuration.Configuration;
+
+import org.apache.turbine.Turbine;
import org.apache.turbine.TurbineConstants;
-import org.apache.turbine.services.resources.TurbineResources;
+
import org.apache.turbine.util.RunData;
/**
@@ -79,9 +82,11 @@
* Turbine servlet.
*
* @author <a href="mailto:mbryson@mont.mindspring.com">Dave Bryson</a>
+ * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
* @version $Id$
*/
-public class DefaultSessionValidator extends SessionValidator
+public class DefaultSessionValidator
+ extends SessionValidator
{
/**
* Execute the action. The default is to populate the RunData
@@ -92,8 +97,10 @@
* @param data Turbine RunData context information.
* @exception Exception, a generic exception.
*/
- public void doPerform(RunData data) throws Exception
+ public void doPerform(RunData data)
+ throws Exception
{
+ Configuration conf = Turbine.getConfiguration();
/*
* Pull user from session.
*/
@@ -106,21 +113,21 @@
// only set the message if nothing else has already set it
// (e.g. the LogoutUser action)
if (data.getMessage() == null)
- data.setMessage(TurbineResources.getString(
- TurbineConstants.LOGIN_MESSAGE));
+ {
+ data.setMessage(conf.getString(TurbineConstants.LOGIN_MESSAGE));
+ }
+
// set the screen to be the login page
- data.setScreen(TurbineResources.getString(
- TurbineConstants.SCREEN_LOGIN));
+ data.setScreen(conf.getString(TurbineConstants.SCREEN_LOGIN));
+
// we're not doing any actions buddy! (except action.login which
// will have been performed already)
data.setAction(null);
}
else if (!data.hasScreen())
{
- data.setMessage(TurbineResources.getString(
- TurbineConstants.LOGIN_MESSAGE_NOSCREEN));
- data.setScreen(TurbineResources.getString(
- TurbineConstants.SCREEN_HOMEPAGE));
+ data.setMessage(conf.getString(TurbineConstants.LOGIN_MESSAGE_NOSCREEN));
+ data.setScreen(conf.getString(TurbineConstants.SCREEN_HOMEPAGE));
}
else if (data.getParameters().containsKey("_session_access_counter"))
{
@@ -131,8 +138,7 @@
{
data.getUser().setTemp("prev_screen", data.getScreen());
data.getUser().setTemp("prev_parameters", data.getParameters());
- data.setScreen(TurbineResources.getString(
- TurbineConstants.SCREEN_INVALID_STATE));
+ data.setScreen(conf.getString(TurbineConstants.SCREEN_INVALID_STATE));
data.setAction("");
}
}
1.7 +53 -28 jakarta-turbine-2/src/java/org/apache/turbine/modules/actions/sessionvalidator/TemplateSecureSessionValidator.java
Index: TemplateSecureSessionValidator.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/modules/actions/sessionvalidator/TemplateSecureSessionValidator.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- TemplateSecureSessionValidator.java 12 Feb 2003 17:52:17 -0000 1.6
+++ TemplateSecureSessionValidator.java 28 Feb 2003 13:38:38 -0000 1.7
@@ -54,8 +54,18 @@
* <http://www.apache.org/>.
*/
+import org.apache.commons.configuration.Configuration;
+
+import org.apache.commons.lang.StringUtils;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import org.apache.turbine.Turbine;
import org.apache.turbine.TurbineConstants;
-import org.apache.turbine.services.resources.TurbineResources;
+
+import org.apache.turbine.services.security.TurbineSecurity;
+
import org.apache.turbine.util.RunData;
/**
@@ -81,8 +91,12 @@
* @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
* @version $Id$
*/
-public class TemplateSecureSessionValidator extends SessionValidator
+public class TemplateSecureSessionValidator
+ extends SessionValidator
{
+ /** Logging */
+ private static Log log = LogFactory.getLog(TemplateSecureSessionValidator.class);
+
/**
* doPerform is virtually identical to DefaultSessionValidator
* except that it calls template methods instead of bare screen
@@ -93,33 +107,49 @@
* @see DefaultSessionValidator * @param data Turbine information.
* @exception Exception, a generic exception.
*/
- public void doPerform(RunData data) throws Exception
+ public void doPerform(RunData data)
+ throws Exception
{
+ 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() == null) || (!data.getUser().hasLoggedIn()))
+ 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 (data.getMessage() == null)
+ if (StringUtils.isEmpty(data.getMessage()))
{
- data.setMessage(TurbineResources.getString(
- TurbineConstants.LOGIN_MESSAGE));
+ data.setMessage(conf.getString(TurbineConstants.LOGIN_MESSAGE));
}
/*
* Set the screen template to the login page.
*/
- data.getTemplateInfo().setScreenTemplate(
- TurbineResources.getString(TurbineConstants.TEMPLATE_LOGIN));
+
+ 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
@@ -128,23 +158,21 @@
data.setAction(null);
}
- /*
- * Make sure we have some way to return a response.
- */
+ log.debug("Login Check finished!");
+
+ //Make sure we have some way to return a response.
if (!data.hasScreen() &&
- data.getTemplateInfo().getScreenTemplate() == null)
+ StringUtils.isEmpty(data.getTemplateInfo().getScreenTemplate()))
{
- String template = TurbineResources.getString(
- TurbineConstants.TEMPLATE_HOMEPAGE);
+ String template = conf.getString(TurbineConstants.TEMPLATE_HOMEPAGE);
- if (template != null)
+ if (StringUtils.isNotEmpty(template))
{
data.getTemplateInfo().setScreenTemplate(template);
}
else
{
- data.setScreen(TurbineResources.getString(
- TurbineConstants.SCREEN_HOMEPAGE));
+ data.setScreen(conf.getString(TurbineConstants.SCREEN_HOMEPAGE));
}
}
@@ -166,20 +194,17 @@
if (data.getTemplateInfo().getScreenTemplate() != null)
{
data.getUser().setTemp("prev_template",
- data.getTemplateInfo().getScreenTemplate());
- data.getTemplateInfo().setScreenTemplate(
- TurbineResources.getString(
- TurbineConstants.TEMPLATE_INVALID_STATE));
+ data.getTemplateInfo().getScreenTemplate()
+ .replace('/', ','));
+ data.getTemplateInfo().setScreenTemplate(conf.getString(TurbineConstants.TEMPLATE_INVALID_STATE));
}
else
{
data.getUser().setTemp("prev_screen",
- data.getScreen().replace('/', ','));
- data.setScreen(TurbineResources.getString(
- TurbineConstants.SCREEN_INVALID_STATE));
+ data.getScreen().replace('/', ','));
+ data.setScreen(conf.getString(TurbineConstants.SCREEN_INVALID_STATE));
}
- data.getUser()
- .setTemp("prev_parameters", data.getParameters());
+ data.getUser().setTemp("prev_parameters", data.getParameters());
data.setAction("");
}
}
1.7 +31 -19 jakarta-turbine-2/src/java/org/apache/turbine/modules/actions/sessionvalidator/TemplateSessionValidator.java
Index: TemplateSessionValidator.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/modules/actions/sessionvalidator/TemplateSessionValidator.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- TemplateSessionValidator.java 12 Feb 2003 17:52:17 -0000 1.6
+++ TemplateSessionValidator.java 28 Feb 2003 13:38:38 -0000 1.7
@@ -54,9 +54,18 @@
* <http://www.apache.org/>.
*/
+import org.apache.commons.configuration.Configuration;
+
+import org.apache.commons.lang.StringUtils;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import org.apache.turbine.Turbine;
import org.apache.turbine.TurbineConstants;
-import org.apache.turbine.services.resources.TurbineResources;
+
import org.apache.turbine.services.security.TurbineSecurity;
+
import org.apache.turbine.util.RunData;
/**
@@ -77,43 +86,49 @@
* @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
* @version $Id$
*/
-public class TemplateSessionValidator extends SessionValidator
+public class TemplateSessionValidator
+ extends SessionValidator
{
+ /** Logging */
+ private static Log log = LogFactory.getLog(TemplateSessionValidator.class);
+
/**
* Execute the action.
*
* @param data Turbine information.
* @exception Exception, a generic exception.
*/
- public void doPerform(RunData data) throws Exception
+ public void doPerform(RunData data)
+ throws Exception
{
+ Configuration conf = Turbine.getConfiguration();
+
/*
* Pull user from session.
*/
data.populate();
- // The user may have not logged in, so create a "guest" user.
+ // 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();
}
// make sure we have some way to return a response
if (!data.hasScreen() &&
- data.getTemplateInfo().getScreenTemplate() == null)
+ StringUtils.isEmpty(data.getTemplateInfo().getScreenTemplate()))
{
- String template = TurbineResources.getString(
- TurbineConstants.TEMPLATE_HOMEPAGE);
+ String template = conf.getString(TurbineConstants.TEMPLATE_HOMEPAGE);
- if (template != null)
+ if (StringUtils.isNotEmpty(template))
{
data.getTemplateInfo().setScreenTemplate(template);
}
else
{
- data.setScreen(TurbineResources.getString(
- TurbineConstants.SCREEN_HOMEPAGE));
+ data.setScreen(conf.getString(TurbineConstants.SCREEN_HOMEPAGE));
}
}
// the session_access_counter can be placed as a hidden field in
@@ -129,18 +144,15 @@
if (data.getTemplateInfo().getScreenTemplate() != null)
{
data.getUser().setTemp("prev_template",
- data.getTemplateInfo().getScreenTemplate()
- .replace('/', ','));
- data.getTemplateInfo().setScreenTemplate(
- TurbineResources.getString(
- TurbineConstants.TEMPLATE_INVALID_STATE));
+ data.getTemplateInfo().getScreenTemplate()
+ .replace('/', ','));
+ data.getTemplateInfo().setScreenTemplate(conf.getString(TurbineConstants.TEMPLATE_INVALID_STATE));
}
else
{
data.getUser().setTemp("prev_screen",
- data.getScreen().replace('/', ','));
- data.setScreen(TurbineResources.getString(
- TurbineConstants.SCREEN_INVALID_STATE));
+ data.getScreen().replace('/', ','));
+ data.setScreen(conf.getString(TurbineConstants.SCREEN_INVALID_STATE));
}
data.getUser().setTemp("prev_parameters", data.getParameters());
data.setAction("");
---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org