You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by tr...@apache.org on 2009/09/03 15:51:33 UTC

svn commit: r810940 - /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/authorization/UnmodifiableAccessControlList.java

Author: tripod
Date: Thu Sep  3 13:51:32 2009
New Revision: 810940

URL: http://svn.apache.org/viewvc?rev=810940&view=rev
Log:
Extend from JackrabbitAccessControlList

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/authorization/UnmodifiableAccessControlList.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/authorization/UnmodifiableAccessControlList.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/authorization/UnmodifiableAccessControlList.java?rev=810940&r1=810939&r2=810940&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/authorization/UnmodifiableAccessControlList.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/authorization/UnmodifiableAccessControlList.java Thu Sep  3 13:51:32 2009
@@ -22,8 +22,16 @@
 import javax.jcr.security.Privilege;
 
 import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+import javax.jcr.PropertyType;
+
 import java.security.Principal;
 import java.util.List;
+import java.util.Map;
+import java.util.Collections;
+import java.util.HashMap;
+
+import org.apache.jackrabbit.api.security.JackrabbitAccessControlList;
 
 /**
  * An implementation of the <code>AccessControlList</code> interface that only
@@ -32,10 +40,14 @@
  * and {@link #removeAccessControlEntry(AccessControlEntry) removeAccessControlEntry})
  * throw an <code>AccessControlException</code>.
  */
-public class UnmodifiableAccessControlList implements AccessControlList {
+public class UnmodifiableAccessControlList implements JackrabbitAccessControlList {
 
     private final AccessControlEntry[] accessControlEntries;
 
+    private final Map<String, Integer> restrictions;
+
+    private final String path;
+
     /**
      * Construct a new <code>UnmodifiableAccessControlList</code>
      *
@@ -45,7 +57,20 @@
      * specified <code>AccessControlList</code>.
      */
     public UnmodifiableAccessControlList(AccessControlList acl) throws RepositoryException {
-        accessControlEntries = acl.getAccessControlEntries();
+        if (acl instanceof JackrabbitAccessControlList) {
+            JackrabbitAccessControlList jAcl = (JackrabbitAccessControlList) acl;
+            accessControlEntries = acl.getAccessControlEntries();
+            path = jAcl.getPath();
+            Map<String, Integer> r = new HashMap<String, Integer>();
+            for (String name: jAcl.getRestrictionNames()) {
+                r.put(name, jAcl.getRestrictionType(name));
+            }
+            restrictions = Collections.unmodifiableMap(r);
+        } else {
+            accessControlEntries = acl.getAccessControlEntries();
+            path = null;
+            restrictions = Collections.emptyMap();
+        }
     }
 
     /**
@@ -55,6 +80,8 @@
      */
     public UnmodifiableAccessControlList(List<AccessControlEntry> accessControlEntries) {
         this.accessControlEntries = accessControlEntries.toArray(new AccessControlEntry[accessControlEntries.size()]);
+        path = null;
+        restrictions = Collections.emptyMap();
     }
 
     //--------------------------------------------------< AccessControlList >---
@@ -82,4 +109,36 @@
             throws AccessControlException, RepositoryException {
         throw new AccessControlException("Unmodifiable ACL. Use AccessControlManager#getApplicablePolicies in order to obtain an modifiable ACL.");
     }
+
+    public String[] getRestrictionNames() {
+        return restrictions.keySet().toArray(new String[restrictions.size()]);
+    }
+
+    public int getRestrictionType(String restrictionName) {
+        if (restrictions.containsKey(restrictionName)) {
+            return restrictions.get(restrictionName);
+        } else {
+            return PropertyType.UNDEFINED;
+        }
+    }
+
+    public boolean isEmpty() {
+        return accessControlEntries.length == 0;
+    }
+
+    public int size() {
+        return accessControlEntries.length;
+    }
+
+    public boolean addEntry(Principal principal, Privilege[] privileges, boolean isAllow) throws AccessControlException, RepositoryException {
+        throw new AccessControlException("Unmodifiable ACL. Use AccessControlManager#getApplicablePolicies in order to obtain an modifiable ACL.");
+    }
+
+    public boolean addEntry(Principal principal, Privilege[] privileges, boolean isAllow, Map<String, Value> restrictions) throws AccessControlException, RepositoryException {
+        throw new AccessControlException("Unmodifiable ACL. Use AccessControlManager#getApplicablePolicies in order to obtain an modifiable ACL.");
+    }
+
+    public String getPath() {
+        return path;
+    }
 }
\ No newline at end of file