jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r1564336 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/core/ main/java/org/apache/jackrabbit/oak/security/authorization/permission/ test/java/org/apache/jackrabbit/oak/core/
Date Tue, 04 Feb 2014 15:15:07 GMT
Author: angela
Date: Tue Feb  4 15:15:07 2014
New Revision: 1564336

URL: http://svn.apache.org/r1564336
Log:
minor improvement

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ImmutableRoot.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ImmutableTree.java
    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/MoveAwarePermissionValidator.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/permission/PermissionValidator.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/permission/PermissionValidatorProvider.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/core/ImmutableTreeTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ImmutableRoot.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ImmutableRoot.java?rev=1564336&r1=1564335&r2=1564336&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ImmutableRoot.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ImmutableRoot.java
Tue Feb  4 15:15:07 2014
@@ -50,7 +50,13 @@ public final class ImmutableRoot impleme
     }
 
     public ImmutableRoot(@Nonnull Root root, @Nonnull TreeTypeProvider typeProvider) {
-        this(ImmutableTree.createFromRoot(root, typeProvider));
+        if (root instanceof AbstractRoot) {
+            rootTree = new ImmutableTree(((AbstractRoot) root).getBaseState(), typeProvider);
+        } else if (root instanceof ImmutableRoot) {
+            rootTree = ((ImmutableRoot) root).getTree("/");
+        } else {
+            throw new IllegalArgumentException("Unsupported Root implementation: " + root.getClass());
+        }
     }
 
     public ImmutableRoot(@Nonnull ImmutableTree rootTree) {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ImmutableTree.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ImmutableTree.java?rev=1564336&r1=1564335&r2=1564336&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ImmutableTree.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ImmutableTree.java
Tue Feb  4 15:15:07 2014
@@ -122,16 +122,6 @@ public final class ImmutableTree extends
         this.typeProvider = typeProvider;
     }
 
-    public static ImmutableTree createFromRoot(@Nonnull Root root, @Nonnull TreeTypeProvider
typeProvider) {
-        if (root instanceof AbstractRoot) {
-            return new ImmutableTree(((AbstractRoot) root).getBaseState(), typeProvider);
-        } else if (root instanceof ImmutableRoot) {
-            return ((ImmutableRoot) root).getTree("/");
-        } else {
-            throw new IllegalArgumentException("Unsupported Root implementation: " + root.getClass());
-        }
-    }
-
     @Override
     protected ImmutableTree createChild(String name) {
         return new ImmutableTree(this, name, state.getChildNode(name));

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=1564336&r1=1564335&r2=1564336&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
Tue Feb  4 15:15:07 2014
@@ -151,7 +151,7 @@ final class CompiledPermissionImpl imple
         if (tree.isRoot()) {
             return new TreePermissionImpl(tree, TreeTypeProvider.TYPE_DEFAULT, TreePermission.EMPTY);
         }
-        int type = tree.getType();
+        int type = PermissionUtil.getType(tree, null);
         switch (type) {
             case TreeTypeProvider.TYPE_HIDDEN:
                 // TODO: OAK-753 decide on where to filter out hidden items.
@@ -323,7 +323,7 @@ final class CompiledPermissionImpl imple
     }
 
     @Nonnull PrivilegeBits internalGetPrivileges(@Nullable ImmutableTree tree) {
-        int type = (tree == null) ? TreeTypeProvider.TYPE_DEFAULT : tree.getType();
+        int type = (tree == null) ? TreeTypeProvider.TYPE_DEFAULT : PermissionUtil.getType(tree,
null);
         switch (type) {
             case TreeTypeProvider.TYPE_HIDDEN:
                 return PrivilegeBits.EMPTY;

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/permission/MoveAwarePermissionValidator.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/permission/MoveAwarePermissionValidator.java?rev=1564336&r1=1564335&r2=1564336&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/permission/MoveAwarePermissionValidator.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/permission/MoveAwarePermissionValidator.java
Tue Feb  4 15:15:07 2014
@@ -42,13 +42,12 @@ public class MoveAwarePermissionValidato
 
     private final MoveContext moveCtx;
 
-    MoveAwarePermissionValidator(@Nonnull NodeState rootBefore,
-                                 @Nonnull NodeState rootAfter,
-                                 @Nonnull TreeTypeProvider typeProvider,
+    MoveAwarePermissionValidator(@Nonnull ImmutableTree rootBefore,
+                                 @Nonnull ImmutableTree rootAfter,
                                  @Nonnull PermissionProvider permissionProvider,
                                  @Nonnull PermissionValidatorProvider provider,
                                  @Nonnull MoveTracker moveTracker) {
-        super(rootBefore, rootAfter, typeProvider, permissionProvider, provider);
+        super(rootBefore, rootAfter, permissionProvider, provider);
         moveCtx = new MoveContext(moveTracker, rootBefore, rootAfter);
     }
 
@@ -114,8 +113,8 @@ public class MoveAwarePermissionValidato
         private final ImmutableRoot rootAfter;
 
         private MoveContext(@Nonnull MoveTracker moveTracker,
-                            @Nonnull NodeState before,
-                            @Nonnull NodeState after) {
+                            @Nonnull ImmutableTree before,
+                            @Nonnull ImmutableTree after) {
             this.moveTracker = moveTracker;
             rootBefore = new ImmutableRoot(before);
             rootAfter = new ImmutableRoot(after);

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/permission/PermissionValidator.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/permission/PermissionValidator.java?rev=1564336&r1=1564335&r2=1564336&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/permission/PermissionValidator.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/permission/PermissionValidator.java
Tue Feb  4 15:15:07 2014
@@ -16,13 +16,6 @@
  */
 package org.apache.jackrabbit.oak.security.authorization.permission;
 
-import static com.google.common.base.Preconditions.checkNotNull;
-import static org.apache.jackrabbit.JcrConstants.JCR_CREATED;
-import static org.apache.jackrabbit.JcrConstants.MIX_REFERENCEABLE;
-import static org.apache.jackrabbit.oak.api.CommitFailedException.ACCESS;
-import static org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants.JCR_CREATEDBY;
-import static org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants.MIX_CREATED;
-
 import javax.annotation.CheckForNull;
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
@@ -32,6 +25,7 @@ import org.apache.jackrabbit.oak.api.Com
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.Tree;
 import org.apache.jackrabbit.oak.core.AbstractTree;
+import org.apache.jackrabbit.oak.core.ImmutableRoot;
 import org.apache.jackrabbit.oak.core.ImmutableTree;
 import org.apache.jackrabbit.oak.core.TreeTypeProvider;
 import org.apache.jackrabbit.oak.plugins.lock.LockConstants;
@@ -48,6 +42,13 @@ import org.apache.jackrabbit.oak.spi.sta
 import org.apache.jackrabbit.oak.util.ChildOrderDiff;
 import org.apache.jackrabbit.oak.util.TreeUtil;
 
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.apache.jackrabbit.JcrConstants.JCR_CREATED;
+import static org.apache.jackrabbit.JcrConstants.MIX_REFERENCEABLE;
+import static org.apache.jackrabbit.oak.api.CommitFailedException.ACCESS;
+import static org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants.JCR_CREATEDBY;
+import static org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants.MIX_CREATED;
+
 /**
  * Validator implementation that checks for sufficient permission for all
  * write operations executed by a given content session.
@@ -65,29 +66,27 @@ class PermissionValidator extends Defaul
 
     private final long permission;
 
-    PermissionValidator(@Nonnull NodeState rootBefore,
-                        @Nonnull NodeState rootAfter,
-                        @Nonnull TreeTypeProvider typeProvider,
+    PermissionValidator(@Nonnull ImmutableTree rootBefore,
+                        @Nonnull ImmutableTree rootAfter,
                         @Nonnull PermissionProvider permissionProvider,
                         @Nonnull PermissionValidatorProvider provider) {
-        this.parentBefore = new ImmutableTree(rootBefore, typeProvider);
-        this.parentAfter = new ImmutableTree(rootAfter, typeProvider);
+        this.parentBefore = rootBefore;
+        this.parentAfter = rootAfter;
         this.parentPermission = permissionProvider.getTreePermission(parentBefore, TreePermission.EMPTY);
 
         this.permissionProvider = permissionProvider;
         this.provider = provider;
 
-        this.isReferenceable = new TypePredicate(rootAfter, MIX_REFERENCEABLE);
-        this.isCreated = new TypePredicate(rootAfter, MIX_CREATED);
+        this.isReferenceable = new TypePredicate(rootAfter.getNodeState(), MIX_REFERENCEABLE);
+        this.isCreated = new TypePredicate(rootAfter.getNodeState(), MIX_CREATED);
 
         permission = Permissions.getPermission(PermissionUtil.getPath(parentBefore, parentAfter),
Permissions.NO_PERMISSION);
     }
 
-    protected PermissionValidator(
-                        @Nullable ImmutableTree parentBefore,
-                        @Nullable ImmutableTree parentAfter,
-                        @Nullable TreePermission parentPermission,
-                        @Nonnull PermissionValidator parentValidator) {
+    protected PermissionValidator(@Nullable ImmutableTree parentBefore,
+                                  @Nullable ImmutableTree parentAfter,
+                                  @Nullable TreePermission parentPermission,
+                                  @Nonnull PermissionValidator parentValidator) {
         this.parentBefore = parentBefore;
         this.parentAfter = parentAfter;
         this.parentPermission = parentPermission;

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/permission/PermissionValidatorProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/permission/PermissionValidatorProvider.java?rev=1564336&r1=1564335&r2=1564336&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/permission/PermissionValidatorProvider.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/permission/PermissionValidatorProvider.java
Tue Feb  4 15:15:07 2014
@@ -18,10 +18,10 @@ package org.apache.jackrabbit.oak.securi
 
 import java.security.Principal;
 import java.util.Set;
-
 import javax.annotation.Nonnull;
 
 import org.apache.jackrabbit.oak.core.ImmutableRoot;
+import org.apache.jackrabbit.oak.core.ImmutableTree;
 import org.apache.jackrabbit.oak.core.TreeTypeProvider;
 import org.apache.jackrabbit.oak.core.TreeTypeProviderImpl;
 import org.apache.jackrabbit.oak.spi.commit.MoveTracker;
@@ -71,15 +71,15 @@ public class PermissionValidatorProvider
     @Nonnull
     @Override
     public Validator getRootValidator(NodeState before, NodeState after) {
-        TreeTypeProvider tp =
-                new TreeTypeProviderImpl(getAccessControlContext());
-        PermissionProvider pp = acConfig.getPermissionProvider(
-                new ImmutableRoot(before), workspaceName, principals);
+        TreeTypeProvider tp = new TreeTypeProviderImpl(getAccessControlContext());
+        PermissionProvider pp = acConfig.getPermissionProvider(new ImmutableRoot(before),
workspaceName, principals);
 
+        ImmutableTree rootBefore = new ImmutableTree(before, tp);
+        ImmutableTree rootAfter = new ImmutableTree(after, tp);
         if (moveTracker.isEmpty()) {
-            return new PermissionValidator(before, after, tp, pp, this);
+            return new PermissionValidator(rootBefore, rootAfter, pp, this);
         } else {
-            return new MoveAwarePermissionValidator(before, after, tp, pp, this, moveTracker);
+            return new MoveAwarePermissionValidator(rootBefore, rootAfter, pp, this, moveTracker);
         }
     }
 

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/core/ImmutableTreeTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/core/ImmutableTreeTest.java?rev=1564336&r1=1564335&r2=1564336&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/core/ImmutableTreeTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/core/ImmutableTreeTest.java
Tue Feb  4 15:15:07 2014
@@ -18,26 +18,29 @@
  */
 package org.apache.jackrabbit.oak.core;
 
-import static org.apache.jackrabbit.oak.OakAssert.assertSequence;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
 import org.apache.jackrabbit.oak.NodeStoreFixture;
 import org.apache.jackrabbit.oak.OakBaseTest;
 import org.apache.jackrabbit.oak.api.CommitFailedException;
 import org.apache.jackrabbit.oak.api.ContentSession;
 import org.apache.jackrabbit.oak.api.Root;
 import org.apache.jackrabbit.oak.api.Tree;
+import org.apache.jackrabbit.oak.core.ImmutableTree;
+import org.apache.jackrabbit.oak.core.TreeTypeProvider;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 
+import static org.apache.jackrabbit.oak.OakAssert.assertSequence;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
 
 public class ImmutableTreeTest extends OakBaseTest {
 
     private Root root;
+    private MutableTree mutableTree;
 
     public ImmutableTreeTest(NodeStoreFixture fixture) {
         super(fixture);
@@ -57,6 +60,7 @@ public class ImmutableTreeTest extends O
 
         // Acquire a fresh new root to avoid problems from lingering state
         root = session.getLatestRoot();
+        mutableTree = (MutableTree) root.getTree("/");
     }
 
     @After
@@ -66,9 +70,7 @@ public class ImmutableTreeTest extends O
 
     @Test
     public void testGetPath() {
-        MutableTree tree = (MutableTree) root.getTree("/");
-
-        ImmutableTree immutable = new ImmutableTree(tree.getNodeState());
+        ImmutableTree immutable = new ImmutableTree(mutableTree.getNodeState());
         assertEquals("/", immutable.getPath());
 
         immutable = immutable.getChild("x");
@@ -83,7 +85,7 @@ public class ImmutableTreeTest extends O
 
     @Test
     public void testGetNodeState() {
-        ImmutableTree tree = ImmutableTree.createFromRoot(root, TreeTypeProvider.EMPTY);
+        ImmutableTree tree = new ImmutableTree(mutableTree.getNodeState());
         assertNotNull(tree.getNodeState());
 
         for (Tree child : tree.getChildren()) {
@@ -94,7 +96,7 @@ public class ImmutableTreeTest extends O
 
     @Test
     public void testRoot() {
-        ImmutableTree tree = ImmutableTree.createFromRoot(root, TreeTypeProvider.EMPTY);
+        ImmutableTree tree = new ImmutableTree(mutableTree.getNodeState());
         assertTrue(tree.isRoot());
         try {
             tree.getParent();
@@ -107,7 +109,7 @@ public class ImmutableTreeTest extends O
 
     @Test
     public void testGetParent() {
-        ImmutableTree tree = ImmutableTree.createFromRoot(root, TreeTypeProvider.EMPTY);
+        ImmutableTree tree = new ImmutableTree(mutableTree.getNodeState());
         try {
             tree.getParent();
             fail();
@@ -154,5 +156,5 @@ public class ImmutableTreeTest extends O
          
          tree = new ImmutableTree(t.getNodeState());
          assertSequence(tree.getChildren(), "node3", "node2", "node1");
-     }   
+    }
 }



Mime
View raw message