jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r1376479 - /jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user/UserManagerImpl.java
Date Thu, 23 Aug 2012 13:26:09 GMT
Author: angela
Date: Thu Aug 23 13:26:08 2012
New Revision: 1376479

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

Modified:
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user/UserManagerImpl.java

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=1376479&r1=1376478&r2=1376479&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
Thu Aug 23 13:26:08 2012
@@ -21,7 +21,6 @@ import java.security.NoSuchAlgorithmExce
 import java.security.Principal;
 import java.util.Iterator;
 import javax.annotation.CheckForNull;
-import javax.jcr.Node;
 import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
@@ -40,6 +39,7 @@ import org.apache.jackrabbit.oak.namepat
 import org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal;
 import org.apache.jackrabbit.oak.spi.security.user.MembershipProvider;
 import org.apache.jackrabbit.oak.spi.security.user.PasswordUtility;
+import org.apache.jackrabbit.oak.spi.security.user.Type;
 import org.apache.jackrabbit.oak.spi.security.user.UserConfig;
 import org.apache.jackrabbit.oak.spi.security.user.UserConstants;
 import org.apache.jackrabbit.oak.spi.security.user.UserProvider;
@@ -112,8 +112,11 @@ public class UserManagerImpl implements 
 
     @Override
     public Iterator<Authorizable> findAuthorizables(String relPath, String value, int
searchType) throws RepositoryException {
-        // TODO : create and execute a query
-        throw new UnsupportedOperationException("Not Implemented");
+        String[] oakPaths =  new String[] {namePathMapper.getOakPath(relPath)};
+        Type authorizableType = getAuthorizableType(searchType);
+        Iterator<Tree> result = userProvider.findAuthorizables(oakPaths, value, null,
true, Long.MAX_VALUE, authorizableType);
+
+        return AuthorizableIterator.create(result, this);
     }
 
     @Override
@@ -139,11 +142,12 @@ public class UserManagerImpl implements 
         checkValidID(userID);
         checkValidPrincipal(principal, false);
 
+        String oakPath = namePathMapper.getOakPath(intermediatePath);
         Tree userTree = getUserProvider().createUser(userID, intermediatePath);
         setPrincipal(userTree, principal);
         setPassword(userTree, password, true);
 
-        User user = new UserImpl(getNode(userTree), userTree, this);
+        User user = new UserImpl(userTree, this);
         onCreate(user, password);
 
         log.debug("User created: " + userID);
@@ -176,10 +180,11 @@ public class UserManagerImpl implements 
         checkValidID(groupID);
         checkValidPrincipal(principal, true);
 
-        Tree groupTree = getUserProvider().createGroup(groupID, intermediatePath);
+        String oakPath = namePathMapper.getOakPath(intermediatePath);
+        Tree groupTree = getUserProvider().createGroup(groupID, oakPath);
         setPrincipal(groupTree, principal);
 
-        Group group = new GroupImpl(getNode(groupTree), groupTree, this);
+        Group group = new GroupImpl(groupTree, this);
         onCreate(group);
 
         log.debug("Group created: " + groupID);
@@ -331,24 +336,15 @@ public class UserManagerImpl implements 
         if (tree == null) {
             return null;
         }
-        Node node = getNode(tree);
-        if (node.isNodeType(getJcrName(UserConstants.NT_REP_USER))) {
-            return new UserImpl(node, tree, this);
-        } else if (node.isNodeType(getJcrName(UserConstants.NT_REP_GROUP))) {
-            return new GroupImpl(node, tree, this);
+        if (userProvider.isAuthorizableType(tree, Type.USER)) {
+            return new UserImpl(tree, this);
+        } else if (userProvider.isAuthorizableType(tree, Type.GROUP)) {
+            return new GroupImpl(tree, this);
         } else {
-            throw new RepositoryException("Unexpected node type " + node.getPrimaryNodeType().getName()
+ ". Expected rep:User or rep:Group.");
+            throw new RepositoryException("Not a user or group tree " + tree.getPath() +
".");
         }
     }
 
-    String getJcrName(String oakName) {
-        return namePathMapper.getJcrName(oakName);
-    }
-
-    private Node getNode(Tree tree) throws RepositoryException {
-        return session.getNode(namePathMapper.getJcrPath(tree.getPath()));
-    }
-
     private void checkValidID(String ID) throws RepositoryException {
         if (ID == null || ID.length() == 0) {
             throw new IllegalArgumentException("Invalid ID " + ID);
@@ -365,4 +361,17 @@ public class UserManagerImpl implements 
             throw new IllegalArgumentException("'everyone' is a reserved group principal
name.");
         }
     }
+
+    private static Type getAuthorizableType(int searchType) {
+        switch (searchType) {
+            case UserManager.SEARCH_TYPE_USER:
+                return Type.USER;
+            case UserManager.SEARCH_TYPE_GROUP:
+                return Type.GROUP;
+            case UserManager.SEARCH_TYPE_AUTHORIZABLE:
+                return Type.AUTHORIZABLE;
+            default:
+                throw new IllegalArgumentException("Invalid search type " + searchType);
+        }
+    }
 }
\ No newline at end of file



Mime
View raw message