mirror of https://github.com/apache/archiva.git
fix permission management for scan repo rest services
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1159532 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
53d4ecac05
commit
f4bb416191
|
@ -53,7 +53,7 @@ public interface RepositoriesService
|
||||||
@Path( "scanRepository" )
|
@Path( "scanRepository" )
|
||||||
@GET
|
@GET
|
||||||
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
|
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
|
||||||
@RedbackAuthorization( noRestriction = true )
|
@RedbackAuthorization( permission = ArchivaRoleConstants.OPERATION_RUN_INDEXER )
|
||||||
Boolean scanRepository( @QueryParam( "repositoryId" ) String repositoryId,
|
Boolean scanRepository( @QueryParam( "repositoryId" ) String repositoryId,
|
||||||
@QueryParam( "fullScan" ) boolean fullScan );
|
@QueryParam( "fullScan" ) boolean fullScan );
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,6 +37,10 @@
|
||||||
<groupId>org.apache.archiva</groupId>
|
<groupId>org.apache.archiva</groupId>
|
||||||
<artifactId>archiva-security</artifactId>
|
<artifactId>archiva-security</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.archiva</groupId>
|
||||||
|
<artifactId>archiva-scheduler-repository</artifactId>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.codehaus.redback</groupId>
|
<groupId>org.codehaus.redback</groupId>
|
||||||
<artifactId>redback-authorization-api</artifactId>
|
<artifactId>redback-authorization-api</artifactId>
|
||||||
|
@ -162,5 +166,12 @@
|
||||||
<version>${redback.version}</version>
|
<version>${redback.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.archiva</groupId>
|
||||||
|
<artifactId>metadata-store-file</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -3,13 +3,19 @@ package org.apache.archiva.rest.services;
|
||||||
import org.apache.archiva.rest.api.model.ManagedRepository;
|
import org.apache.archiva.rest.api.model.ManagedRepository;
|
||||||
import org.apache.archiva.rest.api.model.RemoteRepository;
|
import org.apache.archiva.rest.api.model.RemoteRepository;
|
||||||
import org.apache.archiva.rest.api.services.RepositoriesService;
|
import org.apache.archiva.rest.api.services.RepositoriesService;
|
||||||
|
import org.apache.archiva.scheduler.repository.RepositoryArchivaTaskScheduler;
|
||||||
|
import org.apache.archiva.scheduler.repository.RepositoryTask;
|
||||||
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
|
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
|
||||||
import org.apache.maven.archiva.configuration.Configuration;
|
import org.apache.maven.archiva.configuration.Configuration;
|
||||||
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
|
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
|
||||||
import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration;
|
import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration;
|
||||||
|
import org.codehaus.plexus.taskqueue.TaskQueueException;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Named;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -22,9 +28,15 @@ public class DefaultRepositoriesService
|
||||||
implements RepositoriesService
|
implements RepositoriesService
|
||||||
{
|
{
|
||||||
|
|
||||||
|
private Logger log = LoggerFactory.getLogger( getClass() );
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
protected ArchivaConfiguration archivaConfiguration;
|
protected ArchivaConfiguration archivaConfiguration;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
@Named( value = "archivaTaskScheduler#repository" )
|
||||||
|
private RepositoryArchivaTaskScheduler repositoryTaskScheduler;
|
||||||
|
|
||||||
public List<ManagedRepository> getManagedRepositories()
|
public List<ManagedRepository> getManagedRepositories()
|
||||||
{
|
{
|
||||||
List<ManagedRepositoryConfiguration> managedRepoConfigs =
|
List<ManagedRepositoryConfiguration> managedRepoConfigs =
|
||||||
|
@ -63,6 +75,21 @@ public class DefaultRepositoriesService
|
||||||
|
|
||||||
public Boolean scanRepository( String repositoryId, boolean fullScan )
|
public Boolean scanRepository( String repositoryId, boolean fullScan )
|
||||||
{
|
{
|
||||||
return null; //To change body of implemented methods use File | Settings | File Templates.
|
if ( repositoryTaskScheduler.isProcessingRepositoryTask( repositoryId ) )
|
||||||
|
{
|
||||||
|
log.info( "scanning of repository with id {} already scheduled" );
|
||||||
|
}
|
||||||
|
RepositoryTask task = new RepositoryTask();
|
||||||
|
task.setRepositoryId( repositoryId );
|
||||||
|
task.setScanAll( fullScan );
|
||||||
|
try
|
||||||
|
{
|
||||||
|
repositoryTaskScheduler.queueTask( task );
|
||||||
|
}
|
||||||
|
catch ( TaskQueueException e )
|
||||||
|
{
|
||||||
|
log.error( "failed to schedule scanning of repo with id {}", repositoryId, e );
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
http://www.springframework.org/schema/context
|
http://www.springframework.org/schema/context
|
||||||
http://www.springframework.org/schema/context/spring-context-3.0.xsd
|
http://www.springframework.org/schema/context/spring-context-3.0.xsd
|
||||||
http://cxf.apache.org/jaxrs
|
http://cxf.apache.org/jaxrs
|
||||||
http://cxf.apache.org/schemas/jaxrs.xsd">
|
http://cxf.apache.org/schemas/jaxrs.xsd" default-lazy-init="true">
|
||||||
|
|
||||||
<import resource="classpath:META-INF/cxf/cxf.xml"/>
|
<import resource="classpath:META-INF/cxf/cxf.xml"/>
|
||||||
<!--
|
<!--
|
||||||
|
|
|
@ -30,4 +30,10 @@ public abstract class AbstractArchivaRestTest
|
||||||
{
|
{
|
||||||
public String guestAuthzHeader =
|
public String guestAuthzHeader =
|
||||||
"Basic " + org.apache.cxf.common.util.Base64Utility.encode( ( "guest" + ":" ).getBytes() );
|
"Basic " + org.apache.cxf.common.util.Base64Utility.encode( ( "guest" + ":" ).getBytes() );
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getSpringConfigLocation()
|
||||||
|
{
|
||||||
|
return "classpath*:META-INF/spring-context.xml,classpath:META-INF/spring-context-test.xml";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,4 +70,30 @@ public class RepositoriesServiceTest
|
||||||
log.info( "repos {}", repos );
|
log.info( "repos {}", repos );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test( expected = ServerWebApplicationException.class )
|
||||||
|
public void scanRepoKarmaFailed()
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
RepositoriesService service = getRepositoriesService();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
service.scanRepository( "id", true );
|
||||||
|
}
|
||||||
|
catch ( ServerWebApplicationException e )
|
||||||
|
{
|
||||||
|
assertEquals( 403, e.getStatus() );
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void scanRepo()
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
RepositoriesService service = getRepositoriesService();
|
||||||
|
WebClient.client( service ).header( "Authorization", authorizationHeader );
|
||||||
|
WebClient.getConfig( service ).getHttpConduit().getClient().setReceiveTimeout( 300000 );
|
||||||
|
assertTrue( service.scanRepository( service.getManagedRepositories().get( 0 ).getId(), true ) );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
~ Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
~ or more contributor license agreements. See the NOTICE file
|
||||||
|
~ distributed with this work for additional information
|
||||||
|
~ regarding copyright ownership. The ASF licenses this file
|
||||||
|
~ to you under the Apache License, Version 2.0 (the
|
||||||
|
~ "License"); you may not use this file except in compliance
|
||||||
|
~ with the License. You may obtain a copy of the License at
|
||||||
|
~
|
||||||
|
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
~
|
||||||
|
~ Unless required by applicable law or agreed to in writing,
|
||||||
|
~ software distributed under the License is distributed on an
|
||||||
|
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
~ KIND, either express or implied. See the License for the
|
||||||
|
~ specific language governing permissions and limitations
|
||||||
|
~ under the License.
|
||||||
|
-->
|
||||||
|
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||||
|
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd" default-lazy-init="true">
|
||||||
|
|
||||||
|
<bean name="scheduler" class="org.codehaus.redback.components.scheduler.DefaultScheduler">
|
||||||
|
<property name="properties">
|
||||||
|
<props>
|
||||||
|
<prop key="org.quartz.scheduler.instanceName">scheduler1</prop>
|
||||||
|
<prop key="org.quartz.threadPool.class">org.quartz.simpl.SimpleThreadPool</prop>
|
||||||
|
<prop key="org.quartz.threadPool.threadCount">2</prop>
|
||||||
|
<prop key="org.quartz.threadPool.threadPriority">4</prop>
|
||||||
|
<prop key="org.quartz.jobStore.class">org.quartz.simpl.RAMJobStore</prop>
|
||||||
|
</props>
|
||||||
|
</property>
|
||||||
|
</bean>
|
||||||
|
</beans>
|
|
@ -43,7 +43,7 @@
|
||||||
</logger>
|
</logger>
|
||||||
|
|
||||||
<logger name="org.springframework">
|
<logger name="org.springframework">
|
||||||
<level value="ERROR"/>
|
<level value="info"/>
|
||||||
</logger>
|
</logger>
|
||||||
|
|
||||||
<root>
|
<root>
|
||||||
|
|
Loading…
Reference in New Issue