Search in sources :

Example 31 with GroupPrincipal

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

the class L3_EveryoneTest method testEveryoneExists.

public void testEveryoneExists() throws RepositoryException {
    Principal everyone = principalManager.getEveryone();
    assertNotNull(everyone);
    assertTrue(everyone instanceof GroupPrincipal);
    Authorizable everyoneAuthorizable = ((JackrabbitSession) superuser).getUserManager().getAuthorizable(everyone);
    assertNull(everyoneAuthorizable);
}
Also used : GroupPrincipal(org.apache.jackrabbit.api.security.principal.GroupPrincipal) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) Principal(java.security.Principal) GroupPrincipal(org.apache.jackrabbit.api.security.principal.GroupPrincipal)

Example 32 with GroupPrincipal

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

the class GroupTest method testMembersInPrincipal.

public void testMembersInPrincipal() throws NotExecutableException, RepositoryException {
    User auth = getTestUser(superuser);
    Group newGroup = null;
    Group newGroup2 = null;
    try {
        newGroup = userMgr.createGroup(getTestPrincipal());
        newGroup2 = userMgr.createGroup(getTestPrincipal());
        save(superuser);
        newGroup.addMember(newGroup2);
        save(superuser);
        newGroup2.addMember(auth);
        save(superuser);
        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();
            save(superuser);
        }
        if (newGroup2 != null) {
            newGroup2.removeMember(auth);
            newGroup2.remove();
            save(superuser);
        }
    }
}
Also used : GroupPrincipal(org.apache.jackrabbit.api.security.principal.GroupPrincipal)

Example 33 with GroupPrincipal

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

the class DefaultPrincipalProviderTest method testGroupMembership.

/**
 * Test for: Principal assiocated with Group does not update members
 * @see <a href=https://issues.apache.org/jira/browse/JCR-3552>JCR-3552</a>
 */
public void testGroupMembership() throws Exception {
    Group g = null;
    User u = null;
    Principal up = getTestPrincipal();
    try {
        // create a group and user, add the user to the group and assert membership
        g = userMgr.createGroup(getTestPrincipal());
        u = userMgr.createUser(up.getName(), buildPassword(up));
        save(superuser);
        g.addMember(u);
        save(superuser);
        Principal groupPrincipal = principalProvider.getPrincipal(g.getPrincipal().getName());
        assertTrue(groupPrincipal instanceof GroupPrincipal);
        assertTrue(((GroupPrincipal) groupPrincipal).isMember(u.getPrincipal()));
        // remove the user from the group and assert the user is no longer a member of the group
        g.removeMember(u);
        save(superuser);
        groupPrincipal = principalProvider.getPrincipal(g.getPrincipal().getName());
        assertFalse(((GroupPrincipal) groupPrincipal).isMember(u.getPrincipal()));
    } finally {
        if (null != g) {
            g.remove();
        }
        if (null != u) {
            u.remove();
        }
        save(superuser);
    }
}
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) EveryonePrincipal(org.apache.jackrabbit.core.security.principal.EveryonePrincipal) TestPrincipal(org.apache.jackrabbit.core.security.TestPrincipal) Principal(java.security.Principal) GroupPrincipal(org.apache.jackrabbit.api.security.principal.GroupPrincipal)

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