Search in sources :

Example 41 with PrincipalIterator

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

the class DefaultPrincipalProviderTest method testInheritedMemberShip.

public void testInheritedMemberShip() throws RepositoryException, NotExecutableException {
    Principal up = getTestPrincipal();
    User u = null;
    Group gr1 = null;
    Group gr2 = null;
    try {
        u = userMgr.createUser(up.getName(), buildPassword(up));
        gr1 = userMgr.createGroup(getTestPrincipal());
        gr2 = userMgr.createGroup(getTestPrincipal());
        save(superuser);
        gr1.addMember(gr2);
        gr2.addMember(u);
        save(superuser);
        PrincipalIterator it = principalProvider.getGroupMembership(u.getPrincipal());
        while (it.hasNext()) {
            Principal p = it.nextPrincipal();
            if (p.equals(gr1.getPrincipal())) {
                // success return
                return;
            }
        }
        fail("User principal " + up.getName() + " must have inherited group membership for " + gr1.getPrincipal().getName());
    } finally {
        if (gr2 != null && u != null)
            gr2.removeMember(u);
        if (gr1 != null && gr2 != null)
            gr1.removeMember(gr2);
        if (gr1 != null)
            gr1.remove();
        if (gr2 != null)
            gr2.remove();
        if (u != null)
            u.remove();
        save(superuser);
    }
}
Also used : Group(org.apache.jackrabbit.api.security.user.Group) User(org.apache.jackrabbit.api.security.user.User) PrincipalIterator(org.apache.jackrabbit.api.security.principal.PrincipalIterator) EveryonePrincipal(org.apache.jackrabbit.core.security.principal.EveryonePrincipal) TestPrincipal(org.apache.jackrabbit.core.security.TestPrincipal) Principal(java.security.Principal)

Example 42 with PrincipalIterator

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

the class GetGroupPrincipalsTest method runTest.

@Override
public void runTest() throws Exception {
    PrincipalManager principalManager = ((JackrabbitSession) session).getPrincipalManager();
    for (int i = 0; i < 1000; i++) {
        Principal p = principalManager.getPrincipal(principalName);
        PrincipalIterator principals = principalManager.getGroupMembership(p);
    //            while (principals.hasNext()) {
    //                Principal groupPrincipal = principals.nextPrincipal();
    //            }
    }
}
Also used : PrincipalManager(org.apache.jackrabbit.api.security.principal.PrincipalManager) PrincipalIterator(org.apache.jackrabbit.api.security.principal.PrincipalIterator) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession) Principal(java.security.Principal)

Example 43 with PrincipalIterator

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

the class ImpersonationImplTest method testGetImpersonatorsImpersonatorRemoved.

@Test
public void testGetImpersonatorsImpersonatorRemoved() throws Exception {
    Principal p = impersonator.getPrincipal();
    impersonator.remove();
    PrincipalIterator it = impersonation.getImpersonators();
    assertTrue(it.hasNext());
    assertTrue(Iterators.contains(it, p));
}
Also used : PrincipalIterator(org.apache.jackrabbit.api.security.principal.PrincipalIterator) Principal(java.security.Principal) Test(org.junit.Test)

Example 44 with PrincipalIterator

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

the class PrincipalManagerImplTest method assertMembership.

private static void assertMembership(@Nonnull PrincipalManager mgr, int searchType) {
    PrincipalIterator it = mgr.getPrincipals(searchType);
    while (it.hasNext()) {
        Principal p = it.nextPrincipal();
        if (p.equals(EveryonePrincipal.getInstance())) {
            continue;
        }
        boolean atleastEveryone = false;
        for (PrincipalIterator membership = mgr.getGroupMembership(p); membership.hasNext(); ) {
            Principal gr = membership.nextPrincipal();
            assertTrue(isGroup(gr));
            if (gr.equals(EveryonePrincipal.getInstance())) {
                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)

Example 45 with PrincipalIterator

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

the class PrincipalManagerImplTest method testFindPrincipalByTypeAll.

@Test
public void testFindPrincipalByTypeAll() {
    for (Principal pcpl : testPrincipals) {
        PrincipalIterator it = principalMgr.findPrincipals(pcpl.getName(), PrincipalManager.SEARCH_TYPE_ALL);
        assertTrue("findPrincipals does not find principal with filter '" + pcpl.getName() + '\'', Iterators.contains(it, pcpl));
    }
}
Also used : PrincipalIterator(org.apache.jackrabbit.api.security.principal.PrincipalIterator) Principal(java.security.Principal) Test(org.junit.Test)

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