merged MRM-124 branch (-r706118) - archiva web services

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@706126 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Maria Odea B. Ching 2008-10-20 05:59:47 +00:00
parent c64358cfd1
commit c303ba78c7
48 changed files with 3472 additions and 99 deletions

View File

@ -117,4 +117,9 @@ public abstract class AbstractLegacyRepositoryContent
// Default process.
return type + "s";
}
public void setLegacyPathParser( PathParser parser )
{
this.legacyPathParser = parser;
}
}

View File

@ -78,6 +78,10 @@ public class ManagedDefaultRepositoryContent
// TODO: log this somewhere?
}
}
else
{
throw new ContentNotFoundException( "Unable to delete non-existing project directory." );
}
}
public String getId()

View File

@ -454,4 +454,9 @@ public class ManagedLegacyRepositoryContent
}
}
}
public void setFileTypes( FileTypes fileTypes )
{
this.filetypes = fileTypes;
}
}

View File

@ -33,10 +33,13 @@ public abstract class AbstractArchivaXmlTestCase
extends TestCase
{
protected static final String OSLASH = "\u00f8";
protected static final String TRYGVIS = "Trygve Laugst" + OSLASH + "l";
protected static final String INFIN = "\u221e";
protected static final String INFINITE_ARCHIVA = "The " + INFIN + " Archiva";
protected File getExampleXml( String filename )
{
File examplesDir = new File( "src/test/examples" );

View File

@ -35,18 +35,20 @@ public class ArtifactVersionsConstraint
private String sortColumn = "repositoryId";
public ArtifactVersionsConstraint( String repoId, String groupId, String artifactId )
public ArtifactVersionsConstraint( String repoId, String groupId, String artifactId, boolean includeWhenGathered )
{
if( repoId != null )
{
whereClause = "repositoryId.equals(selectedRepoId) && groupId.equals(selectedGroupId) && artifactId.equals(selectedArtifactId) " +
"&& whenGathered != null";
whereClause = "repositoryId.equals(selectedRepoId) && groupId.equals(selectedGroupId) && artifactId.equals(selectedArtifactId) "
+ ( includeWhenGathered ? "&& whenGathered != null" : "" );
declParams = new String[] { "String selectedRepoId", "String selectedGroupId", "String selectedArtifactId" };
params = new Object[] { repoId, groupId, artifactId };
}
else
{
whereClause = "groupId.equals(selectedGroupId) && artifactId.equals(selectedArtifactId) && this.whenGathered != null";
whereClause =
"groupId.equals(selectedGroupId) && artifactId.equals(selectedArtifactId) " +
( includeWhenGathered ? "&& whenGathered != null" : "" );
declParams = new String[] { "String selectedGroupId", "String selectedArtifactId" };
params = new Object[] { groupId, artifactId };
}
@ -54,7 +56,7 @@ public class ArtifactVersionsConstraint
public ArtifactVersionsConstraint( String repoId, String groupId, String artifactId, String sortColumn )
{
this( repoId, groupId, artifactId );
this( repoId, groupId, artifactId, true );
this.sortColumn = sortColumn;
}

View File

@ -87,14 +87,14 @@ public class ArtifactVersionsConstraintTest
{
populateDb();
assertConstraint( "Artifacts By Repository", 3,
new ArtifactVersionsConstraint( null, "org.apache.archiva", "artifact-one" ) );
new ArtifactVersionsConstraint( null, "org.apache.archiva", "artifact-one", true ) );
}
public void testQueryAllVersionsOfArtifactInARepo() throws Exception
{
populateDb();
assertConstraint( "Artifacts By Repository", 2,
new ArtifactVersionsConstraint( TEST_REPO, "org.apache.archiva", "artifact-one" ) );
new ArtifactVersionsConstraint( TEST_REPO, "org.apache.archiva", "artifact-one", true ) );
}
private void assertConstraint( String msg, int count, ArtifactVersionsConstraint constraint )

View File

@ -84,6 +84,18 @@
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-rss</artifactId>
</dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-xmlrpc-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-xmlrpc-services</artifactId>
</dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-xmlrpc-security</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
@ -221,6 +233,11 @@
<artifactId>commons-logging-api</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>com.atlassian.xmlrpc</groupId>
<artifactId>atlassian-xmlrpc-binder-server-spring</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>
<build>
<resources>

View File

@ -30,4 +30,27 @@
<bean id="propertyPlaceholder" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:application.properties" />
</bean>
<bean name="testXmlRpcService" lazy-init="true" scope="singleton" class="org.apache.archiva.web.xmlrpc.services.PingServiceImpl"/>
<bean name="administrationService" lazy-init="true" scope="singleton" class="org.apache.archiva.web.xmlrpc.services.AdministrationServiceImpl">
<constructor-arg ref="archivaConfiguration"/>
<constructor-arg ref="repositoryContentConsumers"/>
<constructor-arg ref="databaseConsumers"/>
<constructor-arg ref="repositoryContentFactory"/>
<constructor-arg ref="artifactDAO#jdo"/>
<constructor-arg ref="databaseCleanupConsumer#not-present-remove-db-artifact"/>
<constructor-arg ref="databaseCleanupConsumer#not-present-remove-db-project"/>
<constructor-arg ref="archivaTaskScheduler"/>
</bean>
<bean name="xmlrpcServicesList" lazy-init="true" scope="singleton" class="java.util.ArrayList">
<constructor-arg ref="administrationService"/>
</bean>
<bean name="xmlRpcAuthenticator" class="org.apache.archiva.web.xmlrpc.security.XmlRpcAuthenticator">
<constructor-arg>
<ref bean="securitySystem"/>
</constructor-arg>
</bean>
</beans>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Licensed to the Apache Software Foundation (ASF) under one
~ or more contributor license agreements. See the NOTICE file
@ -18,106 +18,143 @@
~ under the License.
-->
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" version="2.4"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Apache Archiva</display-name>
<display-name>Apache Archiva</display-name>
<filter>
<filter-name>webwork-cleanup</filter-name>
<filter-class>org.apache.struts2.dispatcher.ActionContextCleanUp</filter-class>
</filter>
<filter>
<filter-name>webwork-cleanup</filter-name>
<filter-class>org.apache.struts2.dispatcher.ActionContextCleanUp</filter-class>
</filter>
<filter>
<filter-name>sitemesh</filter-name>
<filter-class>com.opensymphony.module.sitemesh.filter.PageFilter</filter-class>
</filter>
<filter>
<filter-name>sitemesh</filter-name>
<filter-class>
com.opensymphony.module.sitemesh.filter.PageFilter
</filter-class>
</filter>
<filter>
<filter-name>webwork</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter>
<filter-name>webwork</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<!-- this must be before the sitemesh filter -->
<filter-mapping>
<filter-name>webwork-cleanup</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- this must be before the sitemesh filter -->
<filter-mapping>
<filter-name>webwork-cleanup</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>sitemesh</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>sitemesh</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>webwork</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>webwork</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<!-- TODO: some Spring technique for this? -->
<listener-class>org.apache.maven.archiva.web.startup.ArchivaStartup</listener-class>
</listener>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<listener>
<!-- TODO: some Spring technique for this? -->
<listener-class>
org.apache.maven.archiva.web.startup.ArchivaStartup
</listener-class>
</listener>
<context-param>
<param-name>contextClass</param-name>
<param-value>org.codehaus.plexus.spring.PlexusWebApplicationContext</param-value>
</context-param>
<context-param>
<param-name>contextClass</param-name>
<param-value>
org.codehaus.plexus.spring.PlexusWebApplicationContext
</param-value>
</context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath*:META-INF/plexus/components.xml
classpath*:META-INF/spring-context.xml
/WEB-INF/classes/META-INF/plexus/application.xml
/WEB-INF/classes/META-INF/plexus/components.xml
/WEB-INF/applicationContext.xml
</param-value>
</context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath*:META-INF/plexus/components.xml
classpath*:META-INF/spring-context.xml
/WEB-INF/classes/META-INF/plexus/application.xml
/WEB-INF/classes/META-INF/plexus/components.xml
/WEB-INF/applicationContext.xml
</param-value>
</context-param>
<servlet>
<servlet-name>RepositoryServlet</servlet-name>
<servlet-class>org.apache.maven.archiva.webdav.RepositoryServlet</servlet-class>
<!-- Loading this on startup so as to take advantage of configuration listeners -->
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>RssFeedServlet</servlet-name>
<servlet-class>org.apache.maven.archiva.web.rss.RssFeedServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>RssFeedServlet</servlet-name>
<url-pattern>/feeds/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>RepositoryServlet</servlet-name>
<url-pattern>/repository/*</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>RepositoryServlet</servlet-name>
<servlet-class>
org.apache.maven.archiva.webdav.RepositoryServlet
</servlet-class>
<!-- Loading this on startup so as to take advantage of configuration listeners -->
<load-on-startup>1</load-on-startup>
</servlet>
<resource-ref>
<res-ref-name>jdbc/users</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
<resource-ref>
<res-ref-name>jdbc/archiva</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
<resource-ref>
<res-ref-name>mail/Session</res-ref-name>
<res-type>javax.mail.Session</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
<servlet>
<servlet-name>XmlRpcServlet</servlet-name>
<servlet-class>
com.atlassian.xmlrpc.spring.BinderSpringXmlRpcServlet
</servlet-class>
<init-param>
<param-name>serviceListBeanName</param-name>
<param-value>xmlrpcServicesList</param-value>
</init-param>
<init-param>
<param-name>authHandlerBeanName</param-name>
<param-value>xmlRpcAuthenticator</param-value>
</init-param>
<init-param>
<param-name>enabledForExtensions</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>RssFeedServlet</servlet-name>
<servlet-class>
org.apache.maven.archiva.web.rss.RssFeedServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>RssFeedServlet</servlet-name>
<url-pattern>/feeds/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>RepositoryServlet</servlet-name>
<url-pattern>/repository/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>XmlRpcServlet</servlet-name>
<url-pattern>/xmlrpc</url-pattern>
</servlet-mapping>
<resource-ref>
<res-ref-name>jdbc/users</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
<resource-ref>
<res-ref-name>jdbc/archiva</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
<resource-ref>
<res-ref-name>mail/Session</res-ref-name>
<res-type>javax.mail.Session</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
</web-app>

View File

@ -0,0 +1,40 @@
<?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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-xmlrpc</artifactId>
<version>1.2-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>archiva-xmlrpc-api</artifactId>
<name>Archiva Web :: XML-RPC API</name>
<dependencies>
<dependency>
<groupId>com.atlassian.xmlrpc</groupId>
<artifactId>atlassian-xmlrpc-binder-annotations</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,115 @@
package org.apache.archiva.web.xmlrpc.api;
/*
* 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.
*/
import java.util.List;
import org.apache.archiva.web.xmlrpc.api.beans.ManagedRepository;
import org.apache.archiva.web.xmlrpc.api.beans.RemoteRepository;
import com.atlassian.xmlrpc.ServiceObject;
@ServiceObject( "AdministrationService" )
public interface AdministrationService
{
/**
* Executes repository scanner on the given repository.
*
* @param repoId id of the repository to be scanned
* @return
* @throws Exception
*/
public Boolean executeRepositoryScanner( String repoId ) throws Exception;
/**
* Executes the database scanner.
*
* @return
* @throws Exception
*/
public Boolean executeDatabaseScanner() throws Exception;
/**
* Gets all available database consumers.
* @return
*/
public List<String> getAllDatabaseConsumers();
/**
* Configures (enable or disable) database consumer.
*
* @param consumerId id of the database consumer
* @param enable flag whether to enable or disable the specified consumer
* @return
* @throws Exception
*/
public Boolean configureDatabaseConsumer( String consumerId, boolean enable ) throws Exception;
/**
* Gets all available repository consumers.
*
* @return
*/
public List<String> getAllRepositoryConsumers();
// TODO should we already implement config of consumers per repository?
/**
* Configures (enable or disable) repository consumer.
*
* @param repoId
* @param consumerId
* @param enable
* @return
* @throws Exception
*/
public Boolean configureRepositoryConsumer( String repoId, String consumerId, boolean enable ) throws Exception;
/**
* Gets all managed repositories.
*
* @return
*/
public List<ManagedRepository> getAllManagedRepositories();
/**
* Gets all remote repositories.
*
* @return
*/
public List<RemoteRepository> getAllRemoteRepositories();
/**
* Deletes given artifact from the specified repository.
*
* @param repoId id of the repository where the artifact to be deleted resides
* @param groupId groupId of the artifact to be deleted
* @param artifactId artifactId of the artifact to be deleted
* @param version version of the artifact to be deleted
* @return
* @throws Exception
*/
public Boolean deleteArtifact( String repoId, String groupId, String artifactId, String version )
throws Exception;
//TODO
// consider the following as additional services:
// - getAllConfiguredRepositoryConsumers( String repoId ) - list all enabled consumers for the repo
// - getAllConfiguredDatabaseConsumers() - list all enabled db consumers
}

View File

@ -0,0 +1,28 @@
package org.apache.archiva.web.xmlrpc.api;
/*
* 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.
*/
import com.atlassian.xmlrpc.ServiceObject;
@ServiceObject("Search")
public interface SearchService
{
}

View File

@ -0,0 +1,28 @@
package org.apache.archiva.web.xmlrpc.api;
/*
* 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.
*/
import com.atlassian.xmlrpc.ServiceObject;
@ServiceObject("Test")
public interface TestService
{
public String ping();
}

View File

@ -0,0 +1,152 @@
package org.apache.archiva.web.xmlrpc.api.beans;
/*
* 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.
*/
import java.io.Serializable;
import com.atlassian.xmlrpc.ServiceBean;
import com.atlassian.xmlrpc.ServiceBeanField;
@ServiceBean
public class ManagedRepository
implements Serializable
{
private String id;
private String name;
private String url;
private String layout;
private boolean snapshots = false;
private boolean releases = false;
public ManagedRepository()
{
}
public ManagedRepository( String id, String name, String url, String layout, boolean snapshots, boolean releases )
{
this.id = id;
this.name = name;
this.url = url;
this.layout = layout;
this.snapshots = snapshots;
this.releases = releases;
}
public boolean equals(Object other)
{
if ( this == other)
{
return true;
}
if ( !(other instanceof ManagedRepository) )
{
return false;
}
ManagedRepository that = (ManagedRepository) other;
boolean result = true;
result = result && ( getId() == null ? that.getId() == null : getId().equals( that.getId() ) );
return result;
}
public String getId()
{
return this.id;
}
public String getLayout()
{
return this.layout;
}
public String getName()
{
return this.name;
}
public String getUrl()
{
return this.url;
}
public int hashCode()
{
int result = 17;
long tmp;
result = 37 * result + ( id != null ? id.hashCode() : 0 );
return result;
}
public boolean isReleases()
{
return this.releases;
}
/**
* Get null
*/
public boolean isSnapshots()
{
return this.snapshots;
}
@ServiceBeanField( "id" )
public void setId(String id)
{
this.id = id;
}
@ServiceBeanField( "layout" )
public void setLayout(String layout)
{
this.layout = layout;
}
@ServiceBeanField( "name" )
public void setName(String name)
{
this.name = name;
}
@ServiceBeanField( "releases" )
public void setReleases(boolean releases)
{
this.releases = releases;
}
@ServiceBeanField( "snapshots" )
public void setSnapshots(boolean snapshots)
{
this.snapshots = snapshots;
}
@ServiceBeanField( "url" )
public void setUrl(String url)
{
this.url = url;
}
}

View File

@ -0,0 +1,121 @@
package org.apache.archiva.web.xmlrpc.api.beans;
/*
* 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.
*/
import java.io.Serializable;
import com.atlassian.xmlrpc.ServiceBean;
import com.atlassian.xmlrpc.ServiceBeanField;
@ServiceBean
public class RemoteRepository
implements Serializable
{
private String id;
private String name;
private String url;
private String layout;
public RemoteRepository()
{
}
public RemoteRepository( String id, String name, String url, String layout )
{
this.id = id;
this.name = name;
this.url = url;
this.layout = layout;
}
public boolean equals(Object other)
{
if ( this == other)
{
return true;
}
if ( !(other instanceof RemoteRepository) )
{
return false;
}
RemoteRepository that = (RemoteRepository) other;
boolean result = true;
result = result && ( getId() == null ? that.getId() == null : getId().equals( that.getId() ) );
return result;
}
public String getId()
{
return this.id;
}
public String getLayout()
{
return this.layout;
}
public String getName()
{
return this.name;
}
public String getUrl()
{
return this.url;
}
public int hashCode()
{
int result = 17;
long tmp;
result = 37 * result + ( id != null ? id.hashCode() : 0 );
return result;
}
@ServiceBeanField( "id" )
public void setId(String id)
{
this.id = id;
}
@ServiceBeanField( "layout" )
public void setLayout(String layout)
{
this.layout = layout;
}
@ServiceBeanField( "name" )
public void setName(String name)
{
this.name = name;
}
@ServiceBeanField( "url" )
public void setUrl(String url)
{
this.url = url;
}
}

View File

@ -0,0 +1,94 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2005-2006 The Apache Software Foundation.
~
~ Licensed 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.
-->
<project>
<parent>
<artifactId>archiva-xmlrpc</artifactId>
<groupId>org.apache.archiva</groupId>
<version>1.2-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>archiva-xmlrpc-client</artifactId>
<name>Archiva Web :: XML-RPC Client</name>
<dependencies>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-xmlrpc-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.xmlrpc</groupId>
<artifactId>xmlrpc-client</artifactId>
<version>3.1</version>
</dependency>
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.8.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<configuration>
<executable>java</executable>
<mainClass>org.apache.archiva.web.xmlrpc.client.SampleClient</mainClass>
<arguments>
<!--
URL: ex. http://127.0.0.1:8080/archiva/xmlrpc
USERNAME & PASSWORD: Archiva credentials
-->
<argument>URL</argument>
<argument>USERNAME</argument>
<argument>PASSWORD</argument>
</arguments>
</configuration>
</plugin>
<!-- override parent config, commons-logging cannot be excluded from commons-beanutils - NoClassDef error occurs -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.0-alpha-3</version>
<executions>
<execution>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<bannedDependencies>
<excludes>
<exclude>org.codehaus.plexus:plexus-container-default</exclude>
<exclude>velocity:velocity-dep</exclude>
<exclude>classworlds:classworlds</exclude>
<exclude>javax.transaction:jta</exclude>
<exclude>javax.sql:jdbc-stdext</exclude>
<exclude>ant:ant-optional</exclude>
<!-- exclude>org.apache.maven.wagon:wagon-http-lightweight</exclude -->
<exclude>xom:xom</exclude>
</excludes>
</bannedDependencies>
</rules>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,193 @@
package org.apache.archiva.web.xmlrpc.client;
/*
* 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.
*/
import java.lang.reflect.InvocationTargetException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.archiva.web.xmlrpc.api.AdministrationService;
import org.apache.archiva.web.xmlrpc.api.beans.ManagedRepository;
import org.apache.archiva.web.xmlrpc.api.beans.RemoteRepository;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.client.XmlRpcClient;
import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
import org.apache.xmlrpc.client.XmlRpcClientRequestImpl;
import org.apache.xmlrpc.client.util.ClientFactory;
/**
* TestClient
*
* Test client for Archiva Web Services.
* To execute:
*
* 1. set the <arguments> in the exec-maven-plugin config in the pom.xml in the following order:
* - url
* - username
* - password
* 2. execute 'mvn exec:java' from the command-line
*
* @author
* @version $Id$
*/
public class SampleClient
{
public static void main( String[] args )
{
try
{
XmlRpcClient client = new XmlRpcClient();
XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
config.setServerURL( new URL( args[0] ) );
config.setBasicUserName( args[1] );
config.setBasicPassword( args[2] );
config.setEnabledForExtensions( true );
client.setConfig( config );
/* managed repositories */
Object[] params = new Object[]{};
Object[] managedRepos = (Object[])
client.execute( "AdministrationService.getAllManagedRepositories", params );
System.out.println( "\n******** Managed Repositories ********" );
for( int i = 0; i < managedRepos.length; i++ )
{
System.out.println( "=================================" );
ManagedRepository managedRepo = new ManagedRepository();
try
{
BeanUtils.populate( managedRepo, (Map)managedRepos[i] );
}
catch ( IllegalAccessException e )
{
e.printStackTrace();
}
catch ( InvocationTargetException e )
{
e.printStackTrace();
}
System.out.println( "Id: " + managedRepo.getId() );
System.out.println( "Name: " + managedRepo.getName() );
System.out.println( "Layout: " + managedRepo.getLayout() );
System.out.println( "URL: " + managedRepo.getUrl() );
System.out.println( "Releases: " + managedRepo.isReleases() );
System.out.println( "Snapshots: " + managedRepo.isSnapshots() );
}
/* remote repositories */
params = new Object[]{};
Object[] remoteRepos = (Object[])
client.execute( "AdministrationService.getAllRemoteRepositories", params );
System.out.println( "\n******** Remote Repositories ********" );
for( int i = 0; i < remoteRepos.length; i++ )
{
System.out.println( "=================================" );
RemoteRepository remoteRepo = new RemoteRepository();
try
{
BeanUtils.populate( remoteRepo, (Map) remoteRepos[i] );
}
catch ( IllegalAccessException e )
{
e.printStackTrace();
}
catch ( InvocationTargetException e )
{
e.printStackTrace();
}
System.out.println( "Id: " + remoteRepo.getId() );
System.out.println( "Name: " + remoteRepo.getName() );
System.out.println( "Layout: " + remoteRepo.getLayout() );
System.out.println( "URL: " + remoteRepo.getUrl() );
}
/* repo consumers */
params = new Object[]{};
Object[] repoConsumers = (Object[])
client.execute( "AdministrationService.getAllRepositoryConsumers", params );
System.out.println( "\n******** Repository Consumers ********" );
for( int i = 0; i < repoConsumers.length; i++ )
{
System.out.println( repoConsumers[i] );
}
/* db consumers */
params = new Object[]{};
Object[] dbConsumers = (Object[])
client.execute( "AdministrationService.getAllDatabaseConsumers", params );
System.out.println( "\n******** Database Consumers ********" );
for( int i = 0; i < dbConsumers.length; i++ )
{
System.out.println( dbConsumers[i] );
}
/* configure repo consumer */
Object[] configureRepoConsumerParams = new Object[] { "internal", "repository-purge", true };
Object configured = client.execute( "AdministrationService.configureRepositoryConsumer", configureRepoConsumerParams );
System.out.println( "\nConfigured repo consumer 'repository-purge' : " + ( ( Boolean ) configured ).booleanValue() );
/* configure db consumer */
Object[] configureDbConsumerParams = new Object[] { "update-db-bytecode-stats", false };
configured = client.execute( "AdministrationService.configureDatabaseConsumer", configureDbConsumerParams );
System.out.println( "\nConfigured db consumer 'update-db-bytecode-stats' : " + ( ( Boolean ) configured ).booleanValue() );
/* execute repo scanner */
Object[] executeRepoScanParams = new Object[] { "internal" };
configured = client.execute( "AdministrationService.executeRepositoryScanner", executeRepoScanParams );
System.out.println( "\nExecuted repo scanner of repository 'internal' : " + ( ( Boolean ) configured ).booleanValue() );
/* execute db scanner */
Object[] executeDbScanParams = new Object[] {};
configured = client.execute( "AdministrationService.executeDatabaseScanner", executeDbScanParams );
System.out.println( "\nExecuted database scanner : " + ( ( Boolean ) configured ).booleanValue() );
/* delete artifact */
/*
* NOTE: before enabling & invoking deleteArtifact, make sure that the repository and artifact exists first!
Object[] deleteArtifactParams = new Object[] { "internal", "javax.activation", "activation", "1.1" };
Object artifactDeleted = client.execute( "AdministrationService.deleteArtifact", deleteArtifactParams );
System.out.println( "\nDeleted artifact 'javax.activation:activation:1.1' from repository 'internal' : " +
( (Boolean) artifactDeleted ).booleanValue() );
*/
}
catch ( MalformedURLException e )
{
e.printStackTrace();
}
catch ( XmlRpcException e )
{
e.printStackTrace();
}
}
}

View File

@ -0,0 +1,83 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2005-2006 The Apache Software Foundation.
~
~ Licensed 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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-xmlrpc</artifactId>
<version>1.2-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>archiva-xmlrpc-security</artifactId>
<name>Archiva Web :: XML-RPC Security</name>
<dependencies>
<dependency>
<groupId>org.apache.xmlrpc</groupId>
<artifactId>xmlrpc-server</artifactId>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.codehaus.redback</groupId>
<artifactId>redback-system</artifactId>
</dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-security</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-spring</artifactId>
<scope>test</scope>
</dependency>
<!-- use spring for the unit tests?
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<scope>test</scope>
</dependency>
-->
<dependency>
<groupId>org.codehaus.redback</groupId>
<artifactId>redback-authorization-rbac</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.codehaus.redback</groupId>
<artifactId>redback-keys-memory</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.codehaus.redback</groupId>
<artifactId>redback-users-memory</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.codehaus.redback</groupId>
<artifactId>redback-rbac-memory</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,69 @@
package org.apache.archiva.web.xmlrpc.security;
/*
* 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.
*/
import java.util.ArrayList;
import java.util.List;
/**
* ServiceMethodsPermissionsMapping
*
* Used by the XmlRpcAuthenticationHandler to check the permissions specific to the requested service method.
* New methods in exposed services must be registered in the appropriate operation below.
*
* @version $Id: ServiceMethodsPermissionsMapping.java
*/
public class ServiceMethodsPermissionsMapping
{
public static final List<String> SERVICE_METHODS_FOR_OPERATION_MANAGE_CONFIGURATION = new ArrayList<String>()
{
{
add( "AdministrationService.configureRepositoryConsumer" );
add( "AdministrationService.configureDatabaseConsumer" );
add( "AdministrationService.executeDatabaseScanner" );
add( "AdministrationService.getAllManagedRepositories" );
add( "AdministrationService.getAllRemoteRepositories" );
add( "AdministrationService.getAllDatabaseConsumers" );
add( "AdministrationService.getAllRepositoryConsumers" );
add( "AdministrationService.deleteArtifact" );
}
};
public static final List<String> SERVICE_METHODS_FOR_OPERATION_RUN_INDEXER = new ArrayList<String>()
{
{
add( "AdministrationService.executeRepositoryScanner");
}
};
public static final List<String> SERVICE_METHODS_FOR_OPERATION_ACCESS_REPORT = new ArrayList<String>();
public static final List<String> SERVICE_METHODS_FOR_OPERATION_REPOSITORY_ACCESS = new ArrayList<String>();
public static final List<String> SERVICE_METHODS_FOR_OPERATION_ADD_REPOSITORY = new ArrayList<String>();
public static final List<String> SERVICE_METHODS_FOR_OPERATION_DELETE_REPOSITORY = new ArrayList<String>();
public static final List<String> SERVICE_METHODS_FOR_OPERATION_EDIT_REPOSITORY = new ArrayList<String>();
public static final List<String> SERVICE_METHODS_FOR_OPERATION_REPOSITORY_UPLOAD = new ArrayList<String>();
}

View File

@ -0,0 +1,117 @@
package org.apache.archiva.web.xmlrpc.security;
/*
* 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.
*/
import org.apache.maven.archiva.security.ArchivaRoleConstants;
import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.XmlRpcRequest;
import org.apache.xmlrpc.common.XmlRpcHttpRequestConfigImpl;
import org.apache.xmlrpc.server.AbstractReflectiveHandlerMapping.AuthenticationHandler;
import org.codehaus.plexus.redback.authentication.AuthenticationException;
import org.codehaus.plexus.redback.authentication.PasswordBasedAuthenticationDataSource;
import org.codehaus.plexus.redback.authorization.AuthorizationException;
import org.codehaus.plexus.redback.authorization.AuthorizationResult;
import org.codehaus.plexus.redback.policy.AccountLockedException;
import org.codehaus.plexus.redback.system.SecuritySession;
import org.codehaus.plexus.redback.system.SecuritySystem;
import org.codehaus.plexus.redback.users.UserNotFoundException;
/**
* XmlRpcAuthenticator
*
* Custom authentication and authorization handler for xmlrpc requests.
*
* @version $Id
*/
public class XmlRpcAuthenticator
implements AuthenticationHandler
{
private final SecuritySystem securitySystem;
public XmlRpcAuthenticator( SecuritySystem securitySystem )
{
this.securitySystem = securitySystem;
}
public boolean isAuthorized( XmlRpcRequest pRequest )
throws XmlRpcException
{
if ( pRequest.getConfig() instanceof XmlRpcHttpRequestConfigImpl )
{
XmlRpcHttpRequestConfigImpl config = (XmlRpcHttpRequestConfigImpl) pRequest.getConfig();
SecuritySession session =
authenticate( new PasswordBasedAuthenticationDataSource( config.getBasicUserName(),
config.getBasicPassword() ) );
String method = pRequest.getMethodName();
AuthorizationResult result = authorize( session, method );
return result.isAuthorized();
}
throw new XmlRpcException( "Unsupported transport (must be http)" );
}
private SecuritySession authenticate( PasswordBasedAuthenticationDataSource authenticationDataSource )
throws XmlRpcException
{
try
{
return securitySystem.authenticate( authenticationDataSource );
}
catch ( AccountLockedException e )
{
throw new XmlRpcException( 401, e.getMessage(), e );
}
catch ( AuthenticationException e )
{
throw new XmlRpcException( 401, e.getMessage(), e );
}
catch ( UserNotFoundException e )
{
throw new XmlRpcException( 401, e.getMessage(), e );
}
}
private AuthorizationResult authorize( SecuritySession session, String methodName )
throws XmlRpcException
{
try
{
// sample attempt at simplifying authorization checking of requested service method
// TODO test with a sample client to see if this would work!
if ( ServiceMethodsPermissionsMapping.SERVICE_METHODS_FOR_OPERATION_MANAGE_CONFIGURATION.contains( methodName ) )
{
return securitySystem.authorize( session, ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION );
}
else if ( ServiceMethodsPermissionsMapping.SERVICE_METHODS_FOR_OPERATION_RUN_INDEXER.contains( methodName ) )
{
return securitySystem.authorize( session, ArchivaRoleConstants.OPERATION_RUN_INDEXER );
}
else
{
return securitySystem.authorize( session, ArchivaRoleConstants.GLOBAL_REPOSITORY_MANAGER_ROLE );
}
}
catch ( AuthorizationException e )
{
throw new XmlRpcException( 401, e.getMessage(), e );
}
}
}

View File

@ -0,0 +1,220 @@
package org.apache.archiva.xmlrpc.security;
/*
* 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.
*/
import org.apache.archiva.web.xmlrpc.security.XmlRpcAuthenticator;
import org.apache.maven.archiva.security.ArchivaRoleConstants;
import org.apache.xmlrpc.XmlRpcRequest;
import org.apache.xmlrpc.common.XmlRpcHttpRequestConfigImpl;
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.redback.users.UserNotFoundException;
import org.codehaus.plexus.spring.PlexusInSpringTestCase;
import org.easymock.MockControl;
import org.easymock.classextension.MockClassControl;
/**
* XmlRpcAuthenticatorTest
*
* @version $Id XmlRpcAuthenticatorTest.java
*/
public class XmlRpcAuthenticatorTest
//extends AbstractDependencyInjectionSpringContextTests
extends PlexusInSpringTestCase
{
protected static final String USER_GUEST = "guest";
protected static final String USER_ADMIN = "admin";
protected static final String USER_ALPACA = "alpaca";
private static final String PASSWORD = "password123";
protected SecuritySystem securitySystem;
protected RoleManager roleManager;
private MockControl xmlRpcRequestControl;
private XmlRpcRequest xmlRpcRequest;
private XmlRpcAuthenticator authenticator;
private MockControl configControl;
private XmlRpcHttpRequestConfigImpl config;
public void setUp()
throws Exception
{
super.setUp();
securitySystem = (SecuritySystem) lookup( SecuritySystem.class, "testable" );
roleManager = (RoleManager) lookup( RoleManager.class, "default" );
// Some basic asserts.
assertNotNull( securitySystem );
assertNotNull( roleManager );
// Setup Admin User.
User adminUser = createUser( USER_ADMIN, "Admin User", null );
roleManager.assignRole( ArchivaRoleConstants.TEMPLATE_SYSTEM_ADMIN, adminUser.getPrincipal().toString() );
// Setup Guest User.
User guestUser = createUser( USER_GUEST, "Guest User", null );
roleManager.assignRole( ArchivaRoleConstants.TEMPLATE_GUEST, guestUser.getPrincipal().toString() );
configControl = MockClassControl.createControl( XmlRpcHttpRequestConfigImpl.class );
config = ( XmlRpcHttpRequestConfigImpl ) configControl.getMock();
xmlRpcRequestControl = MockControl.createControl( XmlRpcRequest.class );
xmlRpcRequest = ( XmlRpcRequest ) xmlRpcRequestControl.getMock();
authenticator = new XmlRpcAuthenticator( securitySystem );
}
private User createUser( String principal, String fullname, String password )
throws UserNotFoundException
{
UserManager userManager = securitySystem.getUserManager();
User user = userManager.createUser( principal, fullname, principal + "@testable.archiva.apache.org" );
securitySystem.getPolicy().setEnabled( false );
userManager.addUser( user );
securitySystem.getPolicy().setEnabled( true );
user.setPassword( password );
userManager.updateUser( user );
return user;
}
public void testIsAuthorizedUserExistsButNotAuthorized()
throws Exception
{
createUser( USER_ALPACA, "Al 'Archiva' Paca", PASSWORD );
UserManager userManager = securitySystem.getUserManager();
try
{
User user = userManager.findUser( USER_ALPACA );
assertEquals( USER_ALPACA, user.getPrincipal() );
}
catch ( UserNotFoundException e )
{
fail( "User should exist in the database." );
}
xmlRpcRequestControl.expectAndReturn( xmlRpcRequest.getConfig(), config, 2 );
configControl.expectAndReturn( config.getBasicUserName(), USER_ALPACA );
configControl.expectAndReturn( config.getBasicPassword(), PASSWORD );
xmlRpcRequestControl.expectAndReturn( xmlRpcRequest.getMethodName(),
"AdministrationService.getAllManagedRepositories" );
xmlRpcRequestControl.replay();
configControl.replay();
boolean isAuthorized = authenticator.isAuthorized( xmlRpcRequest );
xmlRpcRequestControl.verify();
configControl.verify();
assertFalse( isAuthorized );
}
public void testIsAuthorizedUserExistsAndAuthorized()
throws Exception
{
createUser( USER_ALPACA, "Al 'Archiva' Paca", PASSWORD );
UserManager userManager = securitySystem.getUserManager();
try
{
User user = userManager.findUser( USER_ALPACA );
assertEquals( USER_ALPACA, user.getPrincipal() );
}
catch ( UserNotFoundException e )
{
fail( "User should exist in the database." );
}
//TODO cannot assign global repo manager role - it says role does not exist :|
//roleManager.assignRole( ArchivaRoleConstants.GLOBAL_REPOSITORY_MANAGER_ROLE, USER_ALPACA );
xmlRpcRequestControl.expectAndReturn( xmlRpcRequest.getConfig(), config, 2 );
configControl.expectAndReturn( config.getBasicUserName(), USER_ALPACA );
configControl.expectAndReturn( config.getBasicPassword(), PASSWORD );
xmlRpcRequestControl.expectAndReturn( xmlRpcRequest.getMethodName(),
"AdministrationService.getAllManagedRepositories" );
xmlRpcRequestControl.replay();
configControl.replay();
boolean isAuthorized = authenticator.isAuthorized( xmlRpcRequest );
xmlRpcRequestControl.verify();
configControl.verify();
//assertTrue( isAuthorized );
}
public void testIsAuthorizedUserDoesNotExist()
throws Exception
{
UserManager userManager = securitySystem.getUserManager();
try
{
userManager.findUser( USER_ALPACA );
fail( "User should not exist in the database." );
}
catch ( UserNotFoundException e )
{
assertEquals( "Unable to find user 'alpaca'", e.getMessage() );
}
xmlRpcRequestControl.expectAndReturn( xmlRpcRequest.getConfig(), config, 2 );
configControl.expectAndReturn( config.getBasicUserName(), USER_ALPACA );
configControl.expectAndReturn( config.getBasicPassword(), PASSWORD );
xmlRpcRequestControl.expectAndReturn( xmlRpcRequest.getMethodName(),
"AdministrationService.getAllManagedRepositories" );
xmlRpcRequestControl.replay();
configControl.replay();
boolean isAuthorized = authenticator.isAuthorized( xmlRpcRequest );
xmlRpcRequestControl.verify();
configControl.verify();
assertFalse( isAuthorized );
}
}

View File

@ -0,0 +1,210 @@
<redback-role-model>
<modelVersion>1.0.0</modelVersion>
<applications>
<application>
<id>Redback XWork Integration Security Core</id>
<version>1.0</version>
<resources>
<resource>
<id>global</id>
<name>*</name>
<permanent>true</permanent>
<description>
global resource implies full access for authorization
</description>
</resource>
<resource>
<id>username</id>
<name>${username}</name>
<permanent>true</permanent>
<description>
replaced with the username of the principal at authorization
check time
</description>
</resource>
</resources>
<operations>
<operation>
<id>configuration-edit</id>
<name>configuration-edit</name>
<description>edit configuration</description>
<permanent>true</permanent>
</operation>
<operation>
<id>user-management-user-create</id>
<name>user-management-user-create</name>
<description>create user</description>
<permanent>true</permanent>
</operation>
<operation>
<id>user-management-user-edit</id>
<name>user-management-user-edit</name>
<description>edit user</description>
<permanent>true</permanent>
</operation>
<operation>
<id>user-management-user-role</id>
<name>user-management-user-role</name>
<description>user roles</description>
<permanent>true</permanent>
</operation>
<operation>
<id>user-management-user-delete</id>
<name>user-management-user-delete</name>
<description>delete user</description>
<permanent>true</permanent>
</operation>
<operation>
<id>user-management-user-list</id>
<name>user-management-user-list</name>
<description>list users</description>
<permanent>true</permanent>
</operation>
<operation>
<id>user-management-role-grant</id>
<name>user-management-role-grant</name>
<description>grant role</description>
<permanent>true</permanent>
</operation>
<operation>
<id>user-management-role-drop</id>
<name>user-management-role-drop</name>
<description>drop role</description>
<permanent>true</permanent>
</operation>
<operation>
<id>user-management-rbac-admin</id>
<name>user-management-rbac-admin</name>
<description>administer rbac</description>
<permanent>true</permanent>
</operation>
<operation>
<id>guest-access</id>
<name>guest-access</name>
<description>access guest</description>
<permanent>true</permanent>
</operation>
<operation>
<id>add-repository</id>
<name>add-repository</name>
<description>add repository</description>
<permanent>true</permanent>
</operation>
</operations>
<roles>
<role>
<id>system-administrator</id>
<name>System Administrator</name>
<permanent>true</permanent>
<assignable>true</assignable>
<permissions>
<permission>
<id>edit-redback-configuration</id>
<name>Edit Redback Configuration</name>
<operation>configuration-edit</operation>
<resource>global</resource>
<permanent>true</permanent>
</permission>
<permission>
<id>manage-rbac-setup</id>
<name>User RBAC Management</name>
<operation>user-management-rbac-admin</operation>
<resource>global</resource>
<permanent>true</permanent>
</permission>
</permissions>
<childRoles>
<childRole>user-administrator</childRole>
</childRoles>
</role>
<role>
<id>user-administrator</id>
<name>User Administrator</name>
<permanent>true</permanent>
<assignable>true</assignable>
<permissions>
<permission>
<id>drop-roles-for-anyone</id>
<name>Drop Roles for Anyone</name>
<operation>user-management-role-drop</operation>
<resource>global</resource>
<permanent>true</permanent>
</permission>
<permission>
<id>grant-roles-for-anyone</id>
<name>Grant Roles for Anyone</name>
<operation>user-management-role-grant</operation>
<resource>global</resource>
<permanent>true</permanent>
</permission>
<permission>
<id>user-create</id>
<name>Create Users</name>
<operation>user-management-user-create</operation>
<resource>global</resource>
<permanent>true</permanent>
</permission>
<permission>
<id>user-delete</id>
<name>Delete Users</name>
<operation>user-management-user-delete</operation>
<resource>global</resource>
<permanent>true</permanent>
</permission>
<permission>
<id>user-edit</id>
<name>Edit Users</name>
<operation>user-management-user-edit</operation>
<resource>global</resource>
<permanent>true</permanent>
</permission>
<permission>
<id>access-users-roles</id>
<name>Access Users Roles</name>
<operation>user-management-user-role</operation>
<resource>global</resource>
<permanent>true</permanent>
</permission>
<permission>
<id>access-user-list</id>
<name>Access User List</name>
<operation>user-management-user-list</operation>
<resource>global</resource>
<permanent>true</permanent>
</permission>
</permissions>
</role>
<role>
<id>registered-user</id>
<name>Registered User</name>
<permanent>true</permanent>
<assignable>true</assignable>
<permissions>
<permission>
<id>edit-user-by-username</id>
<name>Edit User Data by Username</name>
<operation>user-management-user-edit</operation>
<resource>username</resource>
<permanent>true</permanent>
</permission>
</permissions>
</role>
<role>
<id>guest</id>
<name>Guest</name>
<permanent>true</permanent>
<assignable>true</assignable>
<permissions>
<permission>
<id>guest-permission</id>
<name>Guest Permission</name>
<operation>guest-access</operation>
<resource>global</resource>
<permanent>true</permanent>
</permission>
</permissions>
</role>
</roles>
</application>
</applications>
</redback-role-model>

View File

@ -0,0 +1,192 @@
<?xml version="1.0" ?>
<component-set>
<components>
<!-- x
<component>
<role>org.apache.maven.archiva.security.UserRepositories</role>
<role-hint>default</role-hint>
<implementation>org.apache.maven.archiva.security.DefaultUserRepositories</implementation>
<description>DefaultUserRepositories</description>
<requirements>
<requirement>
<role>org.codehaus.plexus.redback.system.SecuritySystem</role>
<role-hint>testable</role-hint>
<field-name>securitySystem</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.redback.role.RoleManager</role>
<role-hint>default</role-hint>
<field-name>roleManager</field-name>
</requirement>
<requirement>
<role>org.apache.maven.archiva.configuration.ArchivaConfiguration</role>
<field-name>archivaConfiguration</field-name>
</requirement>
</requirements>
</component>
-->
<component>
<role>org.codehaus.plexus.redback.system.SecuritySystem</role>
<role-hint>testable</role-hint>
<implementation>org.codehaus.plexus.redback.system.DefaultSecuritySystem</implementation>
<description>DefaultSecuritySystem:</description>
<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>
<component>
<role>org.codehaus.plexus.redback.authorization.Authorizer</role>
<role-hint>rbac</role-hint>
<implementation>org.codehaus.plexus.redback.authorization.rbac.RbacAuthorizer</implementation>
<description>RbacAuthorizer:</description>
<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>
<requirement>
<role>org.codehaus.plexus.redback.configuration.UserConfiguration</role>
<role-hint>default</role-hint>
<field-name>config</field-name>
</requirement>
</requirements>
</component>
<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>
<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>
<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>
-->
</components>
</component-set>

View File

@ -0,0 +1,60 @@
<?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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-xmlrpc</artifactId>
<version>1.2-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>archiva-xmlrpc-services</artifactId>
<name>Archiva Web :: XML-RPC Services</name>
<dependencies>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-xmlrpc-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-configuration</artifactId>
</dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-scheduled</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-spring</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,440 @@
package org.apache.archiva.web.xmlrpc.services;
/*
* 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.
*/
import java.util.ArrayList;
import java.util.List;
import org.apache.archiva.web.xmlrpc.api.AdministrationService;
import org.apache.archiva.web.xmlrpc.api.beans.ManagedRepository;
import org.apache.archiva.web.xmlrpc.api.beans.RemoteRepository;
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.configuration.Configuration;
import org.apache.maven.archiva.configuration.DatabaseScanningConfiguration;
import org.apache.maven.archiva.configuration.IndeterminateConfigurationException;
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration;
import org.apache.maven.archiva.configuration.RepositoryScanningConfiguration;
import org.apache.maven.archiva.consumers.ConsumerException;
import org.apache.maven.archiva.consumers.DatabaseCleanupConsumer;
import org.apache.maven.archiva.consumers.DatabaseUnprocessedArtifactConsumer;
import org.apache.maven.archiva.consumers.InvalidRepositoryContentConsumer;
import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer;
import org.apache.maven.archiva.database.ArchivaDatabaseException;
import org.apache.maven.archiva.database.ArtifactDAO;
import org.apache.maven.archiva.database.constraints.ArtifactVersionsConstraint;
import org.apache.maven.archiva.database.updater.DatabaseConsumers;
import org.apache.maven.archiva.model.ArchivaArtifact;
import org.apache.maven.archiva.model.VersionedReference;
import org.apache.maven.archiva.repository.ContentNotFoundException;
import org.apache.maven.archiva.repository.ManagedRepositoryContent;
import org.apache.maven.archiva.repository.RepositoryContentFactory;
import org.apache.maven.archiva.repository.RepositoryException;
import org.apache.maven.archiva.repository.RepositoryNotFoundException;
import org.apache.maven.archiva.repository.scanner.RepositoryContentConsumers;
import org.apache.maven.archiva.scheduled.ArchivaTaskScheduler;
import org.apache.maven.archiva.scheduled.DefaultArchivaTaskScheduler;
import org.apache.maven.archiva.scheduled.tasks.ArchivaTask;
import org.apache.maven.archiva.scheduled.tasks.DatabaseTask;
import org.apache.maven.archiva.scheduled.tasks.RepositoryTask;
import org.codehaus.plexus.registry.RegistryException;
/**
* AdministrationServiceImpl
*
* @version $Id: AdministrationServiceImpl.java
*/
public class AdministrationServiceImpl
implements AdministrationService
{
private ArchivaConfiguration archivaConfiguration;
private RepositoryContentConsumers repoConsumersUtil;
private DatabaseConsumers dbConsumersUtil;
private RepositoryContentFactory repoFactory;
private ArtifactDAO artifactDAO;
private DatabaseCleanupConsumer cleanupArtifacts;
private DatabaseCleanupConsumer cleanupProjects;
private ArchivaTaskScheduler taskScheduler;
public AdministrationServiceImpl( ArchivaConfiguration archivaConfig, RepositoryContentConsumers repoConsumersUtil,
DatabaseConsumers dbConsumersUtil, RepositoryContentFactory repoFactory,
ArtifactDAO artifactDAO, DatabaseCleanupConsumer cleanupArtifacts,
DatabaseCleanupConsumer cleanupProjects, ArchivaTaskScheduler taskScheduler )
{
this.archivaConfiguration = archivaConfig;
this.repoConsumersUtil = repoConsumersUtil;
this.dbConsumersUtil = dbConsumersUtil;
this.repoFactory = repoFactory;
this.artifactDAO = artifactDAO;
this.cleanupArtifacts = cleanupArtifacts;
this.cleanupProjects = cleanupProjects;
this.taskScheduler = taskScheduler;
}
/**
* @see AdministrationService#configureDatabaseConsumer(String, boolean)
*/
public Boolean configureDatabaseConsumer( String consumerId, boolean enable ) throws Exception
{
List<DatabaseCleanupConsumer> cleanupConsumers = dbConsumersUtil.getAvailableCleanupConsumers();
List<DatabaseUnprocessedArtifactConsumer> unprocessedConsumers =
dbConsumersUtil.getAvailableUnprocessedConsumers();
boolean found = false;
boolean isCleanupConsumer = false;
for( DatabaseCleanupConsumer consumer : cleanupConsumers )
{
if( consumer.getId().equals( consumerId ) )
{
found = true;
isCleanupConsumer = true;
break;
}
}
if( !found )
{
for( DatabaseUnprocessedArtifactConsumer consumer : unprocessedConsumers )
{
if( consumer.getId().equals( consumerId ) )
{
found = true;
break;
}
}
}
if( !found )
{
throw new Exception( "Invalid database consumer." );
}
Configuration config = archivaConfiguration.getConfiguration();
DatabaseScanningConfiguration dbScanningConfig = config.getDatabaseScanning();
if( isCleanupConsumer )
{
dbScanningConfig.addCleanupConsumer( consumerId );
}
else
{
dbScanningConfig.addUnprocessedConsumer( consumerId );
}
config.setDatabaseScanning( dbScanningConfig );
saveConfiguration( config );
return new Boolean( true );
}
/**
* @see AdministrationService#configureRepositoryConsumer(String, String, boolean)
*/
public Boolean configureRepositoryConsumer( String repoId, String consumerId, boolean enable )
throws Exception
{
// TODO use repoId once consumers are configured per repository! (MRM-930)
List<KnownRepositoryContentConsumer> knownConsumers = repoConsumersUtil.getAvailableKnownConsumers();
List<InvalidRepositoryContentConsumer> invalidConsumers = repoConsumersUtil.getAvailableInvalidConsumers();
boolean found = false;
boolean isKnownContentConsumer = false;
for( KnownRepositoryContentConsumer consumer : knownConsumers )
{
if( consumer.getId().equals( consumerId ) )
{
found = true;
isKnownContentConsumer = true;
break;
}
}
if( !found )
{
for( InvalidRepositoryContentConsumer consumer : invalidConsumers )
{
if( consumer.getId().equals( consumerId ) )
{
found = true;
break;
}
}
}
if( !found )
{
throw new Exception( "Invalid repository consumer." );
}
Configuration config = archivaConfiguration.getConfiguration();
RepositoryScanningConfiguration repoScanningConfig = config.getRepositoryScanning();
if( isKnownContentConsumer )
{
repoScanningConfig.addKnownContentConsumer( consumerId );
}
else
{
repoScanningConfig.addInvalidContentConsumer( consumerId );
}
config.setRepositoryScanning( repoScanningConfig );
saveConfiguration( config );
return new Boolean( true );
}
/**
* @see AdministrationService#deleteArtifact(String, String, String, String)
*/
public Boolean deleteArtifact( String repoId, String groupId, String artifactId, String version )
throws Exception
{
Configuration config = archivaConfiguration.getConfiguration();
ManagedRepositoryConfiguration repoConfig = config.findManagedRepositoryById( repoId );
if( repoConfig == null )
{
throw new Exception( "Repository does not exist." );
}
try
{
ManagedRepositoryContent repoContent = repoFactory.getManagedRepositoryContent( repoId );
VersionedReference ref = new VersionedReference();
ref.setGroupId( groupId );
ref.setArtifactId( artifactId );
ref.setVersion( version );
// delete from file system
repoContent.deleteVersion( ref );
ArtifactVersionsConstraint constraint = new ArtifactVersionsConstraint( repoId, groupId, artifactId, false );
List<ArchivaArtifact> artifacts = null;
try
{
artifacts = artifactDAO.queryArtifacts( constraint );
if( artifacts == null )
{
return true;
}
}
catch ( ArchivaDatabaseException e )
{
throw new Exception( "Error occurred while cleaning up database." );
}
// cleanup db manually? or use the cleanup consumers as what is done now?
for( ArchivaArtifact artifact : artifacts )
{
if( artifact.getVersion().equals( version ) )
{
try
{
cleanupArtifacts.processArchivaArtifact( artifact );
cleanupProjects.processArchivaArtifact( artifact );
}
catch ( ConsumerException ce )
{
// log error
continue;
}
}
}
}
catch ( ContentNotFoundException e )
{
throw new Exception( "Artifact does not exist." );
}
catch ( RepositoryNotFoundException e )
{
throw new Exception( "Repository does not exist." );
}
catch ( RepositoryException e )
{
throw new Exception( "Repository exception occurred." );
}
return new Boolean( true );
}
/**
* @see AdministrationService#executeDatabaseScanner()
*/
public Boolean executeDatabaseScanner() throws Exception
{
if ( taskScheduler.isProcessingDatabaseTask() )
{
return false;
}
DatabaseTask task = new DatabaseTask();
task.setName( DefaultArchivaTaskScheduler.DATABASE_JOB + ":user-requested-via-web-service" );
task.setQueuePolicy( ArchivaTask.QUEUE_POLICY_WAIT );
taskScheduler.queueDatabaseTask( task );
return new Boolean( true );
}
/**
* @see AdministrationService#executeRepositoryScanner(String)
*/
public Boolean executeRepositoryScanner( String repoId ) throws Exception
{
Configuration config = archivaConfiguration.getConfiguration();
if( config.findManagedRepositoryById( repoId ) == null )
{
throw new Exception( "Repository does not exist." );
}
if ( taskScheduler.isProcessingAnyRepositoryTask() )
{
if ( taskScheduler.isProcessingRepositoryTask( repoId ) )
{
return false;
}
}
RepositoryTask task = new RepositoryTask();
task.setRepositoryId( repoId );
task.setName( DefaultArchivaTaskScheduler.REPOSITORY_JOB + ":" + repoId );
task.setQueuePolicy( ArchivaTask.QUEUE_POLICY_WAIT );
taskScheduler.queueRepositoryTask( task );
return new Boolean( true );
}
/**
* @see AdministrationService#getAllDatabaseConsumers()
*/
public List<String> getAllDatabaseConsumers()
{
List<String> consumers = new ArrayList<String>();
List<DatabaseCleanupConsumer> cleanupConsumers = dbConsumersUtil.getAvailableCleanupConsumers();
List<DatabaseUnprocessedArtifactConsumer> unprocessedConsumers = dbConsumersUtil.getAvailableUnprocessedConsumers();
for( DatabaseCleanupConsumer consumer : cleanupConsumers )
{
consumers.add( consumer.getId() );
}
for( DatabaseUnprocessedArtifactConsumer consumer : unprocessedConsumers )
{
consumers.add( consumer.getId() );
}
return consumers;
}
/**
* @see AdministrationService#getAllRepositoryConsumers()
*/
public List<String> getAllRepositoryConsumers()
{
List<String> consumers = new ArrayList<String>();
List<KnownRepositoryContentConsumer> knownConsumers = repoConsumersUtil.getAvailableKnownConsumers();
List<InvalidRepositoryContentConsumer> invalidConsumers = repoConsumersUtil.getAvailableInvalidConsumers();
for( KnownRepositoryContentConsumer consumer : knownConsumers )
{
consumers.add( consumer.getId() );
}
for( InvalidRepositoryContentConsumer consumer : invalidConsumers )
{
consumers.add( consumer.getId() );
}
return consumers;
}
/**
* @see AdministrationService#getAllManagedRepositories()
*/
public List<ManagedRepository> getAllManagedRepositories()
{
List<ManagedRepository> managedRepos = new ArrayList<ManagedRepository>();
Configuration config = archivaConfiguration.getConfiguration();
List<ManagedRepositoryConfiguration> managedRepoConfigs = config.getManagedRepositories();
for( ManagedRepositoryConfiguration repoConfig : managedRepoConfigs )
{
// TODO fix resolution of repo url!
ManagedRepository repo =
new ManagedRepository( repoConfig.getId(), repoConfig.getName(), "URL", repoConfig.getLayout(),
repoConfig.isSnapshots(), repoConfig.isReleases() );
managedRepos.add( repo );
}
return managedRepos;
}
/**
* @see AdministrationService#getAllRemoteRepositories()
*/
public List<RemoteRepository> getAllRemoteRepositories()
{
List<RemoteRepository> remoteRepos = new ArrayList<RemoteRepository>();
Configuration config = archivaConfiguration.getConfiguration();
List<RemoteRepositoryConfiguration> remoteRepoConfigs = config.getRemoteRepositories();
for( RemoteRepositoryConfiguration repoConfig : remoteRepoConfigs )
{
RemoteRepository repo =
new RemoteRepository( repoConfig.getId(), repoConfig.getName(), repoConfig.getUrl(),
repoConfig.getLayout() );
remoteRepos.add( repo );
}
return remoteRepos;
}
private void saveConfiguration( Configuration config )
throws Exception
{
try
{
archivaConfiguration.save( config );
}
catch( RegistryException e )
{
throw new Exception( "Error occurred in the registry." );
}
catch ( IndeterminateConfigurationException e )
{
throw new Exception( "Error occurred while saving the configuration." );
}
}
}

View File

@ -0,0 +1,30 @@
package org.apache.archiva.web.xmlrpc.services;
/*
* 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.
*/
import org.apache.archiva.web.xmlrpc.api.TestService;
public class PingServiceImpl implements TestService
{
public String ping()
{
return "pong";
}
}

View File

@ -0,0 +1,954 @@
package org.apache.archiva.web.xmlrpc.services;
/*
* 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.
*/
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import org.apache.archiva.web.xmlrpc.api.beans.ManagedRepository;
import org.apache.archiva.web.xmlrpc.api.beans.RemoteRepository;
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.configuration.Configuration;
import org.apache.maven.archiva.configuration.DatabaseScanningConfiguration;
import org.apache.maven.archiva.configuration.FileTypes;
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration;
import org.apache.maven.archiva.configuration.RepositoryScanningConfiguration;
import org.apache.maven.archiva.consumers.DatabaseCleanupConsumer;
import org.apache.maven.archiva.consumers.DatabaseUnprocessedArtifactConsumer;
import org.apache.maven.archiva.consumers.InvalidRepositoryContentConsumer;
import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer;
import org.apache.maven.archiva.database.ArtifactDAO;
import org.apache.maven.archiva.database.updater.DatabaseConsumers;
import org.apache.maven.archiva.model.ArchivaArtifact;
import org.apache.maven.archiva.model.ArchivaArtifactModel;
import org.apache.maven.archiva.model.ArtifactReference;
import org.apache.maven.archiva.repository.RepositoryContentFactory;
import org.apache.maven.archiva.repository.content.ManagedDefaultRepositoryContent;
import org.apache.maven.archiva.repository.content.ManagedLegacyRepositoryContent;
import org.apache.maven.archiva.repository.content.PathParser;
import org.apache.maven.archiva.repository.layout.LayoutException;
import org.apache.maven.archiva.repository.scanner.RepositoryContentConsumers;
import org.apache.maven.archiva.scheduled.ArchivaTaskScheduler;
import org.apache.maven.archiva.scheduled.tasks.DatabaseTask;
import org.apache.maven.archiva.scheduled.tasks.RepositoryTask;
import org.codehaus.plexus.spring.PlexusInSpringTestCase;
import org.easymock.MockControl;
import org.easymock.classextension.MockClassControl;
/**
* AdministrationServiceImplTest
*
* @version $Id: AdministrationServiceImplTest.java
*/
public class AdministrationServiceImplTest
extends PlexusInSpringTestCase
{
private MockControl archivaConfigControl;
private ArchivaConfiguration archivaConfig;
private MockControl configControl;
private Configuration config;
private AdministrationServiceImpl service;
private MockControl taskSchedulerControl;
private ArchivaTaskScheduler taskScheduler;
// repository consumers
private MockControl repoConsumerUtilsControl;
private RepositoryContentConsumers repoConsumersUtil;
private MockControl knownContentConsumerControl;
private MockControl invalidContentConsumerControl;
private KnownRepositoryContentConsumer indexArtifactConsumer;
private KnownRepositoryContentConsumer indexPomConsumer;
private InvalidRepositoryContentConsumer checkPomConsumer;
private InvalidRepositoryContentConsumer checkMetadataConsumer;
// database consumers
private MockControl dbConsumersUtilControl;
private DatabaseConsumers dbConsumersUtil;
private MockControl unprocessedConsumersControl;
private MockControl cleanupConsumersControl;
private DatabaseUnprocessedArtifactConsumer processArtifactConsumer;
private DatabaseUnprocessedArtifactConsumer processPomConsumer;
private DatabaseCleanupConsumer cleanupIndexConsumer;
private DatabaseCleanupConsumer cleanupDbConsumer;
// delete artifact
private MockControl repoFactoryControl;
private RepositoryContentFactory repositoryFactory;
private MockControl artifactDaoControl;
private ArtifactDAO artifactDao;
private MockControl cleanupControl;
private DatabaseCleanupConsumer cleanupConsumer;
protected void setUp()
throws Exception
{
super.setUp();
archivaConfigControl = MockControl.createControl( ArchivaConfiguration.class );
archivaConfig = ( ArchivaConfiguration ) archivaConfigControl.getMock();
configControl = MockClassControl.createControl( Configuration.class );
config = ( Configuration ) configControl.getMock();
taskSchedulerControl = MockControl.createControl( ArchivaTaskScheduler.class );
taskScheduler = ( ArchivaTaskScheduler ) taskSchedulerControl.getMock();
// repo consumers
repoConsumerUtilsControl = MockClassControl.createControl( RepositoryContentConsumers.class );
repoConsumersUtil = ( RepositoryContentConsumers ) repoConsumerUtilsControl.getMock();
knownContentConsumerControl = MockControl.createControl( KnownRepositoryContentConsumer.class );
indexArtifactConsumer = ( KnownRepositoryContentConsumer ) knownContentConsumerControl.getMock();
indexPomConsumer = ( KnownRepositoryContentConsumer ) knownContentConsumerControl.getMock();
invalidContentConsumerControl = MockControl.createControl( InvalidRepositoryContentConsumer.class );
checkPomConsumer = ( InvalidRepositoryContentConsumer ) invalidContentConsumerControl.getMock();
checkMetadataConsumer = ( InvalidRepositoryContentConsumer ) invalidContentConsumerControl.getMock();
// db consumers
dbConsumersUtilControl = MockClassControl.createControl( DatabaseConsumers.class );
dbConsumersUtil = ( DatabaseConsumers ) dbConsumersUtilControl.getMock();
cleanupConsumersControl = MockControl.createControl( DatabaseCleanupConsumer.class );
cleanupIndexConsumer = ( DatabaseCleanupConsumer ) cleanupConsumersControl.getMock();
cleanupDbConsumer = ( DatabaseCleanupConsumer ) cleanupConsumersControl.getMock();
unprocessedConsumersControl = MockControl.createControl( DatabaseUnprocessedArtifactConsumer.class );
processArtifactConsumer = ( DatabaseUnprocessedArtifactConsumer ) unprocessedConsumersControl.getMock();
processPomConsumer = ( DatabaseUnprocessedArtifactConsumer ) unprocessedConsumersControl.getMock();
// delete artifact
repoFactoryControl = MockClassControl.createControl( RepositoryContentFactory.class );
repositoryFactory = ( RepositoryContentFactory ) repoFactoryControl.getMock();
artifactDaoControl = MockControl.createControl( ArtifactDAO.class );
artifactDao = ( ArtifactDAO ) artifactDaoControl.getMock();
cleanupControl = MockClassControl.createControl( DatabaseCleanupConsumer.class );
cleanupConsumer = ( DatabaseCleanupConsumer ) cleanupControl.getMock();
service = new AdministrationServiceImpl( archivaConfig, repoConsumersUtil, dbConsumersUtil,
repositoryFactory, artifactDao, cleanupConsumer, cleanupConsumer, taskScheduler );
}
/* Tests for database consumers */
public void testGetAllDbConsumers()
throws Exception
{
recordDbConsumers();
dbConsumersUtilControl.replay();
cleanupConsumersControl.replay();
unprocessedConsumersControl.replay();
List<String> dbConsumers = service.getAllDatabaseConsumers();
dbConsumersUtilControl.verify();
cleanupConsumersControl.verify();
unprocessedConsumersControl.verify();
assertNotNull( dbConsumers );
assertEquals( 4, dbConsumers.size() );
assertTrue( dbConsumers.contains( "cleanup-index" ) );
assertTrue( dbConsumers.contains( "cleanup-database" ) );
assertTrue( dbConsumers.contains( "process-artifact" ) );
assertTrue( dbConsumers.contains( "process-pom" ) );
}
public void testConfigureValidDatabaseConsumer()
throws Exception
{
DatabaseScanningConfiguration dbScanning = new DatabaseScanningConfiguration();
dbScanning.addCleanupConsumer( "cleanup-index" );
dbScanning.addCleanupConsumer( "cleanup-database" );
dbScanning.addUnprocessedConsumer( "process-artifact" );
recordDbConsumers();
// test enable "process-pom" db consumer
archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
configControl.expectAndReturn( config.getDatabaseScanning(), dbScanning );
config.setDatabaseScanning( dbScanning );
configControl.setMatcher( MockControl.ALWAYS_MATCHER );
configControl.setVoidCallable();
archivaConfig.save( config );
archivaConfigControl.setVoidCallable();
dbConsumersUtilControl.replay();
cleanupConsumersControl.replay();
unprocessedConsumersControl.replay();
archivaConfigControl.replay();
configControl.replay();
try
{
boolean success = service.configureDatabaseConsumer( "process-pom", true );
assertTrue( success );
}
catch ( Exception e )
{
fail( "An exception should not have been thrown." );
}
dbConsumersUtilControl.verify();
cleanupConsumersControl.verify();
unprocessedConsumersControl.verify();
archivaConfigControl.verify();
configControl.verify();
// test disable "process-pom" db consumer
dbConsumersUtilControl.reset();
cleanupConsumersControl.reset();
unprocessedConsumersControl.reset();
archivaConfigControl.reset();
configControl.reset();
dbScanning.addUnprocessedConsumer( "process-pom" );
recordDbConsumers();
archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
configControl.expectAndReturn( config.getDatabaseScanning(), dbScanning );
config.setDatabaseScanning( dbScanning );
configControl.setMatcher( MockControl.ALWAYS_MATCHER );
configControl.setVoidCallable();
archivaConfig.save( config );
archivaConfigControl.setVoidCallable();
dbConsumersUtilControl.replay();
cleanupConsumersControl.replay();
unprocessedConsumersControl.replay();
archivaConfigControl.replay();
configControl.replay();
try
{
boolean success = service.configureDatabaseConsumer( "process-pom", false );
assertTrue( success );
}
catch ( Exception e )
{
fail( "An exception should not have been thrown." );
}
dbConsumersUtilControl.verify();
cleanupConsumersControl.verify();
unprocessedConsumersControl.verify();
archivaConfigControl.verify();
configControl.verify();
}
public void testConfigureInvalidDatabaseConsumer()
throws Exception
{
recordDbConsumers();
dbConsumersUtilControl.replay();
cleanupConsumersControl.replay();
unprocessedConsumersControl.replay();
try
{
service.configureDatabaseConsumer( "invalid-consumer", true );
fail( "An exception should have been thrown." );
}
catch ( Exception e )
{
assertEquals( "Invalid database consumer.", e.getMessage() );
}
dbConsumersUtilControl.verify();
cleanupConsumersControl.verify();
unprocessedConsumersControl.verify();
}
/* Tests for repository consumers */
public void testGetAllRepoConsumers()
throws Exception
{
recordRepoConsumers();
repoConsumerUtilsControl.replay();
knownContentConsumerControl.replay();
invalidContentConsumerControl.replay();
List<String> repoConsumers = service.getAllRepositoryConsumers();
repoConsumerUtilsControl.verify();
knownContentConsumerControl.verify();
invalidContentConsumerControl.verify();
assertNotNull( repoConsumers );
assertEquals( 4, repoConsumers.size() );
assertTrue( repoConsumers.contains( "index-artifact" ) );
assertTrue( repoConsumers.contains( "index-pom" ) );
assertTrue( repoConsumers.contains( "check-pom" ) );
assertTrue( repoConsumers.contains( "check-metadata" ) );
}
public void testConfigureValidRepositoryConsumer()
throws Exception
{
RepositoryScanningConfiguration repoScanning = new RepositoryScanningConfiguration();
repoScanning.addKnownContentConsumer( "index-artifact" );
repoScanning.addKnownContentConsumer( "index-pom" );
repoScanning.addInvalidContentConsumer( "check-pom" );
// test enable "check-metadata" consumer
recordRepoConsumers();
archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
configControl.expectAndReturn( config.getRepositoryScanning(), repoScanning );
config.setRepositoryScanning( repoScanning );
configControl.setMatcher( MockControl.ALWAYS_MATCHER );
configControl.setVoidCallable();
archivaConfig.save( config );
archivaConfigControl.setVoidCallable();
repoConsumerUtilsControl.replay();
knownContentConsumerControl.replay();
invalidContentConsumerControl.replay();
archivaConfigControl.replay();
configControl.replay();
try
{
boolean success = service.configureRepositoryConsumer( null, "check-metadata", true );
assertTrue( success );
}
catch ( Exception e )
{
fail( "An exception should not have been thrown." );
}
repoConsumerUtilsControl.verify();
knownContentConsumerControl.verify();
invalidContentConsumerControl.verify();
archivaConfigControl.verify();
configControl.verify();
// test disable "check-metadata" consumer
repoConsumerUtilsControl.reset();
knownContentConsumerControl.reset();
invalidContentConsumerControl.reset();
archivaConfigControl.reset();
configControl.reset();
repoScanning.addInvalidContentConsumer( "check-metadata" );
recordRepoConsumers();
archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
configControl.expectAndReturn( config.getRepositoryScanning(), repoScanning );
config.setRepositoryScanning( repoScanning );
configControl.setMatcher( MockControl.ALWAYS_MATCHER );
configControl.setVoidCallable();
archivaConfig.save( config );
archivaConfigControl.setVoidCallable();
repoConsumerUtilsControl.replay();
knownContentConsumerControl.replay();
invalidContentConsumerControl.replay();
archivaConfigControl.replay();
configControl.replay();
try
{
boolean success = service.configureRepositoryConsumer( null, "check-metadata", false );
repoConsumerUtilsControl.verify();
knownContentConsumerControl.verify();
invalidContentConsumerControl.verify();
archivaConfigControl.verify();
configControl.verify();
assertTrue( success );
}
catch ( Exception e )
{
fail( "An excecption should not have been thrown." );
}
}
public void testConfigureInvalidRepositoryConsumer()
throws Exception
{
recordRepoConsumers();
repoConsumerUtilsControl.replay();
knownContentConsumerControl.replay();
invalidContentConsumerControl.replay();
try
{
service.configureRepositoryConsumer( null, "invalid-consumer", true );
fail( "An exception should have been thrown." );
}
catch ( Exception e )
{
assertEquals( "Invalid repository consumer.", e.getMessage() );
}
repoConsumerUtilsControl.verify();
knownContentConsumerControl.verify();
invalidContentConsumerControl.verify();
}
/* Tests for delete artifact */
public void testDeleteM2ArtifactArtifactExists()
throws Exception
{
File file = new File( getBasedir(), "/target/test-classes/default-repo/" );
assertTrue( file.exists() );
ManagedRepositoryConfiguration managedRepo = createManagedRepo( "internal", "default", "Internal Repository", true, false );
managedRepo.setLocation( file.getAbsolutePath() );
archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
configControl.expectAndReturn( config.findManagedRepositoryById( "internal" ), managedRepo );
ManagedDefaultRepositoryContent repoContent = new ManagedDefaultRepositoryContent();
repoContent.setRepository( managedRepo );
repoFactoryControl.expectAndReturn( repositoryFactory.getManagedRepositoryContent( "internal" ), repoContent );
List<ArchivaArtifact> artifacts = getArtifacts();
artifactDao.queryArtifacts( null );
artifactDaoControl.setMatcher( MockControl.ALWAYS_MATCHER );
artifactDaoControl.setReturnValue( artifacts );
cleanupConsumer.processArchivaArtifact( artifacts.get( 0 ) );
cleanupControl.setVoidCallable( 2 );
archivaConfigControl.replay();
configControl.replay();
repoFactoryControl.replay();
artifactDaoControl.replay();
cleanupControl.replay();
try
{
boolean success = service.deleteArtifact( "internal", "org.apache.archiva", "archiva-test", "1.0" );
assertTrue( success );
}
catch ( Exception e )
{
fail( "An exception should not have been thrown." );
}
archivaConfigControl.verify();
configControl.verify();
repoFactoryControl.verify();
artifactDaoControl.verify();
cleanupControl.verify();
assertFalse( new File( getBasedir(), "/target/test-classes/default-repo/org/apache/archiva/archiva-test/1.0" ).exists() );
assertTrue( new File( getBasedir(), "/target/test-classes/default-repo/org/apache/archiva/archiva-test/1.1" ).exists() );
}
public void testDeleteM1ArtifactArtifactExists()
throws Exception
{
MockControl fileTypesControl = MockClassControl.createControl( FileTypes.class );
FileTypes fileTypes = ( FileTypes ) fileTypesControl.getMock();
MockControl pathParserControl = MockClassControl.createControl( PathParser.class );
PathParser parser = ( PathParser ) pathParserControl.getMock();
File file = new File( getBasedir(), "/target/test-classes/legacy-repo/" );
assertTrue( file.exists() );
ManagedRepositoryConfiguration managedRepo = createManagedRepo( "internal", "legacy", "Internal Repository", true, false );
managedRepo.setLocation( file.getAbsolutePath() );
archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
configControl.expectAndReturn( config.findManagedRepositoryById( "internal" ), managedRepo );
ManagedLegacyRepositoryContent repoContent = new ManagedLegacyRepositoryContent();
repoContent.setRepository( managedRepo );
repoContent.setFileTypes( fileTypes );
repoContent.setLegacyPathParser( parser );
repoFactoryControl.expectAndReturn( repositoryFactory.getManagedRepositoryContent( "internal" ), repoContent );
recordInManagedLegacyRepoContent( fileTypesControl, fileTypes, pathParserControl, parser );
List<ArchivaArtifact> artifacts = getArtifacts();
artifactDao.queryArtifacts( null );
artifactDaoControl.setMatcher( MockControl.ALWAYS_MATCHER );
artifactDaoControl.setReturnValue( artifacts );
cleanupConsumer.processArchivaArtifact( artifacts.get( 0 ) );
cleanupControl.setVoidCallable( 2 );
archivaConfigControl.replay();
configControl.replay();
repoFactoryControl.replay();
artifactDaoControl.replay();
cleanupControl.replay();
fileTypesControl.replay();
pathParserControl.replay();
try
{
boolean success = service.deleteArtifact( "internal", "org.apache.archiva", "archiva-test", "1.0" );
assertTrue( success );
}
catch ( Exception e )
{
fail( "An exception should not have been thrown." );
}
archivaConfigControl.verify();
configControl.verify();
repoFactoryControl.verify();
artifactDaoControl.verify();
cleanupControl.verify();
fileTypesControl.verify();
pathParserControl.verify();
assertFalse( new File( getBasedir(), "/target/test-classes/legacy-repo/org.apache.archiva/jars/archiva-test-1.0.jar" ).exists() );
assertFalse( new File( getBasedir(), "/target/test-classes/legacy-repo/org.apache.archiva/poms/archiva-test-1.0.pom" ).exists() );
assertTrue( new File( getBasedir(), "/target/test-classes/legacy-repo/org.apache.archiva/jars/archiva-test-1.1.jar" ).exists() );
assertTrue( new File( getBasedir(), "/target/test-classes/legacy-repo/org.apache.archiva/jars/archiva-diff-1.0.jar" ).exists() );
assertTrue( new File( getBasedir(), "/target/test-classes/legacy-repo/org.apache.archiva/poms/archiva-test-1.1.pom" ).exists() );
assertTrue( new File( getBasedir(), "/target/test-classes/legacy-repo/org.apache.archiva/poms/archiva-diff-1.0.pom" ).exists() );
}
public void testDeleteArtifactArtifactDoesNotExist()
throws Exception
{
File file = new File( getBasedir(), "/target/test-classes/default-repo/" );
assertTrue( file.exists() );
ManagedRepositoryConfiguration managedRepo = createManagedRepo( "internal", "default", "Internal Repository", true, false );
managedRepo.setLocation( file.getAbsolutePath() );
archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
configControl.expectAndReturn( config.findManagedRepositoryById( "internal" ), managedRepo );
ManagedDefaultRepositoryContent repoContent = new ManagedDefaultRepositoryContent();
repoContent.setRepository( managedRepo );
repoFactoryControl.expectAndReturn( repositoryFactory.getManagedRepositoryContent( "internal" ), repoContent );
archivaConfigControl.replay();
configControl.replay();
repoFactoryControl.replay();
try
{
service.deleteArtifact( "internal", "org.apache.archiva", "archiva-non-existing", "1.0" );
fail( "An exception should have been thrown." );
}
catch ( Exception e )
{
assertEquals( "Artifact does not exist.", e.getMessage() );
}
archivaConfigControl.verify();
configControl.verify();
repoFactoryControl.verify();
}
public void testDeleteArtifacRepositoryDoesNotExist()
throws Exception
{
archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
configControl.expectAndReturn( config.findManagedRepositoryById( "non-existing-repo" ), null );
archivaConfigControl.replay();
configControl.replay();
try
{
service.deleteArtifact( "non-existing-repo", "org.apache.archiva", "archiva-test", "1.0" );
fail( "An exception should have been thrown." );
}
catch ( Exception e )
{
assertEquals( "Repository does not exist.", e.getMessage() );
}
archivaConfigControl.verify();
configControl.verify();
}
/* Tests for repository scanning */
public void testExecuteRepoScannerRepoExistsAndNotBeingScanned()
throws Exception
{
archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
configControl.expectAndReturn( config.findManagedRepositoryById( "internal" ),
createManagedRepo( "internal", "default", "Internal Repository", true, false ) );
RepositoryTask task = new RepositoryTask();
taskSchedulerControl.expectAndReturn( taskScheduler.isProcessingAnyRepositoryTask(), true );
taskSchedulerControl.expectAndReturn( taskScheduler.isProcessingRepositoryTask( "internal" ), false );
taskScheduler.queueRepositoryTask( task );
taskSchedulerControl.setMatcher( MockControl.ALWAYS_MATCHER );
taskSchedulerControl.setVoidCallable();
archivaConfigControl.replay();
configControl.replay();
taskSchedulerControl.replay();
try
{
boolean success = service.executeRepositoryScanner( "internal" );
assertTrue( success );
}
catch ( Exception e )
{
fail( "An exception should not have been thrown." );
}
archivaConfigControl.verify();
configControl.verify();
taskSchedulerControl.verify();
}
public void testExecuteRepoScannerRepoExistsButBeingScanned()
throws Exception
{
archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
configControl.expectAndReturn( config.findManagedRepositoryById( "internal" ),
createManagedRepo( "internal", "default", "Internal Repository", true, false ) );
taskSchedulerControl.expectAndReturn( taskScheduler.isProcessingAnyRepositoryTask(), true );
taskSchedulerControl.expectAndReturn( taskScheduler.isProcessingRepositoryTask( "internal" ), true);
archivaConfigControl.replay();
configControl.replay();
taskSchedulerControl.replay();
try
{
boolean success = service.executeRepositoryScanner( "internal" );
assertFalse( success );
}
catch ( Exception e )
{
fail( "An exception should not have been thrown." );
}
archivaConfigControl.verify();
configControl.verify();
taskSchedulerControl.verify();
}
public void testExecuteRepoScannerRepoDoesNotExist()
throws Exception
{
archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
configControl.expectAndReturn( config.findManagedRepositoryById( "internal" ), null );
archivaConfigControl.replay();
configControl.replay();
try
{
service.executeRepositoryScanner( "internal" );
fail( "An exception should have been thrown." );
}
catch ( Exception e )
{
assertEquals( "Repository does not exist.", e.getMessage() );
}
archivaConfigControl.verify();
configControl.verify();
}
/* Tests for db scanning */
public void testExecuteDbScannerDbNotBeingScanned()
throws Exception
{
DatabaseTask task = new DatabaseTask();
taskSchedulerControl.expectAndReturn( taskScheduler.isProcessingDatabaseTask(), false );
taskScheduler.queueDatabaseTask( task );
taskSchedulerControl.setMatcher( MockControl.ALWAYS_MATCHER );
taskSchedulerControl.setVoidCallable();
taskSchedulerControl.replay();
boolean success = service.executeDatabaseScanner();
taskSchedulerControl.verify();
assertTrue( success );
}
public void testExecuteDbScannerDbIsBeingScanned()
throws Exception
{
taskSchedulerControl.expectAndReturn( taskScheduler.isProcessingDatabaseTask(), true );
taskSchedulerControl.replay();
boolean success = service.executeDatabaseScanner();
taskSchedulerControl.verify();
assertFalse( success );
}
/* Tests for querying repositories */
public void testGetAllManagedRepositories()
throws Exception
{
List<ManagedRepositoryConfiguration> managedRepos = new ArrayList<ManagedRepositoryConfiguration>();
managedRepos.add( createManagedRepo( "internal", "default", "Internal Repository", true, false ) );
managedRepos.add( createManagedRepo( "snapshots", "default", "Snapshots Repository", false, true ) );
archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
configControl.expectAndReturn( config.getManagedRepositories(), managedRepos );
archivaConfigControl.replay();
configControl.replay();
List<ManagedRepository> repos = service.getAllManagedRepositories();
archivaConfigControl.verify();
configControl.verify();
assertNotNull( repos );
assertEquals( 2, repos.size() );
assertManagedRepo( ( ManagedRepository ) repos.get( 0 ), managedRepos.get( 0 ) );
assertManagedRepo( ( ManagedRepository ) repos.get( 1 ), managedRepos.get( 1 ) );
}
public void testGetAllRemoteRepositories()
throws Exception
{
List<RemoteRepositoryConfiguration> remoteRepos = new ArrayList<RemoteRepositoryConfiguration>();
remoteRepos.add( createRemoteRepository( "central", "Central Repository", "default", "http://repo1.maven.org/maven2") );
remoteRepos.add( createRemoteRepository( "dummy", "Dummy Remote Repository", "legacy", "http://dummy.com/dummy") );
archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
configControl.expectAndReturn( config.getRemoteRepositories(), remoteRepos );
archivaConfigControl.replay();
configControl.replay();
List<RemoteRepository> repos = service.getAllRemoteRepositories();
archivaConfigControl.verify();
configControl.verify();
assertNotNull( repos );
assertEquals( 2, repos.size() );
assertRemoteRepo( (RemoteRepository) repos.get( 0 ), remoteRepos.get( 0 ) );
assertRemoteRepo( (RemoteRepository) repos.get( 1 ), remoteRepos.get( 1 ) );
}
/* private methods */
private void assertRemoteRepo( RemoteRepository remoteRepo, RemoteRepositoryConfiguration expectedRepoConfig )
{
assertEquals( expectedRepoConfig.getId(), remoteRepo.getId() );
assertEquals( expectedRepoConfig.getLayout(), remoteRepo.getLayout() );
assertEquals( expectedRepoConfig.getName(), remoteRepo.getName() );
assertEquals( expectedRepoConfig.getUrl(), remoteRepo.getUrl() );
}
private RemoteRepositoryConfiguration createRemoteRepository(String id, String name, String layout, String url)
{
RemoteRepositoryConfiguration remoteConfig = new RemoteRepositoryConfiguration();
remoteConfig.setId( id );
remoteConfig.setName( name );
remoteConfig.setLayout( layout );
remoteConfig.setUrl( url );
return remoteConfig;
}
private void assertManagedRepo( ManagedRepository managedRepo, ManagedRepositoryConfiguration expectedRepoConfig )
{
assertEquals( expectedRepoConfig.getId(), managedRepo.getId() );
assertEquals( expectedRepoConfig.getLayout(), managedRepo.getLayout() );
assertEquals( expectedRepoConfig.getName(), managedRepo.getName() );
//TODO enable assert once fixed in AdministrationServiceImpl!
//assertEquals( "http://localhost:8080/archiva/repository/" + expectedRepoConfig.getId(), managedRepo.getUrl() );
assertEquals( expectedRepoConfig.isReleases(), managedRepo.isReleases() );
assertEquals( expectedRepoConfig.isSnapshots(), managedRepo.isSnapshots() );
}
private ManagedRepositoryConfiguration createManagedRepo( String id, String layout, String name,
boolean hasReleases, boolean hasSnapshots )
{
ManagedRepositoryConfiguration repoConfig = new ManagedRepositoryConfiguration();
repoConfig.setId( id );
repoConfig.setLayout( layout );
repoConfig.setName( name );
repoConfig.setReleases( hasReleases );
repoConfig.setSnapshots( hasSnapshots );
return repoConfig;
}
private void recordRepoConsumers()
{
List<KnownRepositoryContentConsumer> availableKnownConsumers = new ArrayList<KnownRepositoryContentConsumer>();
availableKnownConsumers.add( indexArtifactConsumer );
availableKnownConsumers.add( indexPomConsumer );
List<InvalidRepositoryContentConsumer> availableInvalidConsumers = new ArrayList<InvalidRepositoryContentConsumer>();
availableInvalidConsumers.add( checkPomConsumer );
availableInvalidConsumers.add( checkMetadataConsumer );
repoConsumerUtilsControl.expectAndReturn( repoConsumersUtil.getAvailableKnownConsumers(), availableKnownConsumers );
knownContentConsumerControl.expectAndReturn( indexArtifactConsumer.getId(), "index-artifact" );
knownContentConsumerControl.expectAndReturn( indexPomConsumer.getId(), "index-pom" );
repoConsumerUtilsControl.expectAndReturn( repoConsumersUtil.getAvailableInvalidConsumers(), availableInvalidConsumers );
invalidContentConsumerControl.expectAndReturn( checkPomConsumer.getId(), "check-pom" );
invalidContentConsumerControl.expectAndReturn( checkMetadataConsumer.getId(), "check-metadata" );
}
private void recordDbConsumers()
{
List<DatabaseCleanupConsumer> cleanupConsumers = new ArrayList<DatabaseCleanupConsumer>();
cleanupConsumers.add( cleanupIndexConsumer );
cleanupConsumers.add( cleanupDbConsumer );
List<DatabaseUnprocessedArtifactConsumer> unprocessedConsumers =
new ArrayList<DatabaseUnprocessedArtifactConsumer>();
unprocessedConsumers.add( processArtifactConsumer );
unprocessedConsumers.add( processPomConsumer );
dbConsumersUtilControl.expectAndReturn( dbConsumersUtil.getAvailableCleanupConsumers(), cleanupConsumers );
cleanupConsumersControl.expectAndReturn( cleanupIndexConsumer.getId(), "cleanup-index" );
cleanupConsumersControl.expectAndReturn( cleanupDbConsumer.getId(), "cleanup-database" );
dbConsumersUtilControl.expectAndReturn( dbConsumersUtil.getAvailableUnprocessedConsumers(), unprocessedConsumers );
unprocessedConsumersControl.expectAndReturn( processArtifactConsumer.getId(), "process-artifact" );
unprocessedConsumersControl.expectAndReturn( processPomConsumer.getId(), "process-pom" );
}
private void recordInManagedLegacyRepoContent( MockControl fileTypesControl, FileTypes fileTypes,
MockControl pathParserControl, PathParser parser )
throws LayoutException
{
fileTypesControl.expectAndReturn( fileTypes.matchesArtifactPattern( "org.apache.archiva/poms/archiva-test-1.0.pom" ), true );
fileTypesControl.expectAndReturn( fileTypes.matchesArtifactPattern( "org.apache.archiva/poms/archiva-test-1.1.pom" ), true );
fileTypesControl.expectAndReturn( fileTypes.matchesArtifactPattern( "org.apache.archiva/poms/archiva-diff-1.0.pom" ), true );
fileTypesControl.expectAndReturn( fileTypes.matchesArtifactPattern( "org.apache.archiva/jars/archiva-diff-1.0.jar" ), true );
fileTypesControl.expectAndReturn( fileTypes.matchesArtifactPattern( "org.apache.archiva/jars/archiva-test-1.0.jar" ), true );
fileTypesControl.expectAndReturn( fileTypes.matchesArtifactPattern( "org.apache.archiva/jars/archiva-test-1.1.jar" ), true );
ArtifactReference aRef = createArtifactReference("archiva-test", "org.apache.archiva", "1.1", "pom");
pathParserControl.expectAndReturn( parser.toArtifactReference( "org.apache.archiva/poms/archiva-test-1.1.pom" ), aRef );
aRef = createArtifactReference("archiva-test", "org.apache.archiva", "1.0", "pom");
pathParserControl.expectAndReturn( parser.toArtifactReference( "org.apache.archiva/poms/archiva-test-1.0.pom" ), aRef );
aRef = createArtifactReference("archiva-diff", "org.apache.archiva", "1.0", "pom");
pathParserControl.expectAndReturn( parser.toArtifactReference( "org.apache.archiva/poms/archiva-diff-1.0.pom" ), aRef );
aRef = createArtifactReference("archiva-diff", "org.apache.archiva", "1.0", "jar");
pathParserControl.expectAndReturn( parser.toArtifactReference( "org.apache.archiva/jars/archiva-diff-1.0.jar" ), aRef );
aRef = createArtifactReference("archiva-test", "org.apache.archiva", "1.0", "jar");
pathParserControl.expectAndReturn( parser.toArtifactReference( "org.apache.archiva/jars/archiva-test-1.0.jar" ), aRef );
aRef = createArtifactReference("archiva-test", "org.apache.archiva", "1.1", "jar");
pathParserControl.expectAndReturn( parser.toArtifactReference( "org.apache.archiva/jars/archiva-test-1.1.jar" ), aRef );
}
private List<ArchivaArtifact> getArtifacts()
{
List<ArchivaArtifact> artifacts = new ArrayList<ArchivaArtifact>();
ArchivaArtifactModel model = new ArchivaArtifactModel();
model.setRepositoryId( "internal" );
model.setGroupId( "org.apache.archiva" );
model.setArtifactId( "archiva-test" );
model.setVersion( "1.0" );
model.setType( "jar" );
ArchivaArtifact artifact = new ArchivaArtifact( model );
artifacts.add( artifact );
return artifacts;
}
private ArtifactReference createArtifactReference( String artifactId, String groupId, String version, String type )
{
ArtifactReference aRef = new ArtifactReference();
aRef.setArtifactId( artifactId );
aRef.setGroupId( groupId );
aRef.setType( type );
aRef.setVersion( version );
return aRef;
}
}

View File

@ -0,0 +1,27 @@
<component-set>
<components>
<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>
</components>
</component-set>

View File

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-web</artifactId>
<version>1.2-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>archiva-xmlrpc</artifactId>
<name>Archiva Web :: XML-RPC</name>
<packaging>pom</packaging>
<modules>
<module>archiva-xmlrpc-api</module>
<module>archiva-xmlrpc-services</module>
<module>archiva-xmlrpc-security</module>
<module>archiva-xmlrpc-client</module>
</modules>
</project>

View File

@ -13,7 +13,9 @@
~ 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.
--><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.archiva</groupId>
@ -32,6 +34,7 @@
<module>archiva-webapp</module>
<module>archiva-webdav</module>
<module>archiva-rss</module>
<module>archiva-xmlrpc</module>
</modules>
<profiles>

64
pom.xml
View File

@ -393,6 +393,21 @@
<artifactId>archiva-rss</artifactId>
<version>1.2-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-xmlrpc-api</artifactId>
<version>1.2-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-xmlrpc-services</artifactId>
<version>1.2-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-xmlrpc-security</artifactId>
<version>1.2-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-spring</artifactId>
@ -508,6 +523,11 @@
<artifactId>mail</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>org.apache.xmlrpc</groupId>
<artifactId>xmlrpc-server</artifactId>
<version>3.1</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact-manager</artifactId>
@ -894,6 +914,36 @@
<version>${jetty.version}</version>
</dependency>
<!-- xmlrpc -->
<dependency>
<groupId>com.atlassian.xmlrpc</groupId>
<artifactId>atlassian-xmlrpc-binder-annotations</artifactId>
<version>${binder.version}</version>
</dependency>
<dependency>
<groupId>com.atlassian.xmlrpc</groupId>
<artifactId>atlassian-xmlrpc-binder-server-spring</artifactId>
<version>${binder.version}</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.atlassian.xmlrpc</groupId>
<artifactId>atlassian-xmlrpc-binder</artifactId>
<version>${binder.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.atlassian.xmlrpc</groupId>
<artifactId>atlassian-xmlrpc-binder-testing</artifactId>
<version>${binder.version}</version>
<scope>test</scope>
</dependency>
<!-- Transitive versions to manage -->
<dependency>
<groupId>org.springframework</groupId>
@ -928,6 +978,19 @@
</exclusion>
</exclusions>
</dependency>
<!-- use spring test in xmlrpc?
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>2.5.1</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
-->
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
@ -978,6 +1041,7 @@
<wagon.version>1.0-beta-4</wagon.version>
<redback.version>1.2-SNAPSHOT</redback.version>
<jetty.version>6.1.6</jetty.version>
<binder.version>0.8.1</binder.version>
</properties>
<profiles>
<profile>