[MRM-1473] remove use of plexus-spring

start some changes on archiva-configuration and archiva-security

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1125142 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Olivier Lamy 2011-05-19 22:20:55 +00:00
parent 34d5a62c41
commit c96411890a
23 changed files with 514 additions and 136 deletions

6
RUNNING.TXT Normal file
View File

@ -0,0 +1,6 @@
With maven 3 and the tomcat-maven-plugin, you will be able to run the webapp from the top
and include all the other modules in the webapp classloader.
No more need to install everything to run the jetty plugin.
So just use : mvn tomcat:run -Pdev
and hit in your browser : http://localhost:9091/archiva

View File

@ -34,12 +34,12 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.codehaus.plexus.registry</groupId>
<artifactId>plexus-registry-api</artifactId>
<groupId>org.codehaus.redback.components.registry</groupId>
<artifactId>spring-registry-api</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.plexus.registry</groupId>
<artifactId>plexus-registry-commons</artifactId>
<groupId>org.codehaus.redback.components.registry</groupId>
<artifactId>spring-registry-commons</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>

View File

@ -36,14 +36,16 @@ import org.codehaus.plexus.evaluator.DefaultExpressionEvaluator;
import org.codehaus.plexus.evaluator.EvaluatorException;
import org.codehaus.plexus.evaluator.ExpressionEvaluator;
import org.codehaus.plexus.evaluator.sources.SystemPropertyExpressionSource;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
import org.codehaus.plexus.registry.Registry;
import org.codehaus.plexus.registry.RegistryException;
import org.codehaus.plexus.registry.RegistryListener;
import org.codehaus.redback.components.registry.commons.CommonsConfigurationRegistry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
@ -81,18 +83,21 @@ import java.util.Set;
* before reading it from the registry.
* </p>
*
* @plexus.component role="org.apache.maven.archiva.configuration.ArchivaConfiguration"
* plexus.component role="org.apache.maven.archiva.configuration.ArchivaConfiguration"
*/
@Service("archivaConfiguration")
public class DefaultArchivaConfiguration
implements ArchivaConfiguration, RegistryListener, Initializable
implements ArchivaConfiguration, RegistryListener
//, Initializable
{
private Logger log = LoggerFactory.getLogger( DefaultArchivaConfiguration.class );
/**
* Plexus registry to read the configuration from.
*
* @plexus.requirement role-hint="commons-configuration"
* plexus.requirement role-hint="commons-configuration"
*/
@Inject
private Registry registry;
/**
@ -101,24 +106,26 @@ public class DefaultArchivaConfiguration
private Configuration configuration;
/**
* @plexus.requirement role="org.apache.maven.archiva.policies.PreDownloadPolicy"
* plexus.requirement role="org.apache.maven.archiva.policies.PreDownloadPolicy"
* @todo these don't strictly belong in here
*/
private Map<String, PreDownloadPolicy> prePolicies;
/**
* @plexus.requirement role="org.apache.maven.archiva.policies.PostDownloadPolicy"
* plexus.requirement role="org.apache.maven.archiva.policies.PostDownloadPolicy"
* @todo these don't strictly belong in here
*/
private Map<String, PostDownloadPolicy> postPolicies;
/**
* @plexus.configuration default-value="${user.home}/.m2/archiva.xml"
* TODO take about default value with spring
* plexus.configuration default-value="${user.home}/.m2/archiva.xml"
*/
private String userConfigFilename;
/**
* @plexus.configuration default-value="${appserver.base}/conf/archiva.xml"
* * TODO take about default value with spring
* plexus.configuration default-value="${appserver.base}/conf/archiva.xml"
*/
private String altConfigFilename;
@ -401,7 +408,7 @@ public class DefaultArchivaConfiguration
@SuppressWarnings("unchecked")
public synchronized void save( Configuration configuration )
throws RegistryException, IndeterminateConfigurationException
throws IndeterminateConfigurationException, RegistryException
{
Registry section = registry.getSection( KEY + ".user" );
Registry baseSection = registry.getSection( KEY + ".base" );
@ -531,20 +538,15 @@ public class DefaultArchivaConfiguration
}
}
try
{
( (Initializable) registry ).initialize();
for ( RegistryListener regListener : registryListeners )
{
addRegistryChangeListener( regListener );
}
}
catch ( InitializationException e )
( (CommonsConfigurationRegistry) registry ).initialize();
for ( RegistryListener regListener : registryListeners )
{
throw new RegistryException( "Unable to reinitialize configuration: " + e.getMessage(), e );
addRegistryChangeListener( regListener );
}
triggerEvent( ConfigurationEvent.SAVED );
return registry.getSection( KEY + ".user" );
@ -638,8 +640,8 @@ public class DefaultArchivaConfiguration
}
}
@PostConstruct
public void initialize()
throws InitializationException
{
// Resolve expressions in the userConfigFilename and altConfigFilename
try
@ -652,7 +654,7 @@ public class DefaultArchivaConfiguration
}
catch ( EvaluatorException e )
{
throw new InitializationException( "Unable to evaluate expressions found in "
throw new RuntimeException( "Unable to evaluate expressions found in "
+ "userConfigFilename or altConfigFilename." );
}
registry.addChangeListener( this );

View File

@ -19,6 +19,20 @@ package org.apache.maven.archiva.configuration;
* under the License.
*/
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.Predicate;
import org.apache.commons.configuration.CombinedConfiguration;
import org.apache.maven.archiva.configuration.functors.FiletypeSelectionPredicate;
import org.apache.maven.archiva.configuration.io.registry.ConfigurationRegistryReader;
import org.codehaus.plexus.registry.Registry;
import org.codehaus.plexus.registry.RegistryException;
import org.codehaus.plexus.registry.RegistryListener;
import org.codehaus.plexus.util.SelectorUtils;
import org.codehaus.redback.components.registry.commons.CommonsConfigurationRegistry;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
@ -27,29 +41,16 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.Predicate;
import org.apache.commons.configuration.CombinedConfiguration;
import org.apache.maven.archiva.common.utils.Slf4JPlexusLogger;
import org.apache.maven.archiva.configuration.functors.FiletypeSelectionPredicate;
import org.apache.maven.archiva.configuration.io.registry.ConfigurationRegistryReader;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
import org.codehaus.plexus.registry.Registry;
import org.codehaus.plexus.registry.RegistryException;
import org.codehaus.plexus.registry.RegistryListener;
import org.codehaus.plexus.registry.commons.CommonsConfigurationRegistry;
import org.codehaus.plexus.util.SelectorUtils;
/**
* FileTypes
*
* @version $Id$
*
* @plexus.component role="org.apache.maven.archiva.configuration.FileTypes"
* plexus.component role="org.apache.maven.archiva.configuration.FileTypes"
*/
@Service("fileTypes")
public class FileTypes
implements Initializable, RegistryListener
implements RegistryListener
{
public static final String ARTIFACTS = "artifacts";
@ -60,8 +61,9 @@ public class FileTypes
public static final String IGNORED = "ignored";
/**
* @plexus.requirement
* plexus.requirement
*/
@Inject
private ArchivaConfiguration archivaConfiguration;
/**
@ -165,8 +167,8 @@ public class FileTypes
return false;
}
@PostConstruct
public void initialize()
throws InitializationException
{
// TODO: why is this done by hand?
@ -182,7 +184,6 @@ public class FileTypes
Field fld = commonsRegistry.getClass().getDeclaredField( "configuration" );
fld.setAccessible( true );
fld.set( commonsRegistry, new CombinedConfiguration() );
commonsRegistry.enableLogging( new Slf4JPlexusLogger( FileTypes.class ) );
commonsRegistry.addConfigurationFromResource( "org/apache/maven/archiva/configuration/default-archiva.xml" );
// Read configuration as it was intended.
@ -193,23 +194,23 @@ public class FileTypes
}
catch ( RegistryException e )
{
throw new InitializationException( errMsg + e.getMessage(), e );
throw new RuntimeException( errMsg + e.getMessage(), e );
}
catch ( SecurityException e )
{
throw new InitializationException( errMsg + e.getMessage(), e );
throw new RuntimeException( errMsg + e.getMessage(), e );
}
catch ( NoSuchFieldException e )
{
throw new InitializationException( errMsg + e.getMessage(), e );
throw new RuntimeException( errMsg + e.getMessage(), e );
}
catch ( IllegalArgumentException e )
{
throw new InitializationException( errMsg + e.getMessage(), e );
throw new RuntimeException( errMsg + e.getMessage(), e );
}
catch ( IllegalAccessException e )
{
throw new InitializationException( errMsg + e.getMessage(), e );
throw new RuntimeException( errMsg + e.getMessage(), e );
}
this.archivaConfiguration.addChangeListener( this );

View File

@ -0,0 +1,32 @@
<?xml version="1.0"?>
<!--
~ Licensed to the Apache Software Foundation (ASF) under one
~ or more contributor license agreements. See the NOTICE file
~ distributed with this work for additional information
~ regarding copyright ownership. The ASF licenses this file
~ to you under the Apache License, Version 2.0 (the
~ "License"); you may not use this file except in compliance
~ with the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing,
~ software distributed under the License is distributed on an
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~ KIND, either express or implied. See the License for the
~ specific language governing permissions and limitations
~ under the License.
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd"
default-lazy-init="true">
<context:annotation-config/>
<context:component-scan base-package="org.apache.maven.archiva.configuration"/>
</beans>

View File

@ -55,8 +55,8 @@
<artifactId>plexus-component-api</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.plexus.registry</groupId>
<artifactId>plexus-registry-api</artifactId>
<groupId>org.codehaus.redback.components.registry</groupId>
<artifactId>spring-registry-api</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>

View File

@ -58,8 +58,8 @@
<artifactId>plexus-component-api</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.plexus.registry</groupId>
<artifactId>plexus-registry-api</artifactId>
<groupId>org.codehaus.redback.components.registry</groupId>
<artifactId>spring-registry-api</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -47,8 +47,39 @@
<artifactId>commons-lang</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.plexus.cache</groupId>
<artifactId>plexus-cache-ehcache</artifactId>
<groupId>org.codehaus.redback.components.cache</groupId>
<artifactId>spring-cache-api</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-asm</artifactId>
</exclusion>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.codehaus.redback.components.cache</groupId>
<artifactId>spring-cache-ehcache</artifactId>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache-core</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>

View File

@ -71,8 +71,8 @@
<artifactId>plexus-component-api</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.plexus.registry</groupId>
<artifactId>plexus-registry-commons</artifactId>
<groupId>org.codehaus.redback.components.registry</groupId>
<artifactId>spring-registry-commons</artifactId>
<scope>test</scope>
</dependency>
<dependency>

View File

@ -37,11 +37,6 @@
<artifactId>servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.codehaus.redback.components</groupId>
<artifactId>plexus-spring</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
@ -84,5 +79,10 @@
<artifactId>slf4j-simple</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@ -19,6 +19,7 @@ package org.apache.maven.archiva.security;
* under the License.
*/
import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
import org.codehaus.plexus.redback.authentication.AuthenticationException;
@ -35,11 +36,13 @@ import org.codehaus.plexus.redback.users.User;
import org.codehaus.plexus.redback.users.UserNotFoundException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
/**
* @version
* @plexus.component role="org.apache.maven.archiva.security.ServletAuthenticator" role-hint="default"
*/
@Service("servletAuthenticator")
public class ArchivaServletAuthenticator
implements ServletAuthenticator
{
@ -48,6 +51,7 @@ public class ArchivaServletAuthenticator
/**
* @plexus.requirement
*/
@Inject
private SecuritySystem securitySystem;
public boolean isAuthenticated( HttpServletRequest request, AuthenticationResult result )
@ -113,4 +117,7 @@ public class ArchivaServletAuthenticator
throw new UnauthorizedException( e.getMessage() );
}
}
}

View File

@ -25,6 +25,10 @@ import org.codehaus.plexus.redback.rbac.RBACManager;
import org.codehaus.plexus.redback.system.check.EnvironmentCheck;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import javax.inject.Inject;
import javax.inject.Named;
/**
* ArchivaStandardRolesCheck tests for the existance of expected / standard roles and permissions.
@ -34,6 +38,7 @@ import org.slf4j.LoggerFactory;
* @plexus.component role="org.codehaus.plexus.redback.system.check.EnvironmentCheck"
* role-hint="required-roles"
*/
@Service("environmentCheck#required-roles")
public class ArchivaStandardRolesCheck
implements EnvironmentCheck
{
@ -42,6 +47,7 @@ public class ArchivaStandardRolesCheck
/**
* @plexus.requirement role-hint="cached"
*/
@Inject @Named(value = "rBACManager#cached")
private RBACManager rbacManager;
/**

View File

@ -35,6 +35,9 @@ import org.codehaus.plexus.redback.users.User;
import org.codehaus.plexus.redback.users.UserNotFoundException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import javax.inject.Inject;
/**
* DefaultUserRepositories
@ -42,22 +45,26 @@ import org.slf4j.LoggerFactory;
* @version $Id$
* @plexus.component role="org.apache.maven.archiva.security.UserRepositories" role-hint="default"
*/
@Service("userRepositories")
public class DefaultUserRepositories
implements UserRepositories
{
/**
* @plexus.requirement
*/
@Inject
private SecuritySystem securitySystem;
/**
* @plexus.requirement role-hint="default"
*/
@Inject
private RoleManager roleManager;
/**
* @plexus.requirement
*/
@Inject
private ArchivaConfiguration archivaConfiguration;
private Logger log = LoggerFactory.getLogger( DefaultUserRepositories.class );
@ -192,4 +199,34 @@ public class DefaultUserRepositories
throw new ArchivaSecurityException( e.getMessage() );
}
}
public SecuritySystem getSecuritySystem()
{
return securitySystem;
}
public void setSecuritySystem( SecuritySystem securitySystem )
{
this.securitySystem = securitySystem;
}
public RoleManager getRoleManager()
{
return roleManager;
}
public void setRoleManager( RoleManager roleManager )
{
this.roleManager = roleManager;
}
public ArchivaConfiguration getArchivaConfiguration()
{
return archivaConfiguration;
}
public void setArchivaConfiguration( ArchivaConfiguration archivaConfiguration )
{
this.archivaConfiguration = archivaConfiguration;
}
}

View File

@ -44,7 +44,7 @@ public interface ServletAuthenticator
* @throws AccountLockedException
* @throws MustChangePasswordException
*/
public boolean isAuthenticated( HttpServletRequest request, AuthenticationResult result )
boolean isAuthenticated( HttpServletRequest request, AuthenticationResult result )
throws AuthenticationException, AccountLockedException, MustChangePasswordException;
/**
@ -58,7 +58,7 @@ public interface ServletAuthenticator
* @throws AuthorizationException
* @throws UnauthorizedException
*/
public boolean isAuthorized( HttpServletRequest request, SecuritySession securitySession, String repositoryId,
boolean isAuthorized( HttpServletRequest request, SecuritySession securitySession, String repositoryId,
String permission ) throws AuthorizationException, UnauthorizedException;
/**
@ -74,6 +74,6 @@ public interface ServletAuthenticator
* @return
* @throws UnauthorizedException
*/
public boolean isAuthorized( String principal, String repoId, String permission )
boolean isAuthorized( String principal, String repoId, String permission )
throws UnauthorizedException;
}

View File

@ -37,7 +37,7 @@ public interface UserRepositories
* @throws AccessDeniedException
* @throws ArchivaSecurityException
*/
public List<String> getObservableRepositoryIds( String principal )
List<String> getObservableRepositoryIds( String principal )
throws PrincipalNotFoundException, AccessDeniedException, ArchivaSecurityException;
/**
@ -49,7 +49,7 @@ public interface UserRepositories
* @throws AccessDeniedException
* @throws ArchivaSecurityException
*/
public List<String> getManagableRepositoryIds( String principal )
List<String> getManagableRepositoryIds( String principal )
throws PrincipalNotFoundException, AccessDeniedException, ArchivaSecurityException;
/**
@ -58,7 +58,7 @@ public interface UserRepositories
* @param repoId the repository id to work off of.
* @throws ArchivaSecurityException if there was a problem creating the repository roles.
*/
public void createMissingRepositoryRoles( String repoId )
void createMissingRepositoryRoles( String repoId )
throws ArchivaSecurityException;
/**
@ -70,7 +70,7 @@ public interface UserRepositories
* @throws PrincipalNotFoundException
* @throws ArchivaSecurityException
*/
public boolean isAuthorizedToUploadArtifacts( String principal, String repoId)
boolean isAuthorizedToUploadArtifacts( String principal, String repoId)
throws PrincipalNotFoundException, ArchivaSecurityException;
/**
@ -82,7 +82,7 @@ public interface UserRepositories
* @throws ArchivaSecurityException
* @throws AccessDeniedException
*/
public boolean isAuthorizedToDeleteArtifacts( String principal, String repoId )
boolean isAuthorizedToDeleteArtifacts( String principal, String repoId )
throws AccessDeniedException, ArchivaSecurityException;
}

View File

@ -0,0 +1,33 @@
<?xml version="1.0"?>
<!--
~ Licensed to the Apache Software Foundation (ASF) under one
~ or more contributor license agreements. See the NOTICE file
~ distributed with this work for additional information
~ regarding copyright ownership. The ASF licenses this file
~ to you under the Apache License, Version 2.0 (the
~ "License"); you may not use this file except in compliance
~ with the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing,
~ software distributed under the License is distributed on an
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~ KIND, either express or implied. See the License for the
~ specific language governing permissions and limitations
~ under the License.
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd"
default-lazy-init="true">
<context:annotation-config />
<context:component-scan base-package="org.apache.maven.archiva.security"/>
</beans>

View File

@ -19,8 +19,7 @@ package org.apache.maven.archiva.security;
* under the License.
*/
import java.io.File;
import junit.framework.TestCase;
import org.apache.commons.io.FileUtils;
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
@ -29,15 +28,24 @@ import org.codehaus.plexus.redback.role.RoleManager;
import org.codehaus.plexus.redback.system.SecuritySystem;
import org.codehaus.plexus.redback.users.User;
import org.codehaus.plexus.redback.users.UserManager;
import org.codehaus.plexus.spring.PlexusInSpringTestCase;
import org.junit.Before;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import javax.inject.Inject;
import javax.inject.Named;
import java.io.File;
/**
* AbstractSecurityTest
* AbstractSecurityTest
*
* @version $Id: AbstractSecurityTest
*/
@RunWith( SpringJUnit4ClassRunner.class )
@ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" } )
public abstract class AbstractSecurityTest
extends PlexusInSpringTestCase
extends TestCase
{
protected static final String USER_GUEST = "guest";
@ -45,14 +53,21 @@ public abstract class AbstractSecurityTest
protected static final String USER_ALPACA = "alpaca";
@Inject
@Named( value = "securitySystem#testable" )
protected SecuritySystem securitySystem;
@Inject
@Named( value = "rBACManager#memory" )
private RBACManager rbacManager;
@Inject
protected RoleManager roleManager;
@Inject
private ArchivaConfiguration archivaConfiguration;
@Inject
protected UserRepositories userRepos;
protected void setupRepository( String repoId )
@ -62,7 +77,7 @@ public abstract class AbstractSecurityTest
ManagedRepositoryConfiguration repoConfig = new ManagedRepositoryConfiguration();
repoConfig.setId( repoId );
repoConfig.setName( "Testable repo <" + repoId + ">" );
repoConfig.setLocation( getTestPath( "target/test-repo/" + repoId ) );
repoConfig.setLocation( new File( "./target/test-repo/" + repoId ).getPath() );
archivaConfiguration.getConfiguration().addManagedRepository( repoConfig );
// Add repo roles to security.
@ -88,25 +103,20 @@ public abstract class AbstractSecurityTest
}
@Override
@Before
public void setUp()
throws Exception
{
super.setUp();
File srcConfig = getTestFile( "src/test/resources/repository-archiva.xml" );
File destConfig = getTestFile( "target/test-conf/archiva.xml" );
File srcConfig = new File( "./src/test/resources/repository-archiva.xml" );
File destConfig = new File( "./target/test-conf/archiva.xml" );
destConfig.getParentFile().mkdirs();
destConfig.delete();
FileUtils.copyFile( srcConfig, destConfig );
securitySystem = (SecuritySystem) lookup( SecuritySystem.class, "testable" );
rbacManager = (RBACManager) lookup( RBACManager.class, "memory" );
roleManager = (RoleManager) lookup( RoleManager.class, "default" );
userRepos = (UserRepositories) lookup( UserRepositories.class, "default" );
archivaConfiguration = (ArchivaConfiguration) lookup( ArchivaConfiguration.class );
// Some basic asserts.
assertNotNull( securitySystem );
assertNotNull( rbacManager );

View File

@ -19,6 +19,7 @@ package org.apache.maven.archiva.security;
* under the License.
*/
import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
import org.codehaus.plexus.redback.authentication.AuthenticationException;
@ -30,6 +31,8 @@ import org.codehaus.plexus.redback.users.User;
import org.codehaus.plexus.redback.users.UserManager;
import org.easymock.MockControl;
import org.junit.Before;
import org.junit.Test;
/**
* ArchivaServletAuthenticatorTest
@ -39,27 +42,25 @@ import org.easymock.MockControl;
public class ArchivaServletAuthenticatorTest
extends AbstractSecurityTest
{
@Inject
private ServletAuthenticator servletAuth;
private MockControl httpServletRequestControl;
private HttpServletRequest request;
@Override
@Before
public void setUp()
throws Exception
{
super.setUp();
servletAuth = (ServletAuthenticator) lookup( ServletAuthenticator.class, "default" );
httpServletRequestControl = MockControl.createControl( HttpServletRequest.class );
request = (HttpServletRequest) httpServletRequestControl.getMock();
setupRepository( "corporate" );
}
@Override
protected String getPlexusConfigLocation()
{
return "org/apache/maven/archiva/security/ArchivaServletAuthenticatorTest.xml";
@ -71,6 +72,7 @@ public class ArchivaServletAuthenticatorTest
roleManager.assignTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, repoId, principal );
}
@Test
public void testIsAuthenticatedUserExists()
throws Exception
{
@ -80,6 +82,7 @@ public class ArchivaServletAuthenticatorTest
assertTrue( isAuthenticated );
}
@Test
public void testIsAuthenticatedUserDoesNotExist()
throws Exception
{
@ -95,6 +98,7 @@ public class ArchivaServletAuthenticatorTest
}
}
@Test
public void testIsAuthorizedUserHasWriteAccess()
throws Exception
{
@ -114,6 +118,7 @@ public class ArchivaServletAuthenticatorTest
assertTrue( isAuthorized );
}
@Test
public void testIsAuthorizedUserHasNoWriteAccess()
throws Exception
{
@ -145,6 +150,7 @@ public class ArchivaServletAuthenticatorTest
httpServletRequestControl.verify();
}
@Test
public void testIsAuthorizedUserHasReadAccess()
throws Exception
{
@ -164,6 +170,7 @@ public class ArchivaServletAuthenticatorTest
assertTrue( isAuthorized );
}
@Test
public void testIsAuthorizedUserHasNoReadAccess()
throws Exception
{
@ -186,6 +193,7 @@ public class ArchivaServletAuthenticatorTest
}
}
@Test
public void testIsAuthorizedGuestUserHasWriteAccess()
throws Exception
{
@ -196,6 +204,7 @@ public class ArchivaServletAuthenticatorTest
assertTrue( isAuthorized );
}
@Test
public void testIsAuthorizedGuestUserHasNoWriteAccess()
throws Exception
{
@ -206,6 +215,7 @@ public class ArchivaServletAuthenticatorTest
assertFalse( isAuthorized );
}
@Test
public void testIsAuthorizedGuestUserHasReadAccess()
throws Exception
{
@ -217,6 +227,7 @@ public class ArchivaServletAuthenticatorTest
assertTrue( isAuthorized );
}
@Test
public void testIsAuthorizedGuestUserHasNoReadAccess()
throws Exception
{

View File

@ -22,6 +22,7 @@ package org.apache.maven.archiva.security;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.junit.Test;
/**
* DefaultUserRepositoriesTest
@ -31,12 +32,12 @@ import org.apache.commons.lang.StringUtils;
public class DefaultUserRepositoriesTest
extends AbstractSecurityTest
{
@Override
protected String getPlexusConfigLocation()
{
return "org/apache/maven/archiva/security/DefaultUserRepositoriesTest.xml";
}
@Test
public void testGetObservableRepositoryIds()
throws Exception
{

View File

@ -19,20 +19,29 @@ package org.apache.maven.archiva.security;
* under the License.
*/
import org.codehaus.plexus.spring.PlexusInSpringTestCase;
import junit.framework.TestCase;
import org.codehaus.plexus.redback.role.RoleManager;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import javax.inject.Inject;
/**
* RoleProfilesTest
*
* @version $Id: RoleManagerTest.java 4330 2007-05-10 17:28:56Z jmcconnell $
*/
@RunWith( SpringJUnit4ClassRunner.class )
@ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" } )
public class RoleManagerTest
extends PlexusInSpringTestCase
extends TestCase
{
/**
* @plexus.requirement role-hint="default"
*/
@Inject
RoleManager roleManager;
protected void setUp()
@ -40,9 +49,10 @@ public class RoleManagerTest
{
super.setUp();
roleManager = (RoleManager) lookup( RoleManager.class.getName(), "default" );
}
@Test
public void testExpectedRoles()
throws Exception
{

View File

@ -0,0 +1,165 @@
<?xml version="1.0"?>
<!--
~ Licensed to the Apache Software Foundation (ASF) under one
~ or more contributor license agreements. See the NOTICE file
~ distributed with this work for additional information
~ regarding copyright ownership. The ASF licenses this file
~ to you under the Apache License, Version 2.0 (the
~ "License"); you may not use this file except in compliance
~ with the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing,
~ software distributed under the License is distributed on an
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~ KIND, either express or implied. See the License for the
~ specific language governing permissions and limitations
~ under the License.
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd"
default-lazy-init="true">
<bean name="securitySystem#testable" class="org.codehaus.plexus.redback.system.DefaultSecuritySystem">
<property name="userManager" ref="userManager#memory"/>
<property name="keyManager" ref="keyManager#memory"/>
</bean>
<alias name="securitySystem#testable" alias="securitySystem"/>
<bean name="userRepositories" class="org.apache.maven.archiva.security.DefaultUserRepositories">
<property name="securitySystem" ref="securitySystem#testable"/>
<property name="roleManager" ref="roleManager"/>
<property name="archivaConfiguration" ref="archivaConfiguration"/>
</bean>
<bean name="authorizer#rbac" class="org.codehaus.plexus.redback.authorization.rbac.RbacAuthorizer">
<property name="manager" ref="rBACManager#memory"/>
<property name="userManager" ref="userManager#memory"/>
<property name="evaluator" ref="permissionEvaluator"/>
</bean>
<bean name="permissionEvaluator" class="org.codehaus.plexus.redback.authorization.rbac.evaluator.DefaultPermissionEvaluator">
<property name="userManager" ref="userManager#memory"/>
</bean>
<bean name="roleManager" class="org.codehaus.plexus.redback.role.DefaultRoleManager">
<property name="rbacManager" ref="rBACManager#memory"/>
</bean>
<bean name="rBACManager#cached" class="org.codehaus.plexus.redback.rbac.cached.CachedRbacManager">
<property name="rbacImpl" ref="rBACManager#memory"/>
</bean>
<!--
<component>
<role>org.codehaus.plexus.redback.role.processor.RoleModelProcessor</role>
<role-hint>default</role-hint>
<implementation>org.codehaus.plexus.redback.role.processor.DefaultRoleModelProcessor</implementation>
<description>DefaultRoleModelProcessor: inserts the components of the model that can be populated into the rbac manager</description>
<requirements>
<requirement>
<role>org.codehaus.plexus.redback.rbac.RBACManager</role>
<role-hint>memory</role-hint>
<field-name>rbacManager</field-name>
</requirement>
</requirements>
</component>
<component>
<role>org.codehaus.plexus.redback.role.template.RoleTemplateProcessor</role>
<role-hint>default</role-hint>
<implementation>org.codehaus.plexus.redback.role.template.DefaultRoleTemplateProcessor</implementation>
<description>DefaultRoleTemplateProcessor: inserts the components of a template into the rbac manager</description>
<requirements>
<requirement>
<role>org.codehaus.plexus.redback.rbac.RBACManager</role>
<role-hint>memory</role-hint>
<field-name>rbacManager</field-name>
</requirement>
</requirements>
</component>
<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>
<system/>
<xml fileName="${basedir}/target/test-conf/archiva.xml"
config-name="org.apache.maven.archiva.base" config-at="org.apache.maven.archiva"/>
</properties>
</configuration>
</component>
ignored ??
<component>
<role>org.apache.maven.archiva.security.ServletAuthenticator</role>
<role-hint>default</role-hint>
<implementation>org.apache.maven.archiva.security.ArchivaServletAuthenticator</implementation>
<description>ArchivaServletAuthenticator</description>
<requirements>
<requirement>
<role>org.codehaus.plexus.redback.system.SecuritySystem</role>
<role-hint>testable</role-hint>
<field-name>securitySystem</field-name>
</requirement>
</requirements>
</component>
partially configured
<component>
<role>org.codehaus.plexus.redback.role.RoleManager</role>
<role-hint>default</role-hint>
<implementation>org.codehaus.plexus.redback.role.DefaultRoleManager</implementation>
<description>RoleProfileManager:</description>
<requirements>
<requirement>
<role>org.codehaus.plexus.redback.role.validator.RoleModelValidator</role>
<role-hint>default</role-hint>
<field-name>modelValidator</field-name>
</requirement>
<requirement>
<role>org.codehaus.plexus.redback.role.processor.RoleModelProcessor</role>
<role-hint>default</role-hint>
<field-name>modelProcessor</field-name>
</requirement>
<requirement>
<role>org.codehaus.plexus.redback.role.template.RoleTemplateProcessor</role>
<role-hint>default</role-hint>
<field-name>templateProcessor</field-name>
</requirement>
<requirement>
<role>org.codehaus.plexus.redback.rbac.RBACManager</role>
<role-hint>memory</role-hint>
<field-name>rbacManager</field-name>
</requirement>
</requirements>
</component>
-->
</beans>

View File

@ -160,20 +160,36 @@
<artifactId>struts2-core</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.plexus.registry</groupId>
<artifactId>plexus-registry-api</artifactId>
<groupId>org.codehaus.redback.components.registry</groupId>
<artifactId>spring-registry-api</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.plexus.registry</groupId>
<artifactId>plexus-registry-commons</artifactId>
<groupId>org.codehaus.redback.components.registry</groupId>
<artifactId>spring-registry-commons</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.plexus.cache</groupId>
<artifactId>plexus-cache-api</artifactId>
<groupId>org.codehaus.redback.components.cache</groupId>
<artifactId>spring-cache-api</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.plexus.cache</groupId>
<artifactId>plexus-cache-ehcache</artifactId>
<groupId>org.codehaus.redback.components.cache</groupId>
<artifactId>spring-cache-ehcache</artifactId>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache-core</artifactId>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>

76
pom.xml
View File

@ -90,6 +90,11 @@
<exclude>org.codehaus.plexus:plexus-xwork-integration</exclude>
<exclude>plexus:plexus-utils</exclude>
<exclude>com.google.code.atinject:atinject</exclude>
<exclude>org.codehaus.plexus.cache:plexus-cache-api</exclude>
<exclude>org.codehaus.plexus.cache:plexus-cache-ehcache</exclude>
<exclude>net.sf.ehcache:ehcache</exclude>
<exclude>org.codehaus.plexus.registry:plexus-registry-api</exclude>
<exclude>org.codehaus.plexus.registry:plexus-registry-commons</exclude>
</excludes>
</bannedDependencies>
</rules>
@ -207,7 +212,7 @@
<artifactId>maven-surefire-plugin</artifactId>
<version>2.8.1</version>
<configuration>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
<redirectTestOutputToFile>${surefire.redirectTestOutputToFile}</redirectTestOutputToFile>
</configuration>
</plugin>
<plugin>
@ -749,26 +754,14 @@
<version>1.5.5</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus.cache</groupId>
<artifactId>plexus-cache-api</artifactId>
<version>1.0-alpha-2</version>
<exclusions>
<exclusion>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-container-default</artifactId>
</exclusion>
</exclusions>
<groupId>org.codehaus.redback.components.cache</groupId>
<artifactId>spring-cache-api</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus.cache</groupId>
<artifactId>plexus-cache-ehcache</artifactId>
<version>1.0-alpha-2</version>
<exclusions>
<exclusion>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-container-default</artifactId>
</exclusion>
</exclusions>
<groupId>org.codehaus.redback.components.cache</groupId>
<artifactId>spring-cache-ehcache</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<!-- redback -->
@ -907,20 +900,14 @@
<!-- redback -->
<dependency>
<groupId>org.codehaus.plexus.registry</groupId>
<artifactId>plexus-registry-api</artifactId>
<version>1.0-alpha-2</version>
<exclusions>
<exclusion>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-container-default</artifactId>
</exclusion>
</exclusions>
<groupId>org.codehaus.redback.components.registry</groupId>
<artifactId>spring-registry-api</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus.registry</groupId>
<artifactId>plexus-registry-commons</artifactId>
<version>1.0-alpha-2</version>
<groupId>org.codehaus.redback.components.registry</groupId>
<artifactId>spring-registry-commons</artifactId>
<version>1.0-SNAPSHOT</version>
<exclusions>
<exclusion>
<groupId>ant</groupId>
@ -1152,6 +1139,28 @@
</exclusions>
</dependency>
-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-asm</artifactId>
<version>${spring.version}</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>jdom</groupId>
<artifactId>jdom</artifactId>
@ -1202,8 +1211,8 @@
</dependency>
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>1.3.0</version>
<artifactId>ehcache-core</artifactId>
<version>2.4.2</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
@ -1231,6 +1240,7 @@
<spring.version>3.0.5.RELEASE</spring.version>
<jackrabbit.version>2.2.5</jackrabbit.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<surefire.redirectTestOutputToFile>true</surefire.redirectTestOutputToFile>
</properties>
<profiles>
<profile>