Search in sources :

Example 96 with Group

use of org.apache.jackrabbit.api.security.user.Group in project jackrabbit-oak by apache.

the class GroupTest method testAddMemberTwice.

@Test
public void testAddMemberTwice() throws NotExecutableException, RepositoryException {
    User auth = getTestUser(superuser);
    Group newGroup = null;
    try {
        newGroup = userMgr.createGroup(createGroupId());
        superuser.save();
        assertTrue(newGroup.addMember(auth));
        superuser.save();
        assertFalse(newGroup.addMember(auth));
        superuser.save();
        assertTrue(newGroup.isMember(auth));
    } finally {
        if (newGroup != null) {
            newGroup.removeMember(auth);
            newGroup.remove();
            superuser.save();
        }
    }
}
Also used : Group(org.apache.jackrabbit.api.security.user.Group) User(org.apache.jackrabbit.api.security.user.User) Test(org.junit.Test)

Example 97 with Group

use of org.apache.jackrabbit.api.security.user.Group in project jackrabbit-oak by apache.

the class GroupTest method testRemoveMembership.

@Test
public void testRemoveMembership() throws RepositoryException {
    String grId2 = createGroupId();
    Group gr2 = null;
    try {
        gr2 = userMgr.createGroup(grId2);
        gr2.addMember(user);
        superuser.save();
        Iterator<Group> groups = user.declaredMemberOf();
        while (groups.hasNext()) {
            Group group = groups.next();
            group.removeMember(user);
            superuser.save();
        }
        assertFalse(userMgr.getAuthorizable(group.getID(), Group.class).isDeclaredMember(user));
        assertFalse(userMgr.getAuthorizable(grId2, Group.class).isDeclaredMember(user));
        groups = user.declaredMemberOf();
        while (groups.hasNext()) {
            String id = groups.next().getID();
            assertFalse(group.getID().equals(id));
            assertFalse(grId2.equals(id));
        }
    } finally {
        if (gr2 != null) {
            gr2.remove();
            superuser.save();
        }
    }
}
Also used : Group(org.apache.jackrabbit.api.security.user.Group) Test(org.junit.Test)

Example 98 with Group

use of org.apache.jackrabbit.api.security.user.Group in project jackrabbit-oak by apache.

the class GroupTest method testRemoveMemberTwice.

@Test
public void testRemoveMemberTwice() throws NotExecutableException, RepositoryException {
    User auth = getTestUser(superuser);
    Group newGroup = null;
    try {
        newGroup = userMgr.createGroup(createGroupId());
        superuser.save();
        assertTrue(newGroup.addMember(auth));
        superuser.save();
        assertTrue(newGroup.removeMember(userMgr.getAuthorizable(auth.getID())));
        superuser.save();
        assertFalse(newGroup.removeMember(auth));
        superuser.save();
    } finally {
        if (newGroup != null) {
            newGroup.remove();
            superuser.save();
        }
    }
}
Also used : Group(org.apache.jackrabbit.api.security.user.Group) User(org.apache.jackrabbit.api.security.user.User) Test(org.junit.Test)

Example 99 with Group

use of org.apache.jackrabbit.api.security.user.Group in project jackrabbit-oak by apache.

the class GroupTest method testRemoveGroupClearsMembership.

@Test
public void testRemoveGroupClearsMembership() throws NotExecutableException, RepositoryException {
    User auth = getTestUser(superuser);
    Group newGroup = null;
    String groupId;
    try {
        newGroup = userMgr.createGroup(createGroupId());
        groupId = newGroup.getID();
        superuser.save();
        assertTrue(newGroup.addMember(auth));
        superuser.save();
        boolean isMember = false;
        Iterator<Group> it = auth.declaredMemberOf();
        while (it.hasNext() && !isMember) {
            isMember = groupId.equals(it.next().getID());
        }
        assertTrue(isMember);
    } finally {
        if (newGroup != null) {
            newGroup.remove();
            superuser.save();
        }
    }
    Iterator<Group> it = auth.declaredMemberOf();
    while (it.hasNext()) {
        assertFalse(groupId.equals(it.next().getID()));
    }
    it = auth.memberOf();
    while (it.hasNext()) {
        assertFalse(groupId.equals(it.next().getID()));
    }
}
Also used : Group(org.apache.jackrabbit.api.security.user.Group) User(org.apache.jackrabbit.api.security.user.User) Test(org.junit.Test)

Example 100 with Group

use of org.apache.jackrabbit.api.security.user.Group in project jackrabbit-oak by apache.

the class GroupTest method testAddMember.

@Test
public void testAddMember() throws NotExecutableException, RepositoryException {
    User auth = getTestUser(superuser);
    Group newGroup = null;
    try {
        newGroup = userMgr.createGroup(createGroupId());
        superuser.save();
        assertFalse(newGroup.isMember(auth));
        assertFalse(newGroup.removeMember(auth));
        superuser.save();
        assertTrue(newGroup.addMember(auth));
        superuser.save();
        assertTrue(newGroup.isMember(auth));
        assertTrue(newGroup.isMember(userMgr.getAuthorizable(auth.getID())));
    } finally {
        if (newGroup != null) {
            newGroup.removeMember(auth);
            newGroup.remove();
            superuser.save();
        }
    }
}
Also used : Group(org.apache.jackrabbit.api.security.user.Group) User(org.apache.jackrabbit.api.security.user.User) Test(org.junit.Test)

Aggregations

Group (org.apache.jackrabbit.api.security.user.Group)391 Test (org.junit.Test)205 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)119 User (org.apache.jackrabbit.api.security.user.User)119 UserManager (org.apache.jackrabbit.api.security.user.UserManager)87 Principal (java.security.Principal)71 RepositoryException (javax.jcr.RepositoryException)53 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)35 ExternalGroup (org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalGroup)33 ArrayList (java.util.ArrayList)31 Session (javax.jcr.Session)29 JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)27 EveryonePrincipal (org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal)26 AbstractExternalAuthTest (org.apache.jackrabbit.oak.spi.security.authentication.external.AbstractExternalAuthTest)22 PrincipalImpl (org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl)22 HashSet (java.util.HashSet)21 Privilege (javax.jcr.security.Privilege)21 EveryonePrincipal (org.apache.jackrabbit.core.security.principal.EveryonePrincipal)21 Query (org.apache.jackrabbit.api.security.user.Query)19 TestPrincipal (org.apache.jackrabbit.core.security.TestPrincipal)18