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 17:36:49 UTC
cvs commit: jakarta-turbine-2/src/java/org/apache/turbine/util/template TemplateSecurityCheck.java
henning 2003/02/28 08:36:49
Modified: src/java/org/apache/turbine/util/template
TemplateSecurityCheck.java
Log:
- Removed TurbineResources
- reworked has<xxx> routines to have similar code pathes
- changed checkLogin() to use the Security Service
Revision Changes Path
1.4 +29 -21 jakarta-turbine-2/src/java/org/apache/turbine/util/template/TemplateSecurityCheck.java
Index: TemplateSecurityCheck.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/util/template/TemplateSecurityCheck.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- TemplateSecurityCheck.java 12 Feb 2003 17:24:31 -0000 1.3
+++ TemplateSecurityCheck.java 28 Feb 2003 16:36:47 -0000 1.4
@@ -54,10 +54,16 @@
* <http://www.apache.org/>.
*/
+import org.apache.turbine.Turbine;
+import org.apache.turbine.TurbineConstants;
+
import org.apache.turbine.om.security.Permission;
import org.apache.turbine.om.security.Role;
-import org.apache.turbine.services.resources.TurbineResources;
+
+import org.apache.turbine.services.security.TurbineSecurity;
+
import org.apache.turbine.services.template.TurbineTemplate;
+
import org.apache.turbine.util.RunData;
/**
@@ -74,6 +80,7 @@
* </code>
*
* @author <a href="mbryson@mont.mindspring.com">Dave Bryson</a>
+ * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
* @version $Id$
*/
public class TemplateSecurityCheck
@@ -114,7 +121,8 @@
* @return Whether the user has the role.
* @exception Exception Trouble validating.
*/
- public boolean hasRole(Role role) throws Exception
+ public boolean hasRole(Role role)
+ throws Exception
{
if (!checkLogin())
{
@@ -128,10 +136,8 @@
data.setMessage(getMessage());
return false;
}
- else
- {
- return true;
- }
+
+ return true;
}
/**
@@ -141,19 +147,19 @@
* @return Whether the user has the permission.
* @exception Exception Trouble validating.
*/
- public boolean hasPermission(Permission permission) throws Exception
+ public boolean hasPermission(Permission permission)
+ throws Exception
{
+ boolean value = true;
if (data.getACL() == null || !data.getACL().hasPermission(permission))
{
data.setScreen(getFailScreen());
data.getTemplateInfo().setScreenTemplate(getFailTemplate());
data.setMessage(getMessage());
- return false;
- }
- else
- {
- return true;
+ value = false;
}
+
+ return value;
}
/**
@@ -162,20 +168,22 @@
* @return True if user has logged in.
* @exception Exception, a generic exception.
*/
- public boolean checkLogin() throws Exception
+ public boolean checkLogin()
+ throws Exception
{
- boolean value = false;
+ boolean value = true;
- if (data.getUser() != null && !data.getUser().hasLoggedIn())
+ // Do it like the AccessController
+ if (!TurbineSecurity.isAnonymousUser(data.getUser())
+ && !data.getUser().hasLoggedIn())
{
- data.setMessage(TurbineResources.getString("login.message"));
+ data.setMessage(Turbine.getConfiguration()
+ .getString(TurbineConstants.LOGIN_MESSAGE));
+
data.getTemplateInfo().setScreenTemplate(getFailTemplate());
value = false;
}
- else
- {
- value = true;
- }
+
return value;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org