Search in sources :

Example 11 with GroupPrincipal

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

the class ExternalGroupPrincipalTest method testIsMemberLocalUser.

@Test
public void testIsMemberLocalUser() throws Exception {
    GroupPrincipal principal = getGroupPrincipal();
    assertFalse(principal.isMember(getTestUser().getPrincipal()));
    assertFalse(principal.isMember(new PrincipalImpl(getTestUser().getPrincipal().getName())));
}
Also used : GroupPrincipal(org.apache.jackrabbit.api.security.principal.GroupPrincipal) PrincipalImpl(org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl) Test(org.junit.Test)

Example 12 with GroupPrincipal

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

the class L3_EveryoneTest method testEveryoneAsAuthorizableGroup.

public void testEveryoneAsAuthorizableGroup() throws RepositoryException {
    // EXERCISE: create an authorizable that corresponds to the everyone principal.
    org.apache.jackrabbit.api.security.user.Group everyoneAuthorizable = null;
    superuser.save();
    try {
        GroupPrincipal everyone = (GroupPrincipal) principalManager.getEveryone();
        assertEquals(everyone, everyoneAuthorizable.getPrincipal());
    // EXERCISE: verify that the everyone principal is still a dynamic group
    // EXERCISE: test if the dyanmic nature also applies to the authorizable
    } finally {
        if (everyoneAuthorizable != null) {
            everyoneAuthorizable.remove();
            superuser.save();
        }
    }
}
Also used : GroupPrincipal(org.apache.jackrabbit.api.security.principal.GroupPrincipal)

Example 13 with GroupPrincipal

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

the class L3_EveryoneTest method testEveryoneIsMemberofEveryone.

public void testEveryoneIsMemberofEveryone() throws RepositoryException {
    GroupPrincipal everyone = (GroupPrincipal) principalManager.getEveryone();
    PrincipalIterator it = principalManager.getPrincipals(PrincipalManager.SEARCH_TYPE_ALL);
    // EXERCISE: discuss the dynamic nature of the everyone group principal
    while (it.hasNext()) {
        Principal principal = it.nextPrincipal();
        if (everyone.equals(principal)) {
            assertFalse(everyone.isMember(principal));
        } else {
            assertTrue(everyone.isMember(principal));
        }
    }
}
Also used : GroupPrincipal(org.apache.jackrabbit.api.security.principal.GroupPrincipal) PrincipalIterator(org.apache.jackrabbit.api.security.principal.PrincipalIterator) Principal(java.security.Principal) GroupPrincipal(org.apache.jackrabbit.api.security.principal.GroupPrincipal)

Example 14 with GroupPrincipal

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

the class PrincipalManagerImplTest method testAllMembersKnown.

@Test
public void testAllMembersKnown() {
    for (Principal p : testPrincipals) {
        if (isGroup(p)) {
            Enumeration<? extends Principal> en = ((GroupPrincipal) p).members();
            while (en.hasMoreElements()) {
                Principal memb = en.nextElement();
                assertTrue(principalMgr.hasPrincipal(memb.getName()));
            }
        }
    }
}
Also used : GroupPrincipal(org.apache.jackrabbit.api.security.principal.GroupPrincipal) Principal(java.security.Principal) GroupPrincipal(org.apache.jackrabbit.api.security.principal.GroupPrincipal) Test(org.junit.Test)

Example 15 with GroupPrincipal

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

the class PrincipalManagerImplTest 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 = ((GroupPrincipal) 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 : GroupPrincipal(org.apache.jackrabbit.api.security.principal.GroupPrincipal) PrincipalIterator(org.apache.jackrabbit.api.security.principal.PrincipalIterator) Principal(java.security.Principal) GroupPrincipal(org.apache.jackrabbit.api.security.principal.GroupPrincipal) Test(org.junit.Test)

Aggregations

GroupPrincipal (org.apache.jackrabbit.api.security.principal.GroupPrincipal)33 Principal (java.security.Principal)25 Test (org.junit.Test)23 EveryonePrincipal (org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal)12 Group (org.apache.jackrabbit.api.security.user.Group)9 PrincipalImpl (org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl)8 PrincipalIterator (org.apache.jackrabbit.api.security.principal.PrincipalIterator)6 AbstractPrincipalProviderTest (org.apache.jackrabbit.oak.security.principal.AbstractPrincipalProviderTest)6 ItemBasedPrincipal (org.apache.jackrabbit.api.security.principal.ItemBasedPrincipal)4 AdminPrincipal (org.apache.jackrabbit.oak.spi.security.principal.AdminPrincipal)4 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)3 EveryonePrincipal (org.apache.jackrabbit.core.security.principal.EveryonePrincipal)3 ExternalIdentityRef (org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityRef)3 PrincipalProvider (org.apache.jackrabbit.oak.spi.security.principal.PrincipalProvider)3 AbstractJCRTest (org.apache.jackrabbit.test.AbstractJCRTest)3 Privilege (javax.jcr.security.Privilege)2 JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)2 JackrabbitAccessControlList (org.apache.jackrabbit.api.security.JackrabbitAccessControlList)2 User (org.apache.jackrabbit.api.security.user.User)2 UserManager (org.apache.jackrabbit.api.security.user.UserManager)2