From 684505391aa95224e445a9796db86422abe89357 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Fri, 16 Mar 2012 14:02:29 +0000 Subject: [PATCH] enhance rest method to return ManagedRepository rather than simply string git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1301525 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/archiva/rest/api/services/BrowseService.java | 3 ++- .../apache/archiva/rest/services/AbstractRestService.java | 2 +- .../archiva/rest/services/DefaultBrowseService.java | 5 +++-- .../apache/archiva/security/DefaultUserRepositories.java | 8 +++++++- .../org/apache/archiva/security/UserRepositories.java | 3 +-- .../org/apache/archiva/security/UserRepositoriesStub.java | 2 +- 6 files changed, 15 insertions(+), 8 deletions(-) diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/BrowseService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/BrowseService.java index 15ac8ebf1..77e251a11 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/BrowseService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/BrowseService.java @@ -18,6 +18,7 @@ package org.apache.archiva.rest.api.services; * under the License. */ +import org.apache.archiva.admin.model.beans.ManagedRepository; import org.apache.archiva.metadata.model.ProjectVersionMetadata; import org.apache.archiva.rest.api.model.BrowseResult; import org.apache.archiva.rest.api.model.VersionsList; @@ -70,6 +71,6 @@ public interface BrowseService @GET @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } ) @RedbackAuthorization( noPermission = true, noRestriction = true ) - List getUserRepositories() + List getUserRepositories() throws ArchivaRestServiceException; } diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/AbstractRestService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/AbstractRestService.java index 3cf1545b7..0d8a14240 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/AbstractRestService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/AbstractRestService.java @@ -59,7 +59,7 @@ public abstract class AbstractRestService private List auditListeners = new ArrayList(); @Inject - private UserRepositories userRepositories; + protected UserRepositories userRepositories; @Inject diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultBrowseService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultBrowseService.java index 580b91f7a..11ed250ac 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultBrowseService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultBrowseService.java @@ -18,6 +18,7 @@ package org.apache.archiva.rest.services; * under the License. */ +import org.apache.archiva.admin.model.beans.ManagedRepository; import org.apache.archiva.common.utils.VersionComparator; import org.apache.archiva.metadata.model.ProjectVersionMetadata; import org.apache.archiva.metadata.repository.MetadataResolutionException; @@ -350,10 +351,10 @@ public class DefaultBrowseService } } - public List getUserRepositories() + public List getUserRepositories() throws ArchivaRestServiceException { - return getObservableRepos(); + return userRepositories.getAccessibleRepositories( ) } //--------------------------- diff --git a/archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/archiva/security/DefaultUserRepositories.java b/archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/archiva/security/DefaultUserRepositories.java index 7f27d7cc0..cfd6da5c8 100644 --- a/archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/archiva/security/DefaultUserRepositories.java +++ b/archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/archiva/security/DefaultUserRepositories.java @@ -92,7 +92,13 @@ public class DefaultUserRepositories return repoIds; } - public List getAccessibleRepositories( String principal, String operation ) + public List getAccessibleRepositories( String principal ) + throws ArchivaSecurityException, AccessDeniedException, PrincipalNotFoundException + { + return getAccessibleRepositories( principal, ArchivaRoleConstants.OPERATION_REPOSITORY_ACCESS ); + } + + private List getAccessibleRepositories( String principal, String operation ) throws ArchivaSecurityException, AccessDeniedException, PrincipalNotFoundException { SecuritySession securitySession = createSession( principal ); diff --git a/archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/archiva/security/UserRepositories.java b/archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/archiva/security/UserRepositories.java index 18a46855b..d116f4d32 100644 --- a/archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/archiva/security/UserRepositories.java +++ b/archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/archiva/security/UserRepositories.java @@ -90,14 +90,13 @@ public interface UserRepositories /** * * @param principal - * @param operation * @since 1.4-M3 * @return * @throws ArchivaSecurityException * @throws AccessDeniedException * @throws PrincipalNotFoundException */ - List getAccessibleRepositories( String principal, String operation ) + List getAccessibleRepositories( String principal ) throws ArchivaSecurityException, AccessDeniedException, PrincipalNotFoundException; } diff --git a/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/security/UserRepositoriesStub.java b/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/security/UserRepositoriesStub.java index 73e413422..fb0e2105c 100644 --- a/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/security/UserRepositoriesStub.java +++ b/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/security/UserRepositoriesStub.java @@ -77,7 +77,7 @@ public class UserRepositoriesStub this.repoIds = repoIds; } - public List getAccessibleRepositories( String principal, String operation ) + public List getAccessibleRepositories( String principal ) throws ArchivaSecurityException, AccessDeniedException, PrincipalNotFoundException { return Collections.emptyList(); -- 2.39.5