<version>1.6.2</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.codehaus.plexus.redback</groupId>
+ <artifactId>redback-keys-memory</artifactId>
+ <version>${redback.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.plexus.redback</groupId>
+ <artifactId>redback-rbac-memory</artifactId>
+ <version>${redback.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.plexus.redback</groupId>
+ <artifactId>redback-users-memory</artifactId>
+ <!-- TODO! when online next
+ <version>${redback.version}</version>
+ -->
+ <version>1.0-alpha-2-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
<plugins>
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
import java.util.Map;
/**
extends MultiplexedWebDavServlet
implements RegistryListener
{
- /**
- * @plexus.requirement
- */
private SecuritySystem securitySystem;
- /**
- * @plexus.requirement role-hint="basic"
- */
private HttpAuthenticator httpAuth;
- /**
- * @plexus.requirement
- */
private AuditLog audit;
- /**
- * @plexus.requirement
- */
private ArchivaConfiguration configuration;
- private Map<String, ManagedRepositoryConfiguration> repositoryMap =
- new HashMap<String, ManagedRepositoryConfiguration>();
+ private Map<String, ManagedRepositoryConfiguration> repositoryMap;
- public void initComponents()
+ public synchronized void initComponents()
throws ServletException
{
super.initComponents();
configuration = (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName() );
configuration.addChangeListener( this );
- updateRepositoryMap();
+ repositoryMap = configuration.getConfiguration().getManagedRepositoriesAsMap();
}
- public void initServers( ServletConfig servletConfig )
+ public synchronized void initServers( ServletConfig servletConfig )
throws DavServerException
{
- List repositories = configuration.getConfiguration().getManagedRepositories();
- Iterator itrepos = repositories.iterator();
- while ( itrepos.hasNext() )
+ for ( ManagedRepositoryConfiguration repo : repositoryMap.values() )
{
- ManagedRepositoryConfiguration repo = (ManagedRepositoryConfiguration) itrepos.next();
-
File repoDir = new File( repo.getLocation() );
if ( !repoDir.exists() )
}
}
- public ManagedRepositoryConfiguration getRepository( DavServerRequest request )
+ public synchronized ManagedRepositoryConfiguration getRepository( String prefix )
{
- // TODO: use sync wrapper instead?
- synchronized ( this.repositoryMap )
+ if ( repositoryMap == null )
{
- return repositoryMap.get( request.getPrefix() );
+ repositoryMap = configuration.getConfiguration().getManagedRepositoriesAsMap();
}
+ return repositoryMap.get( prefix );
}
- public String getRepositoryName( DavServerRequest request )
+ private String getRepositoryName( DavServerRequest request )
{
- ManagedRepositoryConfiguration repoConfig = getRepository( request );
+ ManagedRepositoryConfiguration repoConfig = getRepository( request.getPrefix() );
if ( repoConfig == null )
{
return "Unknown";
return repoConfig.getName();
}
- private void updateRepositoryMap()
- {
- synchronized ( this.repositoryMap )
- {
- this.repositoryMap.clear();
- this.repositoryMap.putAll( configuration.getConfiguration().getManagedRepositoriesAsMap() );
- }
- }
-
public boolean isAuthenticated( DavServerRequest davRequest, HttpServletResponse response )
throws ServletException, IOException
{
permission = ArchivaRoleConstants.OPERATION_REPOSITORY_UPLOAD;
}
- AuthorizationResult authzResult = securitySystem.authorize( securitySession, permission, davRequest
- .getPrefix() );
+ AuthorizationResult authzResult =
+ securitySystem.authorize( securitySession, permission, davRequest.getPrefix() );
if ( !authzResult.isAuthorized() )
{
// nothing to do
}
- public void afterConfigurationChange( Registry registry, String propertyName, Object propertyValue )
+ public synchronized void afterConfigurationChange( Registry registry, String propertyName, Object propertyValue )
{
if ( ConfigurationNames.isManagedRepositories( propertyName ) )
{
- // Attempt to reduce the number of times we refresh the repository map.
- if ( propertyName.endsWith( ".id" ) || propertyName.endsWith( ".url" ) )
+ if ( propertyName.endsWith( ".id" ) || propertyName.endsWith( ".location" ) )
{
- synchronized ( this.repositoryMap )
- {
- updateRepositoryMap();
-
- getDavManager().removeAllServers();
-
- try
- {
- initServers( getServletConfig() );
- }
- catch ( DavServerException e )
- {
- log( "Error restarting WebDAV server after configuration change - service disabled: " +
- e.getMessage(), e );
- }
- }
+ repositoryMap = null;
}
}
}
import com.meterware.httpunit.WebResponse;
import com.meterware.servletunit.ServletRunner;
import com.meterware.servletunit.ServletUnitClient;
+import org.apache.maven.archiva.configuration.ArchivaConfiguration;
+import org.apache.maven.archiva.configuration.Configuration;
+import org.apache.maven.archiva.configuration.IndeterminateConfigurationException;
+import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
import org.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.PlexusTestCase;
+import org.codehaus.plexus.registry.RegistryException;
import org.codehaus.plexus.util.FileUtils;
import org.xml.sax.SAXException;
+import javax.servlet.ServletException;
import java.io.File;
import java.io.IOException;
{
private ServletUnitClient sc;
- private String appserverBase;
+ private static final String REQUEST_PATH = "http://localhost/repository/internal/path/to/artifact.jar";
+
+ private File repositoryLocation;
+
+ private ArchivaConfiguration configuration;
+
+ private static final String REPOSITORY_ID = "internal";
+
+ private static final String NEW_REPOSITORY_ID = "new-id";
+
+ private static final String NEW_REPOSITORY_NAME = "New Repository";
protected void setUp()
throws Exception
{
super.setUp();
- appserverBase = getTestFile( "target/appserver-base" ).getAbsolutePath();
+ // TODO: purely to quiet logging - shouldn't be needed
+ String appserverBase = getTestFile( "target/appserver-base" ).getAbsolutePath();
System.setProperty( "appserver.base", appserverBase );
- System.setProperty( "derby.system.home", appserverBase );
+
+ configuration = (ArchivaConfiguration) lookup( ArchivaConfiguration.ROLE );
+
+ repositoryLocation = new File( appserverBase, "data/repositories/internal" );
ServletRunner sr = new ServletRunner();
sr.registerServlet( "/repository/*", UnauthenticatedRepositoryServlet.class.getName() );
public void testPutWithMissingParentCollection()
throws IOException, SAXException
{
- File repository = new File( appserverBase, "data/repositories/internal" );
- FileUtils.deleteDirectory( repository );
+ FileUtils.deleteDirectory( repositoryLocation );
- WebRequest request = new PutMethodWebRequest( "http://localhost/repository/internal/path/to/artifact.jar",
- getClass().getResourceAsStream( "/artifact.jar" ),
+ WebRequest request = new PutMethodWebRequest( REQUEST_PATH, getClass().getResourceAsStream( "/artifact.jar" ),
"application/octet-stream" );
WebResponse response = sc.getResponse( request );
assertNotNull( "No response received", response );
assertEquals( "file contents", "artifact.jar\n",
- FileUtils.fileRead( new File( repository, "path/to/artifact.jar" ) ) );
+ FileUtils.fileRead( new File( repositoryLocation, "path/to/artifact.jar" ) ) );
+ }
+
+ public void testGetRepository()
+ throws IOException, ServletException
+ {
+ RepositoryServlet servlet = (RepositoryServlet) sc.newInvocation( REQUEST_PATH ).getServlet();
+ assertNotNull( servlet );
+
+ ManagedRepositoryConfiguration repository = servlet.getRepository( REPOSITORY_ID );
+ assertNotNull( repository );
+ assertEquals( "Archiva Managed Internal Repository", repository.getName() );
+ }
+
+ public void testGetRepositoryAfterDelete()
+ throws IOException, ServletException, RegistryException, IndeterminateConfigurationException
+ {
+ RepositoryServlet servlet = (RepositoryServlet) sc.newInvocation( REQUEST_PATH ).getServlet();
+ assertNotNull( servlet );
+
+ Configuration c = configuration.getConfiguration();
+ c.removeManagedRepository( c.findManagedRepositoryById( REPOSITORY_ID ) );
+ // TODO! it would be better to use a mock configuration and "save" to more accurately reflect the calls made
+ triggerConfigurationChange( servlet, "managedRepositories.managedRepository(0).id", REPOSITORY_ID );
+
+ ManagedRepositoryConfiguration repository = servlet.getRepository( REPOSITORY_ID );
+ assertNull( repository );
+ }
+
+ public void testGetRepositoryAfterAdd()
+ throws IOException, ServletException, RegistryException, IndeterminateConfigurationException
+ {
+ RepositoryServlet servlet = (RepositoryServlet) sc.newInvocation( REQUEST_PATH ).getServlet();
+ assertNotNull( servlet );
+
+ Configuration c = configuration.getConfiguration();
+ ManagedRepositoryConfiguration repo = new ManagedRepositoryConfiguration();
+ repo.setId( NEW_REPOSITORY_ID );
+ repo.setName( NEW_REPOSITORY_NAME );
+ c.addManagedRepository( repo );
+ // TODO! it would be better to use a mock configuration and "save" to more accurately reflect the calls made
+ triggerConfigurationChange( servlet, "managedRepositories.managedRepository(2).id", NEW_REPOSITORY_ID );
+
+ ManagedRepositoryConfiguration repository = servlet.getRepository( NEW_REPOSITORY_ID );
+ assertNotNull( repository );
+ assertEquals( NEW_REPOSITORY_NAME, repository.getName() );
+
+ // check other is still intact
+ repository = servlet.getRepository( REPOSITORY_ID );
+ assertNotNull( repository );
+ assertEquals( "Archiva Managed Internal Repository", repository.getName() );
+ }
+
+ private void triggerConfigurationChange( RepositoryServlet servlet, String name, String value )
+ {
+ servlet.beforeConfigurationChange( null, name, value );
+ servlet.afterConfigurationChange( null, name, value );
}
}
<role>org.codehaus.plexus.webdav.DavServerManager</role>
<role-hint>default</role-hint>
<implementation>org.codehaus.plexus.webdav.DefaultDavServerManager</implementation>
- <description>DefaultDavServerManager</description>
<configuration>
<provider-hint>proxied</provider-hint>
</configuration>
</component>
+ <!-- TODO! shouldn't need so many components just to use in-memory - is flaky since these are auto-generated -->
<component>
- <role>org.codehaus.plexus.jdo.JdoFactory</role>
- <role-hint>users</role-hint>
- <implementation>org.codehaus.plexus.jdo.DefaultConfigurableJdoFactory</implementation>
- <configuration>
-
- <!-- HSQLDB Configuration -->
- <!--
- NOTE: NO NOT USE THIS CONFIGURATION FOR A PRODUCTION SYSTEM.
- HSQLDB keeps all data in memory at all times.
+ <role>org.codehaus.plexus.redback.system.SecuritySystem</role>
+ <role-hint>default</role-hint>
+ <implementation>org.codehaus.plexus.redback.system.DefaultSecuritySystem</implementation>
+ <requirements>
+ <requirement>
+ <role>org.codehaus.plexus.redback.authentication.AuthenticationManager</role>
+ <field-name>authnManager</field-name>
+ </requirement>
+ <requirement>
+ <role>org.codehaus.plexus.redback.authorization.Authorizer</role>
+ <role-hint>rbac</role-hint>
+ <field-name>authorizer</field-name>
+ </requirement>
+ <requirement>
+ <role>org.codehaus.plexus.redback.users.UserManager</role>
+ <role-hint>memory</role-hint>
+ <field-name>userManager</field-name>
+ </requirement>
+ <requirement>
+ <role>org.codehaus.plexus.redback.keys.KeyManager</role>
+ <role-hint>memory</role-hint>
+ <field-name>keyManager</field-name>
+ </requirement>
+ <requirement>
+ <role>org.codehaus.plexus.redback.policy.UserSecurityPolicy</role>
+ <field-name>policy</field-name>
+ </requirement>
+ </requirements>
+ </component>
- NOTE: JPOX 1.1.1 won't create the tables on start
- http://www.jpox.org/servlet/jira/browse/CORE-2946
- -->
+ <component>
+ <role>org.codehaus.plexus.redback.authentication.Authenticator</role>
+ <role-hint>user-manager</role-hint>
+ <implementation>org.codehaus.plexus.redback.authentication.users.UserManagerAuthenticator</implementation>
+ <requirements>
+ <requirement>
+ <role>org.codehaus.plexus.redback.users.UserManager</role>
+ <role-hint>memory</role-hint>
+ <field-name>userManager</field-name>
+ </requirement>
+ <requirement>
+ <role>org.codehaus.plexus.redback.policy.UserSecurityPolicy</role>
+ <field-name>securityPolicy</field-name>
+ </requirement>
+ </requirements>
+ </component>
- <!--
- <driverName>org.hsqldb.jdbcDriver</driverName>
- <url>jdbc:hsqldb:mem:test</url>
- <userName>sa</userName>
- <password></password>
- -->
+ <component>
+ <role>org.codehaus.plexus.redback.authentication.Authenticator</role>
+ <role-hint>keystore</role-hint>
+ <implementation>org.codehaus.plexus.redback.authentication.keystore.KeyStoreAuthenticator</implementation>
+ <requirements>
+ <requirement>
+ <role>org.codehaus.plexus.redback.keys.KeyManager</role>
+ <role-hint>memory</role-hint>
+ <field-name>keystore</field-name>
+ </requirement>
+ <requirement>
+ <role>org.codehaus.plexus.redback.users.UserManager</role>
+ <role-hint>memory</role-hint>
+ <field-name>userManager</field-name>
+ </requirement>
+ </requirements>
+ </component>
- <!-- Apache Derby Configuration -->
- <driverName>org.apache.derby.jdbc.EmbeddedDriver</driverName>
- <url>jdbc:derby:${basedir}/target/appserver-base/database;create=true</url>
- <userName>sa</userName>
- <password></password>
+ <component>
+ <role>org.codehaus.plexus.redback.authorization.rbac.evaluator.PermissionEvaluator</role>
+ <role-hint>default</role-hint>
+ <implementation>org.codehaus.plexus.redback.authorization.rbac.evaluator.DefaultPermissionEvaluator
+ </implementation>
+ <requirements>
+ <requirement>
+ <role>org.codehaus.plexus.redback.users.UserManager</role>
+ <role-hint>memory</role-hint>
+ <field-name>userManager</field-name>
+ </requirement>
+ </requirements>
+ </component>
- <!-- MySql Configuration -->
- <!--
- <driverName>com.mysql.jdbc.Driver</driverName>
- <url>jdbc:mysql://localhost/archiva</url>
- <userName>archiva</userName>
- <password>archiva</password>
- -->
+ <component>
+ <role>org.codehaus.plexus.redback.authorization.Authorizer</role>
+ <role-hint>rbac</role-hint>
+ <implementation>org.codehaus.plexus.redback.authorization.rbac.RbacAuthorizer</implementation>
+ <requirements>
+ <requirement>
+ <role>org.codehaus.plexus.redback.rbac.RBACManager</role>
+ <role-hint>memory</role-hint>
+ <field-name>manager</field-name>
+ </requirement>
+ <requirement>
+ <role>org.codehaus.plexus.redback.users.UserManager</role>
+ <role-hint>memory</role-hint>
+ <field-name>userManager</field-name>
+ </requirement>
+ <requirement>
+ <role>org.codehaus.plexus.redback.authorization.rbac.evaluator.PermissionEvaluator</role>
+ <role-hint>default</role-hint>
+ <field-name>evaluator</field-name>
+ </requirement>
+ </requirements>
+ </component>
- <!-- Postgresql Configuration -->
- <!--
- <driverName>org.postgresql.Driver</driverName>
- <url>jdbc:postgresql://localhost/continuum</url>
- <userName>username</userName>
- <password></password>
- -->
+ <component>
+ <role>org.codehaus.plexus.redback.role.RoleManager</role>
+ <role-hint>default</role-hint>
+ <implementation>org.codehaus.plexus.redback.role.DefaultRoleManager</implementation>
+ <instantiation-strategy>singleton</instantiation-strategy>
+ <requirements>
+ <requirement>
+ <role>org.codehaus.plexus.redback.role.merger.RoleModelMerger</role>
+ <role-hint>default</role-hint>
+ <field-name>modelMerger</field-name>
+ </requirement>
+ <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>
+ <requirement>
+ <role>org.codehaus.plexus.PlexusContainer</role>
+ <field-name>container</field-name>
+ </requirement>
+ </requirements>
+ </component>
- <!-- JPOX and JDO configuration -->
- <persistenceManagerFactoryClass>org.jpox.PersistenceManagerFactoryImpl</persistenceManagerFactoryClass>
- <otherProperties>
- <property>
- <name>javax.jdo.PersistenceManagerFactoryClass</name>
- <value>org.jpox.PersistenceManagerFactoryImpl</value>
- </property>
- <property>
- <name>org.jpox.autoCreateSchema</name>
- <value>true</value>
- </property>
- <property>
- <name>org.jpox.autoStartMechanism</name>
- <value>SchemaTable</value>
- </property>
- <property>
- <name>org.jpox.autoStartMechanismMode</name>
- <value>Ignored</value>
- </property>
- <property>
- <name>org.jpox.validateTables</name>
- <value>false</value>
- </property>
- <property>
- <name>org.jpox.validateConstraints</name>
- <value>false</value>
- </property>
- <property>
- <name>org.jpox.transactionIsolation</name>
- <value>READ_UNCOMMITTED</value>
- </property>
- <property>
- <name>org.jpox.poid.transactionIsolation</name>
- <value>READ_UNCOMMITTED</value>
- </property>
- <property>
- <name>org.jpox.rdbms.dateTimezone</name>
- <value>JDK_DEFAULT_TIMEZONE</value>
- </property>
- </otherProperties>
- </configuration>
+ <component>
+ <role>org.codehaus.plexus.redback.role.processor.RoleModelProcessor</role>
+ <role-hint>default</role-hint>
+ <implementation>org.codehaus.plexus.redback.role.processor.DefaultRoleModelProcessor</implementation>
+ <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>
+ <requirements>
+ <requirement>
+ <role>org.codehaus.plexus.redback.rbac.RBACManager</role>
+ <role-hint>memory</role-hint>
+ <field-name>rbacManager</field-name>
+ </requirement>
+ </requirements>
+ </component>
</components>
</plexus>