public User addUser(String username, String displayName, String emailAddress, String password, String[] userAuthorizations) {
username = formatUsername(username);
displayName = displayName.trim();
Session session = sessionManager.getSession();
if (findByUsername(username) != null) {
throw new LumifyException("User already exists");
}
Transaction transaction = null;
SqlUser newUser = null;
try {
transaction = session.beginTransaction();
newUser = new SqlUser();
String id = "USER_" + graph.getIdGenerator().nextId();
newUser.setUserId(id);
newUser.setUsername(username);
newUser.setDisplayName(displayName);
newUser.setCreateDate(new Date());
newUser.setEmailAddress(emailAddress);
if (password != null && !password.equals("")) {
byte[] salt = UserPasswordUtil.getSalt();
byte[] passwordHash = UserPasswordUtil.hashPassword(password, salt);
newUser.setPassword(salt, passwordHash);
}
newUser.setUserStatus(UserStatus.OFFLINE);
newUser.setPrivilegesString(Privilege.toString(getDefaultPrivileges()));
LOGGER.debug("add %s to user table", displayName);
session.save(newUser);
transaction.commit();
} catch (HibernateException e) {
if (transaction != null) {
transaction.rollback();
}
throw new LumifyException("HibernateException while adding user", e);
}
userListenerUtil.fireNewUserAddedEvent(newUser);
return newUser;