Switching V1 user service to old return values

This commit is contained in:
Martin Stockhammer 2020-07-19 16:43:38 +02:00
parent 8a4932e9a6
commit b2d94281c6
4 changed files with 73 additions and 60 deletions

View File

@ -21,19 +21,14 @@
import org.apache.archiva.redback.authorization.RedbackAuthorization;
import org.apache.archiva.redback.integration.security.role.RedbackRoleConstants;
import org.apache.archiva.redback.rest.api.model.ActionStatus;
import org.apache.archiva.redback.rest.api.model.AvailabilityStatus;
import org.apache.archiva.redback.rest.api.model.Operation;
import org.apache.archiva.redback.rest.api.model.PasswordStatus;
import org.apache.archiva.redback.rest.api.model.Permission;
import org.apache.archiva.redback.rest.api.model.PingResult;
import org.apache.archiva.redback.rest.api.model.RegistrationKey;
import org.apache.archiva.redback.rest.api.model.ResetPasswordRequest;
import org.apache.archiva.redback.rest.api.model.User;
import org.apache.archiva.redback.rest.api.model.UserRegistrationRequest;
import org.apache.archiva.redback.rest.api.model.VerificationStatus;
import javax.swing.*;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
@ -71,7 +66,7 @@ List<User> getUsers()
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
@Consumes( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
@RedbackAuthorization( permissions = RedbackRoleConstants.USER_MANAGEMENT_USER_CREATE_OPERATION )
ActionStatus createUser( User user )
Boolean createUser( User user )
throws RedbackServiceException;
@ -83,14 +78,14 @@ ActionStatus createUser( User user )
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
@Consumes( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
@RedbackAuthorization( noRestriction = true )
ActionStatus createAdminUser( User user )
Boolean createAdminUser( User user )
throws RedbackServiceException;
@Path( "isAdminUserExists" )
@GET
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
@RedbackAuthorization( noRestriction = true )
AvailabilityStatus isAdminUserExists()
Boolean isAdminUserExists()
throws RedbackServiceException;
@ -98,14 +93,14 @@ AvailabilityStatus isAdminUserExists()
@GET
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
@RedbackAuthorization( permissions = RedbackRoleConstants.USER_MANAGEMENT_USER_DELETE_OPERATION )
ActionStatus deleteUser( @PathParam( "userName" ) String username )
Boolean deleteUser( @PathParam( "userName" ) String username )
throws RedbackServiceException;
@Path( "updateUser" )
@POST
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
@RedbackAuthorization( permissions = RedbackRoleConstants.USER_MANAGEMENT_USER_EDIT_OPERATION )
ActionStatus updateUser( User user )
Boolean updateUser( User user )
throws RedbackServiceException;
/**
@ -115,7 +110,7 @@ ActionStatus updateUser( User user )
@GET
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
@RedbackAuthorization( permissions = RedbackRoleConstants.USER_MANAGEMENT_USER_EDIT_OPERATION )
ActionStatus lockUser( @PathParam( "username" ) String username )
Boolean lockUser( @PathParam( "username" ) String username )
throws RedbackServiceException;
/**
@ -125,7 +120,7 @@ ActionStatus lockUser( @PathParam( "username" ) String username )
@GET
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
@RedbackAuthorization( permissions = RedbackRoleConstants.USER_MANAGEMENT_USER_EDIT_OPERATION )
ActionStatus unlockUser( @PathParam( "username" ) String username )
Boolean unlockUser( @PathParam( "username" ) String username )
throws RedbackServiceException;
@ -136,9 +131,18 @@ ActionStatus unlockUser( @PathParam( "username" ) String username )
@GET
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
@RedbackAuthorization( permissions = RedbackRoleConstants.USER_MANAGEMENT_USER_EDIT_OPERATION )
PasswordStatus passwordChangeRequired( @PathParam( "username" ) String username )
Boolean passwordChangeRequired( @PathParam( "username" ) String username )
throws RedbackServiceException;
/**
* @since 2.0
*/
@Path( "passwordChangeNotRequired/{username}" )
@GET
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
@RedbackAuthorization( permissions = RedbackRoleConstants.USER_MANAGEMENT_USER_EDIT_OPERATION )
Boolean passwordChangeNotRequired( @PathParam( "username" ) String username )
throws RedbackServiceException;
/**
* update only the current user and this fields: fullname, email, password.
* the service verify the curent logged user with the one passed in the method
@ -148,7 +152,7 @@ PasswordStatus passwordChangeRequired( @PathParam( "username" ) String username
@POST
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
@RedbackAuthorization( noRestriction = false, noPermission = true )
ActionStatus updateMe( User user )
Boolean updateMe( User user )
throws RedbackServiceException;
@Path( "ping" )
@ -162,7 +166,7 @@ Boolean ping()
@GET
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
@RedbackAuthorization( permissions = RedbackRoleConstants.USER_MANAGEMENT_USER_EDIT_OPERATION )
ActionStatus removeFromCache( @PathParam( "userName" ) String username )
int removeFromCache( @PathParam( "userName" ) String username )
throws RedbackServiceException;
@Path( "getGuestUser" )
@ -201,7 +205,7 @@ RegistrationKey registerUser( UserRegistrationRequest userRegistrationRequest )
@GET
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
@RedbackAuthorization( noRestriction = true, noPermission = true )
VerificationStatus validateUserFromKey( @PathParam( "key" ) String key )
Boolean validateUserFromKey( @PathParam( "key" ) String key )
throws RedbackServiceException;
/**
@ -214,7 +218,7 @@ VerificationStatus validateUserFromKey( @PathParam( "key" ) String key )
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
@Consumes( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
@RedbackAuthorization( noRestriction = true, noPermission = true )
ActionStatus resetPassword( ResetPasswordRequest resetPasswordRequest )
Boolean resetPassword( ResetPasswordRequest resetPasswordRequest )
throws RedbackServiceException;
/**

View File

@ -40,18 +40,14 @@
import org.apache.archiva.redback.rbac.RbacManagerException;
import org.apache.archiva.redback.rbac.UserAssignment;
import org.apache.archiva.redback.rest.api.model.ActionStatus;
import org.apache.archiva.redback.rest.api.model.AvailabilityStatus;
import org.apache.archiva.redback.rest.api.model.ErrorMessage;
import org.apache.archiva.redback.rest.api.model.Operation;
import org.apache.archiva.redback.rest.api.model.PasswordStatus;
import org.apache.archiva.redback.rest.api.model.Permission;
import org.apache.archiva.redback.rest.api.model.PingResult;
import org.apache.archiva.redback.rest.api.model.RegistrationKey;
import org.apache.archiva.redback.rest.api.model.ResetPasswordRequest;
import org.apache.archiva.redback.rest.api.model.Resource;
import org.apache.archiva.redback.rest.api.model.User;
import org.apache.archiva.redback.rest.api.model.UserRegistrationRequest;
import org.apache.archiva.redback.rest.api.model.VerificationStatus;
import org.apache.archiva.redback.rest.api.services.RedbackServiceException;
import org.apache.archiva.redback.rest.api.services.UserService;
import org.apache.archiva.redback.rest.services.utils.PasswordValidator;
@ -147,7 +143,7 @@ public DefaultUserService( @Named( value = "userManager#default" ) UserManager u
@Override
public ActionStatus createUser( User user )
public Boolean createUser( User user )
throws RedbackServiceException
{
@ -222,11 +218,11 @@ public ActionStatus createUser( User user )
{
throw new RedbackServiceException( new ErrorMessage( e.getMessage() ) );
}
return ActionStatus.SUCCESS;
return Boolean.TRUE;
}
@Override
public ActionStatus deleteUser( String username )
public Boolean deleteUser( String username )
throws RedbackServiceException
{
@ -248,7 +244,7 @@ public ActionStatus deleteUser( String username )
try
{
userManager.deleteUser( username );
return ActionStatus.SUCCESS;
return Boolean.TRUE;
}
catch ( UserNotFoundException e )
{
@ -308,7 +304,7 @@ public List<User> getUsers()
}
@Override
public ActionStatus updateMe( User user )
public Boolean updateMe( User user )
throws RedbackServiceException
{
// check username == one in the session
@ -375,11 +371,11 @@ public ActionStatus updateMe( User user )
updateUser( realUser );
return ActionStatus.SUCCESS;
return Boolean.TRUE;
}
@Override
public ActionStatus updateUser( User user )
public Boolean updateUser( User user )
throws RedbackServiceException
{
try
@ -394,7 +390,7 @@ public ActionStatus updateUser( User user )
rawUser.setPermanent( user.isPermanent() );
userManager.updateUser( rawUser );
return ActionStatus.SUCCESS;
return Boolean.TRUE;
}
catch ( UserNotFoundException e )
{
@ -407,7 +403,7 @@ public ActionStatus updateUser( User user )
}
@Override
public ActionStatus removeFromCache( String userName )
public int removeFromCache( String userName )
throws RedbackServiceException
{
if ( userAssignmentsCache != null )
@ -433,7 +429,7 @@ public ActionStatus removeFromCache( String userName )
}
}
return ActionStatus.SUCCESS;
return -1;
}
@Override
@ -506,13 +502,13 @@ private User getSimpleUser( org.apache.archiva.redback.users.User user )
}
@Override
public ActionStatus createAdminUser( User adminUser )
public Boolean createAdminUser( User adminUser )
throws RedbackServiceException
{
if ( isAdminUserExists().isExists() )
if ( isAdminUserExists() )
{
log.warn( "Admin user exists already" );
return ActionStatus.FAIL;
return Boolean.FALSE;
}
log.debug("Creating admin admin user '{}'", adminUser.getUsername());
if (!RedbackRoleConstants.ADMINISTRATOR_ACCOUNT_NAME.equals(adminUser.getUsername())) {
@ -543,17 +539,17 @@ public ActionStatus createAdminUser( User adminUser )
{
throw new RedbackServiceException( new ErrorMessage( e.getMessage() ) );
}
return ActionStatus.SUCCESS;
return Boolean.TRUE;
}
@Override
public AvailabilityStatus isAdminUserExists()
public Boolean isAdminUserExists()
throws RedbackServiceException
{
try
{
userManager.findUser( config.getString( UserConfigurationKeys.DEFAULT_ADMIN ) );
return new AvailabilityStatus( true );
return Boolean.TRUE;
}
catch ( UserNotFoundException e )
{
@ -565,15 +561,15 @@ public AvailabilityStatus isAdminUserExists()
if ( cause != null && cause instanceof UserNotFoundException )
{
return new AvailabilityStatus( false );
return Boolean.FALSE;
}
throw new RedbackServiceException( new ErrorMessage( e.getMessage() ) );
}
return new AvailabilityStatus( false );
return Boolean.FALSE;
}
@Override
public ActionStatus resetPassword( ResetPasswordRequest resetPasswordRequest )
public Boolean resetPassword( ResetPasswordRequest resetPasswordRequest )
throws RedbackServiceException
{
String username = resetPasswordRequest.getUsername();
@ -617,7 +613,7 @@ public ActionStatus resetPassword( ResetPasswordRequest resetPasswordRequest )
throw new RedbackServiceException( new ErrorMessage( e.getMessage() ) );
}
return ActionStatus.SUCCESS;
return Boolean.TRUE;
}
@Override
@ -736,7 +732,7 @@ public RegistrationKey registerUser( UserRegistrationRequest userRegistrationReq
}
@Override
public VerificationStatus validateUserFromKey( String key )
public Boolean validateUserFromKey( String key )
throws RedbackServiceException
{
String principal = null;
@ -765,7 +761,7 @@ public VerificationStatus validateUserFromKey( String key )
log.info( "account validated for user {}", user.getUsername() );
return new VerificationStatus( true );
return Boolean.TRUE;
}
catch ( MustChangePasswordException | AccountLockedException | AuthenticationException e )
{
@ -976,7 +972,7 @@ private String getBaseUrl()
}
@Override
public ActionStatus unlockUser( String username )
public Boolean unlockUser( String username )
throws RedbackServiceException
{
User user = getUser( username );
@ -984,13 +980,13 @@ public ActionStatus unlockUser( String username )
{
user.setLocked( false );
updateUser( user );
return ActionStatus.SUCCESS;
return Boolean.TRUE;
}
return ActionStatus.FAIL;
return Boolean.FALSE;
}
@Override
public ActionStatus lockUser( String username )
public Boolean lockUser( String username )
throws RedbackServiceException
{
User user = getUser( username );
@ -998,13 +994,13 @@ public ActionStatus lockUser( String username )
{
user.setLocked( true );
updateUser( user );
return ActionStatus.SUCCESS;
return Boolean.TRUE;
}
return ActionStatus.FAIL;
return Boolean.FALSE;
}
@Override
public PasswordStatus passwordChangeRequired( String username )
public Boolean passwordChangeRequired( String username )
throws RedbackServiceException
{
User user = getUser( username );
@ -1012,9 +1008,22 @@ public PasswordStatus passwordChangeRequired( String username )
{
user.setPasswordChangeRequired( true );
updateUser( user );
return new PasswordStatus( true );
return Boolean.TRUE;
}
return new PasswordStatus( false );
return Boolean.FALSE;
}
@Override
public Boolean passwordChangeNotRequired( String username )
throws RedbackServiceException
{
User user = getUser( username );
if ( user == null )
{
user.setPasswordChangeRequired( false );
updateUser( user );
return Boolean.TRUE;
}
return Boolean.FALSE;
}
}

View File

@ -167,7 +167,7 @@ public void startServer()
adminUser.setPassword( BaseSetup.getAdminPwd() );
adminUser.setFullName( "the admin user" );
adminUser.setEmail( "toto@toto.fr" );
if( !userService.createAdminUser( adminUser ).isSuccess( ) ) {
if( !userService.createAdminUser( adminUser ) ) {
log.info( "Could not create admin user." );
}

View File

@ -167,7 +167,7 @@ public void register()
assertTrue( messageContent.contains( "http://wine.fr/bordeaux" ) );
assertTrue( messageContent.contains( "toto" ) );
assertTrue( service.validateUserFromKey( key ).isSuccess() );
assertTrue( service.validateUserFromKey( key ) );
service = getUserService( authorizationHeader );
@ -177,7 +177,7 @@ public void register()
assertTrue( u.isValidated() );
assertTrue( u.isPasswordChangeRequired() );
assertTrue( service.validateUserFromKey( key ).isSuccess() );
assertTrue( service.validateUserFromKey( key ) );
}
catch ( Exception e )
@ -227,7 +227,7 @@ public void registerNoUrl()
assertTrue(messageContent.contains("http://localhost:" + getServerPort() ));
assertTrue( messageContent.toLowerCase( ).contains( "toto" ) );
assertTrue( service.validateUserFromKey( key ).isSuccess() );
assertTrue( service.validateUserFromKey( key ) );
service = getUserService( authorizationHeader );
@ -237,7 +237,7 @@ public void registerNoUrl()
assertTrue( u.isValidated() );
assertTrue( u.isPasswordChangeRequired() );
assertTrue( service.validateUserFromKey( key ).isSuccess() );
assertTrue( service.validateUserFromKey( key ) );
}
catch ( Exception e )
@ -285,7 +285,7 @@ public void resetPassword()
assertTrue(
emailMessages.get( 0 ).getText().contains( "Use the following URL to validate your account." ) );
assertTrue( service.validateUserFromKey( key ).isSuccess() );
assertTrue( service.validateUserFromKey( key ) );
service = getUserService( authorizationHeader );
@ -295,9 +295,9 @@ public void resetPassword()
assertTrue( u.isValidated() );
assertTrue( u.isPasswordChangeRequired() );
assertTrue( service.validateUserFromKey( key ).isSuccess() );
assertTrue( service.validateUserFromKey( key ) );
assertTrue( service.resetPassword( new ResetPasswordRequest( "toto", "http://foo.fr/bar" ) ).isSuccess() );
assertTrue( service.resetPassword( new ResetPasswordRequest( "toto", "http://foo.fr/bar" ) ) );
emailMessages = assertService.getEmailMessageSended();
assertEquals( 2, emailMessages.size() );