* @throws RepositoryException
*/
public void testEnforceAuthorizableFolderHierarchy() throws RepositoryException {
AuthorizableImpl authImpl = (AuthorizableImpl) userMgr.getAuthorizable(superuser.getUserID());
Node userNode = authImpl.getNode();
SessionImpl sImpl = (SessionImpl) userNode.getSession();
Node folder = userNode.addNode("folder", sImpl.getJCRName(UserConstants.NT_REP_AUTHORIZABLE_FOLDER));
String path = folder.getPath();
try {
// authNode - authFolder -> create User
Authorizable a = null;
try {
Principal p = getTestPrincipal();
a = userMgr.createUser(p.getName(), p.getName(), p, path);
fail("Users may not be nested.");
} catch (RepositoryException e) {
// success
} finally {
if (a != null) {
a.remove();
}
}
} finally {
if (sImpl.nodeExists(path)) {
folder.remove();
sImpl.save();
}
}
Node someContent = userNode.addNode("mystuff", "nt:unstructured");
path = someContent.getPath();
try {
// authNode - anyNode -> create User
Authorizable a = null;
try {
Principal p = getTestPrincipal();
a = userMgr.createUser(p.getName(), p.getName(), p, someContent.getPath());
fail("Users may not be nested.");
} catch (RepositoryException e) {
// success
} finally {
if (a != null) {
a.remove();
a = null;
}
}
// authNode - anyNode - authFolder -> create User
if (!sImpl.nodeExists(path)) {
someContent = userNode.addNode("mystuff", "nt:unstructured");
}
folder = someContent.addNode("folder", sImpl.getJCRName(UserConstants.NT_REP_AUTHORIZABLE_FOLDER));
sImpl.save(); // this time save node structure
try {
Principal p = getTestPrincipal();
a = userMgr.createUser(p.getName(), p.getName(), p, folder.getPath());
fail("Users may not be nested.");
} catch (RepositoryException e) {
// success
} finally {
if (a != null) {
a.remove();
}
}
} finally {
if (sImpl.nodeExists(path)) {
someContent.remove();
sImpl.save();
}
}
}