]> source.dussan.org Git - archiva.git/commitdiff
change signature to be able to pass the application url for reset password.
authorOlivier Lamy <olamy@apache.org>
Fri, 25 May 2012 14:38:09 +0000 (14:38 +0000)
committerOlivier Lamy <olamy@apache.org>
Fri, 25 May 2012 14:38:09 +0000 (14:38 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/redback/redback-core/trunk@1342645 13f79535-47bb-0310-9956-ffa450edef68

redback-integrations/redback-rest/redback-rest-api/src/main/java/org/apache/archiva/redback/rest/api/services/UserService.java
redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/DefaultUserService.java
redback-integrations/redback-rest/redback-rest-services/src/test/java/org/apache/archiva/redback/rest/services/UserServiceTest.java

index 331f8d8d80863a618e88518bf5f11af95581c2be..40a54146b41249f569373d809917162769e7ac08 100644 (file)
@@ -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}" )
index f967d6e3b7c354900b89a9ea14c7314ba31af1a2..a694a4f8ee57e9481cbf8e362ff986da17cca0fb 100644 (file)
@@ -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 )
index 41c8fcdee9dba3846fc53a9ef8c3ae6c3e910c0a..dbb17eb6e001ed1b4b65bbec839e6a55e6ba75ad 100644 (file)
@@ -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" );
 
 
         }