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
This commit is contained in:
parent
b8bbe53096
commit
7a1f384418
|
@ -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.Operation;
|
||||||
import org.apache.archiva.redback.rest.api.model.Permission;
|
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.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.User;
|
||||||
import org.apache.archiva.redback.rest.api.model.UserRegistrationRequest;
|
import org.apache.archiva.redback.rest.api.model.UserRegistrationRequest;
|
||||||
|
|
||||||
|
@ -204,16 +205,17 @@ public interface UserService
|
||||||
Boolean validateUserFromKey( @PathParam( "key" ) String key )
|
Boolean validateUserFromKey( @PathParam( "key" ) String key )
|
||||||
throws RedbackServiceException;
|
throws RedbackServiceException;
|
||||||
|
|
||||||
@Path( "resetPassword/{user}" )
|
@Path( "resetPassword" )
|
||||||
@GET
|
@POST
|
||||||
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
|
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
|
||||||
|
@Consumes( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
|
||||||
@RedbackAuthorization( noRestriction = true, noPermission = true )
|
@RedbackAuthorization( noRestriction = true, noPermission = true )
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param user username for send a password reset email
|
* @param user username for send a password reset email
|
||||||
* @since 1.4
|
* @since 1.4
|
||||||
*/
|
*/
|
||||||
Boolean resetPassword( @PathParam( "user" ) String user )
|
Boolean resetPassword( ResetPasswordRequest resetPasswordRequest )
|
||||||
throws RedbackServiceException;
|
throws RedbackServiceException;
|
||||||
|
|
||||||
@Path( "getUserPermissions/{userName}" )
|
@Path( "getUserPermissions/{userName}" )
|
||||||
|
|
|
@ -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.Operation;
|
||||||
import org.apache.archiva.redback.rest.api.model.Permission;
|
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.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.Resource;
|
||||||
import org.apache.archiva.redback.rest.api.model.User;
|
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.UserRegistrationRequest;
|
||||||
|
@ -501,9 +502,10 @@ public class DefaultUserService
|
||||||
return Boolean.FALSE;
|
return Boolean.FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Boolean resetPassword( String username )
|
public Boolean resetPassword( ResetPasswordRequest resetPasswordRequest )
|
||||||
throws RedbackServiceException
|
throws RedbackServiceException
|
||||||
{
|
{
|
||||||
|
String username = resetPasswordRequest.getUsername();
|
||||||
if ( StringUtils.isEmpty( username ) )
|
if ( StringUtils.isEmpty( username ) )
|
||||||
{
|
{
|
||||||
throw new RedbackServiceException( new ErrorMessage( "username.cannot.be.empty" ) );
|
throw new RedbackServiceException( new ErrorMessage( "username.cannot.be.empty" ) );
|
||||||
|
@ -520,8 +522,13 @@ public class DefaultUserService
|
||||||
AuthenticationKey authkey = keyManager.createKey( username, "Password Reset Request",
|
AuthenticationKey authkey = keyManager.createKey( username, "Password Reset Request",
|
||||||
policy.getUserValidationSettings().getEmailValidationTimeout() );
|
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 );
|
log.info( "password reset request for username {}", username );
|
||||||
}
|
}
|
||||||
catch ( UserNotFoundException e )
|
catch ( UserNotFoundException e )
|
||||||
|
|
|
@ -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.Operation;
|
||||||
import org.apache.archiva.redback.rest.api.model.Permission;
|
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.User;
|
||||||
import org.apache.archiva.redback.rest.api.model.UserRegistrationRequest;
|
import org.apache.archiva.redback.rest.api.model.UserRegistrationRequest;
|
||||||
import org.apache.archiva.redback.rest.api.services.UserService;
|
import org.apache.archiva.redback.rest.api.services.UserService;
|
||||||
|
@ -283,14 +284,16 @@ public class UserServiceTest
|
||||||
|
|
||||||
assertTrue( service.validateUserFromKey( key ) );
|
assertTrue( service.validateUserFromKey( key ) );
|
||||||
|
|
||||||
assertTrue( service.resetPassword( "toto" ) );
|
assertTrue( service.resetPassword( new ResetPasswordRequest( "toto", "http://foo.fr/bar" ) ) );
|
||||||
|
|
||||||
emailMessages = assertService.getEmailMessageSended();
|
emailMessages = assertService.getEmailMessageSended();
|
||||||
assertEquals( 2, emailMessages.size() );
|
assertEquals( 2, emailMessages.size() );
|
||||||
assertEquals( "toto@toto.fr", emailMessages.get( 1 ).getTos().get( 0 ) );
|
assertEquals( "toto@toto.fr", emailMessages.get( 1 ).getTos().get( 0 ) );
|
||||||
|
|
||||||
assertTrue( emailMessages.get( 1 ).getText().contains( "Password Reset" ) );
|
String messageContent = emailMessages.get( 1 ).getText();
|
||||||
assertTrue( emailMessages.get( 1 ).getText().contains( "Username: toto" ) );
|
|
||||||
|
assertThat( messageContent ).contains( "Password Reset" ).contains( "Username: toto" ).contains(
|
||||||
|
"http://foo.fr/bar" );
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue