Search in sources :

Example 6 with GroupPrincipal

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

the class GroupTest method testMembersInPrincipal.

@Test
public void testMembersInPrincipal() throws NotExecutableException, RepositoryException {
    User auth = getTestUser(superuser);
    Group newGroup = null;
    Group newGroup2 = null;
    try {
        newGroup = userMgr.createGroup(createGroupId());
        newGroup2 = userMgr.createGroup(createGroupId());
        superuser.save();
        newGroup.addMember(newGroup2);
        superuser.save();
        newGroup2.addMember(auth);
        superuser.save();
        GroupPrincipal ngPrincipal = (GroupPrincipal) newGroup.getPrincipal();
        GroupPrincipal ng2Principal = (GroupPrincipal) newGroup2.getPrincipal();
        assertFalse(ng2Principal.isMember(ngPrincipal));
        // newGroup2 must be member of newGroup's principal
        assertTrue(ngPrincipal.isMember(newGroup2.getPrincipal()));
        // testuser must be member of newGroup2's and newGroup's principal (indirect)
        assertTrue(ng2Principal.isMember(auth.getPrincipal()));
        assertTrue(ngPrincipal.isMember(auth.getPrincipal()));
    } finally {
        if (newGroup != null) {
            newGroup.removeMember(newGroup2);
            newGroup.remove();
            superuser.save();
        }
        if (newGroup2 != null) {
            newGroup2.removeMember(auth);
            newGroup2.remove();
            superuser.save();
        }
    }
}
Also used : Group(org.apache.jackrabbit.api.security.user.Group) User(org.apache.jackrabbit.api.security.user.User) GroupPrincipal(org.apache.jackrabbit.api.security.principal.GroupPrincipal) Test(org.junit.Test)

Example 7 with GroupPrincipal

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

the class EveryoneGroupTest method testGroupPrincipal.

@Test
public void testGroupPrincipal() throws Exception {
    Principal everyonePrincipal = everyone.getPrincipal();
    assertTrue(everyonePrincipal instanceof GroupPrincipal);
    assertTrue(everyonePrincipal.equals(EveryonePrincipal.getInstance()));
    assertTrue(EveryonePrincipal.getInstance().equals(everyonePrincipal));
    GroupPrincipal gr = (GroupPrincipal) everyonePrincipal;
    assertFalse(gr.isMember(everyonePrincipal));
    assertTrue(gr.isMember(getTestUser(superuser).getPrincipal()));
    assertTrue(gr.isMember(new PrincipalImpl("test")));
}
Also used : GroupPrincipal(org.apache.jackrabbit.api.security.principal.GroupPrincipal) Principal(java.security.Principal) GroupPrincipal(org.apache.jackrabbit.api.security.principal.GroupPrincipal) EveryonePrincipal(org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal) PrincipalImpl(org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl) Test(org.junit.Test)

Example 8 with GroupPrincipal

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

the class AbstractPrincipalTest method getGroupPrincipal.

GroupPrincipal getGroupPrincipal(@Nonnull ExternalIdentityRef ref) throws Exception {
    String principalName = idp.getIdentity(ref).getPrincipalName();
    Principal p = principalProvider.getPrincipal(principalName);
    assertNotNull(p);
    assertTrue(p instanceof GroupPrincipal);
    return (GroupPrincipal) p;
}
Also used : GroupPrincipal(org.apache.jackrabbit.api.security.principal.GroupPrincipal) Principal(java.security.Principal) GroupPrincipal(org.apache.jackrabbit.api.security.principal.GroupPrincipal)

Example 9 with GroupPrincipal

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

the class ExternalGroupPrincipalTest method testMembers.

@Test
public void testMembers() throws Exception {
    GroupPrincipal principal = getGroupPrincipal();
    Principal[] expectedMembers = new Principal[] { getUserManager(root).getAuthorizable(USER_ID).getPrincipal(), new PrincipalImpl(idp.getUser(USER_ID).getPrincipalName()) };
    for (Principal expected : expectedMembers) {
        Enumeration<? extends Principal> members = principal.members();
        assertTrue(members.hasMoreElements());
        assertEquals(expected, members.nextElement());
        assertFalse(members.hasMoreElements());
    }
}
Also used : GroupPrincipal(org.apache.jackrabbit.api.security.principal.GroupPrincipal) Principal(java.security.Principal) GroupPrincipal(org.apache.jackrabbit.api.security.principal.GroupPrincipal) PrincipalImpl(org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl) Test(org.junit.Test)

Example 10 with GroupPrincipal

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

the class ExternalGroupPrincipalTest method testIsMemberExternalGroup.

@Test
public void testIsMemberExternalGroup() throws Exception {
    GroupPrincipal principal = getGroupPrincipal();
    Iterable<String> exGroupPrincNames = Iterables.transform(ImmutableList.copyOf(idp.listGroups()), new Function<ExternalGroup, String>() {

        @Nullable
        @Override
        public String apply(ExternalGroup input) {
            return input.getPrincipalName();
        }
    });
    for (String principalName : exGroupPrincNames) {
        assertFalse(principal.isMember(new PrincipalImpl(principalName)));
    }
}
Also used : GroupPrincipal(org.apache.jackrabbit.api.security.principal.GroupPrincipal) ExternalGroup(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalGroup) Nullable(javax.annotation.Nullable) 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