diff --git a/pom.xml b/pom.xml
index b61b5c0b..212b00f2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -765,6 +765,12 @@
xmlunit
1.3
+
+ org.easytesting
+ fest-assert
+ 1.4
+ test
+
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 9c7cc06a..331f8d8d 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
@@ -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.RegistrationKey;
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.GET;
@@ -180,13 +181,13 @@ public interface UserService
@Path( "registerUser" )
@POST
- @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
+ @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
@RedbackAuthorization( noRestriction = true, noPermission = true )
/**
* if redback is not configured for email validation is required, -1 is returned as key
* @since 1.4
*/
- RegistrationKey registerUser( User user )
+ RegistrationKey registerUser( UserRegistrationRequest userRegistrationRequest )
throws RedbackServiceException;
diff --git a/redback-integrations/redback-rest/redback-rest-services/pom.xml b/redback-integrations/redback-rest/redback-rest-services/pom.xml
index 1b0830bf..6450005b 100644
--- a/redback-integrations/redback-rest/redback-rest-services/pom.xml
+++ b/redback-integrations/redback-rest/redback-rest-services/pom.xml
@@ -190,6 +190,12 @@
test
+
+ org.easytesting
+ fest-assert
+ test
+
+
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 fb4116fa..f967d6e3 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
@@ -20,40 +20,41 @@ package org.apache.archiva.redback.rest.services;
*/
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.TokenBasedAuthenticationDataSource;
-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.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.components.cache.Cache;
+import org.apache.archiva.redback.configuration.UserConfiguration;
import org.apache.archiva.redback.integration.filter.authentication.HttpAuthenticator;
import org.apache.archiva.redback.integration.mail.Mailer;
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.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.Resource;
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.UserService;
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.LoggerFactory;
import org.springframework.stereotype.Service;
@@ -537,9 +538,10 @@ public class DefaultUserService
return Boolean.TRUE;
}
- public RegistrationKey registerUser( User user )
+ public RegistrationKey registerUser( UserRegistrationRequest userRegistrationRequest )
throws RedbackServiceException
{
+ User user = userRegistrationRequest.getUser();
if ( user == 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",
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 );
userManager.addUser( u );
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 3bfadbea..c31f67ff 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
@@ -19,16 +19,17 @@ package org.apache.archiva.redback.rest.services;
* 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.ServerWebApplicationException;
import org.apache.cxf.jaxrs.client.WebClient;
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 javax.ws.rs.core.MediaType;
@@ -36,6 +37,8 @@ import java.util.Collection;
import java.util.Collections;
import java.util.List;
+import static org.fest.assertions.Assertions.assertThat;
+
/**
* @author Olivier Lamy
*/
@@ -130,7 +133,7 @@ public class UserServiceTest
u.setEmail( "toto@toto.fr" );
u.setPassword( "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" ) );
@@ -144,8 +147,12 @@ public class UserServiceTest
assertEquals( "toto@toto.fr", emailMessages.get( 0 ).getTos().get( 0 ) );
assertEquals( "Welcome", emailMessages.get( 0 ).getSubject() );
- assertTrue(
- emailMessages.get( 0 ).getText().contains( "Use the following URL to validate your account." ) );
+ String messageContent = emailMessages.get( 0 ).getText();
+
+ 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 ) );
@@ -185,7 +192,7 @@ public class UserServiceTest
u.setEmail( "toto@toto.fr" );
u.setPassword( "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" ) );