You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by th...@apache.org on 2012/01/04 16:23:33 UTC

svn commit: r1227187 - /cocoon/cocoon3/trunk/cocoon-shiro/src/main/java/org/apache/cocoon/sitemap/expression/ShiroInterpreter.java

Author: thorsten
Date: Wed Jan  4 15:23:33 2012
New Revision: 1227187

URL: http://svn.apache.org/viewvc?rev=1227187&view=rev
Log:
Extending shiro interpreter with more permision and role lookups. Patch provided by Ajay, thanks\!

Modified:
    cocoon/cocoon3/trunk/cocoon-shiro/src/main/java/org/apache/cocoon/sitemap/expression/ShiroInterpreter.java

Modified: cocoon/cocoon3/trunk/cocoon-shiro/src/main/java/org/apache/cocoon/sitemap/expression/ShiroInterpreter.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-shiro/src/main/java/org/apache/cocoon/sitemap/expression/ShiroInterpreter.java?rev=1227187&r1=1227186&r2=1227187&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-shiro/src/main/java/org/apache/cocoon/sitemap/expression/ShiroInterpreter.java (original)
+++ cocoon/cocoon3/trunk/cocoon-shiro/src/main/java/org/apache/cocoon/sitemap/expression/ShiroInterpreter.java Wed Jan  4 15:23:33 2012
@@ -19,24 +19,26 @@
 package org.apache.cocoon.sitemap.expression;
 
 import org.apache.cocoon.sitemap.objectmodel.ObjectModel;
+import org.apache.commons.lang3.StringUtils;
 import org.apache.shiro.SecurityUtils;
 import org.apache.shiro.subject.Subject;
 
 public class ShiroInterpreter implements LanguageInterpreter {
 
     public Object resolve(String expression, ObjectModel objectModel) {
-        Object o = null;
+        Object resolvedValue = null;
         Subject subject = SecurityUtils.getSubject();
+        String parameter = StringUtils.substringBetween(expression, "[", "]");
         if (expression.equals("authenticated")) {
-            o = subject.isAuthenticated();
+            resolvedValue = subject.isAuthenticated();
         } else if (expression.equals("principal")) {
-            Object principal = subject.getPrincipal();
-            if (null == principal) {
-                principal = new String("");
-            }
-            o = principal;
+            resolvedValue = subject.getPrincipal();
+        } else if (expression.startsWith("hasPermission")) {
+            resolvedValue = subject.isPermitted(parameter);
+        } else if (expression.startsWith("hasRole")) {
+            resolvedValue = subject.hasRole(parameter);
         }
-        return o != null ? o : new String("");
+        return resolvedValue != null ? resolvedValue : new String("");
     }
 
 }