change signature to be able to pass the application url
git-svn-id: https://svn.apache.org/repos/asf/archiva/redback/redback-core/trunk@1342592 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
dce173abba
commit
532458aac6
6
pom.xml
6
pom.xml
|
@ -765,6 +765,12 @@
|
||||||
<artifactId>xmlunit</artifactId>
|
<artifactId>xmlunit</artifactId>
|
||||||
<version>1.3</version>
|
<version>1.3</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.easytesting</groupId>
|
||||||
|
<artifactId>fest-assert</artifactId>
|
||||||
|
<version>1.4</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</dependencyManagement>
|
</dependencyManagement>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
|
@ -25,6 +25,7 @@ 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.User;
|
import org.apache.archiva.redback.rest.api.model.User;
|
||||||
|
import org.apache.archiva.redback.rest.api.model.UserRegistrationRequest;
|
||||||
|
|
||||||
import javax.ws.rs.Consumes;
|
import javax.ws.rs.Consumes;
|
||||||
import javax.ws.rs.GET;
|
import javax.ws.rs.GET;
|
||||||
|
@ -180,13 +181,13 @@ public interface UserService
|
||||||
|
|
||||||
@Path( "registerUser" )
|
@Path( "registerUser" )
|
||||||
@POST
|
@POST
|
||||||
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
|
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
|
||||||
@RedbackAuthorization( noRestriction = true, noPermission = true )
|
@RedbackAuthorization( noRestriction = true, noPermission = true )
|
||||||
/**
|
/**
|
||||||
* if redback is not configured for email validation is required, -1 is returned as key
|
* if redback is not configured for email validation is required, -1 is returned as key
|
||||||
* @since 1.4
|
* @since 1.4
|
||||||
*/
|
*/
|
||||||
RegistrationKey registerUser( User user )
|
RegistrationKey registerUser( UserRegistrationRequest userRegistrationRequest )
|
||||||
throws RedbackServiceException;
|
throws RedbackServiceException;
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -190,6 +190,12 @@
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.easytesting</groupId>
|
||||||
|
<artifactId>fest-assert</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
|
@ -20,40 +20,41 @@ package org.apache.archiva.redback.rest.services;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import net.sf.ehcache.CacheManager;
|
import net.sf.ehcache.CacheManager;
|
||||||
import org.apache.archiva.redback.components.cache.Cache;
|
|
||||||
import org.apache.archiva.redback.configuration.UserConfiguration;
|
|
||||||
import org.apache.archiva.redback.keys.AuthenticationKey;
|
|
||||||
import org.apache.archiva.redback.policy.AccountLockedException;
|
|
||||||
import org.apache.archiva.redback.policy.MustChangePasswordException;
|
|
||||||
import org.apache.archiva.redback.rbac.RbacManagerException;
|
|
||||||
import org.apache.archiva.redback.rbac.UserAssignment;
|
|
||||||
import org.apache.archiva.redback.role.RoleManager;
|
|
||||||
import org.apache.archiva.redback.role.RoleManagerException;
|
|
||||||
import org.apache.archiva.redback.users.UserManager;
|
|
||||||
import org.apache.archiva.redback.users.UserNotFoundException;
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
|
||||||
import org.apache.archiva.redback.authentication.AuthenticationException;
|
import org.apache.archiva.redback.authentication.AuthenticationException;
|
||||||
import org.apache.archiva.redback.authentication.TokenBasedAuthenticationDataSource;
|
import org.apache.archiva.redback.authentication.TokenBasedAuthenticationDataSource;
|
||||||
import org.apache.archiva.redback.keys.KeyManager;
|
import org.apache.archiva.redback.components.cache.Cache;
|
||||||
import org.apache.archiva.redback.keys.KeyManagerException;
|
import org.apache.archiva.redback.configuration.UserConfiguration;
|
||||||
import org.apache.archiva.redback.keys.KeyNotFoundException;
|
|
||||||
import org.apache.archiva.redback.policy.PasswordEncoder;
|
|
||||||
import org.apache.archiva.redback.policy.UserSecurityPolicy;
|
|
||||||
import org.apache.archiva.redback.rbac.RBACManager;
|
|
||||||
import org.apache.archiva.redback.rbac.RbacObjectNotFoundException;
|
|
||||||
import org.apache.archiva.redback.system.SecuritySystem;
|
|
||||||
import org.apache.archiva.redback.integration.filter.authentication.HttpAuthenticator;
|
import org.apache.archiva.redback.integration.filter.authentication.HttpAuthenticator;
|
||||||
import org.apache.archiva.redback.integration.mail.Mailer;
|
import org.apache.archiva.redback.integration.mail.Mailer;
|
||||||
import org.apache.archiva.redback.integration.security.role.RedbackRoleConstants;
|
import org.apache.archiva.redback.integration.security.role.RedbackRoleConstants;
|
||||||
|
import org.apache.archiva.redback.keys.AuthenticationKey;
|
||||||
|
import org.apache.archiva.redback.keys.KeyManager;
|
||||||
|
import org.apache.archiva.redback.keys.KeyManagerException;
|
||||||
|
import org.apache.archiva.redback.keys.KeyNotFoundException;
|
||||||
|
import org.apache.archiva.redback.policy.AccountLockedException;
|
||||||
|
import org.apache.archiva.redback.policy.MustChangePasswordException;
|
||||||
|
import org.apache.archiva.redback.policy.PasswordEncoder;
|
||||||
|
import org.apache.archiva.redback.policy.UserSecurityPolicy;
|
||||||
|
import org.apache.archiva.redback.rbac.RBACManager;
|
||||||
|
import org.apache.archiva.redback.rbac.RbacManagerException;
|
||||||
|
import org.apache.archiva.redback.rbac.RbacObjectNotFoundException;
|
||||||
|
import org.apache.archiva.redback.rbac.UserAssignment;
|
||||||
import org.apache.archiva.redback.rest.api.model.ErrorMessage;
|
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.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.services.RedbackServiceException;
|
import org.apache.archiva.redback.rest.api.services.RedbackServiceException;
|
||||||
import org.apache.archiva.redback.rest.api.services.UserService;
|
import org.apache.archiva.redback.rest.api.services.UserService;
|
||||||
import org.apache.archiva.redback.rest.services.utils.PasswordValidator;
|
import org.apache.archiva.redback.rest.services.utils.PasswordValidator;
|
||||||
|
import org.apache.archiva.redback.role.RoleManager;
|
||||||
|
import org.apache.archiva.redback.role.RoleManagerException;
|
||||||
|
import org.apache.archiva.redback.system.SecuritySystem;
|
||||||
|
import org.apache.archiva.redback.users.UserManager;
|
||||||
|
import org.apache.archiva.redback.users.UserNotFoundException;
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
@ -537,9 +538,10 @@ public class DefaultUserService
|
||||||
return Boolean.TRUE;
|
return Boolean.TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public RegistrationKey registerUser( User user )
|
public RegistrationKey registerUser( UserRegistrationRequest userRegistrationRequest )
|
||||||
throws RedbackServiceException
|
throws RedbackServiceException
|
||||||
{
|
{
|
||||||
|
User user = userRegistrationRequest.getUser();
|
||||||
if ( user == null )
|
if ( user == null )
|
||||||
{
|
{
|
||||||
throw new RedbackServiceException( new ErrorMessage( "invalid.user.credentials", null ) );
|
throw new RedbackServiceException( new ErrorMessage( "invalid.user.credentials", null ) );
|
||||||
|
@ -593,7 +595,13 @@ public class DefaultUserService
|
||||||
securitySystem.getKeyManager().createKey( u.getPrincipal().toString(), "New User Email Validation",
|
securitySystem.getKeyManager().createKey( u.getPrincipal().toString(), "New User Email Validation",
|
||||||
securityPolicy.getUserValidationSettings().getEmailValidationTimeout() );
|
securityPolicy.getUserValidationSettings().getEmailValidationTimeout() );
|
||||||
|
|
||||||
mailer.sendAccountValidationEmail( Arrays.asList( u.getEmail() ), authkey, getBaseUrl() );
|
String baseUrl = userRegistrationRequest.getApplicationUrl();
|
||||||
|
if ( StringUtils.isBlank( baseUrl ) )
|
||||||
|
{
|
||||||
|
baseUrl = getBaseUrl();
|
||||||
|
}
|
||||||
|
|
||||||
|
mailer.sendAccountValidationEmail( Arrays.asList( u.getEmail() ), authkey, baseUrl );
|
||||||
|
|
||||||
securityPolicy.setEnabled( false );
|
securityPolicy.setEnabled( false );
|
||||||
userManager.addUser( u );
|
userManager.addUser( u );
|
||||||
|
|
|
@ -19,16 +19,17 @@ package org.apache.archiva.redback.rest.services;
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
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.User;
|
||||||
|
import org.apache.archiva.redback.rest.api.model.UserRegistrationRequest;
|
||||||
|
import org.apache.archiva.redback.rest.api.services.UserService;
|
||||||
|
import org.apache.archiva.redback.rest.services.mock.EmailMessage;
|
||||||
|
import org.apache.archiva.redback.rest.services.mock.ServicesAssert;
|
||||||
import org.apache.cxf.jaxrs.client.JAXRSClientFactory;
|
import org.apache.cxf.jaxrs.client.JAXRSClientFactory;
|
||||||
import org.apache.cxf.jaxrs.client.ServerWebApplicationException;
|
import org.apache.cxf.jaxrs.client.ServerWebApplicationException;
|
||||||
import org.apache.cxf.jaxrs.client.WebClient;
|
import org.apache.cxf.jaxrs.client.WebClient;
|
||||||
import org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider;
|
import org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider;
|
||||||
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.User;
|
|
||||||
import org.apache.archiva.redback.rest.api.services.UserService;
|
|
||||||
import org.apache.archiva.redback.rest.services.mock.EmailMessage;
|
|
||||||
import org.apache.archiva.redback.rest.services.mock.ServicesAssert;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
|
@ -36,6 +37,8 @@ import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.fest.assertions.Assertions.assertThat;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Olivier Lamy
|
* @author Olivier Lamy
|
||||||
*/
|
*/
|
||||||
|
@ -130,7 +133,7 @@ public class UserServiceTest
|
||||||
u.setEmail( "toto@toto.fr" );
|
u.setEmail( "toto@toto.fr" );
|
||||||
u.setPassword( "toto123" );
|
u.setPassword( "toto123" );
|
||||||
u.setConfirmPassword( "toto123" );
|
u.setConfirmPassword( "toto123" );
|
||||||
String key = service.registerUser( u ).getKey();
|
String key = service.registerUser( new UserRegistrationRequest( u, "http://wine.fr/bordeaux" ) ).getKey();
|
||||||
|
|
||||||
assertFalse( key.equals( "-1" ) );
|
assertFalse( key.equals( "-1" ) );
|
||||||
|
|
||||||
|
@ -144,8 +147,12 @@ public class UserServiceTest
|
||||||
assertEquals( "toto@toto.fr", emailMessages.get( 0 ).getTos().get( 0 ) );
|
assertEquals( "toto@toto.fr", emailMessages.get( 0 ).getTos().get( 0 ) );
|
||||||
|
|
||||||
assertEquals( "Welcome", emailMessages.get( 0 ).getSubject() );
|
assertEquals( "Welcome", emailMessages.get( 0 ).getSubject() );
|
||||||
assertTrue(
|
String messageContent = emailMessages.get( 0 ).getText();
|
||||||
emailMessages.get( 0 ).getText().contains( "Use the following URL to validate your account." ) );
|
|
||||||
|
log.info( "messageContent: {}", messageContent );
|
||||||
|
|
||||||
|
assertThat( messageContent ).contains( "Use the following URL to validate your account." ).contains(
|
||||||
|
"http://wine.fr/bordeaux" ).containsIgnoringCase( "toto" );
|
||||||
|
|
||||||
assertTrue( service.validateUserFromKey( key ) );
|
assertTrue( service.validateUserFromKey( key ) );
|
||||||
|
|
||||||
|
@ -185,7 +192,7 @@ public class UserServiceTest
|
||||||
u.setEmail( "toto@toto.fr" );
|
u.setEmail( "toto@toto.fr" );
|
||||||
u.setPassword( "toto123" );
|
u.setPassword( "toto123" );
|
||||||
u.setConfirmPassword( "toto123" );
|
u.setConfirmPassword( "toto123" );
|
||||||
String key = service.registerUser( u ).getKey();
|
String key = service.registerUser( new UserRegistrationRequest( u, "http://wine.fr/bordeaux" ) ).getKey();
|
||||||
|
|
||||||
assertFalse( key.equals( "-1" ) );
|
assertFalse( key.equals( "-1" ) );
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue