@Override
public User addUser(String username, String displayName, String emailAddress, String password, String[] userAuthorizations) {
username = formatUsername(username);
displayName = displayName.trim();
User existingUser = findByUsername(username);
if (existingUser != null) {
throw new LumifyException("duplicate username");
}
String authorizationsString = StringUtils.join(userAuthorizations, ",");
byte[] salt = UserPasswordUtil.getSalt();
byte[] passwordHash = UserPasswordUtil.hashPassword(password, salt);
String id = "USER_" + graph.getIdGenerator().nextId();
VertexBuilder userBuilder = graph.prepareVertex(id, VISIBILITY.getVisibility());
LumifyProperties.CONCEPT_TYPE.setProperty(userBuilder, userConceptId, VISIBILITY.getVisibility());
UserLumifyProperties.USERNAME.setProperty(userBuilder, username, VISIBILITY.getVisibility());
UserLumifyProperties.DISPLAY_NAME.setProperty(userBuilder, displayName, VISIBILITY.getVisibility());
UserLumifyProperties.CREATE_DATE.setProperty(userBuilder, new Date(), VISIBILITY.getVisibility());
UserLumifyProperties.PASSWORD_SALT.setProperty(userBuilder, salt, VISIBILITY.getVisibility());
UserLumifyProperties.PASSWORD_HASH.setProperty(userBuilder, passwordHash, VISIBILITY.getVisibility());
UserLumifyProperties.STATUS.setProperty(userBuilder, UserStatus.OFFLINE.toString(), VISIBILITY.getVisibility());
UserLumifyProperties.AUTHORIZATIONS.setProperty(userBuilder, authorizationsString, VISIBILITY.getVisibility());
UserLumifyProperties.PRIVILEGES.setProperty(userBuilder, Privilege.toString(getDefaultPrivileges()), VISIBILITY.getVisibility());
if (emailAddress != null) {
UserLumifyProperties.EMAIL_ADDRESS.setProperty(userBuilder, emailAddress, VISIBILITY.getVisibility());
}
User user = createFromVertex(userBuilder.save(this.authorizations));
graph.flush();
userListenerUtil.fireNewUserAddedEvent(user);
return user;