I am trying to implement a custom service which programmatically creates user under a particular folder i.e /home/users/myproject/user1.
Below are the methods available
createUser(String userID, String password)
Creates an User for the given userID / password pair; neither of the specified parameters can be null.
createUser(String userID, String password, Principal principal, String intermediatePath)
Creates an User for the given parameters.
Second one suits my requirement but when I pass the principal of an existing group it throws an exception saying Authorizable with principal “content-authors” already exists
“org.apache.jackrabbit.api.security.user.AuthorizableExistsException: Authorizable with principal content-authors already exists.”
If I pass a nonexisting group’s principal ex: “TestPrincipal” it resolves to null and says parameter cannot be null.
Below is the code
Session session = request.getResourceResolver().adaptTo(Session.class);
JackrabbitSession js = (JackrabbitSession) session;
UserManager usermanager;
try {
usermanager = (UserManager) js.getUserManager();
PrincipalManager principalMgr = js.getPrincipalManager();
Principal groupPrincipal = principalMgr.getPrincipal("content-authors");
User user= usermanager.createUser("ascdcdc", "dcdsvdfv",groupPrincipal,"/home/users/a");
js.save();
}
Any help is appreciated.
Solved! Go to Solution.