You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@archiva.apache.org by ol...@apache.org on 2013/02/01 16:29:58 UTC

svn commit: r1441485 - in /archiva/redback/redback-core/trunk/redback-integrations/redback-rest: redback-rest-api/src/main/java/org/apache/archiva/redback/rest/api/services/ redback-rest-services/ redback-rest-services/src/main/java/org/apache/archiva/...

Author: olamy
Date: Fri Feb  1 15:29:58 2013
New Revision: 1441485

URL: http://svn.apache.org/viewvc?rev=1441485&view=rev
Log:
add unit test for LdapGroupMappingService

Modified:
    archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-api/src/main/java/org/apache/archiva/redback/rest/api/services/LdapGroupMappingService.java
    archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-services/pom.xml
    archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/DefaultLdapGroupMappingService.java
    archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-services/src/main/resources/META-INF/spring-context.xml
    archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-services/src/test/java/org/apache/archiva/redback/rest/services/AbstractRestServicesTest.java

Modified: archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-api/src/main/java/org/apache/archiva/redback/rest/api/services/LdapGroupMappingService.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-api/src/main/java/org/apache/archiva/redback/rest/api/services/LdapGroupMappingService.java?rev=1441485&r1=1441484&r2=1441485&view=diff
==============================================================================
--- archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-api/src/main/java/org/apache/archiva/redback/rest/api/services/LdapGroupMappingService.java (original)
+++ archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-api/src/main/java/org/apache/archiva/redback/rest/api/services/LdapGroupMappingService.java Fri Feb  1 15:29:58 2013
@@ -44,14 +44,14 @@ public interface LdapGroupMappingService
     @Path( "ldapGroups" )
     @GET
     @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
-    @RedbackAuthorization( permissions = RedbackRoleConstants.USER_ADMINISTRATOR_ROLE )
+    @RedbackAuthorization( permissions = RedbackRoleConstants.CONFIGURATION_EDIT_OPERATION )
     StringList getLdapGroups()
         throws RedbackServiceException;
 
 
     @GET
     @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
-    @RedbackAuthorization( permissions = RedbackRoleConstants.USER_ADMINISTRATOR_ROLE )
+    @RedbackAuthorization( permissions = RedbackRoleConstants.CONFIGURATION_EDIT_OPERATION )
     List<LdapGroupMapping> getLdapGroupMappings()
         throws RedbackServiceException;
 
@@ -59,21 +59,21 @@ public interface LdapGroupMappingService
     @PUT
     @Consumes( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
     @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
-    @RedbackAuthorization( permissions = RedbackRoleConstants.USER_ADMINISTRATOR_ROLE )
+    @RedbackAuthorization( permissions = RedbackRoleConstants.CONFIGURATION_EDIT_OPERATION )
     Boolean addLdapGroupMapping( LdapGroupMapping ldapGroupMapping )
         throws RedbackServiceException;
 
     @DELETE
     @Consumes( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
     @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
-    @RedbackAuthorization( permissions = RedbackRoleConstants.USER_ADMINISTRATOR_ROLE )
+    @RedbackAuthorization( permissions = RedbackRoleConstants.CONFIGURATION_EDIT_OPERATION )
     Boolean removeLdapGroupMapping( String group )
         throws RedbackServiceException;
 
     @POST
     @Consumes( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
     @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
-    @RedbackAuthorization( permissions = RedbackRoleConstants.USER_ADMINISTRATOR_ROLE )
+    @RedbackAuthorization( permissions = RedbackRoleConstants.CONFIGURATION_EDIT_OPERATION )
     Boolean updateLdapGroupMapping( LdapGroupMapping ldapGroupMapping )
         throws RedbackServiceException;
 

Modified: archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-services/pom.xml
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-services/pom.xml?rev=1441485&r1=1441484&r2=1441485&view=diff
==============================================================================
--- archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-services/pom.xml (original)
+++ archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-services/pom.xml Fri Feb  1 15:29:58 2013
@@ -183,6 +183,12 @@
       <scope>test</scope>
     </dependency>
 
+    <dependency>
+      <groupId>org.apache.archiva.redback.components</groupId>
+      <artifactId>spring-apacheds</artifactId>
+      <scope>test</scope>
+    </dependency>
+
   </dependencies>
 
   <build>
@@ -260,10 +266,29 @@
             <test.useTomcat>${test.useTomcat}</test.useTomcat>
             <redback.jdbc.url>${redbackTestJdbcUrl}</redback.jdbc.url>
             <redback.jdbc.driver.name>${redbackTestJdbcDriver}</redback.jdbc.driver.name>
+            <ldapPort>${ldapPort}</ldapPort>
           </systemPropertyVariables>
         </configuration>
       </plugin>
       <plugin>
+        <groupId>org.codehaus.mojo</groupId>
+        <artifactId>build-helper-maven-plugin</artifactId>
+        <executions>
+          <execution>
+            <id>allocate-ldap-port</id>
+            <phase>process-classes</phase>
+            <goals>
+              <goal>reserve-network-port</goal>
+            </goals>
+            <configuration>
+              <portNames>
+                <portName>ldapPort</portName>
+              </portNames>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+      <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-jar-plugin</artifactId>
         <executions>

Modified: archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/DefaultLdapGroupMappingService.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/DefaultLdapGroupMappingService.java?rev=1441485&r1=1441484&r2=1441485&view=diff
==============================================================================
--- archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/DefaultLdapGroupMappingService.java (original)
+++ archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/DefaultLdapGroupMappingService.java Fri Feb  1 15:29:58 2013
@@ -30,6 +30,7 @@ import org.apache.archiva.redback.rest.a
 import org.apache.archiva.redback.rest.api.services.RedbackServiceException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Service;
 
 import javax.inject.Inject;
 import javax.inject.Named;
@@ -44,12 +45,14 @@ import java.util.Map;
  * @author Olivier Lamy
  * @since 2.1
  */
+@Service("ldapGroupMappingService#rest")
 public class DefaultLdapGroupMappingService
     implements LdapGroupMappingService
 {
     private Logger log = LoggerFactory.getLogger( getClass() );
 
     @Inject
+    @Named(value = "ldapRoleMapper#default")
     private LdapRoleMapper ldapRoleMapper;
 
     @Inject
@@ -69,6 +72,7 @@ public class DefaultLdapGroupMappingServ
         try
         {
             ldapConnection = ldapConnectionFactory.getConnection();
+            context = ldapConnection.getDirContext();
             return new StringList( ldapRoleMapper.getAllGroups( context ) );
         }
         catch ( LdapException e )

Modified: archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-services/src/main/resources/META-INF/spring-context.xml
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-services/src/main/resources/META-INF/spring-context.xml?rev=1441485&r1=1441484&r2=1441485&view=diff
==============================================================================
--- archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-services/src/main/resources/META-INF/spring-context.xml (original)
+++ archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-services/src/main/resources/META-INF/spring-context.xml Fri Feb  1 15:29:58 2013
@@ -54,6 +54,7 @@
       <ref bean="roleManagementService#rest"/>
       <ref bean="utilServices#rest"/>
       <ref bean="passwordService#rest"/>
+      <ref bean="ldapGroupMappingService#rest"/>
     </jaxrs:serviceBeans>
     <jaxrs:outInterceptors>
       <ref bean="threadLocalUserCleaner#rest"/>

Modified: archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-services/src/test/java/org/apache/archiva/redback/rest/services/AbstractRestServicesTest.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-services/src/test/java/org/apache/archiva/redback/rest/services/AbstractRestServicesTest.java?rev=1441485&r1=1441484&r2=1441485&view=diff
==============================================================================
--- archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-services/src/test/java/org/apache/archiva/redback/rest/services/AbstractRestServicesTest.java (original)
+++ archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-services/src/test/java/org/apache/archiva/redback/rest/services/AbstractRestServicesTest.java Fri Feb  1 15:29:58 2013
@@ -22,6 +22,7 @@ package org.apache.archiva.redback.rest.
 import junit.framework.TestCase;
 import org.apache.archiva.redback.integration.security.role.RedbackRoleConstants;
 import org.apache.archiva.redback.rest.api.model.User;
+import org.apache.archiva.redback.rest.api.services.LdapGroupMappingService;
 import org.apache.archiva.redback.rest.api.services.LoginService;
 import org.apache.archiva.redback.rest.api.services.RoleManagementService;
 import org.apache.archiva.redback.rest.api.services.UserService;
@@ -48,7 +49,7 @@ import java.util.Collections;
 /**
  * @author Olivier Lamy
  */
-@RunWith( JUnit4.class )
+@RunWith(JUnit4.class)
 public abstract class AbstractRestServicesTest
     extends TestCase
 {
@@ -149,6 +150,7 @@ public abstract class AbstractRestServic
     {
         return getUserService( null );
     }
+
     // START SNIPPET: get-user-service
     protected UserService getUserService( String authzHeader )
     {
@@ -211,4 +213,27 @@ public abstract class AbstractRestServic
         return service;
     }
 
+
+    protected LdapGroupMappingService getLdapGroupMappingService( String authzHeader )
+    {
+        LdapGroupMappingService service =
+            JAXRSClientFactory.create( "http://localhost:" + port + "/" + getRestServicesPath() + "/redbackServices/",
+                                       LdapGroupMappingService.class,
+                                       Collections.singletonList( new JacksonJaxbJsonProvider() ) );
+
+        // for debuging purpose
+        WebClient.getConfig( service ).getHttpConduit().getClient().setReceiveTimeout( 100000 );
+
+        if ( authzHeader != null )
+        {
+            WebClient.client( service ).header( "Authorization", authzHeader );
+        }
+
+        WebClient.client( service ).accept( MediaType.APPLICATION_JSON_TYPE );
+        WebClient.client( service ).type( MediaType.APPLICATION_JSON_TYPE );
+
+        return service;
+    }
+
+
 }