Search in sources :

Example 26 with PrincipalManager

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

the class CompositePrincipalConfigurationTest method testMultipleGetPrincipalManager.

@Test
public void testMultipleGetPrincipalManager() {
    addConfiguration(principalConfigurationMock);
    addConfiguration(new TestPrincipalConfiguration());
    PrincipalManager pMgr = getComposite().getPrincipalManager(root, NamePathMapper.DEFAULT);
    assertTrue(pMgr instanceof PrincipalManagerImpl);
}
Also used : PrincipalManager(org.apache.jackrabbit.api.security.principal.PrincipalManager) Test(org.junit.Test) AbstractCompositeConfigurationTest(org.apache.jackrabbit.oak.spi.security.AbstractCompositeConfigurationTest)

Example 27 with PrincipalManager

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

the class NestedGroupTest method testInheritedMembership.

@Test
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) Group(org.apache.jackrabbit.api.security.user.Group) NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) PrincipalIterator(org.apache.jackrabbit.api.security.principal.PrincipalIterator) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession) Test(org.junit.Test)

Aggregations

PrincipalManager (org.apache.jackrabbit.api.security.principal.PrincipalManager)27 Principal (java.security.Principal)16 Test (org.junit.Test)11 JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)9 PrincipalIterator (org.apache.jackrabbit.api.security.principal.PrincipalIterator)9 HashSet (java.util.HashSet)6 RepositoryException (javax.jcr.RepositoryException)6 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)6 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)4 Session (javax.jcr.Session)3 AccessControlPolicy (javax.jcr.security.AccessControlPolicy)3 JackrabbitAccessControlManager (org.apache.jackrabbit.api.security.JackrabbitAccessControlManager)3 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)3 Group (org.apache.jackrabbit.api.security.user.Group)3 NodeImpl (org.apache.jackrabbit.core.NodeImpl)3 PrincipalImpl (org.apache.jackrabbit.core.security.principal.PrincipalImpl)3 AbstractCompositeConfigurationTest (org.apache.jackrabbit.oak.spi.security.AbstractCompositeConfigurationTest)3 EveryonePrincipal (org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal)3 Group (java.security.acl.Group)2 ArrayList (java.util.ArrayList)2