aboutsummaryrefslogtreecommitdiffstats
path: root/archiva-modules/archiva-web
diff options
context:
space:
mode:
authorMartin Stockhammer <martin_s@apache.org>2021-01-19 20:46:30 +0100
committerMartin Stockhammer <martin_s@apache.org>2021-01-19 20:46:37 +0100
commit069783fb77d39492328e83157f2c89cfa5236dd4 (patch)
treed3b9d61b2aee4517ccd7e5eac6c29940f32eb6d4 /archiva-modules/archiva-web
parentb97724c6a70b18f5667b45a20375ff550bd9015c (diff)
downloadarchiva-069783fb77d39492328e83157f2c89cfa5236dd4.tar.gz
archiva-069783fb77d39492328e83157f2c89cfa5236dd4.zip
Implementing V2 REST service
Diffstat (limited to 'archiva-modules/archiva-web')
-rw-r--r--archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/v2/RepositoryGroupService.java2
-rw-r--r--archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/v2/DefaultRepositoryGroupService.java225
-rw-r--r--archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/v2/DefaultSecurityConfigurationService.java38
-rw-r--r--archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/v2/ErrorKeys.java4
-rw-r--r--archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/resources/META-INF/spring-context.xml1
-rw-r--r--archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/v2/NativeRepositoryGroupServiceTest.java85
6 files changed, 282 insertions, 73 deletions
diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/v2/RepositoryGroupService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/v2/RepositoryGroupService.java
index 7796d1c56..08ff59e14 100644
--- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/v2/RepositoryGroupService.java
+++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/v2/RepositoryGroupService.java
@@ -87,7 +87,7 @@ public interface RepositoryGroupService
PagedResult<RepositoryGroup> getRepositoriesGroups(@QueryParam("q") @DefaultValue( "" ) String searchTerm,
@QueryParam( "offset" ) @DefaultValue( "0" ) Integer offset,
@QueryParam( "limit" ) @DefaultValue( value = DEFAULT_PAGE_LIMIT ) Integer limit,
- @QueryParam( "orderBy") @DefaultValue( "key" ) List<String> orderBy,
+ @QueryParam( "orderBy") @DefaultValue( "id" ) List<String> orderBy,
@QueryParam("order") @DefaultValue( "asc" ) String order)
throws ArchivaRestServiceException;
diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/v2/DefaultRepositoryGroupService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/v2/DefaultRepositoryGroupService.java
index 1855ea8a9..e348cdcab 100644
--- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/v2/DefaultRepositoryGroupService.java
+++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/v2/DefaultRepositoryGroupService.java
@@ -22,7 +22,6 @@ import org.apache.archiva.admin.model.EntityNotFoundException;
import org.apache.archiva.admin.model.RepositoryAdminException;
import org.apache.archiva.admin.model.group.RepositoryGroupAdmin;
import org.apache.archiva.components.rest.model.PagedResult;
-import org.apache.archiva.components.rest.util.PagingHelper;
import org.apache.archiva.components.rest.util.QueryHelper;
import org.apache.archiva.redback.rest.services.RedbackAuthenticationThreadLocal;
import org.apache.archiva.redback.rest.services.RedbackRequestInformation;
@@ -34,6 +33,7 @@ import org.apache.archiva.rest.api.services.v2.RepositoryGroupService;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Service;
import javax.inject.Inject;
import javax.servlet.http.HttpServletResponse;
@@ -50,9 +50,10 @@ import java.util.stream.Collectors;
* REST V2 Implementation for repository groups.
*
* @author Martin Stockhammer <martin_s@apache.org>
- * @since 3.0
* @see RepositoryGroupService
+ * @since 3.0
*/
+@Service("v2.repositoryGroupService#rest")
public class DefaultRepositoryGroupService implements RepositoryGroupService
{
@Context
@@ -63,8 +64,7 @@ public class DefaultRepositoryGroupService implements RepositoryGroupService
private static final Logger log = LoggerFactory.getLogger( DefaultRepositoryGroupService.class );
- private static final QueryHelper<org.apache.archiva.admin.model.beans.RepositoryGroup> QUERY_HELPER = new QueryHelper( new String[]{"id"} );
- private static final PagingHelper PROP_PAGING_HELPER = new PagingHelper( );
+ private static final QueryHelper<org.apache.archiva.admin.model.beans.RepositoryGroup> QUERY_HELPER = new QueryHelper<>( new String[]{"id"} );
@Inject
private RepositoryGroupAdmin repositoryGroupAdmin;
@@ -77,11 +77,11 @@ public class DefaultRepositoryGroupService implements RepositoryGroupService
}
- protected AuditInformation getAuditInformation()
+ protected AuditInformation getAuditInformation( )
{
- RedbackRequestInformation redbackRequestInformation = RedbackAuthenticationThreadLocal.get();
- User user = redbackRequestInformation == null ? null : redbackRequestInformation.getUser();
- String remoteAddr = redbackRequestInformation == null ? null : redbackRequestInformation.getRemoteAddr();
+ RedbackRequestInformation redbackRequestInformation = RedbackAuthenticationThreadLocal.get( );
+ User user = redbackRequestInformation == null ? null : redbackRequestInformation.getUser( );
+ String remoteAddr = redbackRequestInformation == null ? null : redbackRequestInformation.getRemoteAddr( );
return new AuditInformation( user, remoteAddr );
}
@@ -101,8 +101,10 @@ public class DefaultRepositoryGroupService implements RepositoryGroupService
catch ( RepositoryAdminException e )
{
log.error( "Repository admin error: {}", e.getMessage( ), e );
- throw new ArchivaRestServiceException( ErrorMessage.of( ErrorKeys.REPOSITORY_ADMIN_ERROR, e.getMessage() ) );
- } catch ( ArithmeticException e ) {
+ throw new ArchivaRestServiceException( ErrorMessage.of( ErrorKeys.REPOSITORY_ADMIN_ERROR, e.getMessage( ) ) );
+ }
+ catch ( ArithmeticException e )
+ {
log.error( "Could not convert total count: {}", e.getMessage( ) );
throw new ArchivaRestServiceException( ErrorMessage.of( ErrorKeys.INVALID_RESULT_SET_ERROR ) );
}
@@ -112,28 +114,34 @@ public class DefaultRepositoryGroupService implements RepositoryGroupService
@Override
public RepositoryGroup getRepositoryGroup( String repositoryGroupId ) throws ArchivaRestServiceException
{
+ if ( StringUtils.isEmpty( repositoryGroupId ) )
+ {
+ throw new ArchivaRestServiceException( ErrorMessage.of( ErrorKeys.REPOSITORY_GROUP_NOT_EXIST, "" ), 404 );
+ }
try
{
org.apache.archiva.admin.model.beans.RepositoryGroup group = repositoryGroupAdmin.getRepositoryGroup( repositoryGroupId );
return RepositoryGroup.of( group );
}
- catch ( EntityNotFoundException e ) {
+ catch ( EntityNotFoundException e )
+ {
throw new ArchivaRestServiceException( ErrorMessage.of( ErrorKeys.REPOSITORY_GROUP_NOT_EXIST, repositoryGroupId ), 404 );
}
catch ( RepositoryAdminException e )
{
- throw new ArchivaRestServiceException( ErrorMessage.of( ErrorKeys.REPOSITORY_ADMIN_ERROR, e.getMessage() ));
+ throw new ArchivaRestServiceException( ErrorMessage.of( ErrorKeys.REPOSITORY_ADMIN_ERROR, e.getMessage( ) ) );
}
}
- private org.apache.archiva.admin.model.beans.RepositoryGroup toModel( RepositoryGroup group) {
+ private org.apache.archiva.admin.model.beans.RepositoryGroup toModel( RepositoryGroup group )
+ {
org.apache.archiva.admin.model.beans.RepositoryGroup result = new org.apache.archiva.admin.model.beans.RepositoryGroup( );
result.setId( group.getId( ) );
result.setLocation( group.getLocation( ) );
result.setRepositories( new ArrayList<>( group.getRepositories( ) ) );
- result.setMergedIndexPath( group.getMergeConfiguration().getMergedIndexPath() );
- result.setMergedIndexTtl( group.getMergeConfiguration().getMergedIndexTtlMinutes() );
- result.setCronExpression( group.getMergeConfiguration().getIndexMergeSchedule() );
+ result.setMergedIndexPath( group.getMergeConfiguration( ).getMergedIndexPath( ) );
+ result.setMergedIndexTtl( group.getMergeConfiguration( ).getMergedIndexTtlMinutes( ) );
+ result.setCronExpression( group.getMergeConfiguration( ).getIndexMergeSchedule( ) );
return result;
}
@@ -143,72 +151,203 @@ public class DefaultRepositoryGroupService implements RepositoryGroupService
try
{
Boolean result = repositoryGroupAdmin.addRepositoryGroup( toModel( repositoryGroup ), getAuditInformation( ) );
- if (result) {
+ if ( result )
+ {
org.apache.archiva.admin.model.beans.RepositoryGroup newGroup = repositoryGroupAdmin.getRepositoryGroup( repositoryGroup.getId( ) );
- if (newGroup!=null) {
+ if ( newGroup != null )
+ {
return RepositoryGroup.of( newGroup );
- } else {
+ }
+ else
+ {
throw new ArchivaRestServiceException( ErrorMessage.of( ErrorKeys.REPOSITORY_GROUP_ADD_FAILED ) );
}
- } else {
+ }
+ else
+ {
throw new ArchivaRestServiceException( ErrorMessage.of( ErrorKeys.REPOSITORY_GROUP_ADD_FAILED ) );
}
- } catch ( EntityExistsException e ) {
- httpServletResponse.setHeader( "Location", uriInfo.getAbsolutePathBuilder( ).path( repositoryGroup.getId() ).build( ).toString( ) );
- throw new ArchivaRestServiceException( ErrorMessage.of( ErrorKeys.REPOSITORY_GROUP_EXIST, repositoryGroup.getId( )), 303 );
+ }
+ catch ( EntityExistsException e )
+ {
+ httpServletResponse.setHeader( "Location", uriInfo.getAbsolutePathBuilder( ).path( repositoryGroup.getId( ) ).build( ).toString( ) );
+ throw new ArchivaRestServiceException( ErrorMessage.of( ErrorKeys.REPOSITORY_GROUP_EXIST, repositoryGroup.getId( ) ), 303 );
}
catch ( RepositoryAdminException e )
{
- if (e.keyExists()) {
- throw new ArchivaRestServiceException( ErrorMessage.of( ErrorKeys.PREFIX+e.getKey(), e.getParameters() ) );
- } else
- {
- throw new ArchivaRestServiceException( ErrorMessage.of( ErrorKeys.REPOSITORY_ADMIN_ERROR, e.getMessage( ) ) );
- }
+ return handleAdminException( e );
+ }
+ }
+
+ private RepositoryGroup handleAdminException( RepositoryAdminException e ) throws ArchivaRestServiceException
+ {
+ log.error( "Repository admin error: {}", e.getMessage( ), e );
+ if ( e.keyExists( ) )
+ {
+ throw new ArchivaRestServiceException( ErrorMessage.of( ErrorKeys.PREFIX + e.getKey( ), e.getParameters( ) ) );
+ }
+ else
+ {
+ throw new ArchivaRestServiceException( ErrorMessage.of( ErrorKeys.REPOSITORY_ADMIN_ERROR, e.getMessage( ) ) );
}
}
@Override
- public RepositoryGroup updateRepositoryGroup( String groupId, RepositoryGroup repositoryGroup ) throws ArchivaRestServiceException
+ public RepositoryGroup updateRepositoryGroup( String repositoryGroupId, RepositoryGroup repositoryGroup ) throws ArchivaRestServiceException
{
+ if ( StringUtils.isEmpty( repositoryGroupId ) )
+ {
+ throw new ArchivaRestServiceException( ErrorMessage.of( ErrorKeys.REPOSITORY_GROUP_NOT_EXIST, "" ), 404 );
+ }
org.apache.archiva.admin.model.beans.RepositoryGroup updateGroup = toModel( repositoryGroup );
try
{
- org.apache.archiva.admin.model.beans.RepositoryGroup originGroup = repositoryGroupAdmin.getRepositoryGroup( groupId );
- if ( StringUtils.isEmpty( updateGroup.getId())) {
- updateGroup.setId( groupId );
+ org.apache.archiva.admin.model.beans.RepositoryGroup originGroup = repositoryGroupAdmin.getRepositoryGroup( repositoryGroupId );
+ if ( StringUtils.isEmpty( updateGroup.getId( ) ) )
+ {
+ updateGroup.setId( repositoryGroupId );
+ }
+ if ( StringUtils.isEmpty( updateGroup.getLocation( ) ) )
+ {
+ updateGroup.setLocation( originGroup.getLocation( ) );
+ }
+ if ( StringUtils.isEmpty( updateGroup.getMergedIndexPath( ) ) )
+ {
+ updateGroup.setMergedIndexPath( originGroup.getMergedIndexPath( ) );
}
- if (StringUtils.isEmpty( updateGroup.getLocation() )) {
- updateGroup.setLocation( originGroup.getLocation() );
+ if ( updateGroup.getCronExpression( ) == null )
+ {
+ updateGroup.setCronExpression( originGroup.getCronExpression( ) );
+ }
+ if ( updateGroup.getRepositories( ) == null || updateGroup.getRepositories( ).size( ) == 0 )
+ {
+ updateGroup.setRepositories( originGroup.getRepositories( ) );
}
- if (StringUtils.isEmpty( updateGroup.getMergedIndexPath() )) {
- updateGroup.setMergedIndexPath( originGroup.getMergedIndexPath() );
+ if ( updateGroup.getMergedIndexTtl( ) <= 0 )
+ {
+ updateGroup.setMergedIndexTtl( originGroup.getMergedIndexTtl( ) );
}
repositoryGroupAdmin.updateRepositoryGroup( updateGroup, getAuditInformation( ) );
- return RepositoryGroup.of( repositoryGroupAdmin.getRepositoryGroup( groupId ) );
+ return RepositoryGroup.of( repositoryGroupAdmin.getRepositoryGroup( repositoryGroupId ) );
+ }
+ catch ( EntityNotFoundException e )
+ {
+ throw new ArchivaRestServiceException( ErrorMessage.of( ErrorKeys.REPOSITORY_GROUP_NOT_EXIST, repositoryGroupId ), 404 );
}
catch ( RepositoryAdminException e )
{
- log.error( "Repository admin error: {}", e.getMessage( ), e );
- throw new ArchivaRestServiceException( ErrorMessage.of( ErrorKeys.REPOSITORY_ADMIN_ERROR, e.getMessage( ) ) );
+ return handleAdminException( e );
}
}
@Override
public Response deleteRepositoryGroup( String repositoryGroupId ) throws ArchivaRestServiceException
{
- return null;
+ if ( StringUtils.isEmpty( repositoryGroupId ) )
+ {
+ throw new ArchivaRestServiceException( ErrorMessage.of( ErrorKeys.REPOSITORY_GROUP_NOT_EXIST, "" ), 404 );
+ }
+ try
+ {
+ Boolean deleted = repositoryGroupAdmin.deleteRepositoryGroup( repositoryGroupId, getAuditInformation( ) );
+ if ( !deleted )
+ {
+ throw new ArchivaRestServiceException( ErrorMessage.of( ErrorKeys.REPOSITORY_GROUP_DELETE_FAILED ) );
+ }
+ return Response.ok( ).build( );
+ }
+ catch ( EntityNotFoundException e )
+ {
+ throw new ArchivaRestServiceException( ErrorMessage.of( ErrorKeys.REPOSITORY_GROUP_NOT_EXIST, repositoryGroupId ), 404 );
+ }
+ catch ( RepositoryAdminException e )
+ {
+ handleAdminException( e );
+ // cannot happen:
+ return null;
+ }
}
@Override
public RepositoryGroup addRepositoryToGroup( String repositoryGroupId, String repositoryId ) throws ArchivaRestServiceException
{
- return null;
+ if ( StringUtils.isEmpty( repositoryGroupId ) )
+ {
+ throw new ArchivaRestServiceException( ErrorMessage.of( ErrorKeys.REPOSITORY_GROUP_NOT_EXIST, "" ), 404 );
+ }
+ if ( StringUtils.isEmpty( repositoryId ) )
+ {
+ throw new ArchivaRestServiceException( ErrorMessage.of( ErrorKeys.REPOSITORY_NOT_EXIST, "" ), 404 );
+ }
+ try
+ {
+ repositoryGroupAdmin.addRepositoryToGroup( repositoryGroupId, repositoryId, getAuditInformation( ) );
+ return RepositoryGroup.of( repositoryGroupAdmin.getRepositoryGroup( repositoryGroupId ) );
+ }
+ catch ( EntityNotFoundException e )
+ {
+ return handleNotFoundException( repositoryGroupId, repositoryId, e );
+ }
+ catch ( EntityExistsException e )
+ {
+ // This is thrown, if the repositoryId is already assigned to the group. We ignore this for the PUT action (nothing to do).
+ try
+ {
+ return RepositoryGroup.of( repositoryGroupAdmin.getRepositoryGroup( repositoryGroupId ) );
+ }
+ catch ( RepositoryAdminException repositoryAdminException )
+ {
+ return handleAdminException( e );
+ }
+ }
+ catch ( RepositoryAdminException e )
+ {
+ return handleAdminException( e );
+ }
}
@Override
public RepositoryGroup deleteRepositoryFromGroup( String repositoryGroupId, String repositoryId ) throws org.apache.archiva.rest.api.services.v2.ArchivaRestServiceException
{
- return null;
+ if ( StringUtils.isEmpty( repositoryGroupId ) )
+ {
+ throw new ArchivaRestServiceException( ErrorMessage.of( ErrorKeys.REPOSITORY_GROUP_NOT_EXIST, "" ), 404 );
+ }
+ if ( StringUtils.isEmpty( repositoryId ) )
+ {
+ throw new ArchivaRestServiceException( ErrorMessage.of( ErrorKeys.REPOSITORY_NOT_EXIST, "" ), 404 );
+ }
+ try
+ {
+ repositoryGroupAdmin.deleteRepositoryFromGroup( repositoryGroupId, repositoryId, getAuditInformation( ) );
+ return RepositoryGroup.of( repositoryGroupAdmin.getRepositoryGroup( repositoryGroupId ) );
+ }
+ catch ( EntityNotFoundException e )
+ {
+ return handleNotFoundException( repositoryGroupId, repositoryId, e );
+ }
+ catch ( RepositoryAdminException e )
+ {
+ return handleAdminException( e );
+ }
+ }
+
+ protected RepositoryGroup handleNotFoundException( String repositoryGroupId, String repositoryId, EntityNotFoundException e ) throws ArchivaRestServiceException
+ {
+ if ( e.getParameters( ).length > 0 )
+ {
+ if ( repositoryGroupId.equals( e.getParameters( )[0] ) )
+ {
+ throw new ArchivaRestServiceException( ErrorMessage.of( ErrorKeys.REPOSITORY_GROUP_NOT_EXIST, repositoryGroupId ), 404 );
+ }
+ else if ( repositoryId.equals( e.getParameters( )[0] ) )
+ {
+ throw new ArchivaRestServiceException( ErrorMessage.of( ErrorKeys.REPOSITORY_NOT_EXIST, repositoryGroupId ), 404 );
+ }
+ }
+ log.warn( "Entity not found but neither group nor repo set in exception" );
+ throw new ArchivaRestServiceException( ErrorMessage.of( ErrorKeys.REPOSITORY_GROUP_NOT_EXIST, repositoryGroupId ), 404 );
}
+
+
}
diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/v2/DefaultSecurityConfigurationService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/v2/DefaultSecurityConfigurationService.java
index dd9a3f8b6..c4ab09ee2 100644
--- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/v2/DefaultSecurityConfigurationService.java
+++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/v2/DefaultSecurityConfigurationService.java
@@ -19,10 +19,8 @@ package org.apache.archiva.rest.services.v2;/*
import org.apache.archiva.admin.model.RepositoryAdminException;
import org.apache.archiva.admin.model.beans.RedbackRuntimeConfiguration;
import org.apache.archiva.admin.model.runtime.RedbackRuntimeConfigurationAdmin;
-import org.apache.archiva.components.cache.Cache;
import org.apache.archiva.components.rest.model.PagedResult;
import org.apache.archiva.components.rest.model.PropertyEntry;
-import org.apache.archiva.components.rest.util.PagingHelper;
import org.apache.archiva.components.rest.util.QueryHelper;
import org.apache.archiva.redback.authentication.Authenticator;
import org.apache.archiva.redback.common.ldap.connection.LdapConnection;
@@ -83,10 +81,9 @@ public class DefaultSecurityConfigurationService implements SecurityConfiguratio
private static final Logger log = LoggerFactory.getLogger( DefaultSecurityConfigurationService.class );
private static final String[] KNOWN_LDAP_CONTEXT_PROVIDERS = {"com.sun.jndi.ldap.LdapCtxFactory","com.ibm.jndi.LDAPCtxFactory"};
- private List<String> availableContextProviders = new ArrayList<>( );
+ private final List<String> availableContextProviders = new ArrayList<>( );
- private static final QueryHelper<PropertyEntry> PROP_QUERY_HELPER = new QueryHelper( new String[]{"key"} );
- private static final PagingHelper PROP_PAGING_HELPER = new PagingHelper( );
+ private static final QueryHelper<PropertyEntry> PROP_QUERY_HELPER = new QueryHelper<>( new String[]{"key"} );
static
{
@@ -124,10 +121,6 @@ public class DefaultSecurityConfigurationService implements SecurityConfiguratio
@Inject
private LdapUserMapper ldapUserMapper;
- @Inject
- @Named( value = "cache#users" )
- private Cache usersCache;
-
@PostConstruct
void init( )
@@ -215,23 +208,10 @@ public class DefaultSecurityConfigurationService implements SecurityConfiguratio
boolean userManagerChanged = !CollectionUtils.isEqualCollection( newConfiguration.getActiveUserManagers( ), conf.getUserManagerImpls( ) );
boolean rbacManagerChanged = !CollectionUtils.isEqualCollection( newConfiguration.getActiveRbacManagers( ), conf.getRbacManagerImpls( ) );
- boolean ldapConfigured = false;
- for ( String um : newConfiguration.getActiveUserManagers( ) )
- {
- if ( um.contains( "ldap" ) )
- {
- ldapConfigured = true;
- }
- }
+ boolean ldapConfigured = newConfiguration.getActiveUserManagers( ).stream( ).anyMatch( um -> um.contains( "ldap" ) );
if ( !ldapConfigured )
{
- for ( String rbm : newConfiguration.getActiveRbacManagers( ) )
- {
- if ( rbm.contains( "ldap" ) )
- {
- ldapConfigured = true;
- }
- }
+ ldapConfigured= newConfiguration.getActiveRbacManagers( ).stream( ).anyMatch( um -> um.contains( "ldap" ) );
}
updateConfig( newConfiguration, conf );
@@ -347,7 +327,7 @@ public class DefaultSecurityConfigurationService implements SecurityConfiguratio
.collect( Collectors.toList( ) );
return new PagedResult<>( totalCount, offset, limit, result );
} catch (ArithmeticException e) {
- log.error( "The total count of the result properties is higher than max integer value! {}" );
+ log.error( "The total count of the result properties is higher than max integer value!" );
throw new ArchivaRestServiceException( ErrorMessage.of( INVALID_RESULT_SET_ERROR ) );
}
catch ( RepositoryAdminException e )
@@ -461,7 +441,7 @@ public class DefaultSecurityConfigurationService implements SecurityConfiguratio
}
- static final Properties toProperties( Map<String, String> values )
+ static Properties toProperties( Map<String, String> values )
{
Properties result = new Properties( );
for ( Map.Entry<String, String> entry : values.entrySet( ) )
@@ -471,7 +451,7 @@ public class DefaultSecurityConfigurationService implements SecurityConfiguratio
return result;
}
- private static final boolean isContextFactoryAvailable(final String factoryClass)
+ private static boolean isContextFactoryAvailable( final String factoryClass)
{
try
{
@@ -635,7 +615,7 @@ public class DefaultSecurityConfigurationService implements SecurityConfiguratio
}
@Override
- public List<BeanInformation> getAvailableUserManagers( ) throws ArchivaRestServiceException
+ public List<BeanInformation> getAvailableUserManagers( )
{
Map<String, UserManager> beans = applicationContext.getBeansOfType( UserManager.class );
@@ -656,7 +636,7 @@ public class DefaultSecurityConfigurationService implements SecurityConfiguratio
}
@Override
- public List<BeanInformation> getAvailableRbacManagers( ) throws ArchivaRestServiceException
+ public List<BeanInformation> getAvailableRbacManagers( )
{
Map<String, RBACManager> beans = applicationContext.getBeansOfType( RBACManager.class );
diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/v2/ErrorKeys.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/v2/ErrorKeys.java
index 9f65161c7..a77d0e274 100644
--- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/v2/ErrorKeys.java
+++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/v2/ErrorKeys.java
@@ -28,6 +28,7 @@ public interface ErrorKeys
String PREFIX = "archiva.";
String REPOSITORY_GROUP_PREFIX = PREFIX + "repository_group.";
+ String REPOSITORY_PREFIX = PREFIX + "repository.";
String INVALID_RESULT_SET_ERROR = "archiva.result_set.invalid";
String REPOSITORY_ADMIN_ERROR = "archiva.repositoryadmin.error";
@@ -49,4 +50,7 @@ public interface ErrorKeys
String REPOSITORY_GROUP_ADD_FAILED = REPOSITORY_GROUP_PREFIX+"add.failed" ;
String REPOSITORY_GROUP_EXIST = REPOSITORY_GROUP_PREFIX+"exists";
+ String REPOSITORY_GROUP_DELETE_FAILED = REPOSITORY_GROUP_PREFIX + "delete.failed";
+ String REPOSITORY_NOT_EXIST = REPOSITORY_PREFIX + "notexist";
+
}
diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/resources/META-INF/spring-context.xml b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/resources/META-INF/spring-context.xml
index 910fb7e9a..46d4d3fc2 100644
--- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/resources/META-INF/spring-context.xml
+++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/resources/META-INF/spring-context.xml
@@ -117,6 +117,7 @@
<jaxrs:serviceBeans>
<ref bean="v2.defaultSecurityConfigurationService" />
+ <ref bean="v2.repositoryGroupService#rest" />
</jaxrs:serviceBeans>
<jaxrs:features>
diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/v2/NativeRepositoryGroupServiceTest.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/v2/NativeRepositoryGroupServiceTest.java
new file mode 100644
index 000000000..1e4409fba
--- /dev/null
+++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/v2/NativeRepositoryGroupServiceTest.java
@@ -0,0 +1,85 @@
+package org.apache.archiva.rest.services.v2;
+
+/*
+ * 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 io.restassured.response.Response;
+import org.apache.archiva.components.rest.model.PagedResult;
+import org.apache.archiva.components.rest.model.PropertyEntry;
+import org.apache.archiva.rest.api.model.v2.BeanInformation;
+import org.apache.archiva.rest.api.model.v2.CacheConfiguration;
+import org.apache.archiva.rest.api.model.v2.LdapConfiguration;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.MethodOrderer;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInstance;
+import org.junit.jupiter.api.TestMethodOrder;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import static io.restassured.RestAssured.given;
+import static io.restassured.http.ContentType.JSON;
+import static org.junit.jupiter.api.Assertions.*;
+
+/**
+ * @author Martin Stockhammer <martin_s@apache.org>
+ */
+@TestInstance( TestInstance.Lifecycle.PER_CLASS )
+@Tag( "rest-native" )
+@TestMethodOrder( MethodOrderer.Random.class )
+@DisplayName( "Native REST tests for V2 RepositoryGroupService" )
+public class NativeRepositoryGroupServiceTest extends AbstractNativeRestServices
+{
+ @Override
+ protected String getServicePath( )
+ {
+ return "/repository_groups";
+ }
+
+ @BeforeAll
+ void setup( ) throws Exception
+ {
+ super.setupNative( );
+ }
+
+ @AfterAll
+ void destroy( ) throws Exception
+ {
+ super.shutdownNative( );
+ }
+
+ @Test
+ void testGetConfiguration() {
+ String token = getAdminToken( );
+ Response response = given( ).spec( getRequestSpec( token ) ).contentType( JSON )
+ .when( )
+ .get( "" )
+ .prettyPeek()
+ .then( ).statusCode( 200 ).extract( ).response( );
+ assertNotNull( response );
+ }
+
+
+
+}