You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by an...@apache.org on 2005/08/25 16:27:47 UTC

svn commit: r240080 - in /lenya/trunk/src/java/org/apache/lenya: cms/workflow/DocumentWorkflowable.java cms/workflow/LenyaSituation.java cms/workflow/LenyaWorkflowManager.java cms/workflow/RoleCondition.java workflow/impl/WorkflowManagerImpl.java

Author: andreas
Date: Thu Aug 25 07:27:38 2005
New Revision: 240080

URL: http://svn.apache.org/viewcvs?rev=240080&view=rev
Log:
Workflow - RoleCondition uses PolicyManager to check actual policy of a document instead of request policy. This fixes bug #36358.

Modified:
    lenya/trunk/src/java/org/apache/lenya/cms/workflow/DocumentWorkflowable.java
    lenya/trunk/src/java/org/apache/lenya/cms/workflow/LenyaSituation.java
    lenya/trunk/src/java/org/apache/lenya/cms/workflow/LenyaWorkflowManager.java
    lenya/trunk/src/java/org/apache/lenya/cms/workflow/RoleCondition.java
    lenya/trunk/src/java/org/apache/lenya/workflow/impl/WorkflowManagerImpl.java

Modified: lenya/trunk/src/java/org/apache/lenya/cms/workflow/DocumentWorkflowable.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/workflow/DocumentWorkflowable.java?rev=240080&r1=240079&r2=240080&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/workflow/DocumentWorkflowable.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/workflow/DocumentWorkflowable.java Thu Aug 25 07:27:38 2005
@@ -53,6 +53,10 @@
     }
 
     private Document document;
+    
+    protected Document getDocument() {
+        return this.document;
+    }
 
     /**
      * @return The name of the workflow schema.

Modified: lenya/trunk/src/java/org/apache/lenya/cms/workflow/LenyaSituation.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/workflow/LenyaSituation.java?rev=240080&r1=240079&r2=240080&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/workflow/LenyaSituation.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/workflow/LenyaSituation.java Thu Aug 25 07:27:38 2005
@@ -19,12 +19,19 @@
 
 package org.apache.lenya.cms.workflow;
 
+import org.apache.avalon.framework.container.ContainerUtil;
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.avalon.framework.logger.Logger;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.lenya.ac.Identity;
 import org.apache.lenya.workflow.Situation;
 
+import sun.security.action.GetLongAction;
+
 /**
  * The CMS situation
  */
-public class LenyaSituation implements Situation {
+public class LenyaSituation extends AbstractLogEnabled implements Situation {
 
     /**
      * Returns the machine IP address.
@@ -42,43 +49,35 @@
         return this.userId;
     }
 
-	/**
-	 * Creates a new instance of Situation
-	 * @param _roleIds The role IDs.
-     * @param _userId The user ID.
-     * @param _machineIp The machine IP address.
-	 */
-    protected LenyaSituation(String[] _roleIds, String _userId, String _machineIp) {
-        this.roleIds = _roleIds;
-        this.userId = _userId;
-        this.machineIp = _machineIp;
+    /**
+     * Creates a new instance of Situation
+     * @param manager The service manager.
+     */
+    protected LenyaSituation(Identity identity, ServiceManager manager, Logger logger) {
+        this.manager = manager;
+        this.identity = identity;
+        ContainerUtil.enableLogging(this, logger);
     }
 
-    private String[] roleIds;
+    private Identity identity;
 
-    /**
-     * Get the roles
-     * @return the roles
-     */
-    public String[] getRoleIds() {
-        return this.roleIds;
+    private ServiceManager manager;
+
+    protected ServiceManager getServiceManager() {
+        return this.manager;
     }
 
-    /** 
+    /**
      * @see java.lang.Object#toString()
      */
     public String toString() {
-        String rolesString = "";
-        for (int i = 0; i < this.roleIds.length; i++) {
-            if (i > 0) {
-                rolesString += ", ";
-            }
-            rolesString += this.roleIds[i];
-        }
-        return "roles: " + rolesString;
+        return this.userId + " " + this.machineIp;
     }
-    
+
     private String userId;
     private String machineIp;
-    
+
+    public Identity getIdentity() {
+        return this.identity;
+    }
 }

Modified: lenya/trunk/src/java/org/apache/lenya/cms/workflow/LenyaWorkflowManager.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/workflow/LenyaWorkflowManager.java?rev=240080&r1=240079&r2=240080&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/workflow/LenyaWorkflowManager.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/workflow/LenyaWorkflowManager.java Thu Aug 25 07:27:38 2005
@@ -25,12 +25,9 @@
 import org.apache.cocoon.environment.ObjectModelHelper;
 import org.apache.cocoon.environment.Request;
 import org.apache.cocoon.environment.Session;
-import org.apache.lenya.ac.AccessControlException;
 import org.apache.lenya.ac.Identity;
 import org.apache.lenya.ac.Machine;
-import org.apache.lenya.ac.Role;
 import org.apache.lenya.ac.User;
-import org.apache.lenya.ac.impl.PolicyAuthorizer;
 import org.apache.lenya.workflow.Situation;
 import org.apache.lenya.workflow.impl.WorkflowManagerImpl;
 
@@ -64,20 +61,9 @@
                 machineIp = machine.getIp();
             }
 
-            Role[] roles;
-            try {
-                roles = PolicyAuthorizer.getRoles(request);
-            } catch (AccessControlException e) {
-                throw new RuntimeException(e);
-            }
-            String[] roleIds = new String[roles.length];
-            for (int i = 0; i < roles.length; i++) {
-                roleIds[i] = roles[i].getId();
-            }
-
-            situation = new LenyaSituation(roleIds, userId, machineIp);
+            situation = new LenyaSituation(identity, this.manager, getLogger());
         } else {
-            situation = new LenyaSituation(new String[0], null, null);
+            situation = new LenyaSituation(null, this.manager, getLogger());
         }
         return situation;
     }

Modified: lenya/trunk/src/java/org/apache/lenya/cms/workflow/RoleCondition.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/workflow/RoleCondition.java?rev=240080&r1=240079&r2=240080&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/workflow/RoleCondition.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/workflow/RoleCondition.java Thu Aug 25 07:27:38 2005
@@ -22,6 +22,14 @@
 import java.util.HashSet;
 import java.util.Set;
 
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.avalon.framework.service.ServiceSelector;
+import org.apache.lenya.ac.AccessController;
+import org.apache.lenya.ac.AccessControllerResolver;
+import org.apache.lenya.ac.Policy;
+import org.apache.lenya.ac.PolicyManager;
+import org.apache.lenya.ac.Role;
+import org.apache.lenya.ac.impl.DefaultAccessController;
 import org.apache.lenya.workflow.Situation;
 import org.apache.lenya.workflow.Workflow;
 import org.apache.lenya.workflow.WorkflowException;
@@ -32,17 +40,17 @@
  * Role condition
  */
 public class RoleCondition extends AbstractCondition {
-    
+
     private Set roleIds = new HashSet();
-    
+
     protected static final String SEPARATOR = ",";
-    
+
     /**
      * @see org.apache.lenya.workflow.Condition#setExpression(java.lang.String)
      */
     public void setExpression(String expression) throws WorkflowException {
         super.setExpression(expression);
-        
+
         String[] roles = expression.split(SEPARATOR);
         for (int i = 0; i < roles.length; i++) {
             this.roleIds.add(roles[i].trim());
@@ -50,24 +58,63 @@
     }
 
     /**
-     * Returns if the condition is complied in a certain situation.
-     * The condition is complied when the current user has the
-     * role that is required by the RoleCondition.
-     * @see org.apache.lenya.workflow.impl.AbstractCondition#isComplied(Workflow, Situation, Workflowable)
+     * Returns if the condition is complied in a certain situation. The condition is complied when
+     * the current user has the role that is required by the RoleCondition.
+     * @see org.apache.lenya.workflow.impl.AbstractCondition#isComplied(Workflow, Situation,
+     *      Workflowable)
      */
     public boolean isComplied(Workflow workflow, Situation situation, Workflowable instance) {
         LenyaSituation situationImpl = (LenyaSituation) situation;
-        String[] roles = situationImpl.getRoleIds();
 
-        boolean complied = false;
+        DocumentWorkflowable workflowable = (DocumentWorkflowable) instance;
+        LenyaSituation lenyaSituation = (LenyaSituation) situation;
+        ServiceManager manager = lenyaSituation.getServiceManager();
+        String url = workflowable.getDocument().getCanonicalWebappURL();
 
-        for (int i = 0; i < roles.length; i++) {
-            if (this.roleIds.contains(roles[i])) {
-                complied = true;
+        ServiceSelector selector = null;
+        AccessControllerResolver acResolver = null;
+        AccessController accessController = null;
+        try {
+
+            selector = (ServiceSelector) manager.lookup(AccessControllerResolver.ROLE + "Selector");
+            acResolver = (AccessControllerResolver) selector.select(AccessControllerResolver.DEFAULT_RESOLVER);
+            accessController = acResolver.resolveAccessController(url);
+
+            if (accessController instanceof DefaultAccessController) {
+                DefaultAccessController defaultAccessController = (DefaultAccessController) accessController;
+                PolicyManager policyManager = defaultAccessController.getPolicyManager();
+
+                Policy policy = policyManager.getPolicy(defaultAccessController.getAccreditableManager(),
+                        url);
+
+                Role[] roles = policy.getRoles(lenyaSituation.getIdentity());
+                boolean complied = false;
+
+                for (int i = 0; i < roles.length; i++) {
+                    if (this.roleIds.contains(roles[i].getId())) {
+                        complied = true;
+                    }
+                }
+
+                return complied;
+            } else {
+                throw new IllegalStateException("Only supported for default access controllers!");
+            }
+
+        } catch (final Exception e) {
+            throw new RuntimeException(e);
+        } finally {
+            if (selector != null) {
+                if (acResolver != null) {
+                    if (accessController != null) {
+                        acResolver.release(accessController);
+                    }
+                    selector.release(acResolver);
+                }
+                manager.release(selector);
             }
         }
 
-        return complied;
     }
 
 }

Modified: lenya/trunk/src/java/org/apache/lenya/workflow/impl/WorkflowManagerImpl.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/workflow/impl/WorkflowManagerImpl.java?rev=240080&r1=240079&r2=240080&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/workflow/impl/WorkflowManagerImpl.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/workflow/impl/WorkflowManagerImpl.java Thu Aug 25 07:27:38 2005
@@ -16,6 +16,7 @@
  */
 package org.apache.lenya.workflow.impl;
 
+import org.apache.avalon.excalibur.pool.Poolable;
 import org.apache.avalon.framework.logger.AbstractLogEnabled;
 import org.apache.avalon.framework.service.ServiceException;
 import org.apache.avalon.framework.service.ServiceManager;
@@ -35,7 +36,7 @@
  * @version $Id: WorkflowManagerImpl.java 179751 2005-06-03 09:13:35Z andreas $
  */
 public class WorkflowManagerImpl extends AbstractLogEnabled implements WorkflowManager,
-        Serviceable {
+        Serviceable, Poolable {
 
     /**
      * @see org.apache.lenya.workflow.WorkflowManager#invoke(org.apache.lenya.workflow.Workflowable,



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org