in redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/v2/DefaultUserService.java [384:444]
public UserInfo updateMe( SelfUserData user )
throws RedbackServiceException
{
RedbackPrincipal principal = getPrincipal( );
if ( principal == null )
{
throw new RedbackServiceException( ErrorMessage.of( MessageKeys.ERR_AUTH_UNAUTHORIZED_REQUEST ), 401 );
}
// check oldPassword with the current one
// only 3 fields to update
// ui can limit to not update password
org.apache.archiva.redback.users.User foundUser = updateUser( principal.getName( ), realUser -> {
try
{
// current password is only needed, if password change is requested
if ( StringUtils.isNotBlank( user.getPassword( ) ) )
{
String previousEncodedPassword =
securitySystem.getUserManager( ).findUser( principal.getName( ), false ).getEncodedPassword( );
// check oldPassword with the current one
PasswordEncoder encoder = securitySystem.getPolicy( ).getPasswordEncoder( );
if ( !encoder.isPasswordValid( previousEncodedPassword, user.getCurrentPassword( ) ) )
{
return new RedbackServiceException( ErrorMessage.of( MessageKeys.ERR_USER_BAD_PASSWORD ),
Response.Status.BAD_REQUEST.getStatusCode( ) );
}
}
}
catch ( UserNotFoundException e )
{
return new RedbackServiceException( ErrorMessage.of( MessageKeys.ERR_USER_NOT_FOUND ),
Response.Status.BAD_REQUEST.getStatusCode( ) );
}
catch ( UserManagerException e )
{
return new RedbackServiceException( ErrorMessage.of( MessageKeys.ERR_USERMANAGER_FAIL, e.getMessage( ) ) );
}
// only 3 fields to update
if ( StringUtils.isNotBlank( user.getFullName( ) ) )
{
realUser.setFullName( user.getFullName( ) );
}
if ( StringUtils.isNotBlank( user.getEmail( ) ) )
{
realUser.setEmail( user.getEmail( ) );
}
// ui can limit to not update password
if ( StringUtils.isNotBlank( user.getPassword( ) ) )
{
realUser.setPassword( user.getPassword( ) );
}
return null;
} );
return getRestUser( foundUser );
}