From: Olivier Lamy Date: Wed, 8 Jun 2011 16:50:23 +0000 (+0000) Subject: fix unit tests in archiva-security X-Git-Tag: archiva-1.4-M1~699 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=7d9ef40bf31d80f2ada2294e6a24cef2291a28e4;p=archiva.git fix unit tests in archiva-security git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1133465 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/archiva-modules/archiva-web/archiva-security/pom.xml b/archiva-modules/archiva-web/archiva-security/pom.xml index 510fda073..512397898 100644 --- a/archiva-modules/archiva-web/archiva-security/pom.xml +++ b/archiva-modules/archiva-web/archiva-security/pom.xml @@ -53,6 +53,10 @@ org.codehaus.redback redback-rbac-role-manager + + com.google.guava + guava + org.codehaus.redback @@ -84,10 +88,6 @@ derby test - - com.google.guava - guava - test - + diff --git a/archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/maven/archiva/security/DefaultUserRepositories.java b/archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/maven/archiva/security/DefaultUserRepositories.java index 88a28e2ac..c4603e411 100644 --- a/archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/maven/archiva/security/DefaultUserRepositories.java +++ b/archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/maven/archiva/security/DefaultUserRepositories.java @@ -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 getObservableRepositoryIds( String principal ) @@ -92,8 +92,7 @@ public class DefaultUserRepositories List repoIds = new ArrayList(); - List repos = - archivaConfiguration.getConfiguration().getManagedRepositories(); + List 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.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 { diff --git a/archiva-modules/archiva-web/archiva-security/src/test/java/org/apache/maven/archiva/security/AbstractSecurityTest.java b/archiva-modules/archiva-web/archiva-security/src/test/java/org/apache/maven/archiva/security/AbstractSecurityTest.java index 84d6b8c51..6308f075a 100644 --- a/archiva-modules/archiva-web/archiva-security/src/test/java/org/apache/maven/archiva/security/AbstractSecurityTest.java +++ b/archiva-modules/archiva-web/archiva-security/src/test/java/org/apache/maven/archiva/security/AbstractSecurityTest.java @@ -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 ); diff --git a/archiva-modules/archiva-web/archiva-security/src/test/resources/spring-context.xml b/archiva-modules/archiva-web/archiva-security/src/test/resources/spring-context.xml index 44e71526c..24723b149 100644 --- a/archiva-modules/archiva-web/archiva-security/src/test/resources/spring-context.xml +++ b/archiva-modules/archiva-web/archiva-security/src/test/resources/spring-context.xml @@ -78,32 +78,27 @@ -