Search in sources :

Example 16 with AuthorizableExistsException

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

the class UserManagerTest method testCreateGroupWithExistingPrincipal.

@Test
public void testCreateGroupWithExistingPrincipal() throws RepositoryException, NotExecutableException {
    User u = null;
    try {
        Principal p = getTestPrincipal();
        String uid = p.getName();
        // 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 AuthorizableExistsException

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

the class UserManagerTest method testCreateGroupWithExistingUserID.

@Test
public void testCreateGroupWithExistingUserID() throws RepositoryException, NotExecutableException {
    User u = null;
    try {
        String uid = createUserId();
        // create a user with the given ID
        u = userMgr.createUser(uid, "pw");
        superuser.save();
        // assert AuthorizableExistsException for id that is already in use
        Group gr = null;
        try {
            gr = userMgr.createGroup(uid);
            fail("ID " + uid + " is already in use -> must throw AuthorizableExistsException.");
        } catch (AuthorizableExistsException aee) {
        // 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) Test(org.junit.Test)

Example 18 with AuthorizableExistsException

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

the class UserManagerTest method testCreateGroupWithExistingGroupID.

@Test
public void testCreateGroupWithExistingGroupID() throws RepositoryException, NotExecutableException {
    Group g = null;
    try {
        String id = createGroupId();
        // create a user with the given ID
        g = userMgr.createGroup(id);
        superuser.save();
        // assert AuthorizableExistsException for id that is already in use
        Group gr = null;
        try {
            gr = userMgr.createGroup(id);
            fail("ID " + id + " is already in use -> must throw AuthorizableExistsException.");
        } catch (AuthorizableExistsException aee) {
        // expected this
        } finally {
            if (gr != null) {
                gr.remove();
                superuser.save();
            }
        }
    } finally {
        if (g != null) {
            g.remove();
            superuser.save();
        }
    }
}
Also used : Group(org.apache.jackrabbit.api.security.user.Group) AuthorizableExistsException(org.apache.jackrabbit.api.security.user.AuthorizableExistsException) Test(org.junit.Test)

Example 19 with AuthorizableExistsException

use of org.apache.jackrabbit.api.security.user.AuthorizableExistsException in project jackrabbit by apache.

the class NotUserAdministratorTest method testCreateUser.

public void testCreateUser() throws NotExecutableException {
    try {
        Principal p = getTestPrincipal();
        User u = uMgr.createUser(p.getName(), buildPassword(p));
        save(uSession);
        fail("A non-UserAdmin should not be allowed to create a new User.");
        // clean-up: let superuser remove the user created by fault.
        userMgr.getAuthorizable(u.getID()).remove();
    } catch (AuthorizableExistsException e) {
        // should never get here.
        fail(e.getMessage());
    } catch (RepositoryException e) {
    // success
    }
}
Also used : AuthorizableExistsException(org.apache.jackrabbit.api.security.user.AuthorizableExistsException) User(org.apache.jackrabbit.api.security.user.User) RepositoryException(javax.jcr.RepositoryException) Principal(java.security.Principal)

Example 20 with AuthorizableExistsException

use of org.apache.jackrabbit.api.security.user.AuthorizableExistsException in project jackrabbit by apache.

the class UserManagerImplTest method testCreateGroupWithExistingPrincipal.

public void testCreateGroupWithExistingPrincipal() throws RepositoryException, NotExecutableException {
    Principal p = getTestPrincipal();
    String uid = p.getName();
    User u = null;
    try {
        // create a user with the given ID
        u = userMgr.createUser(uid, buildPassword(uid), p, null);
        save(superuser);
        // 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 aee) {
        // expected this
        } finally {
            if (gr != null) {
                gr.remove();
                save(superuser);
            }
        }
    } finally {
        if (u != null) {
            u.remove();
            save(superuser);
        }
    }
}
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) EveryonePrincipal(org.apache.jackrabbit.core.security.principal.EveryonePrincipal) TestPrincipal(org.apache.jackrabbit.core.security.TestPrincipal) Principal(java.security.Principal)

Aggregations

AuthorizableExistsException (org.apache.jackrabbit.api.security.user.AuthorizableExistsException)21 User (org.apache.jackrabbit.api.security.user.User)14 Principal (java.security.Principal)13 Group (org.apache.jackrabbit.api.security.user.Group)13 Test (org.junit.Test)8 TestPrincipal (org.apache.jackrabbit.core.security.TestPrincipal)7 EveryonePrincipal (org.apache.jackrabbit.core.security.principal.EveryonePrincipal)6 RepositoryException (javax.jcr.RepositoryException)3 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)3 EveryonePrincipal (org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal)3 HashMap (java.util.HashMap)1 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)1 ListOrderedMap (org.apache.commons.collections.map.ListOrderedMap)1 PrincipalImpl (org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl)1