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

pom.xml
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/pom.xml
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

diff --git a/pom.xml b/pom.xml
index b61b5c0b1a6a88e6bee1008ffece7595b6e9b36b..212b00f2491970a048222f8cef51e70e2af70d0f 100644 (file)
--- a/pom.xml
+++ b/pom.xml
         <artifactId>xmlunit</artifactId>
         <version>1.3</version>
       </dependency>
+      <dependency>
+        <groupId>org.easytesting</groupId>
+        <artifactId>fest-assert</artifactId>
+        <version>1.4</version>
+        <scope>test</scope>
+      </dependency>
     </dependencies>
   </dependencyManagement>
   <dependencies>
index 9c7cc06ac2a9a72391b489656d4a75b2982b1273..331f8d8d80863a618e88518bf5f11af95581c2be 100644 (file)
@@ -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;
 
 
index 1b0830bf2aa4cd0bd27fbf74c4ecb7f2ea0e80ff..6450005b9d341d3d8e2c1f0ece9008b38e43aaab 100644 (file)
       <scope>test</scope>
     </dependency>
 
+    <dependency>
+      <groupId>org.easytesting</groupId>
+      <artifactId>fest-assert</artifactId>
+      <scope>test</scope>
+    </dependency>
+
   </dependencies>
 
   <build>
index fb4116fae08b3598d64e697a668063b7b480b3da..f967d6e3b7c354900b89a9ea14c7314ba31af1a2 100644 (file)
@@ -20,40 +20,41 @@ package org.apache.archiva.redback.rest.services;
  */
 
 import net.sf.ehcache.CacheManager;
+import org.apache.archiva.redback.authentication.AuthenticationException;
+import org.apache.archiva.redback.authentication.TokenBasedAuthenticationDataSource;
 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.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.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.system.SecuritySystem;
-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.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 );
index 3bfadbeae90c1b6a11b60d6f9b5400b68a67b80d..c31f67ffa8e44b0b5dabeb9c81d3a11991b5d29a 100644 (file)
@@ -19,16 +19,17 @@ package org.apache.archiva.redback.rest.services;
  * under the License.
  */
 
-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.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.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" ) );