jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1378984 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserProviderImpl.java oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user/UserManagerImpl.java
Date Thu, 30 Aug 2012 15:15:01 GMT
Author: jukka
Date: Thu Aug 30 15:15:01 2012
New Revision: 1378984

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

Fixes as suggested by Chetan Mehrotra

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserProviderImpl.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/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=1378984&r1=1378983&r2=1378984&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
Thu Aug 30 15:15:01 2012
@@ -20,7 +20,6 @@ import java.security.Principal;
 import java.text.ParseException;
 import java.util.Collections;
 import java.util.Iterator;
-import java.util.Map;
 import javax.jcr.RepositoryException;
 import javax.jcr.nodetype.ConstraintViolationException;
 import javax.jcr.query.Query;
@@ -30,6 +29,7 @@ import org.apache.jackrabbit.oak.api.Con
 import org.apache.jackrabbit.oak.api.CoreValue;
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.Result;
+import org.apache.jackrabbit.oak.api.ResultRow;
 import org.apache.jackrabbit.oak.api.Root;
 import org.apache.jackrabbit.oak.api.Tree;
 import org.apache.jackrabbit.oak.namepath.NamePathMapper;
@@ -190,32 +190,31 @@ class UserProviderImpl extends Authoriza
 
     @Override
     public Tree getAuthorizableByPrincipal(Principal principal) {
-        Tree authorizableTree = null;
         if (principal instanceof TreeBasedPrincipal) {
-            authorizableTree = root.getTree(((TreeBasedPrincipal) principal).getOakPath());
-        } else {
-            // NOTE: in contrast to JR2 the extra shortcut for ID==principalName
-            // can be omitted as principals names are stored in user defined
-            // index as well.
-            try {
-                CoreValue bindValue = valueFactory.createValue(principal.getName());
-                Map<String, CoreValue> bindings = Collections.singletonMap("principalName",
bindValue);
-                String stmt = "SELECT * FROM [rep:Authorizable] WHERE [rep:principalName]
= $principalName";
-                Result result = queryEngine.executeQuery(stmt,
-                        Query.JCR_SQL2, 1, 0,
-                        Collections.singletonMap("principalName", bindValue),
-                        new NamePathMapper.Default());
-
-                Iterator rows = result.getRows().iterator();
-                if (rows.hasNext()) {
-                    String path = rows.next().toString();
-                    authorizableTree = root.getTree(path);
-                }
-            } catch (ParseException ex) {
-                log.error("query failed", ex);
+            return root.getTree(((TreeBasedPrincipal) principal).getOakPath());
+        }
+
+        // NOTE: in contrast to JR2 the extra shortcut for ID==principalName
+        // can be omitted as principals names are stored in user defined
+        // index as well.
+        try {
+            CoreValue bindValue = valueFactory.createValue(principal.getName());
+            String stmt = "SELECT * FROM [rep:Authorizable] WHERE [rep:principalName] = $principalName";
+            Result result = queryEngine.executeQuery(stmt,
+                    Query.JCR_SQL2, 1, 0,
+                    Collections.singletonMap("principalName", bindValue),
+                    new NamePathMapper.Default());
+
+            Iterator<? extends ResultRow> rows = result.getRows().iterator();
+            if (rows.hasNext()) {
+                String path = rows.next().getPath();
+                return root.getTree(path);
             }
+        } catch (ParseException ex) {
+            log.error("query failed", ex);
         }
-        return authorizableTree;
+
+        return null;
     }
 
     @Override

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=1378984&r1=1378983&r2=1378984&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 30 15:15:01 2012
@@ -142,8 +142,10 @@ public class UserManagerImpl implements 
         checkValidID(userID);
         checkValidPrincipal(principal, false);
 
-        String oakPath = namePathMapper.getOakPath(intermediatePath);
-        Tree userTree = getUserProvider().createUser(userID, intermediatePath);
+        if (intermediatePath != null) {
+            intermediatePath = namePathMapper.getOakPath(intermediatePath);
+        }
+        Tree userTree = userProvider.createUser(userID, intermediatePath);
         setPrincipal(userTree, principal);
         setPassword(userTree, password, true);
 
@@ -180,8 +182,10 @@ public class UserManagerImpl implements 
         checkValidID(groupID);
         checkValidPrincipal(principal, true);
 
-        String oakPath = namePathMapper.getOakPath(intermediatePath);
-        Tree groupTree = getUserProvider().createGroup(groupID, oakPath);
+        if (intermediatePath != null) {
+            intermediatePath = namePathMapper.getOakPath(intermediatePath);
+        }
+        Tree groupTree = getUserProvider().createGroup(groupID, intermediatePath);
         setPrincipal(groupTree, principal);
 
         Group group = new GroupImpl(groupTree, this);



Mime
View raw message