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);
}
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);
}
}
}
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);
}
}
}
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);
}
}
}
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);
}
}
}
Aggregations