[MRM-1490] expose service tru rest

impl Repo management service

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1159531 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Olivier Lamy 2011-08-19 07:53:42 +00:00
parent 014e2fa339
commit 53d4ecac05
13 changed files with 268 additions and 111 deletions

View File

@ -28,6 +28,11 @@
<name>Archiva Web :: REST support :: Api</name>
<dependencies>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-security</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.redback</groupId>
<artifactId>redback-authorization-api</artifactId>

View File

@ -56,23 +56,6 @@ public class ManagedRepository
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()
{
@ -94,12 +77,6 @@ public class ManagedRepository
return this.url;
}
public int hashCode()
{
int result = 17;
result = 37 * result + ( id != null ? id.hashCode() : 0 );
return result;
}
public boolean isReleases()
{
@ -114,33 +91,66 @@ public class ManagedRepository
return this.snapshots;
}
public void setId(String id)
public void setId( String id )
{
this.id = id;
}
public void setLayout(String layout)
public void setLayout( String layout )
{
this.layout = layout;
}
public void setName(String name)
public void setName( String name )
{
this.name = name;
}
public void setReleases(boolean releases)
public void setReleases( boolean releases )
{
this.releases = releases;
}
public void setSnapshots(boolean snapshots)
public void setSnapshots( boolean snapshots )
{
this.snapshots = snapshots;
}
public void setUrl(String url)
public void setUrl( String url )
{
this.url = url;
}
public int hashCode()
{
int result = 17;
result = 37 * result + ( id != null ? id.hashCode() : 0 );
return result;
}
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;
}
@Override
public String toString()
{
return "ManagedRepository{" + "id='" + id + '\'' + ", name='" + name + '\'' + ", url='" + url + '\''
+ ", layout='" + layout + '\'' + ", snapshots=" + snapshots + ", releases=" + releases + '}';
}
}

View File

@ -48,23 +48,6 @@ public class RemoteRepository
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()
{
@ -86,6 +69,28 @@ public class RemoteRepository
return this.url;
}
public void setId( String id )
{
this.id = id;
}
public void setLayout( String layout )
{
this.layout = layout;
}
public void setName( String name )
{
this.name = name;
}
public void setUrl( String url )
{
this.url = url;
}
public int hashCode()
{
int result = 17;
@ -93,23 +98,28 @@ public class RemoteRepository
return result;
}
public void setId(String id)
public boolean equals( Object other )
{
this.id = id;
if ( this == other )
{
return true;
}
public void setLayout(String layout)
if ( !( other instanceof RemoteRepository ) )
{
this.layout = layout;
return false;
}
public void setName(String name)
{
this.name = name;
RemoteRepository that = (RemoteRepository) other;
boolean result = true;
result = result && ( getId() == null ? that.getId() == null : getId().equals( that.getId() ) );
return result;
}
public void setUrl(String url)
@Override
public String toString()
{
this.url = url;
return "RemoteRepository{" + "id='" + id + '\'' + ", name='" + name + '\'' + ", url='" + url + '\''
+ ", layout='" + layout + '\'' + '}';
}
}

View File

@ -21,6 +21,7 @@ package org.apache.archiva.rest.api.services;
import org.apache.archiva.rest.api.model.ManagedRepository;
import org.apache.archiva.rest.api.model.RemoteRepository;
import org.apache.maven.archiva.security.ArchivaRoleConstants;
import org.codehaus.plexus.redback.authorization.RedbackAuthorization;
import javax.ws.rs.GET;
@ -40,13 +41,13 @@ public interface RepositoriesService
@Path( "getManagedRepositories" )
@GET
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
@RedbackAuthorization( noRestriction = true )
@RedbackAuthorization( permission = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION)
List<ManagedRepository> getManagedRepositories();
@Path( "getRemoteRepositories" )
@GET
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
@RedbackAuthorization( noRestriction = true )
@RedbackAuthorization( permission = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION)
List<RemoteRepository> getRemoteRepositories();
@Path( "scanRepository" )

View File

@ -33,6 +33,10 @@
</properties>
<dependencies>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-security</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.redback</groupId>
<artifactId>redback-authorization-api</artifactId>

View File

@ -20,6 +20,8 @@ package org.apache.archiva.rest.services;
*/
import org.apache.archiva.rest.api.services.PingService;
import org.codehaus.plexus.redback.users.User;
import org.codehaus.redback.rest.services.RedbackAuthenticationThreadLocal;
import org.springframework.stereotype.Service;
/**
@ -37,6 +39,7 @@ public class DefaultPingService
public String pingWithAuthz()
{
User user = RedbackAuthenticationThreadLocal.get();
return ping();
}
}

View File

@ -3,26 +3,62 @@ package org.apache.archiva.rest.services;
import org.apache.archiva.rest.api.model.ManagedRepository;
import org.apache.archiva.rest.api.model.RemoteRepository;
import org.apache.archiva.rest.api.services.RepositoriesService;
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.configuration.Configuration;
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration;
import org.springframework.stereotype.Service;
import javax.inject.Inject;
import java.util.ArrayList;
import java.util.List;
/**
* @author Olivier Lamy
* @since 1.4
*/
@Service("repositoriesService#rest")
@Service( "repositoriesService#rest" )
public class DefaultRepositoriesService
implements RepositoriesService
{
@Inject
protected ArchivaConfiguration archivaConfiguration;
public List<ManagedRepository> getManagedRepositories()
{
return null; //To change body of implemented methods use File | Settings | File Templates.
List<ManagedRepositoryConfiguration> managedRepoConfigs =
archivaConfiguration.getConfiguration().getManagedRepositories();
List<ManagedRepository> managedRepos = new ArrayList<ManagedRepository>( managedRepoConfigs.size() );
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;
}
public List<RemoteRepository> getRemoteRepositories()
{
return null; //To change body of implemented methods use File | Settings | File Templates.
Configuration config = archivaConfiguration.getConfiguration();
List<RemoteRepositoryConfiguration> remoteRepoConfigs = config.getRemoteRepositories();
List<RemoteRepository> remoteRepos = new ArrayList<RemoteRepository>( remoteRepoConfigs.size() );
for ( RemoteRepositoryConfiguration repoConfig : remoteRepoConfigs )
{
RemoteRepository repo = new RemoteRepository( repoConfig.getId(), repoConfig.getName(), repoConfig.getUrl(),
repoConfig.getLayout() );
remoteRepos.add( repo );
}
return remoteRepos;
}
public Boolean scanRepository( String repositoryId, boolean fullScan )

View File

@ -41,15 +41,21 @@
<jaxrs:server id="archivaServices" address="/archivaServices">
<jaxrs:serviceBeans>
<ref bean="pingService#rest"/>
</jaxrs:serviceBeans>
<jaxrs:providers>
<ref bean="authenticationInterceptor#rest"/>
<ref bean="permissionInterceptor#rest"/>
<ref bean="repositoriesService#rest"/>
</jaxrs:providers>
<jaxrs:serviceBeans>
<ref bean="pingService#rest"/>
<ref bean="repositoriesService#rest"/>
</jaxrs:serviceBeans>
<jaxrs:outInterceptors>
<ref bean="threadLocalUserCleaner#rest"/>
</jaxrs:outInterceptors>
</jaxrs:server>
</beans>

View File

@ -0,0 +1,33 @@
package org.apache.archiva.rest.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.codehaus.redback.rest.services.AbstractRestServicesTest;
/**
* @author Olivier Lamy
* @since TODO
*/
public abstract class AbstractArchivaRestTest
extends AbstractRestServicesTest
{
public String guestAuthzHeader =
"Basic " + org.apache.cxf.common.util.Base64Utility.encode( ( "guest" + ":" ).getBytes() );
}

View File

@ -24,6 +24,7 @@ import org.apache.cxf.jaxrs.client.JAXRSClientFactory;
import org.apache.cxf.jaxrs.client.ServerWebApplicationException;
import org.apache.cxf.jaxrs.client.WebClient;
import org.codehaus.redback.rest.services.AbstractRestServicesTest;
import org.junit.Ignore;
import org.junit.Test;
/**
@ -31,7 +32,7 @@ import org.junit.Test;
* @since 1.4
*/
public class PingServiceTest
extends AbstractRestServicesTest
extends AbstractArchivaRestTest
{
PingService getPingService()
@ -76,8 +77,21 @@ public class PingServiceTest
{
PingService service = getPingService();
WebClient.getConfig( service ).getHttpConduit().getClient().setReceiveTimeout( 300000 );
WebClient.client( service ).header( "Authorization", authorizationHeader );
String res = service.pingWithAuthz();
assertEquals( "Yeah Baby It rocks!", res );
}
@Ignore("FIXME guest failed ???")
public void pingWithAuthzGuest()
throws Exception
{
PingService service = getPingService();
WebClient.getConfig( service ).getHttpConduit().getClient().setReceiveTimeout( 300000 );
WebClient.client( service ).header( "Authorization", guestAuthzHeader );
String res = service.pingWithAuthz();
assertEquals( "Yeah Baby It rocks!", res );
}
}

View File

@ -19,27 +19,55 @@ package org.apache.archiva.rest.services;
* under the License.
*/
import org.apache.archiva.rest.api.model.RemoteRepository;
import org.apache.archiva.rest.api.services.RepositoriesService;
import org.apache.cxf.jaxrs.client.JAXRSClientFactory;
import org.codehaus.redback.rest.services.AbstractRestServicesTest;
import org.apache.cxf.jaxrs.client.ServerWebApplicationException;
import org.apache.cxf.jaxrs.client.WebClient;
import org.junit.Test;
import java.util.List;
/**
* @author Olivier Lamy
*/
public class RepositoriesServiceTest
extends AbstractRestServicesTest
extends AbstractArchivaRestTest
{
RepositoriesService getPingService()
RepositoriesService getRepositoriesService()
{
return JAXRSClientFactory.create( "http://localhost:" + port + "/services/archivaServices/",
RepositoriesService.class );
}
@Test
public void listRemoteRepositories() throws Exception
@Test( expected = ServerWebApplicationException.class )
public void listRemoteRepositoriesKarmaFailed()
throws Exception
{
RepositoriesService service = getRepositoriesService();
try
{
assertFalse( service.getRemoteRepositories().isEmpty() );
}
catch ( ServerWebApplicationException e )
{
assertEquals( 403, e.getStatus() );
throw e;
}
}
@Test
public void listRemoteRepositoriesKarma()
throws Exception
{
RepositoriesService service = getRepositoriesService();
WebClient.client( service ).header( "Authorization", authorizationHeader );
WebClient.getConfig( service ).getHttpConduit().getClient().setReceiveTimeout( 300000 );
List<RemoteRepository> repos = service.getRemoteRepositories();
assertFalse( repos.isEmpty() );
log.info( "repos {}", repos );
}
}

View File

@ -38,6 +38,13 @@
<logger name="org.codehaus.redback.rest.services" >
<level value="debug"/>
</logger>
<logger name="JPOX">
<level value="ERROR"/>
</logger>
<logger name="org.springframework">
<level value="ERROR"/>
</logger>
<root>
<priority value ="info" />

View File

@ -43,7 +43,7 @@ import javax.inject.Named;
*
* @version $Id$
*/
public abstract class AbstractManagedRepositoriesAction
public abstract class AbstractManagedReposigettoriesAction
extends AbstractRepositoriesAdminAction
{
/**