fix unit tests in archiva-security

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1133465 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Olivier Lamy 2011-06-08 16:50:23 +00:00
parent de7890f4a3
commit 7d9ef40bf3
4 changed files with 42 additions and 42 deletions

View File

@ -53,6 +53,10 @@
<groupId>org.codehaus.redback</groupId> <groupId>org.codehaus.redback</groupId>
<artifactId>redback-rbac-role-manager</artifactId> <artifactId>redback-rbac-role-manager</artifactId>
</dependency> </dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<!-- Test Scoped --> <!-- Test Scoped -->
<dependency> <dependency>
<groupId>org.codehaus.redback</groupId> <groupId>org.codehaus.redback</groupId>
@ -84,10 +88,6 @@
<artifactId>derby</artifactId> <artifactId>derby</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -19,9 +19,7 @@ package org.apache.maven.archiva.security;
* under the License. * under the License.
*/ */
import java.util.ArrayList; import com.google.common.collect.Lists;
import java.util.List;
import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
import org.codehaus.plexus.redback.authentication.AuthenticationResult; import org.codehaus.plexus.redback.authentication.AuthenticationResult;
@ -38,14 +36,16 @@ import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.inject.Inject; import javax.inject.Inject;
import java.util.ArrayList;
import java.util.List;
/** /**
* DefaultUserRepositories * DefaultUserRepositories
* *
* @version $Id$ * @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 public class DefaultUserRepositories
implements UserRepositories implements UserRepositories
{ {
@ -66,7 +66,7 @@ public class DefaultUserRepositories
*/ */
@Inject @Inject
private ArchivaConfiguration archivaConfiguration; private ArchivaConfiguration archivaConfiguration;
private Logger log = LoggerFactory.getLogger( DefaultUserRepositories.class ); private Logger log = LoggerFactory.getLogger( DefaultUserRepositories.class );
public List<String> getObservableRepositoryIds( String principal ) public List<String> getObservableRepositoryIds( String principal )
@ -92,8 +92,7 @@ public class DefaultUserRepositories
List<String> repoIds = new ArrayList<String>(); List<String> repoIds = new ArrayList<String>();
List<ManagedRepositoryConfiguration> repos = List<ManagedRepositoryConfiguration> repos = archivaConfiguration.getConfiguration().getManagedRepositories();
archivaConfiguration.getConfiguration().getManagedRepositories();
for ( ManagedRepositoryConfiguration repo : repos ) for ( ManagedRepositoryConfiguration repo : repos )
{ {
@ -108,8 +107,11 @@ public class DefaultUserRepositories
catch ( AuthorizationException e ) catch ( AuthorizationException e )
{ {
// swallow. // swallow.
log.debug( "Not authorizing '" + principal + "' for repository '" + repo.getId() + "': " if ( log.isDebugEnabled() )
+ e.getMessage() ); {
log.debug( "Not authorizing '{}' for repository '{}': {}",
Lists.<Object>newArrayList( principal, repo.getId(), e.getMessage() ) );
}
} }
} }
@ -160,8 +162,7 @@ public class DefaultUserRepositories
} }
catch ( RoleManagerException e ) catch ( RoleManagerException e )
{ {
throw new ArchivaSecurityException( throw new ArchivaSecurityException( "Unable to create roles for configured repositories: " + e.getMessage(),
"Unable to create roles for configured repositories: " + e.getMessage(),
e ); e );
} }
} }
@ -182,7 +183,7 @@ public class DefaultUserRepositories
throw new ArchivaSecurityException( e.getMessage() ); throw new ArchivaSecurityException( e.getMessage() );
} }
} }
public boolean isAuthorizedToDeleteArtifacts( String principal, String repoId ) public boolean isAuthorizedToDeleteArtifacts( String principal, String repoId )
throws AccessDeniedException, ArchivaSecurityException throws AccessDeniedException, ArchivaSecurityException
{ {

View File

@ -74,6 +74,7 @@ public abstract class AbstractSecurityTest
protected RoleManager roleManager; protected RoleManager roleManager;
@Inject @Inject
@Named( value = "archivaConfiguration#default" )
private ArchivaConfiguration archivaConfiguration; private ArchivaConfiguration archivaConfiguration;
@Inject @Inject
@ -87,7 +88,10 @@ public abstract class AbstractSecurityTest
repoConfig.setId( repoId ); repoConfig.setId( repoId );
repoConfig.setName( "Testable repo <" + repoId + ">" ); repoConfig.setName( "Testable repo <" + repoId + ">" );
repoConfig.setLocation( new File( "./target/test-repo/" + repoId ).getPath() ); 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. // Add repo roles to security.
userRepos.createMissingRepositoryRoles( repoId ); userRepos.createMissingRepositoryRoles( repoId );

View File

@ -78,32 +78,27 @@
<alias name="servletAuthenticator" alias="servletAuthenticator#test"/> <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> <bean name="registry#test" class="org.codehaus.redback.components.registry.commons.CommonsConfigurationRegistry">
<role>org.apache.maven.archiva.configuration.ArchivaConfiguration</role> <property name="properties">
<implementation>org.apache.maven.archiva.configuration.DefaultArchivaConfiguration</implementation> <value>
<requirements> <![CDATA[
<requirement> <configuration>
<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>
<system/> <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"/> config-name="org.apache.maven.archiva.base" config-at="org.apache.maven.archiva"/>
</properties> </configuration>
</configuration> ]]>
</component> </value>
</property>
</bean>
<!--
partially configured partially configured
<component> <component>