Search in sources :

Example 26 with GroupPrincipal

use of org.apache.jackrabbit.api.security.principal.GroupPrincipal 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 = ((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) ItemBasedPrincipal(org.apache.jackrabbit.api.security.principal.ItemBasedPrincipal) GroupPrincipal(org.apache.jackrabbit.api.security.principal.GroupPrincipal) EveryonePrincipal(org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal) Test(org.junit.Test) AbstractJCRTest(org.apache.jackrabbit.test.AbstractJCRTest)

Example 27 with GroupPrincipal

use of org.apache.jackrabbit.api.security.principal.GroupPrincipal 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 = ((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) PrincipalIterator(org.apache.jackrabbit.api.security.principal.PrincipalIterator) Principal(java.security.Principal) ItemBasedPrincipal(org.apache.jackrabbit.api.security.principal.ItemBasedPrincipal) GroupPrincipal(org.apache.jackrabbit.api.security.principal.GroupPrincipal) EveryonePrincipal(org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal) Test(org.junit.Test) AbstractJCRTest(org.apache.jackrabbit.test.AbstractJCRTest)

Example 28 with GroupPrincipal

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

the class ExternalGroupPrincipalProviderTest method testGetPrincipalDynamicGroup.

@Test
public void testGetPrincipalDynamicGroup() throws Exception {
    for (ExternalIdentityRef ref : idp.getUser(USER_ID).getDeclaredGroups()) {
        String princName = idp.getIdentity(ref).getPrincipalName();
        Principal principal = principalProvider.getPrincipal(princName);
        assertNotNull(principal);
        assertTrue(principal instanceof GroupPrincipal);
    }
}
Also used : ExternalIdentityRef(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityRef) GroupPrincipal(org.apache.jackrabbit.api.security.principal.GroupPrincipal) GroupPrincipal(org.apache.jackrabbit.api.security.principal.GroupPrincipal) Principal(java.security.Principal) Test(org.junit.Test)

Example 29 with GroupPrincipal

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

the class ExternalGroupPrincipalTest method testIsMember.

@Test
public void testIsMember() throws Exception {
    ExternalUser externalUser = idp.getUser(USER_ID);
    GroupPrincipal principal = getGroupPrincipal(externalUser.getDeclaredGroups().iterator().next());
    assertTrue(principal.isMember(new PrincipalImpl(externalUser.getPrincipalName())));
    assertTrue(principal.isMember(getUserManager(root).getAuthorizable(USER_ID).getPrincipal()));
}
Also used : GroupPrincipal(org.apache.jackrabbit.api.security.principal.GroupPrincipal) ExternalUser(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalUser) PrincipalImpl(org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl) Test(org.junit.Test)

Example 30 with GroupPrincipal

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

the class ExternalGroupPrincipalTest method testIsMemberLocalGroup.

@Test
public void testIsMemberLocalGroup() throws Exception {
    Group gr = createTestGroup();
    GroupPrincipal principal = getGroupPrincipal();
    assertFalse(principal.isMember(gr.getPrincipal()));
    assertFalse(principal.isMember(new PrincipalImpl(gr.getPrincipal().getName())));
}
Also used : Group(org.apache.jackrabbit.api.security.user.Group) ExternalGroup(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalGroup) GroupPrincipal(org.apache.jackrabbit.api.security.principal.GroupPrincipal) PrincipalImpl(org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl) 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