Search in sources :

Example 16 with Group

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

the class UserManagerTest method testCreateGroupWithExistingPrincipal2.

@Test
public void testCreateGroupWithExistingPrincipal2() throws RepositoryException, NotExecutableException {
    Principal p = getTestPrincipal();
    String uid = createUserId();
    assertFalse(uid.equals(p.getName()));
    User u = null;
    try {
        // create a user with the given ID
        u = userMgr.createUser(uid, "pw", p, null);
        superuser.save();
        // assert AuthorizableExistsException for principal that is already in use
        Group gr = null;
        try {
            gr = userMgr.createGroup(p);
            fail("Principal " + p.getName() + " is already in use -> must throw AuthorizableExistsException.");
        } catch (AuthorizableExistsException e) {
        // expected this
        } finally {
            if (gr != null) {
                gr.remove();
                superuser.save();
            }
        }
    } finally {
        if (u != null) {
            u.remove();
            superuser.save();
        }
    }
}
Also used : Group(org.apache.jackrabbit.api.security.user.Group) AuthorizableExistsException(org.apache.jackrabbit.api.security.user.AuthorizableExistsException) User(org.apache.jackrabbit.api.security.user.User) Principal(java.security.Principal) EveryonePrincipal(org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal) Test(org.junit.Test)

Example 17 with Group

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

the class UserQueryTest method createGroup.

private Group createGroup(String name) throws RepositoryException {
    Group group = userMgr.createGroup(name);
    groups.add(group);
    return group;
}
Also used : Group(org.apache.jackrabbit.api.security.user.Group)

Example 18 with Group

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

the class ExternalGroupPrincipalProviderTest method testGetPrincipalExternalGroup.

@Test
public void testGetPrincipalExternalGroup() throws Exception {
    Group gr = getUserManager(root).getAuthorizable("secondGroup", Group.class);
    assertNotNull(gr);
    assertNull(principalProvider.getPrincipal(gr.getPrincipal().getName()));
}
Also used : Group(org.apache.jackrabbit.api.security.user.Group) ExternalGroup(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalGroup) Test(org.junit.Test)

Example 19 with Group

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

the class ExternalGroupPrincipalProviderTest method testGetPrincipalLocalGroup.

@Test
public void testGetPrincipalLocalGroup() throws Exception {
    Group gr = createTestGroup();
    assertNull(principalProvider.getPrincipal(gr.getPrincipal().getName()));
}
Also used : Group(org.apache.jackrabbit.api.security.user.Group) ExternalGroup(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalGroup) Test(org.junit.Test)

Example 20 with Group

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

the class SyncMBeanImplTest method testInitialSyncExternalGroup.

@Test
public void testInitialSyncExternalGroup() throws Exception {
    ExternalGroup externalGroup = idp.getGroup("a");
    String[] externalId = new String[] { externalGroup.getExternalId().getString() };
    String[] result = syncMBean.syncExternalUsers(externalId);
    assertResultMessages(result, "a", "add");
    UserManager userManager = getUserManager();
    Group aGroup = userManager.getAuthorizable(externalGroup.getId(), Group.class);
    assertNotNull(aGroup);
    // membership of groups are not synced (unless imposed by user-sync with membership depth)
    for (ExternalIdentityRef groupRef : externalGroup.getDeclaredGroups()) {
        assertNull(userManager.getAuthorizable(groupRef.getId()));
    }
}
Also used : Group(org.apache.jackrabbit.api.security.user.Group) ExternalGroup(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalGroup) ExternalGroup(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalGroup) ExternalIdentityRef(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityRef) UserManager(org.apache.jackrabbit.api.security.user.UserManager) 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