boolean isGroup, String intermediatePath) throws RepositoryException {
String authRoot = (isGroup) ? groupPath : userPath;
String folderPath = new StringBuilder()
.append(authRoot)
.append(getFolderPath(authorizableId, intermediatePath, authRoot)).toString();
NodeUtil folder;
Tree tree = root.getTree(folderPath);
while (!tree.isRoot() && !tree.exists()) {
tree = tree.getParent();
}
if (tree.exists()) {
folder = new NodeUtil(tree);
String relativePath = PathUtils.relativize(tree.getPath(), folderPath);
if (!relativePath.isEmpty()) {
folder = folder.getOrAddTree(relativePath, NT_REP_AUTHORIZABLE_FOLDER);
}
} else {
throw new AccessDeniedException("Missing permission to create intermediate authorizable folders.");
}
// test for colliding folder child node.
while (folder.hasChild(nodeName)) {
NodeUtil colliding = folder.getChild(nodeName);
if (colliding.hasPrimaryNodeTypeName(NT_REP_AUTHORIZABLE_FOLDER)) {
log.debug("Existing folder node collides with user/group to be created. Expanding path by: " + colliding.getName());
folder = colliding;
} else {
String msg = "Failed to create authorizable with id '" + authorizableId + "' : " +
"Detected conflicting node of unexpected node type '" + colliding.getPrimaryNodeTypeName() + "'.";
log.error(msg);
throw new ConstraintViolationException(msg);
}
}