jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r1430204 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserQueryManager.java oak-jcr/pom.xml oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/FindAuthorizablesTest.java
Date Tue, 08 Jan 2013 10:44:31 GMT
Author: angela
Date: Tue Jan  8 10:44:30 2013
New Revision: 1430204

URL: http://svn.apache.org/viewvc?rev=1430204&view=rev
Log:
OAK-480 : Authorizable Query

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserQueryManager.java
    jackrabbit/oak/trunk/oak-jcr/pom.xml
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/FindAuthorizablesTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserQueryManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserQueryManager.java?rev=1430204&r1=1430203&r2=1430204&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserQueryManager.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserQueryManager.java
Tue Jan  8 10:44:30 2013
@@ -75,10 +75,8 @@ class UserQueryManager {
 
     @Nonnull
     Iterator<Authorizable> findAuthorizables(String relativePath, String value,
-                                             AuthorizableType authorizableType)
-            throws RepositoryException {
-        String oakPath =  userManager.getNamePathMapper().getOakPath(relativePath);
-        return findAuthorizables(oakPath, value, true, authorizableType);
+                                             AuthorizableType authorizableType) throws RepositoryException
{
+        return findAuthorizables(relativePath, value, true, authorizableType);
     }
 
     /**
@@ -111,6 +109,7 @@ class UserQueryManager {
             Iterator<Authorizable> authorizables = Iterators.transform(result.getRows().iterator(),
new ResultRowToAuthorizable(userManager));
             return Iterators.filter(authorizables, Predicates.<Object>notNull());
         } catch (ParseException e) {
+            log.warn("Invalid user query: " + statement, e);
             throw new RepositoryException(e);
         }
     }
@@ -127,29 +126,28 @@ class UserQueryManager {
         String path;
         String propName;
         String ntName;
-        if (relPath.indexOf('/') == -1) {
+        if (relPath.indexOf('/') == -1 && value != null) {
             // search for properties somewhere below an authorizable node
             path = null;
-            propName = relPath;
+            propName = userManager.getNamePathMapper().getOakName(relPath);
             ntName = null;
         } else {
             // FIXME: proper normalization of the relative path
-            path = (relPath.startsWith("./") ? null : Text.getRelativeParent(relPath, 1));
-            propName = Text.getName(relPath);
+            String oakPath = userManager.getNamePathMapper().getOakPath(relPath);
+            path = Text.getRelativeParent(oakPath, 1);
+            propName = Text.getName(oakPath);
             ntName = getNodeTypeName(type);
         }
 
         stmt.append("//");
-        if (path != null) {
+        if (path != null && !path.isEmpty()) {
             stmt.append(path);
         } else {
             if (ntName != null) {
-                stmt.append("element(*,");
-                stmt.append(ntName);
+                stmt.append("element(*,").append(ntName).append(')');
             } else {
-                stmt.append("element(*");
+                stmt.append("element(*)");
             }
-            stmt.append(')');
         }
 
         if (value != null) {
@@ -176,13 +174,17 @@ class UserQueryManager {
      */
     @Nonnull
     private String getSearchRoot(AuthorizableType type) {
+        String path;
         if (type == AuthorizableType.USER) {
-            return userRoot;
+            path = userRoot;
         } else if (type == AuthorizableType.GROUP) {
-            return groupRoot;
+            path = groupRoot;
         } else {
-            return authorizableRoot;
+            path = authorizableRoot;
         }
+        StringBuilder searchRoot = new StringBuilder();
+        searchRoot.append("/jcr:root").append(path);
+        return searchRoot.toString();
     }
 
     @Nonnull

Modified: jackrabbit/oak/trunk/oak-jcr/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/pom.xml?rev=1430204&r1=1430203&r2=1430204&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/pom.xml (original)
+++ jackrabbit/oak/trunk/oak-jcr/pom.xml Tue Jan  8 10:44:30 2013
@@ -222,12 +222,9 @@
       org.apache.jackrabbit.test.api.observation.AddEventListenerTest#testUUID
       org.apache.jackrabbit.test.api.observation.LockingTest#testAddLockToNode
       org.apache.jackrabbit.test.api.observation.LockingTest#testRemoveLockFromNode
-      org.apache.jackrabbit.oak.jcr.security.user.EveryoneGroupTest#testMembers         
          <!-- findAuthorizables not yet implemented -->
+      org.apache.jackrabbit.oak.jcr.security.user.EveryoneGroupTest#testMembers         
                      <!-- OAK-343 -->
       org.apache.jackrabbit.oak.jcr.security.user.FindAuthorizablesTest#testFindAuthorizableByAddedProperty
   <!-- OAK-343 -->
       org.apache.jackrabbit.oak.jcr.security.user.FindAuthorizablesTest#testFindAuthorizableByRelativePath
    <!-- OAK-343 -->
-      org.apache.jackrabbit.oak.jcr.security.user.FindAuthorizablesTest#testFindUser    
                <!-- findAuthorizables not yet implemented -->
-      org.apache.jackrabbit.oak.jcr.security.user.FindAuthorizablesTest#testFindGroup   
                <!-- findAuthorizables not yet implemented -->
-      org.apache.jackrabbit.oak.jcr.security.user.FindAuthorizablesTest#testFindAuthorizable
            <!-- findAuthorizables not yet implemented -->
       org.apache.jackrabbit.oak.jcr.security.user.UserQueryTest                         
                <!-- OAK-343 -->
       org.apache.jackrabbit.oak.jcr.security.user.UserManagerTest#testGetNewAuthorizable
                <!-- OAK-343 -->
       org.apache.jackrabbit.oak.jcr.security.user.UserManagerTest#testCreateGroupWithExistingPrincipal2
 <!-- OAK-343 -->
@@ -244,9 +241,6 @@
       org.apache.jackrabbit.oak.jcr.security.principal.PrincipalManagerTest#testGroupMembers
            <!-- principal search missing -->
       org.apache.jackrabbit.oak.jcr.security.principal.PrincipalManagerTest#testGroupMembership
         <!-- principal search missing -->
       org.apache.jackrabbit.oak.jcr.security.principal.PrincipalManagerTest#testGetMembersConsistentWithMembership
<!-- principal search missing -->
-      org.apache.jackrabbit.oak.jcr.security.principal.PrincipalManagerTest#testFindPrincipal
           <!-- principal search missing -->
-      org.apache.jackrabbit.oak.jcr.security.principal.PrincipalManagerTest#testFindPrincipalByType
     <!-- principal search missing -->
-      org.apache.jackrabbit.oak.jcr.security.principal.PrincipalManagerTest#testFindPrincipalByTypeAll
  <!-- principal search missing -->
       org.apache.jackrabbit.oak.jcr.security.principal.PrincipalManagerTest#testFindEveryone
            <!-- principal search missing -->
     </known.issues>
   </properties>

Modified: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/FindAuthorizablesTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/FindAuthorizablesTest.java?rev=1430204&r1=1430203&r2=1430204&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/FindAuthorizablesTest.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/FindAuthorizablesTest.java
Tue Jan  8 10:44:30 2013
@@ -154,12 +154,35 @@ public class FindAuthorizablesTest exten
     }
 
     @Test
-    public void testFindUser() throws RepositoryException, NotExecutableException {
+    public void testFindUserInAllUsers() throws RepositoryException, NotExecutableException
{
         User u = null;
         try {
             Principal p = getTestPrincipal();
             String uid = createUserId();
+            u = userMgr.createUser(uid, "pw", p, null);
+            superuser.save();
 
+            boolean found = false;
+            Iterator<Authorizable> it = userMgr.findAuthorizables("./"+UserConstants.REP_PRINCIPAL_NAME,
null, UserManager.SEARCH_TYPE_USER);
+            while (it.hasNext() && !found) {
+                User nu = (User) it.next();
+                found = nu.getID().equals(uid);
+            }
+            assertTrue("Searching for 'null' must find the created user.", found);
+        } finally {
+            if (u != null) {
+                u.remove();
+                superuser.save();
+            }
+        }
+    }
+
+    @Test
+    public void testFindUserInAllUsers2() throws RepositoryException, NotExecutableException
{
+        User u = null;
+        try {
+            Principal p = getTestPrincipal();
+            String uid = createUserId();
             u = userMgr.createUser(uid, "pw", p, null);
             superuser.save();
 
@@ -170,9 +193,50 @@ public class FindAuthorizablesTest exten
                 found = nu.getID().equals(uid);
             }
             assertTrue("Searching for 'null' must find the created user.", found);
+        } finally {
+            if (u != null) {
+                u.remove();
+                superuser.save();
+            }
+        }
+    }
 
-            it = userMgr.findAuthorizables(UserConstants.REP_PRINCIPAL_NAME, p.getName(),
UserManager.SEARCH_TYPE_USER);
-            found = false;
+    @Test
+    public void testFindUserInAllGroups() throws RepositoryException, NotExecutableException
{
+        User u = null;
+        try {
+            Principal p = getTestPrincipal();
+            String uid = createUserId();
+            u = userMgr.createUser(uid, "pw", p, null);
+            superuser.save();
+
+            Iterator<Authorizable> it = userMgr.findAuthorizables(UserConstants.REP_PRINCIPAL_NAME,
null, UserManager.SEARCH_TYPE_GROUP);
+            while (it.hasNext()) {
+                if (it.next().getPrincipal().getName().equals(p.getName())) {
+                    fail("Searching for Groups should never find a user");
+                }
+            }
+        } finally {
+            if (u != null) {
+                u.remove();
+                superuser.save();
+            }
+        }
+    }
+
+    @Test
+    public void testFindUserByPrincipalName() throws RepositoryException, NotExecutableException
{
+        User u = null;
+        try {
+            Principal p = getTestPrincipal();
+            String uid = createUserId();
+
+            u = userMgr.createUser(uid, "pw", p, null);
+            superuser.save();
+
+            boolean found = false;
+
+            Iterator<Authorizable> it = userMgr.findAuthorizables(UserConstants.REP_PRINCIPAL_NAME,
p.getName(), UserManager.SEARCH_TYPE_USER);
             while (it.hasNext() && !found) {
                 User nu = (User) it.next();
                 found = nu.getPrincipal().getName().equals(p.getName());
@@ -183,12 +247,28 @@ public class FindAuthorizablesTest exten
             it = userMgr.findAuthorizables(UserConstants.REP_PRINCIPAL_NAME, p.getName(),
UserManager.SEARCH_TYPE_GROUP);
             assertFalse(it.hasNext());
 
-            it = userMgr.findAuthorizables(UserConstants.REP_PRINCIPAL_NAME, null, UserManager.SEARCH_TYPE_GROUP);
-            while (it.hasNext()) {
-                if (it.next().getPrincipal().getName().equals(p.getName())) {
-                    fail("Searching for Groups should never find a user");
-                }
+        } finally {
+            if (u != null) {
+                u.remove();
+                superuser.save();
             }
+        }
+    }
+
+    @Test
+    public void testFindUserWithGroupType() throws RepositoryException, NotExecutableException
{
+        User u = null;
+        try {
+            Principal p = getTestPrincipal();
+            String uid = createUserId();
+
+            u = userMgr.createUser(uid, "pw", p, null);
+            superuser.save();
+
+            // but search groups should not find anything
+            Iterator<Authorizable> it = userMgr.findAuthorizables(UserConstants.REP_PRINCIPAL_NAME,
p.getName(), UserManager.SEARCH_TYPE_GROUP);
+            assertFalse("Searching for Groups should not find the user", it.hasNext());
+
         } finally {
             if (u != null) {
                 u.remove();
@@ -198,7 +278,7 @@ public class FindAuthorizablesTest exten
     }
 
     @Test
-    public void testFindGroup() throws RepositoryException, NotExecutableException {
+    public void testFindGroupInAllGroups() throws RepositoryException, NotExecutableException
{
         Group gr = null;
         try {
             Principal p = getTestPrincipal();
@@ -212,18 +292,64 @@ public class FindAuthorizablesTest exten
                 found = ng.getPrincipal().getName().equals(p.getName());
             }
             assertTrue("Searching for 'null' must find the created group.", found);
+        } finally {
+            if (gr != null) {
+                gr.remove();
+                superuser.save();
+            }
+        }
+    }
 
-            it = userMgr.findAuthorizables(UserConstants.REP_PRINCIPAL_NAME, p.getName(),
UserManager.SEARCH_TYPE_GROUP);
+    @Test
+    public void testFindGroupByPrinicpalName() throws RepositoryException, NotExecutableException
{
+        Group gr = null;
+        try {
+            Principal p = getTestPrincipal();
+            gr = userMgr.createGroup(p);
+            superuser.save();
+
+            boolean found = false;
+            Iterator<Authorizable> it = userMgr.findAuthorizables(UserConstants.REP_PRINCIPAL_NAME,
p.getName(), UserManager.SEARCH_TYPE_GROUP);
             assertTrue(it.hasNext());
             Group ng = (Group) it.next();
             assertEquals("Searching for principal-name must find the created group.", p.getName(),
ng.getPrincipal().getName());
             assertFalse("Only a single group must be found for a given principal name.",
it.hasNext());
+        } finally {
+            if (gr != null) {
+                gr.remove();
+                superuser.save();
+            }
+        }
+    }
+
+    @Test
+    public void testFindGroupWithUserType() throws RepositoryException, NotExecutableException
{
+        Group gr = null;
+        try {
+            Principal p = getTestPrincipal();
+            gr = userMgr.createGroup(p);
+            superuser.save();
 
-            // but search users should not find anything
-            it = userMgr.findAuthorizables(UserConstants.REP_PRINCIPAL_NAME, p.getName(),
UserManager.SEARCH_TYPE_USER);
+            Iterator<Authorizable> it = userMgr.findAuthorizables(UserConstants.REP_PRINCIPAL_NAME,
p.getName(), UserManager.SEARCH_TYPE_USER);
             assertFalse(it.hasNext());
+        } finally {
+            if (gr != null) {
+                gr.remove();
+                superuser.save();
+            }
+        }
+    }
+
+    @Test
+    public void testFindGroupInAllUsers() throws RepositoryException, NotExecutableException
{
+        Group gr = null;
+        try {
+            Principal p = getTestPrincipal();
+            gr = userMgr.createGroup(p);
+            superuser.save();
 
-            it = userMgr.findAuthorizables(UserConstants.REP_PRINCIPAL_NAME, null, UserManager.SEARCH_TYPE_USER);
+            boolean found = false;
+            Iterator<Authorizable> it = userMgr.findAuthorizables(UserConstants.REP_PRINCIPAL_NAME,
null, UserManager.SEARCH_TYPE_USER);
             while (it.hasNext()) {
                 if (it.next().getPrincipal().getName().equals(p.getName())) {
                     fail("Searching for Users should never find a group");
@@ -238,7 +364,7 @@ public class FindAuthorizablesTest exten
     }
 
     @Test
-    public void testFindAllUsers() throws RepositoryException {
+    public void testFindAllUsersDoesNotContainGroup() throws RepositoryException {
         Iterator<Authorizable> it = userMgr.findAuthorizables(UserConstants.REP_PRINCIPAL_NAME,
null, UserManager.SEARCH_TYPE_USER);
         while (it.hasNext()) {
             assertFalse(it.next().isGroup());
@@ -246,7 +372,7 @@ public class FindAuthorizablesTest exten
     }
 
     @Test
-    public void testFindAllGroups() throws RepositoryException {
+    public void testFindAllGroupsDoesNotContainUser() throws RepositoryException {
         Iterator<Authorizable> it = userMgr.findAuthorizables(UserConstants.REP_PRINCIPAL_NAME,
null, UserManager.SEARCH_TYPE_GROUP);
         while (it.hasNext()) {
             assertTrue(it.next().isGroup());



Mime
View raw message