if(securityManager.hasAccount(username)) {
throw new XPathException("The user account with username " + username + " already exists.");
}
final Account user = new UserAider(username);
user.setPassword(password);
if(getSignature().getArgumentCount() >= 5) {
//set metadata values if present
user.setMetadataValue(AXSchemaType.FULLNAME, args[getSignature().getArgumentCount() - 2].toString());
user.setMetadataValue(EXistSchemaType.DESCRIPTION, args[getSignature().getArgumentCount() - 1].toString());
}
final String[] subGroups;
if(getSignature().getArgumentCount() == 3 || getSignature().getArgumentCount() == 5) {
//create the personal group
final Group group = new GroupAider(username);
group.setMetadataValue(EXistSchemaType.DESCRIPTION, "Personal group for " + username);
group.addManager(currentUser);
securityManager.addGroup(group);
//add the personal group as the primary group
user.addGroup(username);
subGroups = getGroups(args[2]);
} else {
//add the primary group as the primary group
user.addGroup(args[2].getStringValue());
subGroups = getGroups(args[3]);
}
for(int i = 0; i < subGroups.length; i++) {
user.addGroup(subGroups[i]);
}
//create the account
securityManager.addAccount(user);