<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>
@XmlRootElement( name = "managedRepository" )
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()
{
// no op
}
-
+
public ManagedRepository( String id, String name, String url, String layout, boolean snapshots, boolean releases )
{
this.id = id;
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;
- result = 37 * result + ( id != null ? id.hashCode() : 0 );
- return result;
- }
+ }
+
public boolean isReleases()
{
return this.releases;
- }
+ }
/**
* Get null
public boolean isSnapshots()
{
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 + '}';
+ }
}
\ No newline at end of file
@XmlRootElement( name = "remoteRepository" )
public class RemoteRepository
implements Serializable
-{
+{
private String id;
private String name;
private String url;
-
+
private String layout;
public RemoteRepository()
{
// no op
}
-
+
public RemoteRepository( String id, String name, String url, String layout )
{
this.id = id;
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;
- result = 37 * result + ( id != null ? id.hashCode() : 0 );
- return result;
- }
-
- 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 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 RemoteRepository ) )
+ {
+ return false;
+ }
+
+ RemoteRepository that = (RemoteRepository) other;
+ boolean result = true;
+ result = result && ( getId() == null ? that.getId() == null : getId().equals( that.getId() ) );
+ return result;
+ }
+
+ @Override
+ public String toString()
+ {
+ return "RemoteRepository{" + "id='" + id + '\'' + ", name='" + name + '\'' + ", url='" + url + '\''
+ + ", layout='" + layout + '\'' + '}';
+ }
}
\ No newline at end of file
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;
@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" )
</properties>
<dependencies>
+ <dependency>
+ <groupId>org.apache.archiva</groupId>
+ <artifactId>archiva-security</artifactId>
+ </dependency>
<dependency>
<groupId>org.codehaus.redback</groupId>
<artifactId>redback-authorization-api</artifactId>
*/
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;
/**
public String pingWithAuthz()
{
+ User user = RedbackAuthenticationThreadLocal.get();
return ping();
}
}
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 )
<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>
\ No newline at end of file
--- /dev/null
+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() );
+}
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;
/**
* @since 1.4
*/
public class PingServiceTest
- extends AbstractRestServicesTest
+ extends AbstractArchivaRestTest
{
PingService getPingService()
{
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 );
+ }
}
* 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( 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 listRemoteRepositories() throws Exception
+ 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 );
}
}
<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" />
*
* @version $Id$
*/
-public abstract class AbstractManagedRepositoriesAction
+public abstract class AbstractManagedReposigettoriesAction
extends AbstractRepositoriesAdminAction
{
/**