From: Olivier Lamy Date: Fri, 25 May 2012 14:38:09 +0000 (+0000) Subject: change signature to be able to pass the application url for reset password. X-Git-Tag: redback-2.0~137 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=7a1f3844180045ad85f5d692ba04bcd175fc658e;p=archiva.git change signature to be able to pass the application url for reset password. git-svn-id: https://svn.apache.org/repos/asf/archiva/redback/redback-core/trunk@1342645 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/redback-integrations/redback-rest/redback-rest-api/src/main/java/org/apache/archiva/redback/rest/api/services/UserService.java b/redback-integrations/redback-rest/redback-rest-api/src/main/java/org/apache/archiva/redback/rest/api/services/UserService.java index 331f8d8d8..40a54146b 100644 --- a/redback-integrations/redback-rest/redback-rest-api/src/main/java/org/apache/archiva/redback/rest/api/services/UserService.java +++ b/redback-integrations/redback-rest/redback-rest-api/src/main/java/org/apache/archiva/redback/rest/api/services/UserService.java @@ -24,6 +24,7 @@ import org.apache.archiva.redback.integration.security.role.RedbackRoleConstants 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; @@ -204,16 +205,17 @@ public interface UserService 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}" ) diff --git a/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/DefaultUserService.java b/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/DefaultUserService.java index f967d6e3b..a694a4f8e 100644 --- a/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/DefaultUserService.java +++ b/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/DefaultUserService.java @@ -43,6 +43,7 @@ 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.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; @@ -501,9 +502,10 @@ public class DefaultUserService 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" ) ); @@ -520,8 +522,13 @@ public class DefaultUserService 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 ) diff --git a/redback-integrations/redback-rest/redback-rest-services/src/test/java/org/apache/archiva/redback/rest/services/UserServiceTest.java b/redback-integrations/redback-rest/redback-rest-services/src/test/java/org/apache/archiva/redback/rest/services/UserServiceTest.java index 41c8fcdee..dbb17eb6e 100644 --- a/redback-integrations/redback-rest/redback-rest-services/src/test/java/org/apache/archiva/redback/rest/services/UserServiceTest.java +++ b/redback-integrations/redback-rest/redback-rest-services/src/test/java/org/apache/archiva/redback/rest/services/UserServiceTest.java @@ -21,6 +21,7 @@ package org.apache.archiva.redback.rest.services; 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; @@ -283,14 +284,16 @@ public class UserServiceTest 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" ); }