Search in sources :

Example 51 with PrincipalIterator

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

the class PrincipalManagerTest method testGetAllPrincipals.

@Test
public void testGetAllPrincipals() {
    PrincipalIterator it = principalMgr.getPrincipals(PrincipalManager.SEARCH_TYPE_ALL);
    while (it.hasNext()) {
        Principal p = it.nextPrincipal();
        assertTrue(principalMgr.hasPrincipal(p.getName()));
        assertEquals(principalMgr.getPrincipal(p.getName()), 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 52 with PrincipalIterator

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

the class PrincipalManagerTest method testMembers.

@Test
public void testMembers() {
    PrincipalIterator it = principalMgr.getPrincipals(PrincipalManager.SEARCH_TYPE_ALL);
    while (it.hasNext()) {
        Principal p = it.nextPrincipal();
        if (p.equals(principalMgr.getEveryone())) {
            continue;
        }
        if (isGroup(p)) {
            Enumeration<? extends Principal> en = ((java.security.acl.Group) p).members();
            while (en.hasMoreElements()) {
                Principal memb = en.nextElement();
                assertTrue(principalMgr.hasPrincipal(memb.getName()));
            }
        }
    }
}
Also used : Group(java.security.acl.Group) 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 53 with PrincipalIterator

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

the class PrincipalManagerTest method testEveryoneGroupMembership.

@Test
public void testEveryoneGroupMembership() {
    Principal everyone = EveryonePrincipal.getInstance();
    for (PrincipalIterator membership = principalMgr.getGroupMembership(everyone); membership.hasNext(); ) {
        Principal gr = membership.nextPrincipal();
        assertTrue(isGroup(gr));
        if (gr.equals(everyone)) {
            fail("Everyone must never be a member of the EveryOne group.");
        }
    }
}
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 54 with PrincipalIterator

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

the class PrincipalManagerTest method testGetMembersConsistentWithMembership.

@Test
public void testGetMembersConsistentWithMembership() {
    Principal everyone = principalMgr.getEveryone();
    PrincipalIterator it = principalMgr.getPrincipals(PrincipalManager.SEARCH_TYPE_GROUP);
    while (it.hasNext()) {
        Principal p = it.nextPrincipal();
        if (p.equals(everyone)) {
            continue;
        }
        assertTrue(isGroup(p));
        Enumeration<? extends Principal> members = ((java.security.acl.Group) p).members();
        while (members.hasMoreElements()) {
            Principal memb = members.nextElement();
            Principal group = null;
            PrincipalIterator mship = principalMgr.getGroupMembership(memb);
            while (mship.hasNext() && group == null) {
                Principal gr = mship.nextPrincipal();
                if (p.equals(gr)) {
                    group = gr;
                }
            }
            assertNotNull("Group member " + memb.getName() + "does not reveal group upon getGroupMembership", p.getName());
        }
    }
}
Also used : Group(java.security.acl.Group) 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 55 with PrincipalIterator

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

the class PrincipalManagerTest method testFindPrincipal.

@Test
public void testFindPrincipal() {
    for (Principal pcpl : adminPrincipals) {
        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());
    }
}
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)

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