Search in sources :

Example 26 with AlreadyExistException

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);
}
Also used : User(alien4cloud.security.model.User) AlreadyExistException(alien4cloud.exception.AlreadyExistException)

Aggregations

AlreadyExistException (alien4cloud.exception.AlreadyExistException)26 NotFoundException (alien4cloud.exception.NotFoundException)9 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)7 CSARUsedInActiveDeployment (alien4cloud.component.repository.exception.CSARUsedInActiveDeployment)6 ToscaTypeAlreadyDefinedInOtherCSAR (alien4cloud.component.repository.exception.ToscaTypeAlreadyDefinedInOtherCSAR)6 IOException (java.io.IOException)5 Path (java.nio.file.Path)5 InvalidNameException (alien4cloud.exception.InvalidNameException)4 SubstitutionTarget (org.alien4cloud.tosca.model.templates.SubstitutionTarget)4 Audit (alien4cloud.audit.annotation.Audit)3 ParsingException (alien4cloud.tosca.parser.ParsingException)3 ApiOperation (io.swagger.annotations.ApiOperation)3 RelationshipTemplate (org.alien4cloud.tosca.model.templates.RelationshipTemplate)3 ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)2 DeploymentTopology (alien4cloud.model.deployment.DeploymentTopology)2 PluginConfigurationException (alien4cloud.paas.exception.PluginConfigurationException)2 ParsingError (alien4cloud.tosca.parser.ParsingError)2 Csar (org.alien4cloud.tosca.model.Csar)2 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)2 Application (alien4cloud.model.application.Application)1