jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r1528929 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/permission: CompiledPermissionImpl.java PermissionStore.java
Date Thu, 03 Oct 2013 16:46:18 GMT
Author: angela
Date: Thu Oct  3 16:46:18 2013
New Revision: 1528929

URL: http://svn.apache.org/r1528929
Log:
OAK-527: minor improvement (cleanup, indention, formatting)

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/permission/CompiledPermissionImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/permission/PermissionStore.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/permission/CompiledPermissionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/permission/CompiledPermissionImpl.java?rev=1528929&r1=1528928&r2=1528929&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/permission/CompiledPermissionImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/permission/CompiledPermissionImpl.java
Thu Oct  3 16:46:18 2013
@@ -48,7 +48,6 @@ import static com.google.common.base.Pre
 class CompiledPermissionImpl implements CompiledPermissions, PermissionConstants {
 
     private final Set<Principal> principals;
-    private final RestrictionProvider restrictionProvider;
 
     private final Map<String, Tree> userTrees;
     private final Map<String, Tree> groupTrees;
@@ -67,13 +66,12 @@ class CompiledPermissionImpl implements 
                            @Nonnull Set<String> readPaths) {
         checkArgument(!principals.isEmpty());
         this.principals = principals;
-        this.restrictionProvider = restrictionProvider;
         this.bitsProvider = bitsProvider;
         readPathsCheckList = new String[readPaths.size() * 2];
-        int i=0;
-        for (String p: readPaths) {
+        int i = 0;
+        for (String p : readPaths) {
             readPathsCheckList[i++] = p;
-            readPathsCheckList[i++] = p + "/";
+            readPathsCheckList[i++] = p + '/';
         }
 
         userTrees = new HashMap<String, Tree>(principals.size());
@@ -97,7 +95,7 @@ class CompiledPermissionImpl implements 
     //------------------------------------------------< CompiledPermissions >---
     @Override
     public void refresh(@Nonnull ImmutableTree permissionsTree,
-                 @Nonnull PrivilegeBitsProvider bitsProvider) {
+                        @Nonnull PrivilegeBitsProvider bitsProvider) {
         this.bitsProvider = bitsProvider;
         // test if a permission has been added for those principals that didn't have one
before
         for (Principal principal : principals) {
@@ -183,8 +181,8 @@ class CompiledPermissionImpl implements 
 
         boolean respectParent = (tree != null || path != null) &&
                 (Permissions.includes(permissions, Permissions.ADD_NODE) ||
-                Permissions.includes(permissions, Permissions.REMOVE_NODE) ||
-                Permissions.includes(permissions, Permissions.MODIFY_CHILD_NODE_COLLECTION));
+                        Permissions.includes(permissions, Permissions.REMOVE_NODE) ||
+                        Permissions.includes(permissions, Permissions.MODIFY_CHILD_NODE_COLLECTION));
 
         long allows = (isReadable) ? Permissions.READ : Permissions.NO_PERMISSION;
         long denies = Permissions.NO_PERMISSION;
@@ -278,7 +276,7 @@ class CompiledPermissionImpl implements 
         if (readPathsCheckList.length > 0) {
             String targetPath = (tree != null) ? tree.getPath() : treePath;
             if (targetPath != null) {
-                for (int i=0; i<readPathsCheckList.length; i++) {
+                for (int i = 0; i < readPathsCheckList.length; i++) {
                     if (targetPath.equals(readPathsCheckList[i++])) {
                         return true;
                     }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/permission/PermissionStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/permission/PermissionStore.java?rev=1528929&r1=1528928&r2=1528929&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/permission/PermissionStore.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/permission/PermissionStore.java
Thu Oct  3 16:46:18 2013
@@ -17,17 +17,17 @@
 package org.apache.jackrabbit.oak.security.authorization.permission;
 
 import java.util.Collection;
-import java.util.Comparator;
-import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
 import java.util.NoSuchElementException;
 import java.util.TreeSet;
-
 import javax.annotation.CheckForNull;
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 
+import com.google.common.base.Predicate;
+import com.google.common.base.Strings;
+import com.google.common.collect.Iterators;
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.Tree;
 import org.apache.jackrabbit.oak.api.Type;
@@ -38,17 +38,14 @@ import org.apache.jackrabbit.oak.spi.sec
 import org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeBits;
 import org.apache.jackrabbit.util.Text;
 
-import com.google.common.base.Predicate;
-import com.google.common.base.Strings;
-import com.google.common.collect.Iterators;
-import com.google.common.primitives.Longs;
-
 import static com.google.common.base.Preconditions.checkNotNull;
 
 /**
  * The Permission store reads the principal based access control permissions. One store is
currently used to handle
  * 1 set of principal trees (so the compiled permissions use 2 stores, one for the user principals
and one for the
  * group principals)
+ * <p/>
+ * TODO: implement caching
  */
 class PermissionStore implements PermissionConstants {
 
@@ -56,8 +53,6 @@ class PermissionStore implements Permiss
 
     private final RestrictionProvider restrictionProvider;
 
-    private final Map<String, Collection<PermissionEntry>> cache = new HashMap<String,
Collection<PermissionEntry>>();
-
     PermissionStore(Map<String, Tree> principalTrees, RestrictionProvider restrictionProvider)
{
         this.principalTrees = principalTrees;
         this.restrictionProvider = restrictionProvider;
@@ -65,32 +60,28 @@ class PermissionStore implements Permiss
 
     @Nonnull
     private Collection<PermissionEntry> getEntries(String path) {
-        Collection<PermissionEntry> ret = cache.get(path);
-        if (ret == null) {
-            ret = new TreeSet<PermissionEntry>();
-            String name = PermissionUtil.getEntryName(path);
-            for (Map.Entry<String, Tree> principalRoot : principalTrees.entrySet())
{
-                Tree child = principalRoot.getValue().getChild(name);
-                if (child.exists()) {
-                    if (PermissionUtil.checkACLPath(child, path)) {
-                        loadPermissionsFromNode(path, ret, child);
-                    } else {
-                        // check for child node
-                        for (Tree node: child.getChildren()) {
-                            if (PermissionUtil.checkACLPath(node, path)) {
-                                loadPermissionsFromNode(path, ret, node);
-                            }
+        Collection<PermissionEntry> ret = new TreeSet<PermissionEntry>();
+        String name = PermissionUtil.getEntryName(path);
+        for (Map.Entry<String, Tree> principalRoot : principalTrees.entrySet()) {
+            Tree child = principalRoot.getValue().getChild(name);
+            if (child.exists()) {
+                if (PermissionUtil.checkACLPath(child, path)) {
+                    loadPermissionsFromNode(path, ret, child);
+                } else {
+                    // check for child node
+                    for (Tree node : child.getChildren()) {
+                        if (PermissionUtil.checkACLPath(node, path)) {
+                            loadPermissionsFromNode(path, ret, node);
                         }
                     }
                 }
             }
-            //cache.put(path, ret);
         }
         return ret;
     }
 
     private void loadPermissionsFromNode(String path, Collection<PermissionEntry> ret,
Tree node) {
-        for (Tree ace: node.getChildren()) {
+        for (Tree ace : node.getChildren()) {
             if (ace.getName().charAt(0) != 'c') {
                 ret.add(new PermissionEntry(path, ace, restrictionProvider));
             }
@@ -105,7 +96,7 @@ class PermissionStore implements Permiss
     }
 
     public void flush() {
-        cache.clear();
+        // TODO clear cache
     }
 
     private class EntryIterator implements Iterator<PermissionEntry> {
@@ -156,7 +147,7 @@ class PermissionStore implements Permiss
 
         @CheckForNull
         private void seekNext() {
-            for (next = null; next == null;) {
+            for (next = null; next == null; ) {
                 if (nextEntries.hasNext()) {
                     PermissionEntry pe = nextEntries.next();
                     if (predicate.apply(pe)) {
@@ -212,7 +203,6 @@ class PermissionStore implements Permiss
         }
     }
 
-
     public static final class PermissionEntry implements Comparable<PermissionEntry>
{
 
         /**
@@ -273,19 +263,19 @@ class PermissionStore implements Permiss
         public int compareTo(PermissionEntry o) {
             final int anotherVal = o.index;
             // reverse order
-            return (index<anotherVal ? 1 : (index==anotherVal ? 0 : -1));
+            return (index < anotherVal ? 1 : (index == anotherVal ? 0 : -1));
         }
 
         @Override
         public boolean equals(Object o) {
-            if (this == o) return true;
-            if (o == null || getClass() != o.getClass()) return false;
-
+            if (this == o) {
+                return true;
+            }
+            if (o == null || getClass() != o.getClass()) {
+                return false;
+            }
             PermissionEntry that = (PermissionEntry) o;
-
-            if (index != that.index) return false;
-
-            return true;
+            return index == that.index;
         }
 
         @Override
@@ -293,13 +283,4 @@ class PermissionStore implements Permiss
             return index;
         }
     }
-
-    private static final class EntryComparator implements Comparator<PermissionEntry>
{
-        @Override
-        public int compare(@Nonnull PermissionEntry entry,
-                           @Nonnull PermissionEntry otherEntry) {
-            return Longs.compare(otherEntry.index, entry.index);
-        }
-    }
-
 }



Mime
View raw message