diff --git a/redback-integrations/redback-rest/redback-rest-api/src/main/java/org/apache/archiva/redback/rest/api/Constants.java b/redback-integrations/redback-rest/redback-rest-api/src/main/java/org/apache/archiva/redback/rest/api/Constants.java index 54a03e82..0d0697ea 100644 --- a/redback-integrations/redback-rest/redback-rest-api/src/main/java/org/apache/archiva/redback/rest/api/Constants.java +++ b/redback-integrations/redback-rest/redback-rest-api/src/main/java/org/apache/archiva/redback/rest/api/Constants.java @@ -37,6 +37,7 @@ public interface Constants String ERR_USER_ID_INVALID = "redback:user.id.invalid"; String ERR_USER_FULL_NAME_EMPTY = "redback:user.fullname.empty"; String ERR_USER_EMAIL_EMPTY = "redback:user.email.empty"; + String ERR_USER_EMAIL_INVALID = "redback:user.email.invalid"; String ERR_USER_ASSIGN_ROLE = "redback:user.role.assign.failure"; String ERR_USER_NOT_VALIDATED = "redback:user.not_validated"; String ERR_USER_ADMIN_EXISTS = "redback:user.admin.exists"; diff --git a/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/v2/DefaultUserService.java b/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/v2/DefaultUserService.java index d7c64b3d..53a4fb2d 100644 --- a/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/v2/DefaultUserService.java +++ b/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/v2/DefaultUserService.java @@ -940,29 +940,29 @@ public void validateCredentialsLoose( User user ) new RedbackServiceException( "issues during validating user", 422 ); if ( StringUtils.isEmpty( user.getUserId() ) ) { - redbackServiceException.addErrorMessage( new ErrorMessage( "username.required", null ) ); + redbackServiceException.addErrorMessage( ErrorMessage.of( ERR_USER_ID_EMPTY ) ); } else { if ( !user.getUserId().matches( VALID_USERNAME_CHARS ) ) { - redbackServiceException.addErrorMessage( new ErrorMessage( "username.invalid.characters", null ) ); + redbackServiceException.addErrorMessage( ErrorMessage.of( ERR_USER_ID_INVALID ) ); } } if ( StringUtils.isEmpty( user.getFullName() ) ) { - redbackServiceException.addErrorMessage( new ErrorMessage( "fullName.required", null ) ); + redbackServiceException.addErrorMessage( ErrorMessage.of( ERR_USER_FULL_NAME_EMPTY ) ); } if ( StringUtils.isEmpty( user.getEmail() ) ) { - redbackServiceException.addErrorMessage( new ErrorMessage( "email.required", null ) ); + redbackServiceException.addErrorMessage( ErrorMessage.of( ERR_USER_EMAIL_EMPTY ) ); } if ( !StringUtils.equals( user.getPassword(), user.getConfirmPassword() ) ) { - redbackServiceException.addErrorMessage( new ErrorMessage( "passwords.do.not.match", null ) ); + redbackServiceException.addErrorMessage( ErrorMessage.of( ERR_AUTH_INVALID_CREDENTIALS, "nomatch" ) ); } try @@ -974,7 +974,7 @@ public void validateCredentialsLoose( User user ) } catch ( AddressException e ) { - redbackServiceException.addErrorMessage( new ErrorMessage( "email.invalid", null ) ); + redbackServiceException.addErrorMessage( ErrorMessage.of( ERR_USER_EMAIL_INVALID ) ); } if ( !redbackServiceException.getErrorMessages().isEmpty() ) { @@ -997,12 +997,12 @@ public void validateCredentialsStrict( User user ) if ( ( StringUtils.isEmpty( user.getPassword() ) ) ) { - throw new RedbackServiceException( new ErrorMessage( "password.required", null ) ); + throw new RedbackServiceException( ErrorMessage.of( ERR_AUTH_INVALID_CREDENTIALS, "empty" ) ); } } catch ( UserManagerException e ) { - throw new RedbackServiceException( new ErrorMessage( e.getMessage() ) ); + throw new RedbackServiceException( ErrorMessage.of( ERR_AUTH_INVALID_CREDENTIALS, e.getMessage() ) ); } } @@ -1046,7 +1046,7 @@ private org.apache.archiva.redback.users.User updateUser( String userId, Functio } catch ( UserManagerException e ) { - throw new RedbackServiceException( new ErrorMessage( e.getMessage() ) ); + throw new RedbackServiceException( ErrorMessage.of( ERR_USERMANAGER_FAIL, e.getMessage() ) ); } }