Unified error messages

This commit is contained in:
Martin Stockhammer 2020-10-24 15:50:50 +02:00
parent 7c293d574a
commit 2587c0a77e
2 changed files with 10 additions and 9 deletions

View File

@ -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";

View File

@ -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() ) );
}
}