]> source.dussan.org Git - archiva.git/commitdiff
fix unit tests in archiva-security
authorOlivier Lamy <olamy@apache.org>
Wed, 8 Jun 2011 16:50:23 +0000 (16:50 +0000)
committerOlivier Lamy <olamy@apache.org>
Wed, 8 Jun 2011 16:50:23 +0000 (16:50 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1133465 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-web/archiva-security/pom.xml
archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/maven/archiva/security/DefaultUserRepositories.java
archiva-modules/archiva-web/archiva-security/src/test/java/org/apache/maven/archiva/security/AbstractSecurityTest.java
archiva-modules/archiva-web/archiva-security/src/test/resources/spring-context.xml

index 510fda0733f4e618957427d15a413fa9b12ea4f0..512397898a92f47383e8cc9a7bb6eb27910d932c 100644 (file)
       <groupId>org.codehaus.redback</groupId>
       <artifactId>redback-rbac-role-manager</artifactId>
     </dependency>
+    <dependency>
+      <groupId>com.google.guava</groupId>
+      <artifactId>guava</artifactId>
+    </dependency>
     <!-- Test Scoped -->
     <dependency>
       <groupId>org.codehaus.redback</groupId>
       <artifactId>derby</artifactId>
       <scope>test</scope>
     </dependency>
-    <dependency>
-      <groupId>com.google.guava</groupId>
-      <artifactId>guava</artifactId>
-      <scope>test</scope>
-    </dependency>
+
   </dependencies>
 </project>
index 88a28e2ac25de692b09f31e8f80c7abb8516d3e5..c4603e4116fad0c5f3ec938e22eca407820c10e0 100644 (file)
@@ -19,9 +19,7 @@ package org.apache.maven.archiva.security;
  * under the License.
  */
 
-import java.util.ArrayList;
-import java.util.List;
-
+import com.google.common.collect.Lists;
 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
 import org.codehaus.plexus.redback.authentication.AuthenticationResult;
@@ -38,14 +36,16 @@ import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Service;
 
 import javax.inject.Inject;
+import java.util.ArrayList;
+import java.util.List;
 
 /**
  * DefaultUserRepositories
- * 
+ *
  * @version $Id$
- * plexus.component role="org.apache.maven.archiva.security.UserRepositories" role-hint="default"
+ *          plexus.component role="org.apache.maven.archiva.security.UserRepositories" role-hint="default"
  */
-@Service("userRepositories")
+@Service( "userRepositories" )
 public class DefaultUserRepositories
     implements UserRepositories
 {
@@ -66,7 +66,7 @@ public class DefaultUserRepositories
      */
     @Inject
     private ArchivaConfiguration archivaConfiguration;
-    
+
     private Logger log = LoggerFactory.getLogger( DefaultUserRepositories.class );
 
     public List<String> getObservableRepositoryIds( String principal )
@@ -92,8 +92,7 @@ public class DefaultUserRepositories
 
         List<String> repoIds = new ArrayList<String>();
 
-        List<ManagedRepositoryConfiguration> repos =
-            archivaConfiguration.getConfiguration().getManagedRepositories();
+        List<ManagedRepositoryConfiguration> repos = archivaConfiguration.getConfiguration().getManagedRepositories();
 
         for ( ManagedRepositoryConfiguration repo : repos )
         {
@@ -108,8 +107,11 @@ public class DefaultUserRepositories
             catch ( AuthorizationException e )
             {
                 // swallow.
-                log.debug( "Not authorizing '" + principal + "' for repository '" + repo.getId() + "': "
-                    + e.getMessage() );
+                if ( log.isDebugEnabled() )
+                {
+                    log.debug( "Not authorizing '{}' for repository '{}': {}",
+                               Lists.<Object>newArrayList( principal, repo.getId(), e.getMessage() ) );
+                }
             }
         }
 
@@ -160,8 +162,7 @@ public class DefaultUserRepositories
         }
         catch ( RoleManagerException e )
         {
-            throw new ArchivaSecurityException(
-                                                "Unable to create roles for configured repositories: " + e.getMessage(),
+            throw new ArchivaSecurityException( "Unable to create roles for configured repositories: " + e.getMessage(),
                                                 e );
         }
     }
@@ -182,7 +183,7 @@ public class DefaultUserRepositories
             throw new ArchivaSecurityException( e.getMessage() );
         }
     }
-    
+
     public boolean isAuthorizedToDeleteArtifacts( String principal, String repoId )
         throws AccessDeniedException, ArchivaSecurityException
     {
index 84d6b8c51938fd8f05bb393e5b2b6da027b9ae51..6308f075ac08e519ac128cd4ef90c9ffee342bca 100644 (file)
@@ -74,6 +74,7 @@ public abstract class AbstractSecurityTest
     protected RoleManager roleManager;
 
     @Inject
+    @Named( value = "archivaConfiguration#default" )
     private ArchivaConfiguration archivaConfiguration;
 
     @Inject
@@ -87,7 +88,10 @@ public abstract class AbstractSecurityTest
         repoConfig.setId( repoId );
         repoConfig.setName( "Testable repo <" + repoId + ">" );
         repoConfig.setLocation( new File( "./target/test-repo/" + repoId ).getPath() );
-        archivaConfiguration.getConfiguration().addManagedRepository( repoConfig );
+        if ( !archivaConfiguration.getConfiguration().getManagedRepositoriesAsMap().containsKey( repoId ) )
+        {
+            archivaConfiguration.getConfiguration().addManagedRepository( repoConfig );
+        }
 
         // Add repo roles to security.
         userRepos.createMissingRepositoryRoles( repoId );
index 44e71526ca0b965b38b26714cc2520a52a9ec481..24723b1493a2b6355efebca4aebb965a364efce9 100644 (file)
 
   <alias name="servletAuthenticator" alias="servletAuthenticator#test"/>
 
-  <!--
+  <bean name="archivaConfiguration#default"  class="org.apache.maven.archiva.configuration.DefaultArchivaConfiguration">
+    <property name="registry" ref="registry#test"/>
+  </bean>
+  <alias name="archivaConfiguration#default" alias="archivaConfiguration"/>
 
-    <component>
-      <role>org.apache.maven.archiva.configuration.ArchivaConfiguration</role>
-      <implementation>org.apache.maven.archiva.configuration.DefaultArchivaConfiguration</implementation>
-      <requirements>
-        <requirement>
-          <role>org.codehaus.plexus.registry.Registry</role>
-          <role-hint>configured</role-hint>
-        </requirement>
-      </requirements>
-    </component>
-    <component>
-      <role>org.codehaus.plexus.registry.Registry</role>
-      <role-hint>configured</role-hint>
-      <implementation>org.codehaus.plexus.registry.commons.CommonsConfigurationRegistry</implementation>
-      <configuration>
-        <properties>
+  <bean name="registry#test" class="org.codehaus.redback.components.registry.commons.CommonsConfigurationRegistry">
+    <property name="properties">
+      <value>
+        <![CDATA[
+        <configuration>
           <system/>
-          <xml fileName="${basedir}/target/test-conf/archiva.xml"
+          <xml fileName="${basedir}/target/test-conf/archiva.xml" config-forceCreate="true"
+               config-optional="true"
                config-name="org.apache.maven.archiva.base" config-at="org.apache.maven.archiva"/>
-        </properties>
-      </configuration>
-    </component>
-
+        </configuration>
+        ]]>
+      </value>
+    </property>
+  </bean>
 
+  <!--
     partially configured
 
     <component>