in redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/DefaultUserService.java [148:224]
public Boolean createUser( User user )
throws RedbackServiceException
{
try
{
org.apache.archiva.redback.users.User u = userManager.findUser( user.getUsername() );
if ( u != null )
{
throw new RedbackServiceException(
new ErrorMessage( "user " + user.getUsername() + " already exists" ) );
}
}
catch ( UserNotFoundException e )
{
//ignore we just want to prevent non human readable error message from backend :-)
log.debug( "user {} not exists", user.getUsername() );
}
catch ( UserManagerException e )
{
throw new RedbackServiceException( new ErrorMessage( e.getMessage() ) );
}
// data validation
if ( StringUtils.isEmpty( user.getUsername() ) )
{
throw new RedbackServiceException( new ErrorMessage( "username cannot be empty" ) );
}
if ( StringUtils.isEmpty( user.getFullName() ) )
{
throw new RedbackServiceException( new ErrorMessage( "fullName cannot be empty" ) );
}
if ( StringUtils.isEmpty( user.getEmail() ) )
{
throw new RedbackServiceException( new ErrorMessage( "email cannot be empty" ) );
}
try
{
org.apache.archiva.redback.users.User u =
userManager.createUser( user.getUsername(), user.getFullName(), user.getEmail() );
u.setPassword( user.getPassword() );
u.setLocked( user.isLocked() );
u.setPasswordChangeRequired( user.isPasswordChangeRequired() );
u.setPermanent( user.isPermanent() );
u.setValidated( user.isValidated() );
u = userManager.addUser( u );
if ( !user.isPasswordChangeRequired() )
{
u.setPasswordChangeRequired( false );
try
{
u = userManager.updateUser( u );
log.debug( "user {} created", u.getUsername() );
}
catch ( UserNotFoundException e )
{
throw new RedbackServiceException( e.getMessage() );
}
}
roleManager.assignRole( RedbackRoleConstants.REGISTERED_USER_ROLE_ID, u.getUsername() );
}
catch ( RoleManagerException rpe )
{
log.error( "RoleProfile Error: {}", rpe.getMessage(), rpe );
throw new RedbackServiceException( new ErrorMessage( "assign.role.failure", null ) );
}
catch ( UserManagerException e )
{
throw new RedbackServiceException( new ErrorMessage( e.getMessage() ) );
}
return Boolean.TRUE;
}