jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r1372942 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/ oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/identifier/ oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/ oak-core/sr...
Date Tue, 14 Aug 2012 15:49:55 GMT
Author: angela
Date: Tue Aug 14 15:49:55 2012
New Revision: 1372942

URL: http://svn.apache.org/viewvc?rev=1372942&view=rev
Log:
OAK-50 : Implement User Management (WIP)

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NamePathMapper.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/identifier/IdentifierManager.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserProviderImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/user/UserProvider.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/NodeUtil.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionDelegate.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user/AuthorizableIterator.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user/MembershipManager.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user/UserManagerImpl.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NamePathMapper.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NamePathMapper.java?rev=1372942&r1=1372941&r2=1372942&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NamePathMapper.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NamePathMapper.java
Tue Aug 14 15:49:55 2012
@@ -24,6 +24,8 @@ import javax.annotation.Nonnull;
  */
 public interface NamePathMapper extends NameMapper, PathMapper {
 
+    public NamePathMapper DEFAULT = new Default();
+
     /**
      * Default implementation that doesn't perform any conversions for cases
      * where a mapper object only deals with oak internal names and paths.

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/identifier/IdentifierManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/identifier/IdentifierManager.java?rev=1372942&r1=1372941&r2=1372942&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/identifier/IdentifierManager.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/identifier/IdentifierManager.java
Tue Aug 14 15:49:55 2012
@@ -16,6 +16,7 @@
  */
 package org.apache.jackrabbit.oak.plugins.identifier;
 
+import java.io.UnsupportedEncodingException;
 import java.text.ParseException;
 import java.util.Collections;
 import java.util.Map;
@@ -23,6 +24,7 @@ import java.util.Set;
 import java.util.UUID;
 import javax.annotation.CheckForNull;
 import javax.annotation.Nonnull;
+import javax.jcr.RepositoryException;
 import javax.jcr.query.Query;
 
 import org.apache.jackrabbit.JcrConstants;
@@ -57,6 +59,16 @@ public class IdentifierManager {
         return UUID.randomUUID().toString();
     }
 
+    @Nonnull
+    public static String generateUUID(String hint) throws RepositoryException {
+        try {
+            UUID uuid = UUID.nameUUIDFromBytes(hint.getBytes("UTF-8"));
+            return uuid.toString();
+        } catch (UnsupportedEncodingException e) {
+            throw new RepositoryException("Unexpected error while creating authorizable node",
e);
+        }
+    }
+
     public static boolean isValidUUID(String uuid) {
         try {
             UUID.fromString(uuid);
@@ -87,6 +99,13 @@ public class IdentifierManager {
         }
     }
 
+    /**
+     * The tree identified by the specified {@code identifier} or {@code null}.
+     *
+     * @param identifier The identifier of the Node such as exposed by {@link javax.jcr.Node#getIdentifier()}
+     * @return The tree with the given {@code identifier} or {@code null} if no
+     * such tree exists or isn't accessible to the content session.
+     */
     @CheckForNull
     public Tree getTree(String identifier) {
         if (isValidUUID(identifier)) {
@@ -99,8 +118,20 @@ public class IdentifierManager {
         }
     }
 
+    /**
+     * Searches all reference properties to the specified {@code tree} that match
+     * the given name and node type constraints.
+     *
+     * @param tree The tree for which references should be searched.
+     * @param propertyName A name constraint for the reference properties;
+     * {@code null} if no constraint should be enforced.
+     * @param nodeTypeNames Node type constraints to be enforced when using
+     * for reference properties.
+     * @return A set of oak paths of those reference properties referring to the
+     * specified {@code tree} and matching the constraints.
+     */
     @Nonnull
-    public Set<String> getReferences(Tree tree, String name) {
+    public Set<String> getReferences(Tree tree, String propertyName, String... nodeTypeNames)
{
         if (!isReferenceable(tree)) {
             return Collections.emptySet();
         } else {
@@ -110,8 +141,20 @@ public class IdentifierManager {
         }
     }
 
+    /**
+     * Searches all weak reference properties to the specified {@code tree} that
+     * match the given name and node type constraints.
+     *
+     * @param tree The tree for which weak references should be searched.
+     * @param propertyName A name constraint for the weak reference properties;
+     * {@code null} if no constraint should be enforced.
+     * @param nodeTypeNames Node type constraints to be enforced when using
+     * for reference properties or {@code null} to avoid node type constraints.
+     * @return A set of oak paths of those weak reference properties referring to the
+     * specified {@code tree} and matching the constraints.
+     */
     @Nonnull
-    public Set<String> getWeakReferences(Tree tree, String name) {
+    public Set<String> getWeakReferences(Tree tree, String propertyName, String...
nodeTypeNames) {
         if (!isReferenceable(tree)) {
             return Collections.emptySet();
         } else {
@@ -132,7 +175,7 @@ public class IdentifierManager {
             Map<String, CoreValue> bindings = Collections.singletonMap("id", contentSession.getCoreValueFactory().createValue(id));
 
             Result result = contentSession.getQueryEngine().executeQuery("SELECT * FROM [nt:base]
WHERE [jcr:uuid] = $id", Query.JCR_SQL2,
-                    contentSession, Long.MAX_VALUE, 0, bindings, new NamePathMapper.Default());
+                    contentSession, Long.MAX_VALUE, 0, bindings, NamePathMapper.DEFAULT);
 
             String path = null;
             for (ResultRow rr : result.getRows()) {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserProviderImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserProviderImpl.java?rev=1372942&r1=1372941&r2=1372942&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserProviderImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserProviderImpl.java
Tue Aug 14 15:49:55 2012
@@ -16,15 +16,15 @@
  */
 package org.apache.jackrabbit.oak.security.user;
 
-import java.io.UnsupportedEncodingException;
-import java.util.UUID;
 import javax.jcr.RepositoryException;
 import javax.jcr.nodetype.ConstraintViolationException;
 
 import org.apache.jackrabbit.JcrConstants;
+import org.apache.jackrabbit.api.security.user.UserManager;
 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.plugins.identifier.IdentifierManager;
 import org.apache.jackrabbit.oak.spi.security.user.UserConstants;
 import org.apache.jackrabbit.oak.spi.security.user.UserManagerConfig;
 import org.apache.jackrabbit.oak.spi.security.user.UserProvider;
@@ -121,6 +121,7 @@ public class UserProviderImpl implements
 
     private final ContentSession contentSession;
     private final Root root;
+    private final IdentifierManager identifierManager;
 
     private final int defaultDepth;
 
@@ -130,6 +131,7 @@ public class UserProviderImpl implements
     public UserProviderImpl(ContentSession contentSession, Root root, UserManagerConfig config)
{
         this.contentSession = contentSession;
         this.root = root;
+        this.identifierManager = new IdentifierManager(contentSession, root);
 
         defaultDepth = config.getConfigValue(UserManagerConfig.PARAM_DEFAULT_DEPTH, DEFAULT_DEPTH);
 
@@ -148,21 +150,45 @@ public class UserProviderImpl implements
     }
 
     @Override
-    public Tree getAuthorizable(String authorizableId) {
-        // TODO: add implementation (requires identifier utility in oak-core)
-        return null;
+    public Tree getAuthorizable(String authorizableId) throws RepositoryException {
+        Tree tree = identifierManager.getTree(getContentID(authorizableId));
+        if (isAuthorizableTree(tree, UserManager.SEARCH_TYPE_AUTHORIZABLE)) {
+            return tree;
+        } else {
+            return null;
+        }
     }
 
     @Override
-    public String getContentID(String authorizableId) throws RepositoryException {
-        try {
-            UUID uuid = UUID.nameUUIDFromBytes(authorizableId.toLowerCase().getBytes("UTF-8"));
-            return uuid.toString();
-        } catch (UnsupportedEncodingException e) {
-            throw new RepositoryException("Unexpected error while creating authorizable node",
e);
+    public Tree getAuthorizable(String authorizableId, int authorizableType) throws RepositoryException
{
+        Tree tree = identifierManager.getTree(getContentID(authorizableId));
+        if (isAuthorizableTree(tree, authorizableType)) {
+            return tree;
+        } else {
+            return null;
         }
     }
 
+    @Override()
+    public Tree getAuthorizableByPath(String authorizableOakPath) {
+        Tree tree = root.getTree(authorizableOakPath);
+        if (isAuthorizableTree(tree, UserManager.SEARCH_TYPE_AUTHORIZABLE)) {
+            return tree;
+        } else {
+            return null;
+        }
+    }
+
+    //------------------------------------------------------------< private >---
+    private String getContentID(String authorizableId) throws RepositoryException {
+        return IdentifierManager.generateUUID(authorizableId.toLowerCase());
+    }
+
+    private boolean isAuthorizableTree(Tree tree, int type) {
+        // TODO: check for node type according to the specified type constraint
+        return true;
+    }
+
     private Tree createAuthorizableNode(String authorizableId, boolean isGroup, String intermediatePath)
throws RepositoryException {
         String nodeName = Text.escapeIllegalJcrChars(authorizableId);
         NodeUtil folder = createFolderNodes(authorizableId, nodeName, isGroup, intermediatePath);

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/user/UserProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/user/UserProvider.java?rev=1372942&r1=1372941&r2=1372942&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/user/UserProvider.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/user/UserProvider.java
Tue Aug 14 15:49:55 2012
@@ -35,8 +35,11 @@ public interface UserProvider {
     Tree createGroup(String groupId, String intermediateJcrPath) throws RepositoryException;
 
     @CheckForNull
-    Tree getAuthorizable(String authorizableId);
+    Tree getAuthorizable(String authorizableId) throws RepositoryException;
 
-    @Nonnull
-    String getContentID(String authorizableId) throws RepositoryException;
+    @CheckForNull
+    Tree getAuthorizable(String authorizableId, int authorizableType) throws RepositoryException;
+
+    @CheckForNull
+    Tree getAuthorizableByPath(String authorizableOakPath);
 }
\ No newline at end of file

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/NodeUtil.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/NodeUtil.java?rev=1372942&r1=1372941&r2=1372942&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/NodeUtil.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/NodeUtil.java
Tue Aug 14 15:49:55 2012
@@ -60,7 +60,7 @@ public class NodeUtil {
     public NodeUtil(Tree tree, ContentSession contentSession) {
         this.tree = tree;
         this.factory = contentSession.getCoreValueFactory();
-        this.mapper = new NamePathMapper.Default();
+        this.mapper = NamePathMapper.DEFAULT;
     }
 
     @Nonnull

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionDelegate.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionDelegate.java?rev=1372942&r1=1372941&r2=1372942&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionDelegate.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionDelegate.java
Tue Aug 14 15:49:55 2012
@@ -423,6 +423,10 @@ public class SessionDelegate {
         return observationManager;
     }
 
+    public IdentifierManager getIdManager() {
+        return idManager;
+    }
+
     @Nonnull
     public ContentSession getContentSession() {
         return contentSession;
@@ -439,10 +443,6 @@ public class SessionDelegate {
         return TODO.unimplemented().returnValue(new UserManagerImpl(this, root, null));
     }
 
-    IdentifierManager getIdManager() {
-        return idManager;
-    }
-
     //--------------------------------------------------< SessionNameMapper >---
 
     private class SessionNameMapper extends AbstractNameMapper {

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user/AuthorizableIterator.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user/AuthorizableIterator.java?rev=1372942&r1=1372941&r2=1372942&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user/AuthorizableIterator.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user/AuthorizableIterator.java
Tue Aug 14 15:49:55 2012
@@ -16,22 +16,21 @@
  */
 package org.apache.jackrabbit.oak.jcr.security.user;
 
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.NoSuchElementException;
+import javax.jcr.Property;
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+
 import org.apache.jackrabbit.api.security.user.Authorizable;
 import org.apache.jackrabbit.commons.flat.PropertySequence;
 import org.apache.jackrabbit.oak.api.CoreValue;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import javax.jcr.Node;
-import javax.jcr.Property;
-import javax.jcr.PropertyIterator;
-import javax.jcr.RepositoryException;
-import javax.jcr.Value;
-import java.util.Arrays;
-import java.util.Iterator;
-import java.util.List;
-import java.util.NoSuchElementException;
-
 /**
  * AuthorizableIterator...
  */
@@ -39,7 +38,7 @@ class AuthorizableIterator implements It
 
     private static final Logger log = LoggerFactory.getLogger(AuthorizableIterator.class);
 
-    private final Iterator<?> nodeIds;
+    private final Iterator<?> authorizableIds;
     private final AuthorizableTypePredicate predicate;
     private final UserManagerImpl userManager;
     private final long size;
@@ -54,13 +53,13 @@ class AuthorizableIterator implements It
         this(authorizableNodeIds.iterator(), authorizableType, userManager, -1);  // TODO
calculate size here
     }
 
-    AuthorizableIterator(PropertyIterator authorizableNodeIds, int authorizableType, UserManagerImpl
userManager) {
-        this(authorizableNodeIds, authorizableType, userManager, authorizableNodeIds.getSize());
+    AuthorizableIterator(Collection<String> authorizablePaths, int authorizableType,
UserManagerImpl userManager) {
+        this(authorizablePaths.iterator(), authorizableType, userManager, authorizablePaths.size());
     }
 
-    private AuthorizableIterator(Iterator<?> nodeIds, int authorizableType,
+    private AuthorizableIterator(Iterator<?> authorizableIds, int authorizableType,
                                  UserManagerImpl userManager, long size) {
-        this.nodeIds = nodeIds;
+        this.authorizableIds = authorizableIds;
         this.predicate = new AuthorizableTypePredicate(authorizableType);
         this.userManager = userManager;
         this.size = size;
@@ -96,11 +95,16 @@ class AuthorizableIterator implements It
     }
 
     private Authorizable fetchNext() {
-        while (nodeIds.hasNext()) {
+        while (authorizableIds.hasNext()) {
+            Object next = authorizableIds.next();
             try {
-                String nid = getNodeId(nodeIds.next());
-                Node n = userManager.getSession().getNodeByIdentifier(nid);
-                Authorizable a = userManager.getAuthorizable(n);
+                Authorizable a;
+                if (next instanceof String) {
+                    a = userManager.getAuthorizableByPath(next.toString());
+                } else {
+                    String nid = getNodeId(next);
+                    a = userManager.getAuthorizableByNodeID(nid);
+                }
                 if (a != null && predicate.evaluate(a)) {
                     return a;
                 }
@@ -108,7 +112,6 @@ class AuthorizableIterator implements It
                 log.debug(e.getMessage());
             }
         }
-
         return null;
     }
 
@@ -118,7 +121,7 @@ class AuthorizableIterator implements It
         } else if (o instanceof Value) {
             return ((Value) o).getString();
         } else if (o instanceof Property) {
-            return ((Property) o).getString();
+            return ((Property) o).getParent().getUUID();
         } else {
             return o.toString();
         }

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user/MembershipManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user/MembershipManager.java?rev=1372942&r1=1372941&r2=1372942&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user/MembershipManager.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user/MembershipManager.java
Tue Aug 14 15:49:55 2012
@@ -18,10 +18,11 @@ package org.apache.jackrabbit.oak.jcr.se
 
 import java.util.Collections;
 import java.util.Comparator;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Set;
 import javax.jcr.Node;
-import javax.jcr.PropertyIterator;
 import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
 
@@ -40,6 +41,8 @@ import org.apache.jackrabbit.oak.api.Cor
 import org.apache.jackrabbit.oak.api.CoreValueFactory;
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.Tree;
+import org.apache.jackrabbit.oak.namepath.NamePathMapper;
+import org.apache.jackrabbit.oak.plugins.identifier.IdentifierManager;
 import org.apache.jackrabbit.oak.spi.security.user.UserConstants;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -60,17 +63,24 @@ class MembershipManager implements UserC
     }
 
     Iterator<Group> getMembership(AuthorizableImpl authorizable, boolean includeInherited)
throws RepositoryException {
-        PropertyIterator refs = null;
-        try {
-            String nodeID = authorizable.getContentID();
-            refs = authorizable.getNode().getWeakReferences(null);
-        } catch (RepositoryException e) {
-            log.error("Failed to retrieve membership references of " + authorizable.getID(),
e);
-            // TODO retrieve by traversing
+        Set<String> groupPaths = new HashSet<String>();
+
+        String nodeID = authorizable.getContentID();
+        IdentifierManager idManager = userManager.getSessionDelegate().getIdManager();
+        NamePathMapper mapper = userManager.getSessionDelegate().getNamePathMapper();
+
+        Set<String> refPaths = idManager.getWeakReferences(authorizable.getTree(),
null, NT_REP_GROUP, NT_REP_MEMBERS);
+        for (String propPath : refPaths) {
+            int index = propPath.indexOf('/'+REP_MEMBERS);
+            if (index > 0) {
+                groupPaths.add(mapper.getJcrPath(propPath.substring(0,index)));
+            } else {
+                log.debug("Not a membership reference property " + propPath);
+            }
         }
 
-        if (refs != null) {
-            AuthorizableIterator iterator = new AuthorizableIterator(refs, UserManager.SEARCH_TYPE_GROUP,
userManager);
+        if (!groupPaths.isEmpty()) {
+            AuthorizableIterator iterator = new AuthorizableIterator(groupPaths, UserManager.SEARCH_TYPE_GROUP,
userManager);
             if (includeInherited) {
                 return getAllMembership(iterator);
             } else {

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user/UserManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user/UserManagerImpl.java?rev=1372942&r1=1372941&r2=1372942&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user/UserManagerImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user/UserManagerImpl.java
Tue Aug 14 15:49:55 2012
@@ -21,7 +21,7 @@ import java.security.NoSuchAlgorithmExce
 import java.security.Principal;
 import java.util.Iterator;
 import java.util.List;
-import javax.jcr.ItemNotFoundException;
+import javax.annotation.CheckForNull;
 import javax.jcr.Node;
 import javax.jcr.PathNotFoundException;
 import javax.jcr.PropertyType;
@@ -82,16 +82,9 @@ public class UserManagerImpl implements 
     @Override
     public Authorizable getAuthorizable(String id) throws RepositoryException {
         Authorizable authorizable = null;
-        // TODO: replace
-//        Tree tree = userProvider.getAuthorizable(id);
-//        if (tree != null) {
-//            authorizable = getAuthorizable(tree);
-//        }
-        try {
-            Node node = getSession().getNodeByIdentifier(userProvider.getContentID(id));
-            authorizable = getAuthorizable(node);
-        } catch (ItemNotFoundException e) {
-            log.debug("No authorizable with ID " + id);
+        Tree tree = userProvider.getAuthorizable(id);
+        if (tree != null) {
+            authorizable = getAuthorizable(tree);
         }
         return authorizable;
     }
@@ -104,13 +97,13 @@ public class UserManagerImpl implements 
         Session session = getSession();
         Authorizable authorizable = null;
         if (principal instanceof ItemBasedPrincipal) {
-            String authPath = ((ItemBasedPrincipal) principal).getPath();
-            if (session.nodeExists(authPath)) {
-                Node n = session.getNode(authPath);
-                authorizable = getAuthorizable(n);
-            }
+            String authJcrPath = ((ItemBasedPrincipal) principal).getPath();
+            String oakPath = sessionDelegate.getNamePathMapper().getOakPath(authJcrPath);
+            authorizable = getAuthorizable(userProvider.getAuthorizableByPath(oakPath));
         } else {
             // another Principal implementation.
+            // first try shortcut for cases where principalName equals the ID.
+            // second use a query to find the authorizable by principalName.
             String name = principal.getName();
             Authorizable a = getAuthorizable(name);
             if (a != null && name.equals(a.getPrincipal().getName())) {
@@ -132,18 +125,13 @@ public class UserManagerImpl implements 
      */
     @Override
     public Authorizable getAuthorizableByPath(String path) throws RepositoryException {
-        Session session = getSession();
-        if (session.nodeExists(path)) {
-            return getAuthorizable(session.getNode(path));
-        } else {
-            return null;
-        }
+        String oakPath = sessionDelegate.getOakPathOrThrow(path);
+        return getAuthorizable(userProvider.getAuthorizableByPath(oakPath));
     }
 
     @Override
     public Iterator<Authorizable> findAuthorizables(String relPath, String value) throws
RepositoryException {
-        // TODO : create and execute a query
-        throw new UnsupportedOperationException("Not Implemented");
+        return findAuthorizables(relPath, value, SEARCH_TYPE_AUTHORIZABLE);
     }
 
     @Override
@@ -394,16 +382,26 @@ public class UserManagerImpl implements 
         return membershipManager;
     }
 
-    Authorizable getAuthorizable(Node node) throws RepositoryException {
+    @CheckForNull
+    Authorizable getAuthorizable(Tree tree) throws RepositoryException {
+        if (tree == null) {
+            return null;
+        }
+        Node node = util.getNode(tree);
         if (node.isNodeType(getJcrName(UserConstants.NT_REP_USER))) {
-            return new UserImpl(node, util.getTree(node), this);
+            return new UserImpl(node, tree, this);
         } else if (node.isNodeType(getJcrName(UserConstants.NT_REP_GROUP))) {
-            return new GroupImpl(node, util.getTree(node), this);
+            return new GroupImpl(node, tree, this);
         } else {
             throw new RepositoryException("Unexpected node type " + node.getPrimaryNodeType().getName()
+ ". Expected rep:User or rep:Group.");
         }
     }
 
+    @CheckForNull
+    Authorizable getAuthorizableByNodeID(String identifier) throws RepositoryException {
+        return getAuthorizable(sessionDelegate.getIdManager().getTree(identifier));
+    }
+
     String getJcrName(String oakName) {
         return sessionDelegate.getNamePathMapper().getJcrName(oakName);
     }



Mime
View raw message