public void createUser(final String name, String password, Map<String, Object> extraProperties) throws RepositoryException {
final Node parentNode = this.parentNodeStack.peek();
Session session = parentNode.getSession();
UserManager userManager = AccessControlUtil.getUserManager(session);
Authorizable authorizable = userManager.getAuthorizable(name);
if (authorizable == null) {
//principal does not exist yet, so create it
User user = userManager.createUser(name,
password,
new Principal() {
public String getName() {
return name;
}
},
hashPath(name)
);
authorizable = user;
} else {
//principal already exists, check to make sure it is the expected type
if (authorizable.isGroup()) {
throw new RepositoryException("A group already exists with the requested name: " + name);
}
//user already exists so just update it below
}
if (extraProperties != null) {
ValueFactory valueFactory = session.getValueFactory();
Set<Entry<String, Object>> entrySet = extraProperties.entrySet();
for (Entry<String, Object> entry : entrySet) {
Value value = createValue(valueFactory, entry.getValue());
authorizable.setProperty(entry.getKey(), value);
}
}
}