Search in sources :

Example 1 with AuthorizableExistsException

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

the class UserManagerImpl method setPrincipal.

//--------------------------------------------------------------------------
/**
     *
     * @param node The new user/group node.
     * @param principal A valid non-null principal.
     * @throws AuthorizableExistsException If there is already another user/group
     * with the same principal name.
     * @throws RepositoryException If another error occurs.
     */
void setPrincipal(NodeImpl node, Principal principal) throws AuthorizableExistsException, RepositoryException {
    checkValidPrincipal(principal, node.isNodeType(NT_REP_GROUP));
    /*
         Check if there is *another* authorizable with the same principal.
         The additional validation (nodes not be same) is required in order to
         circumvent problems with re-importing existing authorizable in which
         case the original user/group node is being recreated but the search
         used to look for an colliding authorizable still finds the persisted
         node.
        */
    Authorizable existing = getAuthorizable(principal);
    if (existing != null && !((AuthorizableImpl) existing).getNode().isSame(node)) {
        throw new AuthorizableExistsException("Authorizable for '" + principal.getName() + "' already exists: ");
    }
    if (!node.isNew() || node.hasProperty(P_PRINCIPAL_NAME)) {
        throw new RepositoryException("rep:principalName can only be set once on a new node.");
    }
    setProperty(node, P_PRINCIPAL_NAME, getValue(principal.getName()), true);
}
Also used : AuthorizableExistsException(org.apache.jackrabbit.api.security.user.AuthorizableExistsException) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) RepositoryException(javax.jcr.RepositoryException)

Example 2 with AuthorizableExistsException

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

the class UserManagerImplTest method testCreateGroupWithExistingUserID.

public void testCreateGroupWithExistingUserID() throws RepositoryException, NotExecutableException {
    Principal p = getTestPrincipal();
    String uid = getTestUserId(p);
    User u = null;
    try {
        // create a user with the given ID
        u = userMgr.createUser(uid, buildPassword(uid), p, null);
        save(superuser);
        // 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();
                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)

Example 3 with AuthorizableExistsException

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

the class UserManagerImplTest method testCreateGroupWithExistingPrincipal3.

public void testCreateGroupWithExistingPrincipal3() throws RepositoryException, NotExecutableException {
    Principal p = getTestPrincipal();
    String uid = getTestUserId(p);
    assertFalse(uid.equals(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(getTestPrincipal().getName(), p, null);
            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)

Example 4 with AuthorizableExistsException

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

the class UserManagerImplTest method testCreateGroupWithExistingGroupID2.

public void testCreateGroupWithExistingGroupID2() throws RepositoryException, NotExecutableException {
    Principal p = getTestPrincipal();
    String uid = getTestUserId(p);
    Group g = null;
    try {
        // create a user with the given ID
        g = userMgr.createGroup(uid, p, null);
        save(superuser);
        // assert AuthorizableExistsException for id that is already in use
        Group gr = null;
        try {
            gr = userMgr.createGroup(uid, getTestPrincipal(), null);
            fail("ID " + uid + " is already in use -> must throw AuthorizableExistsException.");
        } catch (AuthorizableExistsException aee) {
        // expected this
        } finally {
            if (gr != null) {
                gr.remove();
                save(superuser);
            }
        }
    } finally {
        if (g != null) {
            g.remove();
            save(superuser);
        }
    }
}
Also used : Group(org.apache.jackrabbit.api.security.user.Group) AuthorizableExistsException(org.apache.jackrabbit.api.security.user.AuthorizableExistsException) EveryonePrincipal(org.apache.jackrabbit.core.security.principal.EveryonePrincipal) TestPrincipal(org.apache.jackrabbit.core.security.TestPrincipal) Principal(java.security.Principal)

Example 5 with AuthorizableExistsException

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

the class UserManagerImplTest method testCreateGroupWithExistingPrincipal2.

public void testCreateGroupWithExistingPrincipal2() throws RepositoryException, NotExecutableException {
    Principal p = getTestPrincipal();
    String uid = getTestUserId(p);
    assertFalse(uid.equals(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