jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r1431287 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/security/principal/ oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/principal/ oak-core/src/test/java/org/apache/jackrabbit/oak/security/pri...
Date Thu, 10 Jan 2013 11:30:29 GMT
Author: angela
Date: Thu Jan 10 11:30:29 2013
New Revision: 1431287

URL: http://svn.apache.org/viewvc?rev=1431287&view=rev
Log:
OAK-524 : Implement PrincipalManager#getPrincipals(int searchType)
OAK-545 : PrincipalManager#findPrincipal should not search for exact name

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/principal/PrincipalManagerImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/principal/PrincipalProviderImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/principal/CompositePrincipalProvider.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/principal/PrincipalProvider.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/principal/PrincipalProviderImplTest.java
    jackrabbit/oak/trunk/oak-jcr/pom.xml
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/principal/PrincipalManagerTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/principal/PrincipalManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/principal/PrincipalManagerImpl.java?rev=1431287&r1=1431286&r2=1431287&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/principal/PrincipalManagerImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/principal/PrincipalManagerImpl.java
Thu Jan 10 11:30:29 2013
@@ -58,8 +58,7 @@ public class PrincipalManagerImpl implem
 
     @Override
     public PrincipalIterator getPrincipals(int searchType) {
-        // TODO OAK-524
-        throw new UnsupportedOperationException("not implemented (see: OAK-524)");
+        return new PrincipalIteratorAdapter(principalProvider.findPrincipals(searchType));
     }
 
     @Override

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/principal/PrincipalProviderImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/principal/PrincipalProviderImpl.java?rev=1431287&r1=1431286&r2=1431287&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/principal/PrincipalProviderImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/principal/PrincipalProviderImpl.java
Thu Jan 10 11:30:29 2013
@@ -22,12 +22,19 @@ import java.util.Collections;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Set;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
 import javax.jcr.RepositoryException;
 
 import com.google.common.base.Function;
+import com.google.common.base.Predicate;
 import com.google.common.base.Predicates;
 import com.google.common.collect.Iterators;
+import org.apache.jackrabbit.api.security.principal.PrincipalManager;
 import org.apache.jackrabbit.api.security.user.Authorizable;
+import org.apache.jackrabbit.api.security.user.Query;
+import org.apache.jackrabbit.api.security.user.QueryBuilder;
+import org.apache.jackrabbit.api.security.user.User;
 import org.apache.jackrabbit.api.security.user.UserManager;
 import org.apache.jackrabbit.oak.api.Root;
 import org.apache.jackrabbit.oak.namepath.NamePathMapper;
@@ -100,18 +107,32 @@ public class PrincipalProviderImpl imple
     }
 
     @Override
-    public Iterator<? extends Principal> findPrincipals(String nameHint, int searchType)
{
+    public Iterator<? extends Principal> findPrincipals(final String nameHint,
+                                                        final int searchType) {
         try {
-        Iterator<Authorizable> authorizables = userManager.findAuthorizables(UserConstants.REP_PRINCIPAL_NAME,
nameHint, UserManager.SEARCH_TYPE_AUTHORIZABLE);
-        return Iterators.transform(
-                Iterators.filter(authorizables, Predicates.<Object>notNull()),
-                new AuthorizableToPrincipal());
+            Iterator<Authorizable> authorizables = findAuthorizables(nameHint, searchType);
+            Iterator<Principal> principals = Iterators.transform(
+                    Iterators.filter(authorizables, Predicates.<Object>notNull()),
+                    new AuthorizableToPrincipal());
+
+            if (matchesEveryone(nameHint, searchType)) {
+                principals = Iterators.concat(principals, Iterators.singletonIterator(EveryonePrincipal.getInstance()));
+                return Iterators.filter(principals, new EveryonePredicate());
+            } else {
+                return principals;
+            }
         } catch (RepositoryException e) {
             log.debug(e.getMessage());
             return Iterators.emptyIterator();
         }
     }
 
+    @Nonnull
+    @Override
+    public Iterator<? extends Principal> findPrincipals(int searchType) {
+        return findPrincipals(null, searchType);
+    }
+
     //------------------------------------------------------------< private >---
     private Authorizable getAuthorizable(Principal principal) {
         try {
@@ -139,6 +160,51 @@ public class PrincipalProviderImpl imple
         return groupPrincipals;
     }
 
+    private Iterator<Authorizable> findAuthorizables(final @Nullable String nameHint,
+                                                     final int searchType) throws RepositoryException
{
+        Query userQuery = new Query() {
+            @Override
+            public <T> void build(QueryBuilder<T> builder) {
+                builder.setCondition(builder.like('@' +UserConstants.REP_PRINCIPAL_NAME,
buildSearchPattern(nameHint)));
+                builder.setSelector(getAuthorizableClass(searchType));
+            }
+        };
+        return userManager.findAuthorizables(userQuery);
+    }
+
+
+    private static Class<? extends Authorizable> getAuthorizableClass(int searchType)
{
+        switch (searchType) {
+            case PrincipalManager.SEARCH_TYPE_GROUP:
+                return org.apache.jackrabbit.api.security.user.Group.class;
+            case PrincipalManager.SEARCH_TYPE_NOT_GROUP:
+                return User.class;
+            case PrincipalManager.SEARCH_TYPE_ALL:
+                return Authorizable.class;
+            default:
+                throw new IllegalArgumentException("Invalid search type " + searchType);
+
+        }
+    }
+
+    private static String buildSearchPattern(String nameHint) {
+        if (nameHint == null) {
+            return "%";
+        } else {
+            StringBuilder sb = new StringBuilder();
+            sb.append('%');
+            sb.append(nameHint.replace("%", "\\%").replace("_", "\\_"));
+            sb.append('%');
+            return sb.toString();
+        }
+
+    }
+
+    private static boolean matchesEveryone(String nameHint, int searchType) {
+        return searchType != PrincipalManager.SEARCH_TYPE_NOT_GROUP &&
+                (nameHint == null || EveryonePrincipal.NAME.contains(nameHint));
+    }
+
     //--------------------------------------------------------------------------
     /**
      * Function to covert an authorizable tree to a principal.
@@ -156,4 +222,27 @@ public class PrincipalProviderImpl imple
             return null;
         }
     }
+
+    /**
+     * Predicate to make sure the everyone principal is only included once in
+     * the result set.
+     */
+    private final class EveryonePredicate implements Predicate<Principal> {
+        private boolean servedEveryone = false;
+        @Override
+        public boolean apply(@Nullable Principal principal) {
+            String pName = (principal == null) ? null : principal.getName();
+            if (EveryonePrincipal.NAME.equals(pName)) {
+                if (servedEveryone) {
+                    return false;
+                } else {
+                    servedEveryone = true;
+                    return true;
+                }
+            } else {
+                // not everyone
+                return true;
+            }
+        }
+    }
 }
\ No newline at end of file

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/principal/CompositePrincipalProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/principal/CompositePrincipalProvider.java?rev=1431287&r1=1431286&r2=1431287&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/principal/CompositePrincipalProvider.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/principal/CompositePrincipalProvider.java
Thu Jan 10 11:30:29 2013
@@ -73,8 +73,17 @@ public class CompositePrincipalProvider 
         Iterator<? extends Principal>[] iterators = new Iterator[providers.size()];
         int i = 0;
         for (PrincipalProvider provider : providers) {
-            iterators[i++] = provider.findPrincipals(nameHint, searchType);
+            if (nameHint == null) {
+                iterators[i++] = provider.findPrincipals(searchType);
+            } else {
+                iterators[i++] = provider.findPrincipals(nameHint, searchType);
+            }
         }
         return Iterators.concat(iterators);
     }
+
+    @Override
+    public Iterator<? extends Principal> findPrincipals(int searchType) {
+        return findPrincipals(null, searchType);
+    }
 }
\ No newline at end of file

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/principal/PrincipalProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/principal/PrincipalProvider.java?rev=1431287&r1=1431286&r2=1431287&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/principal/PrincipalProvider.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/security/principal/PrincipalProvider.java
Thu Jan 10 11:30:29 2013
@@ -90,4 +90,18 @@ public interface PrincipalProvider {
      */
     @Nonnull
     Iterator<? extends Principal> findPrincipals(String nameHint, int searchType);
+
+
+    /**
+     * Find all principals that match the search type.
+     *
+     * @param searchType Limit the search to certain types of principals. Valid
+     * values are any of
+     * <ul><li>{@link org.apache.jackrabbit.api.security.principal.PrincipalManager#SEARCH_TYPE_ALL}</li></ul>
+     * <ul><li>{@link org.apache.jackrabbit.api.security.principal.PrincipalManager#SEARCH_TYPE_NOT_GROUP}</li></ul>
+     * <ul><li>{@link org.apache.jackrabbit.api.security.principal.PrincipalManager#SEARCH_TYPE_GROUP}</li></ul>
+     * @return An iterator of principals.
+     */
+    @Nonnull
+    Iterator<? extends Principal> findPrincipals(int searchType);
 }
\ No newline at end of file

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/principal/PrincipalProviderImplTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/principal/PrincipalProviderImplTest.java?rev=1431287&r1=1431286&r2=1431287&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/principal/PrincipalProviderImplTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/principal/PrincipalProviderImplTest.java
Thu Jan 10 11:30:29 2013
@@ -17,17 +17,29 @@
 package org.apache.jackrabbit.oak.security.principal;
 
 import java.security.Principal;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
 import java.util.Set;
 
+import org.apache.jackrabbit.api.security.principal.PrincipalManager;
+import org.apache.jackrabbit.api.security.user.Group;
+import org.apache.jackrabbit.api.security.user.User;
 import org.apache.jackrabbit.api.security.user.UserManager;
 import org.apache.jackrabbit.oak.api.Root;
 import org.apache.jackrabbit.oak.namepath.NamePathMapper;
 import org.apache.jackrabbit.oak.security.AbstractSecurityTest;
 import org.apache.jackrabbit.oak.spi.security.principal.AdminPrincipal;
 import org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal;
+import org.apache.jackrabbit.oak.spi.security.principal.PrincipalProvider;
 import org.apache.jackrabbit.oak.spi.security.user.UserConfiguration;
+import org.junit.Ignore;
 import org.junit.Test;
 
+import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
@@ -37,12 +49,21 @@ import static org.junit.Assert.assertTru
  */
 public class PrincipalProviderImplTest extends AbstractSecurityTest {
 
+    private Root root;
+    private UserConfiguration userConfig;
+    private PrincipalProvider principalProvider;
+
+    @Override
+    public void before() throws Exception {
+        super.before();
+
+        root = admin.getLatestRoot();
+        userConfig = getSecurityProvider().getUserConfiguration();
+        principalProvider = new PrincipalProviderImpl(root, userConfig, NamePathMapper.DEFAULT);
+    }
+
     @Test
     public void testGetPrincipals() throws Exception {
-        Root root = admin.getLatestRoot();
-        PrincipalProviderImpl principalProvider =
-                new PrincipalProviderImpl(root, getSecurityProvider().getUserConfiguration(),
NamePathMapper.DEFAULT);
-
         String adminId = admin.getAuthInfo().getUserID();
         Set<? extends Principal> principals = principalProvider.getPrincipals(adminId);
 
@@ -62,17 +83,12 @@ public class PrincipalProviderImplTest e
 
     @Test
     public void testEveryone() throws Exception {
-        Root root = admin.getLatestRoot();
-        UserConfiguration config = getSecurityProvider().getUserConfiguration();
-
-        PrincipalProviderImpl principalProvider = new PrincipalProviderImpl(root, config,
NamePathMapper.DEFAULT);
-
         Principal everyone = principalProvider.getPrincipal(EveryonePrincipal.NAME);
         assertTrue(everyone instanceof EveryonePrincipal);
 
-        org.apache.jackrabbit.api.security.user.Group everyoneGroup = null;
+        Group everyoneGroup = null;
         try {
-            UserManager userMgr = config.getUserManager(root, NamePathMapper.DEFAULT);
+            UserManager userMgr = userConfig.getUserManager(root, NamePathMapper.DEFAULT);
             everyoneGroup = userMgr.createGroup(EveryonePrincipal.NAME);
             root.commit();
 
@@ -85,4 +101,154 @@ public class PrincipalProviderImplTest e
             }
         }
     }
+
+    @Ignore("OAK-545") // TODO: OAK-545
+    @Test
+    public void testFindUserPrincipal() throws Exception {
+        User testUser = null;
+        try {
+            UserManager userMgr = userConfig.getUserManager(root, NamePathMapper.DEFAULT);
+            testUser = userMgr.createUser("TestUser", "pw");
+            root.commit();
+
+            String principalName = testUser.getPrincipal().getName();
+            assertNotNull(principalProvider.getPrincipal(principalName));
+
+            List<String> nameHints = new ArrayList<String>();
+            nameHints.add("TestUser");
+            nameHints.add("Test");
+            nameHints.add("User");
+            nameHints.add("stUs");
+
+            assertResult(principalProvider, nameHints, principalName, PrincipalManager.SEARCH_TYPE_NOT_GROUP,
true);
+            assertResult(principalProvider, nameHints, principalName, PrincipalManager.SEARCH_TYPE_ALL,
true);
+            assertResult(principalProvider, nameHints, principalName, PrincipalManager.SEARCH_TYPE_GROUP,
false);
+        } finally {
+            if (testUser != null) {
+                testUser.remove();
+                root.commit();
+            }
+        }
+    }
+
+    @Ignore("OAK-545") // TODO: OAK-545
+    @Test
+    public void testFindGroupPrincipal() throws Exception {
+        Group testGroup = null;
+        try {
+            UserManager userMgr = userConfig.getUserManager(root, NamePathMapper.DEFAULT);
+            testGroup = userMgr.createGroup("TestGroup");
+            root.commit();
+
+            String principalName = testGroup.getPrincipal().getName();
+            assertNotNull(principalProvider.getPrincipal(principalName));
+
+            List<String> nameHints = new ArrayList<String>();
+            nameHints.add("TestGroup");
+            nameHints.add("Test");
+            nameHints.add("Group");
+            nameHints.add("stGr");
+
+            assertResult(principalProvider, nameHints, principalName, PrincipalManager.SEARCH_TYPE_GROUP,
true);
+            assertResult(principalProvider, nameHints, principalName, PrincipalManager.SEARCH_TYPE_ALL,
true);
+            assertResult(principalProvider, nameHints, principalName, PrincipalManager.SEARCH_TYPE_NOT_GROUP,
false);
+        } finally {
+            if (testGroup != null) {
+                testGroup.remove();
+                root.commit();
+            }
+        }
+    }
+
+    @Test
+    public void testFindEveryone() {
+        assertNotNull(principalProvider.getPrincipal(EveryonePrincipal.NAME));
+
+        Map<Integer, Boolean> tests = new HashMap<Integer, Boolean>();
+        tests.put(PrincipalManager.SEARCH_TYPE_ALL, Boolean.TRUE);
+        tests.put(PrincipalManager.SEARCH_TYPE_GROUP, Boolean.TRUE);
+        tests.put(PrincipalManager.SEARCH_TYPE_NOT_GROUP, Boolean.FALSE);
+
+        for (Integer searchType : tests.keySet()) {
+            boolean found = false;
+            Iterator<? extends Principal> it = principalProvider.findPrincipals(EveryonePrincipal.NAME,
searchType);
+            while (it.hasNext()) {
+                Principal p = it.next();
+                if (p.getName().equals(EveryonePrincipal.NAME)) {
+                    found = true;
+                }
+            }
+            Boolean expected = tests.get(searchType);
+            assertEquals(expected.booleanValue(), found);
+
+        }
+    }
+
+    @Test
+    public void testFindEveryoneHint() {
+        assertNotNull(principalProvider.getPrincipal(EveryonePrincipal.NAME));
+
+        List<String> nameHints = new ArrayList<String>();
+        nameHints.add("everyone");
+        nameHints.add("every");
+        nameHints.add("one");
+        nameHints.add("very");
+
+        assertResult(principalProvider, nameHints, EveryonePrincipal.NAME, PrincipalManager.SEARCH_TYPE_ALL,
true);
+        assertResult(principalProvider, nameHints, EveryonePrincipal.NAME, PrincipalManager.SEARCH_TYPE_GROUP,
true);
+        assertResult(principalProvider, nameHints, EveryonePrincipal.NAME, PrincipalManager.SEARCH_TYPE_NOT_GROUP,
false);
+    }
+
+    @Ignore("OAK-545") // TODO: OAK-545
+    @Test
+    public void testFindWithoutHint() throws Exception {
+        User testUser = null;
+        Group testGroup = null;
+        try {
+            UserManager userMgr = userConfig.getUserManager(root, NamePathMapper.DEFAULT);
+            testUser = userMgr.createUser("TestUser", "pw");
+            testGroup = userMgr.createGroup("TestGroup");
+
+            root.commit();
+
+            Set<String> resultNames = new HashSet<String>();
+            Iterator<? extends Principal> principals = principalProvider.findPrincipals(PrincipalManager.SEARCH_TYPE_ALL);
+            while (principals.hasNext()) {
+                resultNames.add(principals.next().getName());
+            }
+
+            assertTrue(resultNames.contains(EveryonePrincipal.NAME));
+            assertTrue(resultNames.contains("TestUser"));
+            assertTrue(resultNames.contains("TestGroup"));
+
+        } finally {
+            if (testUser != null) {
+                testUser.remove();
+            }
+            if (testGroup != null) {
+                testGroup.remove();
+            }
+            root.commit();
+        }
+    }
+
+    private static void assertResult(PrincipalProvider principalProvider,
+                                     List<String> nameHints, String expectedName,
+                                     int searchType, boolean toBeFound) {
+        for (String nameHint : nameHints) {
+            Iterator<? extends Principal> result = principalProvider.findPrincipals(nameHint,
searchType);
+            boolean found = false;
+            while (result.hasNext()) {
+                Principal p = result.next();
+                if (p.getName().equals(expectedName)) {
+                    found = true;
+                }
+            }
+            if (toBeFound) {
+                assertTrue("Expected principal to be found by name hint " + expectedName,
found);
+            } else {
+                assertFalse("Expected principal NOT to be found by name hint " + expectedName,
found);
+            }
+        }
+    }
 }
\ No newline at end of file

Modified: jackrabbit/oak/trunk/oak-jcr/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/pom.xml?rev=1431287&r1=1431286&r2=1431287&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/pom.xml (original)
+++ jackrabbit/oak/trunk/oak-jcr/pom.xml Thu Jan 10 11:30:29 2013
@@ -235,13 +235,9 @@
       org.apache.jackrabbit.oak.jcr.security.user.GroupTest#testInheritedMembers        
                <!-- OAK-343 -->
       org.apache.jackrabbit.oak.jcr.security.user.GroupTest#testCyclicGroups            
                <!-- OAK-343 -->
       org.apache.jackrabbit.oak.jcr.security.user.AuthorizableTest#testRemoveListedAuthorizable
         <!-- OAK-343 -->
-      org.apache.jackrabbit.oak.jcr.security.principal.PrincipalManagerTest#testGetPrincipals
           <!-- principal search missing -->
-      org.apache.jackrabbit.oak.jcr.security.principal.PrincipalManagerTest#testGetGroupPrincipals
      <!-- principal search missing -->
-      org.apache.jackrabbit.oak.jcr.security.principal.PrincipalManagerTest#testGetAllPrincipals
        <!-- principal search missing -->
-      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#testFindEveryone
            <!-- principal search missing -->
+      org.apache.jackrabbit.oak.jcr.security.principal.PrincipalManagerTest#testFindPrincipal
           <!-- OAK-545 -->
+      org.apache.jackrabbit.oak.jcr.security.principal.PrincipalManagerTest#testFindPrincipalByType
     <!-- OAK-545 -->
+      org.apache.jackrabbit.oak.jcr.security.principal.PrincipalManagerTest#testFindPrincipalByTypeAll
  <!-- OAK-545 -->
     </known.issues>
   </properties>
 

Modified: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/principal/PrincipalManagerTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/principal/PrincipalManagerTest.java?rev=1431287&r1=1431286&r2=1431287&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/principal/PrincipalManagerTest.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/principal/PrincipalManagerTest.java
Thu Jan 10 11:30:29 2013
@@ -259,9 +259,12 @@ public class PrincipalManagerTest extend
             if (pcpl.equals(everyone)) {
                 continue;
             }
+
+            assertTrue(principalMgr.hasPrincipal(pcpl.getName()));
+
             PrincipalIterator it = principalMgr.findPrincipals(pcpl.getName());
             // search must find at least a single principal
-            assertTrue("findPrincipals does not find principal with filter " + pcpl.getName(),
it.hasNext());
+            assertTrue("findPrincipals does not find principal with filter '" + pcpl.getName()
+ '\'', it.hasNext());
         }
     }
 
@@ -273,6 +276,8 @@ public class PrincipalManagerTest extend
                 continue;
             }
 
+            assertTrue(principalMgr.hasPrincipal(pcpl.getName()));
+
             if (isGroup(pcpl)) {
                 PrincipalIterator it = principalMgr.findPrincipals(pcpl.getName(),
                         PrincipalManager.SEARCH_TYPE_GROUP);
@@ -282,7 +287,7 @@ public class PrincipalManagerTest extend
                 PrincipalIterator it = principalMgr.findPrincipals(pcpl.getName(),
                         PrincipalManager.SEARCH_TYPE_NOT_GROUP);
                 // search must find at least a single matching non-group principal
-                assertTrue("findPrincipals does not find principal with filter " + pcpl.getName(),
it.hasNext());
+                assertTrue("findPrincipals does not find principal with filter '" + pcpl.getName()
+ "' and type " + PrincipalManager.SEARCH_TYPE_NOT_GROUP, it.hasNext());
             }
         }
     }
@@ -295,9 +300,14 @@ public class PrincipalManagerTest extend
                 continue;
             }
 
+            assertTrue(principalMgr.hasPrincipal(pcpl.getName()));
+
             PrincipalIterator it = principalMgr.findPrincipals(pcpl.getName(), PrincipalManager.SEARCH_TYPE_ALL);
             PrincipalIterator it2 = principalMgr.findPrincipals(pcpl.getName());
 
+            assertTrue("Principal "+ pcpl.getName() + " not found", it.hasNext());
+            assertTrue("Principal "+ pcpl.getName() + " not found", it2.hasNext());
+
             // both search must reveal the same result and size
             assertTrue(it.getSize() == it2.getSize());
 
@@ -316,6 +326,7 @@ public class PrincipalManagerTest extend
     @Test
     public void testFindEveryone() {
         Principal everyone = principalMgr.getEveryone();
+        assertTrue(principalMgr.hasPrincipal(everyone.getName()));
 
         boolean containedInResult = false;
 



Mime
View raw message