You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by ja...@apache.org on 2009/04/30 00:10:42 UTC

svn commit: r769965 - in /ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method: MethodContext.java conditional/HasPermissionCondition.java ifops/CheckPermission.java ifops/IfHasPermission.java

Author: jaz
Date: Wed Apr 29 22:10:42 2009
New Revision: 769965

URL: http://svn.apache.org/viewvc?rev=769965&view=rev
Log:
Integration with new Authz API - JIRA OFBIZ-2381

Note: implemented the same as widgets use of action="" uses old api, without action="" uses new api

Modified:
    ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/MethodContext.java
    ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/HasPermissionCondition.java
    ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/ifops/CheckPermission.java
    ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/ifops/IfHasPermission.java

Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/MethodContext.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/MethodContext.java?rev=769965&r1=769964&r2=769965&view=diff
==============================================================================
--- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/MethodContext.java (original)
+++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/MethodContext.java Wed Apr 29 22:10:42 2009
@@ -21,7 +21,6 @@
 import java.util.Iterator;
 import java.util.Locale;
 import java.util.Map;
-import java.util.Map;
 import java.util.TimeZone;
 
 import javax.servlet.http.HttpServletRequest;
@@ -37,6 +36,7 @@
 import org.ofbiz.entity.GenericValue;
 import org.ofbiz.minilang.SimpleMethod;
 import org.ofbiz.security.Security;
+import org.ofbiz.security.authz.Authorization;
 import org.ofbiz.service.DispatchContext;
 import org.ofbiz.service.LocalDispatcher;
 
@@ -57,6 +57,7 @@
     protected ClassLoader loader;
     protected LocalDispatcher dispatcher;
     protected GenericDelegator delegator;
+    protected Authorization authz;
     protected Security security;
     protected GenericValue userLogin;
 
@@ -76,6 +77,7 @@
         this.timeZone = UtilHttp.getTimeZone(request);
         this.dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");
         this.delegator = (GenericDelegator) request.getAttribute("delegator");
+        this.authz = (Authorization) request.getAttribute("authz");
         this.security = (Security) request.getAttribute("security");
         this.userLogin = (GenericValue) request.getSession().getAttribute("userLogin");
 
@@ -96,6 +98,7 @@
         this.timeZone = (TimeZone) context.get("timeZone");
         this.dispatcher = ctx.getDispatcher();
         this.delegator = ctx.getDelegator();
+        this.authz = ctx.getAuthorization();
         this.security = ctx.getSecurity();
         this.results = FastMap.newInstance();
         this.userLogin = (GenericValue) context.get("userLogin");
@@ -111,7 +114,7 @@
 
     /**
      * This is a very simple constructor which assumes the needed objects (dispatcher,
-     * delegator, security, request, response, etc) are in the context.
+     * delegator, authz, security, request, response, etc) are in the context.
      * Will result in calling method as a service or event, as specified.
      */
     public MethodContext(Map<String, ? extends Object> context, ClassLoader loader, int methodType) {
@@ -122,6 +125,7 @@
         this.timeZone = (TimeZone) context.get("timeZone");
         this.dispatcher = (LocalDispatcher) context.get("dispatcher");
         this.delegator = (GenericDelegator) context.get("delegator");
+        this.authz = (Authorization) context.get("authz");
         this.security = (Security) context.get("security");
         this.userLogin = (GenericValue) context.get("userLogin");
 
@@ -137,6 +141,7 @@
             if (this.request != null) {
                 if (this.dispatcher == null) this.dispatcher = (LocalDispatcher) this.request.getAttribute("dispatcher");
                 if (this.delegator == null) this.delegator = (GenericDelegator) this.request.getAttribute("delegator");
+                if (this.authz == null) this.authz = (Authorization) this.request.getAttribute("authz");
                 if (this.security == null) this.security = (Security) this.request.getAttribute("security");
                 if (this.userLogin == null) this.userLogin = (GenericValue) this.request.getSession().getAttribute("userLogin");
             }
@@ -272,6 +277,10 @@
         return this.delegator;
     }
 
+    public Authorization getAuthz() {
+        return this.authz;
+    }
+    
     public Security getSecurity() {
         return this.security;
     }

Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/HasPermissionCondition.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/HasPermissionCondition.java?rev=769965&r1=769964&r2=769965&view=diff
==============================================================================
--- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/HasPermissionCondition.java (original)
+++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/HasPermissionCondition.java Wed Apr 29 22:10:42 2009
@@ -23,6 +23,7 @@
 import org.ofbiz.minilang.SimpleMethod;
 import org.ofbiz.minilang.method.MethodContext;
 import org.ofbiz.security.Security;
+import org.ofbiz.security.authz.Authorization;
 import org.w3c.dom.Element;
 
 /**
@@ -62,6 +63,7 @@
             String permission = methodContext.expandString(this.permission);
             String action = methodContext.expandString(this.action);
 
+            Authorization authz = methodContext.getAuthz();
             Security security = methodContext.getSecurity();
             if (action != null && action.length() > 0) {
                 // run hasEntityPermission
@@ -70,7 +72,7 @@
                 }
             } else {
                 // run hasPermission
-                if (security.hasPermission(permission, userLogin)) {
+                if (authz.hasPermission(userLogin.getString("userLoginId"), permission, methodContext.getEnvMap(), true)) {                
                     runSubOps = true;
                 }
             }

Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/ifops/CheckPermission.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/ifops/CheckPermission.java?rev=769965&r1=769964&r2=769965&view=diff
==============================================================================
--- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/ifops/CheckPermission.java (original)
+++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/ifops/CheckPermission.java Wed Apr 29 22:10:42 2009
@@ -18,7 +18,6 @@
  *******************************************************************************/
 package org.ofbiz.minilang.method.ifops;
 
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
@@ -33,10 +32,11 @@
 import org.ofbiz.minilang.method.MethodContext;
 import org.ofbiz.minilang.method.MethodOperation;
 import org.ofbiz.security.Security;
+import org.ofbiz.security.authz.Authorization;
 import org.w3c.dom.Element;
 
 /**
- * Iff the user does not have the specified permission the fail-message
+ * If the user does not have the specified permission the fail-message
  * or fail-property sub-elements are used to add a message to the error-list.
  */
 public class CheckPermission extends MethodOperation {
@@ -103,15 +103,16 @@
         // if no user is logged in, treat as if the user does not have permission: do not run subops
         GenericValue userLogin = methodContext.getUserLogin();
         if (userLogin != null) {
+            Authorization authz = methodContext.getAuthz();            
             Security security = methodContext.getSecurity();
-            if (this.permissionInfo.hasPermission(methodContext, userLogin, security)) {
+            if (this.permissionInfo.hasPermission(methodContext, userLogin, authz, security)) {
                 hasPermission = true;
             }
 
             // if failed, check alternate permissions
             if (!hasPermission && altPermissions != null) {
                 for (PermissionInfo altPermInfo: altPermissions) {
-                    if (altPermInfo.hasPermission(methodContext, userLogin, security)) {
+                    if (altPermInfo.hasPermission(methodContext, userLogin, authz, security)) {
                         hasPermission = true;
                         break;
                     }
@@ -172,7 +173,7 @@
             this.action = altPermissionElement.getAttribute("action");
         }
 
-        public boolean hasPermission(MethodContext methodContext, GenericValue userLogin, Security security) {
+        public boolean hasPermission(MethodContext methodContext, GenericValue userLogin, Authorization authz, Security security) {
             String permission = methodContext.expandString(this.permission);
             String action = methodContext.expandString(this.action);
 
@@ -181,7 +182,7 @@
                 return security.hasEntityPermission(permission, action, userLogin);
             } else {
                 // run hasPermission
-                return security.hasPermission(permission, userLogin);
+                return authz.hasPermission(userLogin.getString("userLoginId"), permission, methodContext.getEnvMap(), true);                
             }
         }
     }

Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/ifops/IfHasPermission.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/ifops/IfHasPermission.java?rev=769965&r1=769964&r2=769965&view=diff
==============================================================================
--- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/ifops/IfHasPermission.java (original)
+++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/ifops/IfHasPermission.java Wed Apr 29 22:10:42 2009
@@ -29,6 +29,7 @@
 import org.ofbiz.minilang.method.MethodContext;
 import org.ofbiz.minilang.method.MethodOperation;
 import org.ofbiz.security.Security;
+import org.ofbiz.security.authz.Authorization;
 import org.w3c.dom.Element;
 
 /**
@@ -80,6 +81,7 @@
             String permission = methodContext.expandString(permissionExdr);
             String action = methodContext.expandString(actionExdr);
 
+            Authorization authz = methodContext.getAuthz();
             Security security = methodContext.getSecurity();
             if (action != null && action.length() > 0) {
                 // run hasEntityPermission
@@ -88,7 +90,7 @@
                 }
             } else {
                 // run hasPermission
-                if (security.hasPermission(permission, userLogin)) {
+                if (authz.hasPermission(userLogin.getString("userLoginId"), permission, methodContext.getEnvMap(), true)) {                
                     runSubOps = true;
                 }
             }