jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1478208 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak: api/ core/ security/authentication/token/ security/authorization/ security/privilege/ security/user/ security/user/query/ spi/security/user/util/
Date Wed, 01 May 2013 21:55:57 GMT
Author: mduerig
Date: Wed May  1 21:55:56 2013
New Revision: 1478208

URL: http://svn.apache.org/r1478208
Log:
OAK-798: Review / refactor TreeImpl and related classes
Replace usage of Root.getTreeOrNull with Root.getTree

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Root.java
    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/RootImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/token/TokenProviderImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/AccessControlManagerImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeBitsProvider.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeDefinitionReader.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeDefinitionWriter.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeMigrator.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeValidator.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/AuthorizableBaseProvider.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserImporter.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserInitializer.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserManagerImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserProvider.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/query/ResultRowToAuthorizable.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/user/util/UserUtility.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Root.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Root.java?rev=1478208&r1=1478207&r2=1478208&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Root.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Root.java Wed
May  1 21:55:56 2013
@@ -18,7 +18,6 @@
  */
 package org.apache.jackrabbit.oak.api;
 
-import javax.annotation.CheckForNull;
 import javax.annotation.Nonnull;
 
 /**
@@ -92,19 +91,6 @@ public interface Root {
     Tree getTree(@Nonnull String path);
 
     /**
-     * Retrieve the {@code Tree} at the given absolute {@code path}. The path
-     * must resolve to a tree in this root.
-     *
-     * @param path absolute path to the tree
-     * @return tree at the given path or {@code null} if no such tree exists or
-     *         if the tree at {@code path} is not accessible.
-     * @deprecated Use {@link #getTree(String)} and {@link Tree#exists()} instead.
-     */
-    @CheckForNull
-    @Deprecated
-    Tree getTreeOrNull(String path);
-
-    /**
      * Get a tree location for a given absolute {@code path}
      *
      * @param path absolute path to the location
@@ -116,13 +102,13 @@ public interface Root {
 
     /**
      * Rebase this root instance to the latest revision. After a call to this method,
-     * trees obtained through {@link #getTreeOrNull(String)} may become disconnected.
+     * trees obtained through {@link #getTree(String)} may become disconnected.
      */
     void rebase();
 
     /**
      * Reverts all changes made to this root and refreshed to the latest trunk.
-     * After a call to this method, trees obtained through {@link #getTreeOrNull(String)}
+     * After a call to this method, trees obtained through {@link #getTree(String)}
      * may become disconnected.
      */
     void refresh();
@@ -130,7 +116,7 @@ public interface Root {
     /**
      * Atomically apply all changes made to the tree beneath this root to the
      * underlying store and refreshes this root. After a call to this method,
-     * all trees obtained through {@link #getTreeOrNull(String)} become invalid and fresh
+     * all trees obtained through {@link #getTree(String)} become invalid and fresh
      * instances must be obtained.
      *
      * @throws CommitFailedException

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=1478208&r1=1478207&r2=1478208&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
Wed May  1 21:55:56 2013
@@ -67,13 +67,6 @@ public final class ImmutableRoot impleme
         return child;
     }
 
-    @Override
-    @Deprecated
-    public ImmutableTree getTreeOrNull(String path) {
-        ImmutableTree tree = getTree(path);
-        return tree.exists() ? tree : null;
-    }
-
     @Nonnull
     @Override
     @Deprecated

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/RootImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/RootImpl.java?rev=1478208&r1=1478207&r2=1478208&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/RootImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/RootImpl.java
Wed May  1 21:55:56 2013
@@ -212,13 +212,6 @@ public class RootImpl implements Root {
 
     @Override
     @Deprecated
-    public TreeImpl getTreeOrNull(String path) {
-        checkLive();
-        return rootTree.getTreeOrNull(path);
-    }
-
-    @Override
-    @Deprecated
     public TreeLocation getLocation(String path) {
         checkArgument(PathUtils.isAbsolute(path));
         checkLive();

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/token/TokenProviderImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/token/TokenProviderImpl.java?rev=1478208&r1=1478207&r2=1478208&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/token/TokenProviderImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/token/TokenProviderImpl.java
Wed May  1 21:55:56 2013
@@ -164,7 +164,7 @@ public class TokenProviderImpl implement
         try {
             Authorizable user = userManager.getAuthorizable(userId);
             if (user != null && !user.isGroup()) {
-                NodeUtil userNode = new NodeUtil(root.getTreeOrNull(user.getPath()));
+                NodeUtil userNode = new NodeUtil(root.getTree(user.getPath()));
                 NodeUtil tokenParent = userNode.getChild(TOKENS_NODE_NAME);
                 if (tokenParent == null) {
                     tokenParent = userNode.addChild(TOKENS_NODE_NAME, TOKENS_NT_NAME);
@@ -229,7 +229,7 @@ public class TokenProviderImpl implement
     @Override
     public boolean removeToken(TokenInfo tokenInfo) {
         Tree tokenTree = getTokenTree(tokenInfo);
-        if (tokenTree != null) {
+        if (tokenTree != null && tokenTree.exists()) {
             try {
                 if (tokenTree.remove()) {
                     root.commit();
@@ -245,7 +245,7 @@ public class TokenProviderImpl implement
     @Override
     public boolean resetTokenExpiration(TokenInfo tokenInfo, long loginTime) {
         Tree tokenTree = getTokenTree(tokenInfo);
-        if (tokenTree != null) {
+        if (tokenTree != null && tokenTree.exists()) {
             NodeUtil tokenNode = new NodeUtil(tokenTree);
             long expTime = getExpirationTime(tokenNode, 0);
             if (tokenInfo.isExpired(loginTime)) {
@@ -309,7 +309,7 @@ public class TokenProviderImpl implement
     @CheckForNull
     private Tree getTokenTree(TokenInfo tokenInfo) {
         if (tokenInfo instanceof TokenInfoImpl) {
-            return root.getTreeOrNull(((TokenInfoImpl) tokenInfo).tokenPath);
+            return root.getTree(((TokenInfoImpl) tokenInfo).tokenPath);
         } else {
             return null;
         }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/AccessControlManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/AccessControlManagerImpl.java?rev=1478208&r1=1478207&r2=1478208&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/AccessControlManagerImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/AccessControlManagerImpl.java
Wed May  1 21:55:56 2013
@@ -16,6 +16,8 @@
  */
 package org.apache.jackrabbit.oak.security.authorization;
 
+import static com.google.common.base.Preconditions.checkNotNull;
+
 import java.security.Principal;
 import java.text.ParseException;
 import java.util.ArrayList;
@@ -26,6 +28,7 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+
 import javax.annotation.CheckForNull;
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
@@ -85,8 +88,6 @@ import org.apache.jackrabbit.util.Text;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import static com.google.common.base.Preconditions.checkNotNull;
-
 /**
  * Default implementation of the {@code JackrabbitAccessControlManager} interface.
  * This implementation covers both editing access control content by path and
@@ -180,7 +181,7 @@ public class AccessControlManagerImpl im
         if (oakPath != null) {
             String parentPath = Text.getRelativeParent(oakPath, 1);
             while (!parentPath.isEmpty()) {
-                Tree t = root.getTreeOrNull(parentPath);
+                Tree t = root.getTree(parentPath);
                 AccessControlPolicy plc = createACL(parentPath, t, true);
                 if (plc != null) {
                     effective.add(plc);
@@ -259,7 +260,7 @@ public class AccessControlManagerImpl im
                 acl = new NodeACL(path);
             }
 
-            Map<String, Value> restrictions = new HashMap();
+            Map<String, Value> restrictions = new HashMap<String, Value>();
             for (String name : ace.getRestrictionNames()) {
                 if (!REP_NODE_PATH.equals(name)) {
                     restrictions.put(name, ace.getRestriction(name));
@@ -372,9 +373,9 @@ public class AccessControlManagerImpl im
         for (ResultRow row : aceResult.getRows()) {
             String acePath = row.getPath();
             String aclName = Text.getName(Text.getRelativeParent(acePath, 1));
-            Tree accessControlledTree = root.getTreeOrNull(Text.getRelativeParent(acePath,
2));
+            Tree accessControlledTree = root.getTree(Text.getRelativeParent(acePath, 2));
 
-            if (aclName.isEmpty() || accessControlledTree == null) {
+            if (aclName.isEmpty() || !accessControlledTree.exists()) {
                 log.debug("Isolated access control entry -> ignore query result at " +
acePath);
                 continue;
             }
@@ -424,8 +425,8 @@ public class AccessControlManagerImpl im
 
     @Nonnull
     private Tree getTree(@Nullable String oakPath, long permissions) throws RepositoryException
{
-        Tree tree = (oakPath == null) ? root.getTreeOrNull("/") : root.getTreeOrNull(oakPath);
-        if (tree == null) {
+        Tree tree = (oakPath == null) ? root.getTree("/") : root.getTree(oakPath);
+        if (!tree.exists()) {
             throw new PathNotFoundException("No tree at " + oakPath);
         }
         if (permissions != Permissions.NO_PERMISSION) {
@@ -483,15 +484,15 @@ public class AccessControlManagerImpl im
         return ntMgr.isNodeType(tree, nodeTypeName);
     }
 
-    private boolean isACE(@Nullable Tree tree) {
-        return tree != null && ntMgr.isNodeType(tree, NT_REP_ACE);
+    private boolean isACE(@Nonnull Tree tree) {
+        return tree.exists() && ntMgr.isNodeType(tree, NT_REP_ACE);
     }
 
     @CheckForNull
     private Tree getAclTree(@Nullable String oakPath, @Nonnull Tree accessControlledTree)
{
         if (isAccessControlled(accessControlledTree, getMixinName(oakPath))) {
-            Tree policyTree = accessControlledTree.getChildOrNull(getAclName(oakPath));
-            if (policyTree != null) {
+            Tree policyTree = accessControlledTree.getChild(getAclName(oakPath));
+            if (policyTree.exists()) {
                 return policyTree;
             }
         }
@@ -524,13 +525,13 @@ public class AccessControlManagerImpl im
 
     @CheckForNull
     private JackrabbitAccessControlList createACL(@Nullable String oakPath,
-                                                  @Nullable Tree accessControlledTree,
+                                                  @Nonnull Tree accessControlledTree,
                                                   boolean isReadOnly) throws RepositoryException
{
         JackrabbitAccessControlList acl = null;
         String aclName = getAclName(oakPath);
         String mixinName = getMixinName(oakPath);
 
-        if (accessControlledTree != null && isAccessControlled(accessControlledTree,
mixinName)) {
+        if (accessControlledTree.exists() && isAccessControlled(accessControlledTree,
mixinName)) {
             Tree aclTree = accessControlledTree.getChildOrNull(aclName);
             if (aclTree != null) {
                 List<JackrabbitAccessControlEntry> entries = new ArrayList<JackrabbitAccessControlEntry>();
@@ -556,7 +557,7 @@ public class AccessControlManagerImpl im
         RestrictionProvider restrProvider = new PrincipalRestrictionProvider(restrictionProvider,
namePathMapper);
         List<JackrabbitAccessControlEntry> entries = new ArrayList<JackrabbitAccessControlEntry>();
         for (ResultRow row : aceResult.getRows()) {
-            Tree aceTree = root.getTreeOrNull(row.getPath());
+            Tree aceTree = root.getTree(row.getPath());
             if (isACE(aceTree)) {
                 String aclPath = Text.getRelativeParent(aceTree.getPath(), 1);
                 String path;

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeBitsProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeBitsProvider.java?rev=1478208&r1=1478207&r2=1478208&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeBitsProvider.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeBitsProvider.java
Wed May  1 21:55:56 2013
@@ -16,12 +16,14 @@
  */
 package org.apache.jackrabbit.oak.security.privilege;
 
+import static com.google.common.base.Preconditions.checkNotNull;
+
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
-import javax.annotation.CheckForNull;
+
 import javax.annotation.Nonnull;
 
 import com.google.common.collect.ImmutableSet;
@@ -29,8 +31,6 @@ import org.apache.jackrabbit.oak.api.Roo
 import org.apache.jackrabbit.oak.api.Tree;
 import org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeConstants;
 
-import static com.google.common.base.Preconditions.checkNotNull;
-
 /**
  * Reads and writes privilege definitions from and to the repository content
  * without applying any validation.
@@ -45,7 +45,7 @@ public final class PrivilegeBitsProvider
     public PrivilegeBitsProvider(Root root) {
         this.root = root;
         Tree privilegesTree = getPrivilegesTree();
-        if (privilegesTree != null && privilegesTree.hasProperty(REP_NEXT)) {
+        if (privilegesTree.exists() && privilegesTree.hasProperty(REP_NEXT)) {
             next = PrivilegeBits.getInstance(privilegesTree);
         } else {
             next = PrivilegeBits.BUILT_IN.get(REP_USER_MANAGEMENT).nextBits();
@@ -58,9 +58,9 @@ public final class PrivilegeBitsProvider
      *
      * @return The privileges root.
      */
-    @CheckForNull
+    @Nonnull
     Tree getPrivilegesTree() {
-        return root.getTreeOrNull(PRIVILEGES_PATH);
+        return root.getTree(PRIVILEGES_PATH);
     }
 
     @Nonnull
@@ -86,7 +86,7 @@ public final class PrivilegeBitsProvider
         }
 
         Tree privilegesTree = getPrivilegesTree();
-        if (privilegesTree == null) {
+        if (!privilegesTree.exists()) {
             return PrivilegeBits.EMPTY;
         }
         PrivilegeBits bits = PrivilegeBits.getInstance();
@@ -116,7 +116,7 @@ public final class PrivilegeBitsProvider
             return bitsToNames.get(privilegeBits);
         } else {
             Tree privilegesTree = getPrivilegesTree();
-            if (privilegesTree == null) {
+            if (!privilegesTree.exists()) {
                 return Collections.emptySet();
             }
 

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeDefinitionReader.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeDefinitionReader.java?rev=1478208&r1=1478207&r2=1478208&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeDefinitionReader.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeDefinitionReader.java
Wed May  1 21:55:56 2013
@@ -16,9 +16,9 @@
  */
 package org.apache.jackrabbit.oak.security.privilege;
 
-import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
+
 import javax.annotation.CheckForNull;
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
@@ -38,7 +38,7 @@ class PrivilegeDefinitionReader implemen
     private final Tree privilegesTree;
 
     PrivilegeDefinitionReader(@Nonnull Root root) {
-        this.privilegesTree = root.getTreeOrNull(PRIVILEGES_PATH);
+        this.privilegesTree = root.getTree(PRIVILEGES_PATH);
     }
 
     /**
@@ -48,18 +48,14 @@ class PrivilegeDefinitionReader implemen
      */
     @Nonnull
     Map<String, PrivilegeDefinition> readDefinitions() {
-        if (privilegesTree == null) {
-            return Collections.emptyMap();
-        } else {
-            Map<String, PrivilegeDefinition> definitions = new HashMap<String, PrivilegeDefinition>();
-            for (Tree child : privilegesTree.getChildren()) {
-                if (isPrivilegeDefinition(child)) {
-                    PrivilegeDefinition def = readDefinition(child);
-                    definitions.put(def.getName(), def);
-                }
+        Map<String, PrivilegeDefinition> definitions = new HashMap<String, PrivilegeDefinition>();
+        for (Tree child : privilegesTree.getChildren()) {
+            if (isPrivilegeDefinition(child)) {
+                PrivilegeDefinition def = readDefinition(child);
+                definitions.put(def.getName(), def);
             }
-            return definitions;
         }
+        return definitions;
     }
 
     /**

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeDefinitionWriter.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeDefinitionWriter.java?rev=1478208&r1=1478207&r2=1478208&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeDefinitionWriter.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeDefinitionWriter.java
Wed May  1 21:55:56 2013
@@ -96,8 +96,8 @@ class PrivilegeDefinitionWriter implemen
     private void writeDefinitions(Iterable<PrivilegeDefinition> definitions) throws
RepositoryException {
         try {
             // make sure the privileges path is defined
-            Tree privilegesTree = root.getTreeOrNull(PRIVILEGES_PATH);
-            if (privilegesTree == null) {
+            Tree privilegesTree = root.getTree(PRIVILEGES_PATH);
+            if (!privilegesTree.exists()) {
                 throw new RepositoryException("Privilege store does not exist.");
             }
             NodeUtil privilegesNode = new NodeUtil(privilegesTree);

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeMigrator.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeMigrator.java?rev=1478208&r1=1478207&r2=1478208&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeMigrator.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeMigrator.java
Wed May  1 21:55:56 2013
@@ -72,7 +72,7 @@ public class PrivilegeMigrator {
 
                 @Override
                 protected Tree getReadTree() {
-                    return root.getTreeOrNull("/");
+                    return root.getTree("/");
                 }
             };
             for (PrivilegeDefinition def : readCustomDefinitions(privilegeStream, nsRegistry))
{

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeValidator.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeValidator.java?rev=1478208&r1=1478207&r2=1478208&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeValidator.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeValidator.java
Wed May  1 21:55:56 2013
@@ -16,9 +16,12 @@
  */
 package org.apache.jackrabbit.oak.security.privilege;
 
+import static org.apache.jackrabbit.oak.api.CommitFailedException.CONSTRAINT;
+
 import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
+
 import javax.annotation.Nonnull;
 
 import org.apache.jackrabbit.oak.api.CommitFailedException;
@@ -35,8 +38,6 @@ import org.apache.jackrabbit.oak.spi.sta
 import org.apache.jackrabbit.oak.spi.state.NodeStateUtils;
 import org.apache.jackrabbit.util.Text;
 
-import static org.apache.jackrabbit.oak.api.CommitFailedException.CONSTRAINT;
-
 /**
  * Validator implementation that is responsible for validating any modifications
  * made to privileges stored in the repository.
@@ -130,8 +131,8 @@ class PrivilegeValidator extends Default
 
     @Nonnull
     private Tree getPrivilegesTree(Root root) throws CommitFailedException {
-        Tree privilegesTree = root.getTreeOrNull(PRIVILEGES_PATH);
-        if (privilegesTree == null) {
+        Tree privilegesTree = root.getTree(PRIVILEGES_PATH);
+        if (!privilegesTree.exists()) {
             throw new CommitFailedException(CONSTRAINT, 44, "Privilege store not initialized.");
         }
         return privilegesTree;

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/AuthorizableBaseProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/AuthorizableBaseProvider.java?rev=1478208&r1=1478207&r2=1478208&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/AuthorizableBaseProvider.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/AuthorizableBaseProvider.java
Wed May  1 21:55:56 2013
@@ -16,6 +16,8 @@
  */
 package org.apache.jackrabbit.oak.security.user;
 
+import static com.google.common.base.Preconditions.checkNotNull;
+
 import javax.annotation.CheckForNull;
 import javax.annotation.Nonnull;
 
@@ -27,8 +29,6 @@ import org.apache.jackrabbit.oak.spi.sec
 import org.apache.jackrabbit.oak.spi.security.user.UserConstants;
 import org.apache.jackrabbit.oak.spi.security.user.util.UserUtility;
 
-import static com.google.common.base.Preconditions.checkNotNull;
-
 /**
  * Base class for {@link UserProvider} and {@link MembershipProvider}.
  */
@@ -56,7 +56,7 @@ abstract class AuthorizableBaseProvider 
 
     @CheckForNull
     Tree getByPath(@Nonnull String authorizableOakPath) {
-        Tree tree = root.getTreeOrNull(authorizableOakPath);
+        Tree tree = root.getTree(authorizableOakPath);
         if (UserUtility.isType(tree, AuthorizableType.AUTHORIZABLE)) {
             return tree;
         } else {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserImporter.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserImporter.java?rev=1478208&r1=1478207&r2=1478208&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserImporter.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserImporter.java
Wed May  1 21:55:56 2013
@@ -16,6 +16,9 @@
  */
 package org.apache.jackrabbit.oak.security.user;
 
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.apache.jackrabbit.oak.api.Type.STRINGS;
+
 import java.security.Principal;
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -25,6 +28,7 @@ import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 import javax.jcr.ImportUUIDBehavior;
@@ -45,10 +49,10 @@ import org.apache.jackrabbit.oak.api.Pro
 import org.apache.jackrabbit.oak.api.Root;
 import org.apache.jackrabbit.oak.api.Tree;
 import org.apache.jackrabbit.oak.api.Type;
-import org.apache.jackrabbit.oak.namepath.NamePathMapper;
 import org.apache.jackrabbit.oak.core.IdentifierManager;
-import org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl;
+import org.apache.jackrabbit.oak.namepath.NamePathMapper;
 import org.apache.jackrabbit.oak.spi.security.ConfigurationParameters;
+import org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl;
 import org.apache.jackrabbit.oak.spi.security.user.UserConstants;
 import org.apache.jackrabbit.oak.spi.xml.NodeInfo;
 import org.apache.jackrabbit.oak.spi.xml.PropInfo;
@@ -60,9 +64,6 @@ import org.apache.jackrabbit.oak.util.Tr
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import static com.google.common.base.Preconditions.checkNotNull;
-import static org.apache.jackrabbit.oak.api.Type.STRINGS;
-
 /**
  * {@code UserImporter} implements both {@code ode>ProtectedPropertyImporter}
  * and {@code ProtectedNodeImporter} and provides import facilities for protected
@@ -528,7 +529,7 @@ class UserImporter implements ProtectedP
             // handling non-existing members in case of best-effort
             if (!nonExisting.isEmpty()) {
                 log.info("ImportBehavior.BESTEFFORT: Found " + nonExisting.size() + " entries
of rep:members pointing to non-existing authorizables. Adding to rep:members.");
-                Tree groupTree = root.getTreeOrNull(gr.getPath());
+                Tree groupTree = root.getTree(gr.getPath());
 
                 MembershipProvider membershipProvider = userManager.getMembershipProvider();
                 for (Membership.Member member : nonExisting) {
@@ -611,7 +612,7 @@ class UserImporter implements ProtectedP
             }
 
             if (!nonExisting.isEmpty()) {
-                Tree userTree = checkNotNull(root.getTreeOrNull(a.getPath()));
+                Tree userTree = checkNotNull(root.getTree(a.getPath()));
                 // copy over all existing impersonators to the nonExisting list
                 PropertyState impersonators = userTree.getProperty(REP_IMPERSONATORS);
                 if (impersonators != null) {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserInitializer.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserInitializer.java?rev=1478208&r1=1478207&r2=1478208&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserInitializer.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserInitializer.java
Wed May  1 21:55:56 2013
@@ -16,6 +16,8 @@
  */
 package org.apache.jackrabbit.oak.security.user;
 
+import static com.google.common.base.Preconditions.checkNotNull;
+
 import javax.annotation.Nonnull;
 import javax.jcr.RepositoryException;
 
@@ -44,8 +46,6 @@ import org.apache.jackrabbit.oak.util.No
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import static com.google.common.base.Preconditions.checkNotNull;
-
 /**
  * Creates initial set of users to be present in a given workspace. This
  * implementation uses the {@code UserManager} such as defined by the
@@ -105,7 +105,7 @@ class UserInitializer implements Workspa
 
         String errorMsg = "Failed to initialize user content.";
         try {
-            NodeUtil rootTree = checkNotNull(new NodeUtil(root.getTreeOrNull("/")));
+            NodeUtil rootTree = checkNotNull(new NodeUtil(root.getTree("/")));
             NodeUtil index = rootTree.getOrAddChild(IndexConstants.INDEX_DEFINITIONS_NAME,
JcrConstants.NT_UNSTRUCTURED);
 
             if (!index.hasChild("authorizableId")) {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserManagerImpl.java?rev=1478208&r1=1478207&r2=1478208&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserManagerImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserManagerImpl.java
Wed May  1 21:55:56 2013
@@ -16,11 +16,14 @@
  */
 package org.apache.jackrabbit.oak.security.user;
 
+import static com.google.common.base.Preconditions.checkNotNull;
+
 import java.io.UnsupportedEncodingException;
 import java.security.NoSuchAlgorithmException;
 import java.security.Principal;
 import java.util.Iterator;
 import java.util.List;
+
 import javax.annotation.CheckForNull;
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
@@ -52,8 +55,6 @@ import org.apache.jackrabbit.oak.spi.sec
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import static com.google.common.base.Preconditions.checkNotNull;
-
 /**
  * UserManagerImpl...
  */
@@ -281,7 +282,7 @@ public class UserManagerImpl implements 
     //--------------------------------------------------------------------------
     @CheckForNull
     Authorizable getAuthorizable(Tree tree) throws RepositoryException {
-        if (tree == null) {
+        if (tree == null || !tree.exists()) {
             return null;
         }
         return getAuthorizable(userProvider.getAuthorizableId(tree), tree);

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserProvider.java?rev=1478208&r1=1478207&r2=1478208&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserProvider.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserProvider.java
Wed May  1 21:55:56 2013
@@ -16,10 +16,14 @@
  */
 package org.apache.jackrabbit.oak.security.user;
 
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.apache.jackrabbit.oak.api.Type.STRING;
+
 import java.security.Principal;
 import java.text.ParseException;
 import java.util.Collections;
 import java.util.Iterator;
+
 import javax.annotation.CheckForNull;
 import javax.annotation.Nonnull;
 import javax.jcr.RepositoryException;
@@ -44,9 +48,6 @@ import org.apache.jackrabbit.util.Text;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import static com.google.common.base.Preconditions.checkNotNull;
-import static org.apache.jackrabbit.oak.api.Type.STRING;
-
 /**
  * User provider implementation and manager for group memberships with the
  * following characteristics:
@@ -145,7 +146,7 @@ import static org.apache.jackrabbit.oak.
  *
  * <h3>By Path</h3>
  * Access by path consists of a simple lookup by path such as exposed by
- * {@link Root#getTreeOrNull(String)}. The resulting tree is validated to really
+ * {@link Root#getTree(String)}. The resulting tree is validated to really
  * represent a user/group tree.
  *
  * <h3>By Principal</h3>
@@ -198,7 +199,7 @@ class UserProvider extends AuthorizableB
     @CheckForNull
     Tree getAuthorizableByPrincipal(Principal principal) {
         if (principal instanceof TreeBasedPrincipal) {
-            return root.getTreeOrNull(((TreeBasedPrincipal) principal).getOakPath());
+            return root.getTree(((TreeBasedPrincipal) principal).getOakPath());
         }
 
         // NOTE: in contrast to JR2 the extra shortcut for ID==principalName
@@ -217,7 +218,7 @@ class UserProvider extends AuthorizableB
             Iterator<? extends ResultRow> rows = result.getRows().iterator();
             if (rows.hasNext()) {
                 String path = rows.next().getPath();
-                return root.getTreeOrNull(path);
+                return root.getTree(path);
             }
         } catch (ParseException ex) {
             log.error("Failed to retrieve authorizable by principal", ex);
@@ -273,9 +274,9 @@ class UserProvider extends AuthorizableB
                                        boolean isGroup, String intermediatePath) throws RepositoryException
{
         String authRoot = (isGroup) ? groupPath : userPath;
         NodeUtil folder;
-        Tree authTree = root.getTreeOrNull(authRoot);
-        if (authTree == null) {
-            folder = new NodeUtil(root.getTreeOrNull("/"));
+        Tree authTree = root.getTree(authRoot);
+        if (!authTree.exists()) {
+            folder = new NodeUtil(root.getTree("/"));
             for (String name : Text.explode(authRoot, '/', false)) {
                 folder = folder.getOrAddChild(name, NT_REP_AUTHORIZABLE_FOLDER);
             }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/query/ResultRowToAuthorizable.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/query/ResultRowToAuthorizable.java?rev=1478208&r1=1478207&r2=1478208&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/query/ResultRowToAuthorizable.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/query/ResultRowToAuthorizable.java
Wed May  1 21:55:56 2013
@@ -64,13 +64,13 @@ class ResultRowToAuthorizable implements
     private Authorizable getAuthorizable(String resultPath) {
         Authorizable authorizable = null;
         try {
-            Tree tree = root.getTreeOrNull(resultPath);
+            Tree tree = root.getTree(resultPath);
             AuthorizableType type = UserUtility.getType(tree);
-            while (tree != null && type == null) {
-                tree = tree.getParentOrNull();
+            while (tree.exists() && !tree.isRoot() && type == null) {
+                tree = tree.getParent();
                 type = UserUtility.getType(tree);
             }
-            if (tree != null && (targetType == null || targetType == type)) {
+            if (tree.exists() && (targetType == null || targetType == type)) {
                 authorizable = userManager.getAuthorizableByPath(tree.getPath());
             }
         } catch (RepositoryException e) {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/user/util/UserUtility.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/user/util/UserUtility.java?rev=1478208&r1=1478207&r2=1478208&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/user/util/UserUtility.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/user/util/UserUtility.java
Wed May  1 21:55:56 2013
@@ -61,8 +61,8 @@ public final class UserUtility implement
     }
 
     @CheckForNull
-    public static AuthorizableType getType(@Nullable Tree authorizableNode) {
-        String ntName = (authorizableNode == null) ? null : TreeUtil.getPrimaryTypeName(authorizableNode);
+    public static AuthorizableType getType(@Nonnull Tree authorizableNode) {
+        String ntName = TreeUtil.getPrimaryTypeName(authorizableNode);
         if (ntName != null) {
             if (UserConstants.NT_REP_GROUP.equals(ntName)) {
                 return AuthorizableType.GROUP;



Mime
View raw message