if(passwd.length() == 0) {
passwd = null;
}
final SecurityManager manager = factory.getBrokerPool().getSecurityManager();
if(manager.hasAccount(name)) {
throw new PermissionDeniedException("Account '"+name+"' exist");
}
if(!manager.hasAdminPrivileges(user)) {
throw new PermissionDeniedException("Account '"+user.getName()+"' not allowed to create new account");
}
final UserAider u = new UserAider(name);
u.setEncodedPassword(passwd);
u.setPasswordDigest(passwdDigest);
for(final String g : groups) {
if(!u.hasGroup(g)) {
u.addGroup(g);
}
}
if(enabled != null) {
u.setEnabled(enabled);
}
if(umask != null) {
u.setUserMask(umask);
}
if(metadata != null) {
for(final String key : metadata.keySet()) {
if(AXSchemaType.valueOfNamespace(key) != null) {
u.setMetadataValue(AXSchemaType.valueOfNamespace(key), metadata.get(key));
} else if(EXistSchemaType.valueOfNamespace(key) != null) {
u.setMetadataValue(EXistSchemaType.valueOfNamespace(key), metadata.get(key));
}
}
}
try {
executeWithBroker(new BrokerOperation<Void>() {
@Override
public Void withBroker(final DBBroker broker) throws EXistException, URISyntaxException, PermissionDeniedException {
manager.addAccount(u);
return null;
}
});
} catch(final URISyntaxException use) {
throw new EXistException(use.getMessage(), use);