use of alien4cloud.exception.AlreadyExistException in project alien4cloud by alien4cloud.
the class UserService method createUser.
/**
* Create a new internal user and saves it.
*
* @param userName The userName of the new user.
* @param email The email of the new user.
* @param firstName The firstName of the new user.
* @param lastName The lastname of the new user.
* @param roles The roles of the new user.
* @param password The password of the new user (hash only will be saved).
*/
public void createUser(String userName, String email, String firstName, String lastName, String[] roles, String password) {
if (alienUserDao.find(userName) != null) {
throw new AlreadyExistException("A user with the given username already exists.");
}
User user = new User();
user.setUsername(userName);
user.setEmail(email);
user.setFirstName(firstName);
user.setLastName(lastName);
user.setRoles(roles);
user.setPassword(BCrypt.hashpw(password, BCrypt.gensalt()));
user.setInternalDirectory(true);
user.setEnabled(true);
user.setAccountNonExpired(true);
user.setAccountNonLocked(true);
user.setCredentialsNonExpired(true);
alienUserDao.save(user);
}
Aggregations