import org.apache.archiva.redback.rest.api.model.Operation;
import org.apache.archiva.redback.rest.api.model.Permission;
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;
Boolean validateUserFromKey( @PathParam( "key" ) String key )
throws RedbackServiceException;
- @Path( "resetPassword/{user}" )
- @GET
+ @Path( "resetPassword" )
+ @POST
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
+ @Consumes( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
@RedbackAuthorization( noRestriction = true, noPermission = true )
/**
*
* @param user username for send a password reset email
* @since 1.4
*/
- Boolean resetPassword( @PathParam( "user" ) String user )
+ Boolean resetPassword( ResetPasswordRequest resetPasswordRequest )
throws RedbackServiceException;
@Path( "getUserPermissions/{userName}" )
import org.apache.archiva.redback.rest.api.model.Operation;
import org.apache.archiva.redback.rest.api.model.Permission;
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;
return Boolean.FALSE;
}
- public Boolean resetPassword( String username )
+ public Boolean resetPassword( ResetPasswordRequest resetPasswordRequest )
throws RedbackServiceException
{
+ String username = resetPasswordRequest.getUsername();
if ( StringUtils.isEmpty( username ) )
{
throw new RedbackServiceException( new ErrorMessage( "username.cannot.be.empty" ) );
AuthenticationKey authkey = keyManager.createKey( username, "Password Reset Request",
policy.getUserValidationSettings().getEmailValidationTimeout() );
- mailer.sendPasswordResetEmail( Arrays.asList( user.getEmail() ), authkey, getBaseUrl() );
+ String applicationUrl = resetPasswordRequest.getApplicationUrl();
+ if ( StringUtils.isBlank( applicationUrl ) )
+ {
+ applicationUrl = getBaseUrl();
+ }
+ mailer.sendPasswordResetEmail( Arrays.asList( user.getEmail() ), authkey, applicationUrl );
log.info( "password reset request for username {}", username );
}
catch ( UserNotFoundException e )
import org.apache.archiva.redback.rest.api.model.Operation;
import org.apache.archiva.redback.rest.api.model.Permission;
+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.services.UserService;
assertTrue( service.validateUserFromKey( key ) );
- assertTrue( service.resetPassword( "toto" ) );
+ assertTrue( service.resetPassword( new ResetPasswordRequest( "toto", "http://foo.fr/bar" ) ) );
emailMessages = assertService.getEmailMessageSended();
assertEquals( 2, emailMessages.size() );
assertEquals( "toto@toto.fr", emailMessages.get( 1 ).getTos().get( 0 ) );
- assertTrue( emailMessages.get( 1 ).getText().contains( "Password Reset" ) );
- assertTrue( emailMessages.get( 1 ).getText().contains( "Username: toto" ) );
+ String messageContent = emailMessages.get( 1 ).getText();
+
+ assertThat( messageContent ).contains( "Password Reset" ).contains( "Username: toto" ).contains(
+ "http://foo.fr/bar" );
}