jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r1371751 - /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeImpl.java
Date Fri, 10 Aug 2012 15:53:15 GMT
Author: angela
Date: Fri Aug 10 15:53:15 2012
New Revision: 1371751

URL: http://svn.apache.org/viewvc?rev=1371751&view=rev
Log:
OAK-51 : Implement JCR Access Control Management  (work in progress)

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeImpl.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeImpl.java?rev=1371751&r1=1371750&r2=1371751&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeImpl.java
Fri Aug 10 15:53:15 2012
@@ -116,7 +116,7 @@ public class TreeImpl implements Tree, P
 
     @Override
     public Tree getParent() {
-        if (parent != null && canRead(parent.getPath())) {
+        if (parent != null && canRead(parent)) {
             return parent;
         } else {
             return null;
@@ -125,7 +125,7 @@ public class TreeImpl implements Tree, P
 
     @Override
     public PropertyState getProperty(String name) {
-        if (canReadProperty(buildChildPath(name))) {
+        if (canReadProperty(name)) {
             return internalGetProperty(name);
         } else {
             return null;
@@ -135,7 +135,7 @@ public class TreeImpl implements Tree, P
     @Override
     public Status getPropertyStatus(String name) {
         // TODO: see OAK-212
-        if (!canReadProperty(buildChildPath(name))) {
+        if (!canReadProperty(name)) {
             return null;
         }
 
@@ -199,7 +199,7 @@ public class TreeImpl implements Tree, P
                     @Override
                     public boolean apply(PropertyState propertyState) {
                         if (propertyState != null) {
-                            return canReadProperty(buildChildPath(propertyState.getName()));
+                            return canReadProperty(propertyState.getName());
                         } else {
                             return false;
                         }
@@ -209,8 +209,9 @@ public class TreeImpl implements Tree, P
 
     @Override
     public TreeImpl getChild(String name) {
-        if (canRead(buildChildPath(name))) {
-            return internalGetChild(name);
+        TreeImpl child = internalGetChild(name);
+        if (child != null && canRead(child)) {
+            return child;
         } else {
             return null;
         }
@@ -268,7 +269,7 @@ public class TreeImpl implements Tree, P
                     @Override
                     public boolean apply(Tree tree) {
                         if (tree != null) {
-                            return canRead(tree.getPath());
+                            return canRead(tree);
                         } else {
                             return false;
                         }
@@ -403,18 +404,14 @@ public class TreeImpl implements Tree, P
      */
     @CheckForNull
     TreeImpl getTree(String path) {
-        TreeImpl tree = null;
-        if (canRead(buildChildPath(path))) {
-            TreeImpl child = this;
-            for (String name : elements(path)) {
-                child = child.internalGetChild(name);
-                if (child == null) {
-                    return null;
-                }
+        TreeImpl child = this;
+        for (String name : elements(path)) {
+            child = child.internalGetChild(name);
+            if (child == null) {
+                return null;
             }
-            tree = child;
         }
-        return tree;
+        return (canRead(child)) ? child : null;
     }
 
     //------------------------------------------------------------< private >---
@@ -450,20 +447,17 @@ public class TreeImpl implements Tree, P
         }
     }
 
-    private String buildChildPath(String relPath) {
-        StringBuilder sb = new StringBuilder();
-        buildPath(sb);
-        sb.append('/');
-        sb.append(relPath);
-        return sb.toString();
+    private boolean canRead(Tree tree) {
+        // FIXME: special handling for access control item and version content
+        return root.getPermissions().canRead(tree.getPath(), false);
     }
 
-    private boolean canRead(String path) {
-        return root.getPermissions().canRead(path, false);
-    }
+    private boolean canReadProperty(String name) {
+        StringBuilder path = new StringBuilder();
+        path.append(getPath()).append(name);
 
-    private boolean canReadProperty(String path) {
-        return root.getPermissions().canRead(path, true);
+        // FIXME: special handling for access control item and version content
+        return root.getPermissions().canRead(path.toString(), true);
     }
 
     private static boolean isSame(NodeState state1, NodeState state2) {



Mime
View raw message