aboutsummaryrefslogtreecommitdiffstats
path: root/archiva-modules/archiva-web
diff options
context:
space:
mode:
authorMartin Stockhammer <martin_s@apache.org>2021-06-01 22:46:51 +0200
committerMartin Stockhammer <martin_s@apache.org>2021-06-01 22:46:51 +0200
commit0ce53483a85b6b7a3a14417434edf56934b474ba (patch)
tree148acd378bdb456482396cb46c315024840fd807 /archiva-modules/archiva-web
parentca18ec34d706efa6fdc6ecde6277ba6004e8eb4e (diff)
downloadarchiva-0ce53483a85b6b7a3a14417434edf56934b474ba.tar.gz
archiva-0ce53483a85b6b7a3a14417434edf56934b474ba.zip
Centralizing repository group handling. First part.
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.java92
-rw-r--r--archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/v2/maven/MavenManagedRepositoryService.java (renamed from archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/v2/MavenManagedRepositoryService.java)6
-rw-r--r--archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java5
-rw-r--r--archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/utils/AuditHelper.java40
-rw-r--r--archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/v2/DefaultMavenManagedRepositoryService.java25
-rw-r--r--archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/v2/DefaultRepositoryGroupService.java28
-rw-r--r--archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/resources/META-INF/spring-context.xml8
-rw-r--r--archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/v2/AbstractNativeRestServices.java16
-rw-r--r--archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/v2/NativeMavenManagedRepositoryServiceTest.java97
-rw-r--r--archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/resources/META-INF/spring-context-test.xml2
-rw-r--r--archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/AbstractRepositoryServletTestCase.java4
-rw-r--r--archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/ArchivaDavResourceFactoryTest.java10
-rw-r--r--archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/RepositoryServletSecurityTest.java5
13 files changed, 244 insertions, 94 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 8a5b6eaeb..a95c68f95 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
@@ -55,20 +55,20 @@ import static org.apache.archiva.rest.api.services.v2.RestConfiguration.DEFAULT_
* @since 3.0
*/
@Path( "/repository_groups" )
-@Schema( name="RepositoryGroups", description = "Managing of repository groups or virtual repositories")
+@Schema( name = "RepositoryGroups", description = "Managing of repository groups or virtual repositories" )
public interface RepositoryGroupService
{
@Path( "" )
@GET
- @Produces( { APPLICATION_JSON } )
+ @Produces( {APPLICATION_JSON} )
@RedbackAuthorization( permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION )
@Operation( summary = "Returns all repository group entries.",
parameters = {
- @Parameter(name = "q", description = "Search term"),
- @Parameter(name = "offset", description = "The offset of the first element returned"),
- @Parameter(name = "limit", description = "Maximum number of items to return in the response"),
- @Parameter(name = "orderBy", description = "List of attribute used for sorting (key, value)"),
- @Parameter(name = "order", description = "The sort order. Either ascending (asc) or descending (desc)")
+ @Parameter( name = "q", description = "Search term" ),
+ @Parameter( name = "offset", description = "The offset of the first element returned" ),
+ @Parameter( name = "limit", description = "Maximum number of items to return in the response" ),
+ @Parameter( name = "orderBy", description = "List of attribute used for sorting (key, value)" ),
+ @Parameter( name = "order", description = "The sort order. Either ascending (asc) or descending (desc)" )
},
security = {
@SecurityRequirement(
@@ -78,22 +78,22 @@ public interface RepositoryGroupService
responses = {
@ApiResponse( responseCode = "200",
description = "If the list could be returned",
- content = @Content(mediaType = APPLICATION_JSON, schema = @Schema(implementation = PagedResult.class))
+ content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = PagedResult.class ) )
),
@ApiResponse( responseCode = "403", description = "Authenticated user is not permitted to gather the information",
- content = @Content(mediaType = APPLICATION_JSON, schema = @Schema(implementation = ArchivaRestError.class )) )
+ content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) )
}
)
- 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( "id" ) List<String> orderBy,
- @QueryParam("order") @DefaultValue( "asc" ) String order)
+ 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( "id" ) List<String> orderBy,
+ @QueryParam( "order" ) @DefaultValue( "asc" ) String order )
throws ArchivaRestServiceException;
@Path( "{repositoryGroupId}" )
@GET
- @Produces( { APPLICATION_JSON } )
+ @Produces( {APPLICATION_JSON} )
@RedbackAuthorization( permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION )
@Operation( summary = "Returns a single repository group configuration.",
security = {
@@ -104,12 +104,12 @@ public interface RepositoryGroupService
responses = {
@ApiResponse( responseCode = "200",
description = "If the configuration is returned",
- content = @Content(mediaType = APPLICATION_JSON, schema = @Schema(implementation = RepositoryGroup.class))
+ content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = RepositoryGroup.class ) )
),
@ApiResponse( responseCode = "403", description = "Authenticated user is not permitted to gather the information",
- content = @Content(mediaType = APPLICATION_JSON, schema = @Schema(implementation = ArchivaRestError.class )) ),
+ content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) ),
@ApiResponse( responseCode = "404", description = "The repository group with the given id does not exist",
- content = @Content(mediaType = APPLICATION_JSON, schema = @Schema(implementation = ArchivaRestError.class )) )
+ content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) )
}
)
RepositoryGroup getRepositoryGroup( @PathParam( "repositoryGroupId" ) String repositoryGroupId )
@@ -117,14 +117,14 @@ public interface RepositoryGroupService
@Path( "" )
@POST
- @Consumes( { APPLICATION_JSON } )
- @Produces( { APPLICATION_JSON } )
+ @Consumes( {APPLICATION_JSON} )
+ @Produces( {APPLICATION_JSON} )
@RedbackAuthorization( permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION )
@Operation( summary = "Creates a new group entry.",
requestBody =
- @RequestBody(required = true, description = "The configuration of the repository group.",
- content = @Content(mediaType = APPLICATION_JSON, schema = @Schema(implementation = RepositoryGroup.class))
- )
+ @RequestBody( required = true, description = "The configuration of the repository group.",
+ content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = RepositoryGroup.class ) )
+ )
,
security = {
@SecurityRequirement(
@@ -134,17 +134,17 @@ public interface RepositoryGroupService
responses = {
@ApiResponse( responseCode = "201",
description = "If the list could be returned",
- content = @Content(mediaType = APPLICATION_JSON, schema = @Schema(implementation = RepositoryGroup.class))
+ content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = RepositoryGroup.class ) )
),
@ApiResponse( responseCode = "303", description = "The repository group exists already",
headers = {
- @Header( name="Location", description = "The URL of existing group", schema = @Schema(type="string"))
+ @Header( name = "Location", description = "The URL of existing group", schema = @Schema( type = "string" ) )
}
),
@ApiResponse( responseCode = "403", description = "Authenticated user is not permitted to gather the information",
- content = @Content(mediaType = APPLICATION_JSON, schema = @Schema(implementation = ArchivaRestError.class )) ),
+ content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) ),
@ApiResponse( responseCode = "422", description = "The body data is not valid",
- content = @Content(mediaType = APPLICATION_JSON, schema = @Schema(implementation = ArchivaRestError.class )) )
+ content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) )
}
)
RepositoryGroup addRepositoryGroup( RepositoryGroup repositoryGroup )
@@ -152,13 +152,13 @@ public interface RepositoryGroupService
@Path( "{repositoryGroupId}" )
@PUT
- @Consumes( { APPLICATION_JSON } )
- @Produces( { APPLICATION_JSON } )
+ @Consumes( {APPLICATION_JSON} )
+ @Produces( {APPLICATION_JSON} )
@RedbackAuthorization( permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION )
@Operation( summary = "Returns all repository group entries.",
requestBody =
- @RequestBody(required = true, description = "The configuration of the repository group.",
- content = @Content(mediaType = APPLICATION_JSON, schema = @Schema(implementation = RepositoryGroup.class))
+ @RequestBody( required = true, description = "The configuration of the repository group.",
+ content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = RepositoryGroup.class ) )
)
,
security = {
@@ -169,14 +169,14 @@ public interface RepositoryGroupService
responses = {
@ApiResponse( responseCode = "200",
description = "If the group is returned",
- content = @Content(mediaType = APPLICATION_JSON, schema = @Schema(implementation = RepositoryGroup.class))
+ content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = RepositoryGroup.class ) )
),
@ApiResponse( responseCode = "403", description = "Authenticated user is not permitted to gather the information",
- content = @Content(mediaType = APPLICATION_JSON, schema = @Schema(implementation = ArchivaRestError.class )) ),
+ content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) ),
@ApiResponse( responseCode = "404", description = "The group with the given id does not exist",
- content = @Content(mediaType = APPLICATION_JSON, schema = @Schema(implementation = ArchivaRestError.class )) ),
+ content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) ),
@ApiResponse( responseCode = "422", description = "The body data is not valid",
- content = @Content(mediaType = APPLICATION_JSON, schema = @Schema(implementation = ArchivaRestError.class )) )
+ content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) )
}
)
RepositoryGroup updateRepositoryGroup( @PathParam( "repositoryGroupId" ) String groupId, RepositoryGroup repositoryGroup )
@@ -184,7 +184,7 @@ public interface RepositoryGroupService
@Path( "{repositoryGroupId}" )
@DELETE
- @Produces( { APPLICATION_JSON } )
+ @Produces( {APPLICATION_JSON} )
@RedbackAuthorization( permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION )
@Operation( summary = "Deletes the repository group entry with the given id.",
security = {
@@ -197,9 +197,9 @@ public interface RepositoryGroupService
description = "If the group was deleted"
),
@ApiResponse( responseCode = "403", description = "Authenticated user is not permitted to delete the group",
- content = @Content(mediaType = APPLICATION_JSON, schema = @Schema(implementation = ArchivaRestError.class )) ),
+ content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) ),
@ApiResponse( responseCode = "404", description = "The group with the given id does not exist",
- content = @Content(mediaType = APPLICATION_JSON, schema = @Schema(implementation = ArchivaRestError.class )) ),
+ content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) ),
}
)
Response deleteRepositoryGroup( @PathParam( "repositoryGroupId" ) String repositoryGroupId )
@@ -207,7 +207,7 @@ public interface RepositoryGroupService
@Path( "{repositoryGroupId}/repositories/{repositoryId}" )
@PUT
- @Produces( { APPLICATION_JSON } )
+ @Produces( {APPLICATION_JSON} )
@RedbackAuthorization( permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION )
@Operation( summary = "Adds the repository with the given id to the repository group.",
security = {
@@ -220,18 +220,18 @@ public interface RepositoryGroupService
description = "If the repository was added or if it was already part of the group"
),
@ApiResponse( responseCode = "403", description = "Authenticated user is not permitted to delete the group",
- content = @Content(mediaType = APPLICATION_JSON, schema = @Schema(implementation = ArchivaRestError.class )) ),
+ content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) ),
@ApiResponse( responseCode = "404", description = "The group with the given id does not exist",
- content = @Content(mediaType = APPLICATION_JSON, schema = @Schema(implementation = ArchivaRestError.class )) ),
+ content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) ),
}
)
RepositoryGroup addRepositoryToGroup( @PathParam( "repositoryGroupId" ) String repositoryGroupId,
- @PathParam( "repositoryId" ) String repositoryId )
+ @PathParam( "repositoryId" ) String repositoryId )
throws ArchivaRestServiceException;
@Path( "{repositoryGroupId}/repositories/{repositoryId}" )
@DELETE
- @Produces( { APPLICATION_JSON } )
+ @Produces( {APPLICATION_JSON} )
@RedbackAuthorization( permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION )
@Operation( summary = "Removes the repository with the given id from the repository group.",
security = {
@@ -244,13 +244,13 @@ public interface RepositoryGroupService
description = "If the repository was removed."
),
@ApiResponse( responseCode = "403", description = "Authenticated user is not permitted to delete the group",
- content = @Content(mediaType = APPLICATION_JSON, schema = @Schema(implementation = ArchivaRestError.class )) ),
+ content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) ),
@ApiResponse( responseCode = "404", description = "The group with the given id does not exist, or the repository was not part of the group.",
- content = @Content(mediaType = APPLICATION_JSON, schema = @Schema(implementation = ArchivaRestError.class )) ),
+ content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) ),
}
)
RepositoryGroup deleteRepositoryFromGroup( @PathParam( "repositoryGroupId" ) String repositoryGroupId,
- @PathParam( "repositoryId" ) String repositoryId )
+ @PathParam( "repositoryId" ) String repositoryId )
throws ArchivaRestServiceException;
diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/v2/MavenManagedRepositoryService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/v2/maven/MavenManagedRepositoryService.java
index 5aff95ef6..5e63682ee 100644
--- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/v2/MavenManagedRepositoryService.java
+++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/v2/maven/MavenManagedRepositoryService.java
@@ -1,4 +1,4 @@
-package org.apache.archiva.rest.api.services.v2;
+package org.apache.archiva.rest.api.services.v2.maven;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -31,6 +31,8 @@ import org.apache.archiva.redback.authorization.RedbackAuthorization;
import org.apache.archiva.rest.api.model.v2.FileInfo;
import org.apache.archiva.rest.api.model.v2.MavenManagedRepository;
import org.apache.archiva.rest.api.model.v2.MavenManagedRepositoryUpdate;
+import org.apache.archiva.rest.api.services.v2.ArchivaRestError;
+import org.apache.archiva.rest.api.services.v2.ArchivaRestServiceException;
import org.apache.archiva.security.common.ArchivaRoleConstants;
import javax.ws.rs.Consumes;
@@ -51,6 +53,8 @@ import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
import static org.apache.archiva.rest.api.services.v2.RestConfiguration.DEFAULT_PAGE_LIMIT;
/**
+ * Service interface for managing managed maven repositories
+ *
* @author Martin Stockhammer <martin_s@apache.org>
* @since 3.0
*/
diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java
index f99b06db7..06c2e4ee6 100644
--- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java
+++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java
@@ -47,6 +47,7 @@ import org.apache.archiva.redback.system.SecuritySystem;
import org.apache.archiva.redback.users.User;
import org.apache.archiva.redback.users.UserManagerException;
import org.apache.archiva.redback.users.UserNotFoundException;
+import org.apache.archiva.repository.base.RepositoryGroupHandler;
import org.apache.archiva.repository.content.BaseRepositoryContentLayout;
import org.apache.archiva.repository.content.ContentNotFoundException;
import org.apache.archiva.repository.content.LayoutException;
@@ -128,6 +129,10 @@ public class DefaultRepositoriesService
@Inject
private RepositoryRegistry repositoryRegistry;
+ @SuppressWarnings( "unused" )
+ @Inject
+ private RepositoryGroupHandler repositoryGroupHandler;
+
@Inject
private SecuritySystem securitySystem;
diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/utils/AuditHelper.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/utils/AuditHelper.java
new file mode 100644
index 000000000..b6b4acae6
--- /dev/null
+++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/utils/AuditHelper.java
@@ -0,0 +1,40 @@
+package org.apache.archiva.rest.services.utils;
+/*
+ * 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.admin.model.AuditInformation;
+import org.apache.archiva.redback.rest.services.RedbackAuthenticationThreadLocal;
+import org.apache.archiva.redback.rest.services.RedbackRequestInformation;
+import org.apache.archiva.redback.users.User;
+
+/**
+ * @author Martin Stockhammer <martin_s@apache.org>
+ */
+public class AuditHelper
+{
+ private static final AuditInformation NULL_RESULT = new AuditInformation( null, null );
+ public static AuditInformation getAuditData() {
+ RedbackRequestInformation redbackRequestInformation = RedbackAuthenticationThreadLocal.get( );
+ if (redbackRequestInformation==null) {
+ return NULL_RESULT;
+ } else
+ {
+ return new AuditInformation( redbackRequestInformation.getUser( ), redbackRequestInformation.getRemoteAddr( ) );
+ }
+ }
+}
diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/v2/DefaultMavenManagedRepositoryService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/v2/DefaultMavenManagedRepositoryService.java
index 6fd85d5cf..7b776a7f7 100644
--- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/v2/DefaultMavenManagedRepositoryService.java
+++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/v2/DefaultMavenManagedRepositoryService.java
@@ -35,35 +35,28 @@ import org.apache.archiva.redback.users.UserNotFoundException;
import org.apache.archiva.repository.ManagedRepository;
import org.apache.archiva.repository.ReleaseScheme;
import org.apache.archiva.repository.Repository;
-import org.apache.archiva.repository.RepositoryException;
import org.apache.archiva.repository.RepositoryRegistry;
import org.apache.archiva.repository.RepositoryType;
import org.apache.archiva.repository.content.ContentItem;
import org.apache.archiva.repository.content.LayoutException;
-import org.apache.archiva.repository.storage.fs.FilesystemStorage;
import org.apache.archiva.repository.storage.fs.FsStorageUtil;
-import org.apache.archiva.repository.storage.util.StorageUtil;
-import org.apache.archiva.rest.api.model.v2.Artifact;
import org.apache.archiva.rest.api.model.v2.FileInfo;
import org.apache.archiva.rest.api.model.v2.MavenManagedRepository;
import org.apache.archiva.rest.api.model.v2.MavenManagedRepositoryUpdate;
import org.apache.archiva.rest.api.services.v2.ArchivaRestServiceException;
import org.apache.archiva.rest.api.services.v2.ErrorKeys;
import org.apache.archiva.rest.api.services.v2.ErrorMessage;
-import org.apache.archiva.rest.api.services.v2.MavenManagedRepositoryService;
+import org.apache.archiva.rest.api.services.v2.maven.MavenManagedRepositoryService;
import org.apache.archiva.security.common.ArchivaRoleConstants;
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;
-import javax.ws.rs.PathParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
-import java.io.File;
import java.io.IOException;
import java.util.Collection;
import java.util.Comparator;
@@ -103,7 +96,9 @@ public class DefaultMavenManagedRepositoryService implements MavenManagedReposit
private RepositoryRegistry repositoryRegistry;
private SecuritySystem securitySystem;
- public DefaultMavenManagedRepositoryService( SecuritySystem securitySystem, RepositoryRegistry repositoryRegistry, ManagedRepositoryAdmin managedRepositoryAdmin )
+ public DefaultMavenManagedRepositoryService( SecuritySystem securitySystem,
+ RepositoryRegistry repositoryRegistry,
+ ManagedRepositoryAdmin managedRepositoryAdmin )
{
this.securitySystem = securitySystem;
this.repositoryRegistry = repositoryRegistry;
@@ -113,8 +108,16 @@ public class DefaultMavenManagedRepositoryService implements MavenManagedReposit
protected AuditInformation getAuditInformation( )
{
RedbackRequestInformation redbackRequestInformation = RedbackAuthenticationThreadLocal.get( );
- User user = redbackRequestInformation == null ? null : redbackRequestInformation.getUser( );
- String remoteAddr = redbackRequestInformation == null ? null : redbackRequestInformation.getRemoteAddr( );
+ User user;
+ String remoteAddr;
+ if (redbackRequestInformation==null) {
+ user = null;
+ remoteAddr = null;
+ } else
+ {
+ user = redbackRequestInformation.getUser( );
+ remoteAddr = redbackRequestInformation.getRemoteAddr( );
+ }
return new AuditInformation( user, remoteAddr );
}
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 9290873d6..44ce638ac 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
@@ -34,16 +34,12 @@ package org.apache.archiva.rest.services.v2;/*
* under the License.
*/
-import org.apache.archiva.admin.model.AuditInformation;
import org.apache.archiva.admin.model.EntityExistsException;
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.QueryHelper;
-import org.apache.archiva.redback.rest.services.RedbackAuthenticationThreadLocal;
-import org.apache.archiva.redback.rest.services.RedbackRequestInformation;
-import org.apache.archiva.redback.users.User;
import org.apache.archiva.rest.api.model.v2.RepositoryGroup;
import org.apache.archiva.rest.api.services.v2.ArchivaRestServiceException;
import org.apache.archiva.rest.api.services.v2.ErrorKeys;
@@ -54,7 +50,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
-import javax.inject.Inject;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;
@@ -65,6 +60,8 @@ import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;
+import static org.apache.archiva.rest.services.utils.AuditHelper.getAuditData;
+
/**
* REST V2 Implementation for repository groups.
*
@@ -81,8 +78,7 @@ public class DefaultRepositoryGroupService implements RepositoryGroupService
@Context
UriInfo uriInfo;
- @Inject
- private RepositoryGroupAdmin repositoryGroupAdmin;
+ final private RepositoryGroupAdmin repositoryGroupAdmin;
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"} );
@@ -93,12 +89,8 @@ public class DefaultRepositoryGroupService implements RepositoryGroupService
}
- protected AuditInformation getAuditInformation( )
- {
- RedbackRequestInformation redbackRequestInformation = RedbackAuthenticationThreadLocal.get( );
- User user = redbackRequestInformation == null ? null : redbackRequestInformation.getUser( );
- String remoteAddr = redbackRequestInformation == null ? null : redbackRequestInformation.getRemoteAddr( );
- return new AuditInformation( user, remoteAddr );
+ public DefaultRepositoryGroupService(RepositoryGroupAdmin repositoryGroupAdmin) {
+ this.repositoryGroupAdmin = repositoryGroupAdmin;
}
@Override
@@ -166,7 +158,7 @@ public class DefaultRepositoryGroupService implements RepositoryGroupService
{
try
{
- Boolean result = repositoryGroupAdmin.addRepositoryGroup( toModel( repositoryGroup ), getAuditInformation( ) );
+ Boolean result = repositoryGroupAdmin.addRepositoryGroup( toModel( repositoryGroup ), getAuditData() );
if ( result )
{
org.apache.archiva.admin.model.beans.RepositoryGroup newGroup = repositoryGroupAdmin.getRepositoryGroup( repositoryGroup.getId( ) );
@@ -243,7 +235,7 @@ public class DefaultRepositoryGroupService implements RepositoryGroupService
{
updateGroup.setMergedIndexTtl( originGroup.getMergedIndexTtl( ) );
}
- repositoryGroupAdmin.updateRepositoryGroup( updateGroup, getAuditInformation( ) );
+ repositoryGroupAdmin.updateRepositoryGroup( updateGroup, getAuditData( ) );
return RepositoryGroup.of( repositoryGroupAdmin.getRepositoryGroup( repositoryGroupId ) );
}
catch ( EntityNotFoundException e )
@@ -265,7 +257,7 @@ public class DefaultRepositoryGroupService implements RepositoryGroupService
}
try
{
- Boolean deleted = repositoryGroupAdmin.deleteRepositoryGroup( repositoryGroupId, getAuditInformation( ) );
+ Boolean deleted = repositoryGroupAdmin.deleteRepositoryGroup( repositoryGroupId, getAuditData( ) );
if ( !deleted )
{
throw new ArchivaRestServiceException( ErrorMessage.of( ErrorKeys.REPOSITORY_GROUP_DELETE_FAILED ) );
@@ -297,7 +289,7 @@ public class DefaultRepositoryGroupService implements RepositoryGroupService
}
try
{
- repositoryGroupAdmin.addRepositoryToGroup( repositoryGroupId, repositoryId, getAuditInformation( ) );
+ repositoryGroupAdmin.addRepositoryToGroup( repositoryGroupId, repositoryId, getAuditData( ) );
return RepositoryGroup.of( repositoryGroupAdmin.getRepositoryGroup( repositoryGroupId ) );
}
catch ( EntityNotFoundException e )
@@ -335,7 +327,7 @@ public class DefaultRepositoryGroupService implements RepositoryGroupService
}
try
{
- repositoryGroupAdmin.deleteRepositoryFromGroup( repositoryGroupId, repositoryId, getAuditInformation( ) );
+ repositoryGroupAdmin.deleteRepositoryFromGroup( repositoryGroupId, repositoryId, getAuditData( ) );
return RepositoryGroup.of( repositoryGroupAdmin.getRepositoryGroup( repositoryGroupId ) );
}
catch ( EntityNotFoundException e )
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 53b445abb..46dbc499a 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
@@ -29,11 +29,8 @@
http://cxf.apache.org/jaxrs
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-extension-jaxrs-binding.xml"/>
- -->
- <import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>
+ <import resource="classpath*:META-INF/cxf/cxf.xml"/>
+ <import resource="classpath*:META-INF/cxf/cxf-servlet.xml"/>
<context:annotation-config/>
<context:component-scan
@@ -119,6 +116,7 @@
<ref bean="v2.defaultSecurityConfigurationService" />
<ref bean="v2.repositoryGroupService#rest" />
<ref bean="v2.repositoryService#rest"/>
+ <ref bean="v2.managedMavenRepositoryService#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/AbstractNativeRestServices.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/v2/AbstractNativeRestServices.java
index 06d6f7429..18093fa21 100644
--- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/v2/AbstractNativeRestServices.java
+++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/v2/AbstractNativeRestServices.java
@@ -378,7 +378,7 @@ public abstract class AbstractNativeRestServices
}
else
{
- log.error( "Serer is not in STARTED state!" );
+ log.error( "Server is not in STARTED state!" );
}
}
@@ -410,15 +410,11 @@ public abstract class AbstractNativeRestServices
this.requestSpec = getRequestSpecBuilder( ).build( );
RestAssured.basePath = basePath;
RestAssured.config = RestAssuredConfig.config().objectMapperConfig(new ObjectMapperConfig().jackson2ObjectMapperFactory(
- new Jackson2ObjectMapperFactory() {
- @Override
- public ObjectMapper create( Type cls, String charset) {
- ObjectMapper om = new ObjectMapper().findAndRegisterModules();
- om.configure( DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
- om.setPropertyNamingStrategy( PropertyNamingStrategy.SNAKE_CASE );
- return om;
- }
-
+ ( cls, charset ) -> {
+ ObjectMapper om = new ObjectMapper().findAndRegisterModules();
+ om.configure( DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+ om.setPropertyNamingStrategy( PropertyNamingStrategy.SNAKE_CASE );
+ return om;
}
));
}
diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/v2/NativeMavenManagedRepositoryServiceTest.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/v2/NativeMavenManagedRepositoryServiceTest.java
new file mode 100644
index 000000000..f7d137f56
--- /dev/null
+++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/v2/NativeMavenManagedRepositoryServiceTest.java
@@ -0,0 +1,97 @@
+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.path.json.JsonPath;
+import io.restassured.response.Response;
+import io.restassured.response.ResponseBody;
+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.apache.archiva.rest.api.model.v2.MavenManagedRepository;
+import org.apache.archiva.rest.api.services.v2.RestConfiguration;
+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.Order;
+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.OrderAnnotation.class )
+@DisplayName( "Native REST tests for V2 ManagedRepositoryService" )
+public class NativeMavenManagedRepositoryServiceTest extends AbstractNativeRestServices
+{
+ @Override
+ protected String getServicePath( )
+ {
+ return "/repositories/maven/managed";
+ }
+
+ @BeforeAll
+ void setup( ) throws Exception
+ {
+ super.setupNative( );
+ }
+
+ @AfterAll
+ void destroy( ) throws Exception
+ {
+ super.shutdownNative( );
+ }
+
+ @Test
+ @Order( 1 )
+ void testGetRepositories( )
+ {
+ String token = getAdminToken( );
+ Response response = given( ).spec( getRequestSpec( token ) ).contentType( JSON )
+ .when( )
+ .get( "" )
+ .then( ).statusCode( 200 ).extract( ).response( );
+ JsonPath json = response.getBody( ).jsonPath( );
+ assertEquals( 2, json.getInt( "pagination.total_count" ) );
+ assertEquals( 0, json.getInt( "pagination.offset" ) );
+ assertEquals( Integer.valueOf( RestConfiguration.DEFAULT_PAGE_LIMIT ), json.getInt( "pagination.limit" ) );
+ List<MavenManagedRepository> repositories = json.getList( "data", MavenManagedRepository.class );
+ assertEquals( "internal", repositories.get( 0 ).getId( ) );
+ assertEquals( "snapshots", repositories.get( 1 ).getId( ) );
+ }
+
+
+
+}
diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/resources/META-INF/spring-context-test.xml b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/resources/META-INF/spring-context-test.xml
index bec39deeb..19eba026f 100644
--- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/resources/META-INF/spring-context-test.xml
+++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/resources/META-INF/spring-context-test.xml
@@ -32,7 +32,7 @@
<context:annotation-config/>
<context:component-scan
- base-package="org.apache.archiva.redback.keys,org.apache.archiva.rest.services.utils,org.apache.archiva.repository.content.maven2"/>
+ base-package="org.apache.archiva.redback.keys,org.apache.archiva.rest.services.utils,org.apache.archiva.repository.maven.content"/>
<bean name="scheduler" class="org.apache.archiva.components.scheduler.DefaultScheduler">
<property name="properties">
diff --git a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/AbstractRepositoryServletTestCase.java b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/AbstractRepositoryServletTestCase.java
index 56b8445da..e81e0692b 100644
--- a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/AbstractRepositoryServletTestCase.java
+++ b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/AbstractRepositoryServletTestCase.java
@@ -30,6 +30,7 @@ import org.apache.archiva.indexer.ArchivaIndexingContext;
import org.apache.archiva.repository.base.ArchivaRepositoryRegistry;
import org.apache.archiva.repository.ManagedRepository;
import org.apache.archiva.repository.RepositoryType;
+import org.apache.archiva.repository.base.RepositoryGroupHandler;
import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
import org.apache.archiva.webdav.httpunit.MkColMethodWebRequest;
import org.apache.commons.io.FileUtils;
@@ -99,6 +100,9 @@ public abstract class AbstractRepositoryServletTestCase
@Inject
protected ApplicationContext applicationContext;
+ @SuppressWarnings( "unused" )
+ @Inject
+ RepositoryGroupHandler repositoryGroupHandler;
@Inject
ArchivaRepositoryRegistry repositoryRegistry;
diff --git a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/ArchivaDavResourceFactoryTest.java b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/ArchivaDavResourceFactoryTest.java
index 450a3b92e..e2b259c5c 100644
--- a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/ArchivaDavResourceFactoryTest.java
+++ b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/ArchivaDavResourceFactoryTest.java
@@ -34,6 +34,7 @@ import org.apache.archiva.configuration.FileTypes;
import org.apache.archiva.configuration.RepositoryGroupConfiguration;
import org.apache.archiva.metadata.repository.storage.RepositoryPathTranslator;
import org.apache.archiva.repository.ManagedRepositoryContent;
+import org.apache.archiva.repository.base.RepositoryGroupHandler;
import org.apache.archiva.repository.maven.content.MavenContentHelper;
import org.apache.archiva.repository.maven.metadata.storage.ArtifactMappingProvider;
import org.apache.archiva.proxy.ProxyRegistry;
@@ -158,6 +159,10 @@ public class ArchivaDavResourceFactoryTest
@Inject
FileTypes fileTypes;
+ @SuppressWarnings( "unused" )
+ @Inject
+ RepositoryGroupHandler repositoryGroupHandler;
+
public Path getProjectBase() {
if (this.projectBase.get()==null) {
String pathVal = System.getProperty("mvn.project.base.dir");
@@ -194,8 +199,9 @@ public class ArchivaDavResourceFactoryTest
expect (archivaConfiguration.getDefaultLocale()).andReturn( Locale.getDefault() ).anyTimes();
archivaConfiguration.addListener( EasyMock.anyObject( ) );
expectLastCall().times(0, 4);
- archivaConfiguration.save( config );
-
+ archivaConfiguration.save( eq(config));
+ expectLastCall().times( 0, 5 );
+ archivaConfiguration.save( eq(config), EasyMock.anyString());
expectLastCall().times( 0, 5 );
archivaConfigurationControl.replay();
diff --git a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/RepositoryServletSecurityTest.java b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/RepositoryServletSecurityTest.java
index 0385c25e7..b8310c740 100644
--- a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/RepositoryServletSecurityTest.java
+++ b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/RepositoryServletSecurityTest.java
@@ -35,6 +35,7 @@ import org.apache.archiva.redback.users.User;
import org.apache.archiva.redback.users.memory.SimpleUser;
import org.apache.archiva.repository.RepositoryRegistry;
import org.apache.archiva.metadata.audit.TestAuditListener;
+import org.apache.archiva.repository.base.RepositoryGroupHandler;
import org.apache.archiva.security.ServletAuthenticator;
import org.apache.archiva.security.common.ArchivaRoleConstants;
import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
@@ -91,6 +92,10 @@ public class RepositoryServletSecurityTest
@Inject
protected RepositoryRegistry repositoryRegistry;
+ @SuppressWarnings( "unused" )
+ @Inject
+ RepositoryGroupHandler repositoryGroupHandler;
+
private DavSessionProvider davSessionProvider;
private IMocksControl servletAuthControl;