Search in sources :

Example 1 with PrincipalIterator

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

the class DefaultPrincipalProviderTest method testUnknownUserMemberShip.

// TODO: add tests for 'findPrincipals'
public void testUnknownUserMemberShip() throws RepositoryException {
    Principal userPrincipal = getTestPrincipal();
    PrincipalIterator pit = principalProvider.getGroupMembership(userPrincipal);
    // unknown user must be in 'everyone' group but nothing else
    assertTrue(pit.hasNext());
    assertEquals(EveryonePrincipal.getInstance(), pit.nextPrincipal());
    assertFalse(pit.hasNext());
}
Also used : 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 2 with PrincipalIterator

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

the class DefaultPrincipalProviderTest method testEveryonePrincipal2.

public void testEveryonePrincipal2() throws Exception {
    Group g = null;
    try {
        g = userMgr.createGroup(EveryonePrincipal.NAME);
        save(superuser);
        Principal p = principalProvider.getPrincipal(EveryonePrincipal.NAME);
        assertNotNull(p);
        assertEquals(EveryonePrincipal.getInstance(), p);
        PrincipalIterator pit = principalProvider.findPrincipals(EveryonePrincipal.NAME);
        assertNotNull(pit);
        if (pit.getSize() == -1) {
            assertTrue(pit.hasNext());
            assertEquals(EveryonePrincipal.getInstance(), pit.nextPrincipal());
            assertFalse(pit.hasNext());
        } else {
            assertEquals(1, pit.getSize());
            assertEquals(EveryonePrincipal.getInstance(), pit.nextPrincipal());
        }
    } finally {
        if (g != null) {
            g.remove();
            save(superuser);
        }
    }
}
Also used : Group(org.apache.jackrabbit.api.security.user.Group) 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 3 with PrincipalIterator

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

the class DefaultPrincipalProviderTest method testEveryonePrincipal.

public void testEveryonePrincipal() throws Exception {
    Principal p = principalProvider.getPrincipal(EveryonePrincipal.NAME);
    assertNotNull(p);
    assertEquals(EveryonePrincipal.getInstance(), p);
    PrincipalIterator pit = principalProvider.findPrincipals(EveryonePrincipal.NAME);
    assertNotNull(pit);
    if (pit.getSize() == -1) {
        assertTrue(pit.hasNext());
        assertEquals(EveryonePrincipal.getInstance(), pit.nextPrincipal());
        assertFalse(pit.hasNext());
    } else {
        assertEquals(1, pit.getSize());
        assertEquals(EveryonePrincipal.getInstance(), pit.nextPrincipal());
    }
}
Also used : 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 4 with PrincipalIterator

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

the class NestedGroupTest method testInheritedMembership.

public void testInheritedMembership() throws NotExecutableException, RepositoryException {
    Group gr1 = null;
    Group gr2 = null;
    Group gr3 = null;
    if (!(superuser instanceof JackrabbitSession)) {
        throw new NotExecutableException();
    }
    try {
        gr1 = createGroup(getTestPrincipal());
        gr2 = createGroup(getTestPrincipal());
        gr3 = createGroup(getTestPrincipal());
        assertTrue(addMember(gr1, gr2));
        assertTrue(addMember(gr2, gr3));
        // NOTE: don't test with Group.isMember for not required to detect
        // inherited membership -> rather with PrincipalManager.
        boolean isMember = false;
        PrincipalManager pmgr = ((JackrabbitSession) superuser).getPrincipalManager();
        for (PrincipalIterator it = pmgr.getGroupMembership(gr3.getPrincipal()); it.hasNext() && !isMember; ) {
            isMember = it.nextPrincipal().equals(gr1.getPrincipal());
        }
        assertTrue(isMember);
    } finally {
        if (gr1 != null && gr1.isMember(gr2)) {
            removeMember(gr1, gr2);
        }
        if (gr2 != null && gr2.isMember(gr3)) {
            removeMember(gr2, gr3);
        }
        if (gr1 != null)
            removeGroup(gr1);
        if (gr2 != null)
            removeGroup(gr2);
        if (gr3 != null)
            removeGroup(gr3);
    }
}
Also used : PrincipalManager(org.apache.jackrabbit.api.security.principal.PrincipalManager) NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) PrincipalIterator(org.apache.jackrabbit.api.security.principal.PrincipalIterator) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession)

Example 5 with PrincipalIterator

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

the class AbstractACLTemplateTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    if (!(superuser instanceof JackrabbitSession)) {
        throw new NotExecutableException();
    }
    principalMgr = ((JackrabbitSession) superuser).getPrincipalManager();
    PrincipalIterator it = principalMgr.getPrincipals(PrincipalManager.SEARCH_TYPE_NOT_GROUP);
    if (it.hasNext()) {
        testPrincipal = it.nextPrincipal();
    } else {
        throw new NotExecutableException();
    }
    privilegeMgr = (PrivilegeManagerImpl) ((JackrabbitWorkspace) superuser.getWorkspace()).getPrivilegeManager();
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) PrincipalIterator(org.apache.jackrabbit.api.security.principal.PrincipalIterator) JackrabbitWorkspace(org.apache.jackrabbit.api.JackrabbitWorkspace) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession)

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