Search in sources :

Example 26 with PrincipalIterator

use of org.apache.jackrabbit.api.security.principal.PrincipalIterator in project jackrabbit-oak by apache.

the class PrincipalManagerTest method testMembership.

private void testMembership(int searchType) {
    PrincipalIterator it = principalMgr.getPrincipals(searchType);
    while (it.hasNext()) {
        Principal p = it.nextPrincipal();
        if (p.equals(everyone)) {
            continue;
        }
        boolean atleastEveryone = false;
        for (PrincipalIterator membership = principalMgr.getGroupMembership(p); membership.hasNext(); ) {
            Principal gr = membership.nextPrincipal();
            assertTrue(isGroup(gr));
            if (gr.equals(everyone)) {
                atleastEveryone = true;
            }
        }
        assertTrue("All principals (except everyone) must be member of the everyone group.", atleastEveryone);
    }
}
Also used : PrincipalIterator(org.apache.jackrabbit.api.security.principal.PrincipalIterator) Principal(java.security.Principal) EveryonePrincipal(org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal)

Example 27 with PrincipalIterator

use of org.apache.jackrabbit.api.security.principal.PrincipalIterator in project jackrabbit-oak by apache.

the class PrincipalManagerTest method testGetPrincipals.

@Test
public void testGetPrincipals() {
    PrincipalIterator it = principalMgr.getPrincipals(PrincipalManager.SEARCH_TYPE_NOT_GROUP);
    while (it.hasNext()) {
        Principal p = it.nextPrincipal();
        assertFalse(isGroup(p));
    }
}
Also used : PrincipalIterator(org.apache.jackrabbit.api.security.principal.PrincipalIterator) Principal(java.security.Principal) EveryonePrincipal(org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal) Test(org.junit.Test) AbstractJCRTest(org.apache.jackrabbit.test.AbstractJCRTest)

Example 28 with PrincipalIterator

use of org.apache.jackrabbit.api.security.principal.PrincipalIterator in project jackrabbit-oak by apache.

the class PrincipalManagerTest method testFindPrincipalByType.

@Test
public void testFindPrincipalByType() {
    for (Principal pcpl : adminPrincipals) {
        if (pcpl.equals(everyone)) {
            // special case covered by another test
            continue;
        }
        assertTrue(principalMgr.hasPrincipal(pcpl.getName()));
        if (isGroup(pcpl)) {
            PrincipalIterator it = principalMgr.findPrincipals(pcpl.getName(), PrincipalManager.SEARCH_TYPE_GROUP);
            // search must find at least a single matching group principal
            assertTrue("findPrincipals does not find principal with filter " + pcpl.getName(), it.hasNext());
        } else {
            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() + "' and type " + PrincipalManager.SEARCH_TYPE_NOT_GROUP, it.hasNext());
        }
    }
}
Also used : PrincipalIterator(org.apache.jackrabbit.api.security.principal.PrincipalIterator) Principal(java.security.Principal) EveryonePrincipal(org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal) Test(org.junit.Test) AbstractJCRTest(org.apache.jackrabbit.test.AbstractJCRTest)

Example 29 with PrincipalIterator

use of org.apache.jackrabbit.api.security.principal.PrincipalIterator in project jackrabbit-oak by apache.

the class PrincipalManagerTest method testFindPrincipalByTypeAll.

@Test
public void testFindPrincipalByTypeAll() {
    for (Principal pcpl : adminPrincipals) {
        if (pcpl.equals(everyone)) {
            // special case covered by another test
            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());
        Set<Principal> s1 = new HashSet<Principal>();
        Set<Principal> s2 = new HashSet<Principal>();
        while (it.hasNext() && it2.hasNext()) {
            s1.add(it.nextPrincipal());
            s2.add(it2.nextPrincipal());
        }
        assertEquals(s1, s2);
        assertFalse(it.hasNext() && it2.hasNext());
    }
}
Also used : PrincipalIterator(org.apache.jackrabbit.api.security.principal.PrincipalIterator) Principal(java.security.Principal) EveryonePrincipal(org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal) HashSet(java.util.HashSet) Test(org.junit.Test) AbstractJCRTest(org.apache.jackrabbit.test.AbstractJCRTest)

Example 30 with PrincipalIterator

use of org.apache.jackrabbit.api.security.principal.PrincipalIterator in project jackrabbit-oak by apache.

the class PrincipalManagerTest method getPrincipals.

private Principal[] getPrincipals(Credentials credentials) throws Exception {
    Set<Principal> principals = new HashSet<Principal>();
    if (credentials instanceof SimpleCredentials) {
        Principal p = principalMgr.getPrincipal(((SimpleCredentials) credentials).getUserID());
        if (p != null) {
            principals.add(p);
            PrincipalIterator principalIterator = principalMgr.getGroupMembership(p);
            while (principalIterator.hasNext()) {
                principals.add(principalIterator.nextPrincipal());
            }
        }
    }
    return principals.toArray(new Principal[principals.size()]);
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) PrincipalIterator(org.apache.jackrabbit.api.security.principal.PrincipalIterator) Principal(java.security.Principal) EveryonePrincipal(org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal) HashSet(java.util.HashSet)

Aggregations

PrincipalIterator (org.apache.jackrabbit.api.security.principal.PrincipalIterator)61 Principal (java.security.Principal)40 Test (org.junit.Test)35 EveryonePrincipal (org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal)15 AbstractJCRTest (org.apache.jackrabbit.test.AbstractJCRTest)11 JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)9 PrincipalManager (org.apache.jackrabbit.api.security.principal.PrincipalManager)9 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)9 ArrayList (java.util.ArrayList)8 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)7 Group (java.security.acl.Group)5 RepositoryException (javax.jcr.RepositoryException)4 Group (org.apache.jackrabbit.api.security.user.Group)4 TestPrincipal (org.apache.jackrabbit.core.security.TestPrincipal)4 EveryonePrincipal (org.apache.jackrabbit.core.security.principal.EveryonePrincipal)4 HashSet (java.util.HashSet)3 Impersonation (org.apache.jackrabbit.api.security.user.Impersonation)3 User (org.apache.jackrabbit.api.security.user.User)3 Session (javax.jcr.Session)2 Subject (javax.security.auth.Subject)2