NodeUtil folder = userNode.addChild("folder", UserConstants.NT_REP_AUTHORIZABLE_FOLDER);
String path = folder.getTree().getPath();
try {
// authNode - authFolder -> create User
try {
Principal p = new PrincipalImpl("test2");
Authorizable a = userMgr.createUser(p.getName(), p.getName(), p, path);
root.commit();
fail("Users may not be nested.");
} catch (CommitFailedException e) {
// success
} finally {
root.refresh();
Authorizable a = userMgr.getAuthorizable("test2");
if (a != null) {
a.remove();
root.commit();
}
}
} finally {
root.refresh();
folder.getTree().remove();
root.commit();
}
NodeUtil someContent = userNode.addChild("mystuff", JcrConstants.NT_UNSTRUCTURED);
path = someContent.getTree().getPath();
try {
// authNode - anyNode -> create User
try {
Principal p = new PrincipalImpl("test3");
userMgr.createUser(p.getName(), p.getName(), p, path);
root.commit();
fail("Users may not be nested.");
} catch (CommitFailedException e) {
// success
} finally {
root.refresh();
Authorizable a = userMgr.getAuthorizable("test3");
if (a != null) {
a.remove();
root.commit();
}
}
// authNode - anyNode - authFolder -> create User
folder = someContent.addChild("folder", UserConstants.NT_REP_AUTHORIZABLE_FOLDER);
root.commit(); // this time save node structure
try {
Principal p = new PrincipalImpl("test4");
userMgr.createUser(p.getName(), p.getName(), p, folder.getTree().getPath());
root.commit();
fail("Users may not be nested.");
} catch (CommitFailedException e) {
// success