From a19b5c2435c13a0b3b6a551f16c85f3414d83f88 Mon Sep 17 00:00:00 2001 From: dzikoysk Date: Fri, 30 Oct 2020 12:26:36 +0100 Subject: [PATCH] GH-294 Provide normalized URI to authenticate hidden repositories in the lookup API endpoint (Fix #294) --- .../reposilite/repository/LookupApiController.java | 6 +++--- .../reposilite/repository/RepositoryAuthenticator.java | 6 +++--- .../repository/RepositoryAuthenticatorTest.groovy | 2 +- reposilite-backend/src/test/workspace/access.md | 4 ++++ reposilite-backend/src/test/workspace/tokens.dat | 8 +++++++- 5 files changed, 18 insertions(+), 8 deletions(-) diff --git a/reposilite-backend/src/main/java/org/panda_lang/reposilite/repository/LookupApiController.java b/reposilite-backend/src/main/java/org/panda_lang/reposilite/repository/LookupApiController.java index 7be8d60f7..d8c8f6c2b 100644 --- a/reposilite-backend/src/main/java/org/panda_lang/reposilite/repository/LookupApiController.java +++ b/reposilite-backend/src/main/java/org/panda_lang/reposilite/repository/LookupApiController.java @@ -62,13 +62,13 @@ public Context handleContext(Context ctx) { ReposiliteContext context = contextFactory.create(ctx); Reposilite.getLogger().info("API " + context.uri() + " from " + context.address()); - String uri = ReposiliteUtils.normalizeUri(rewritePathsEnabled, repositoryService, StringUtils.replaceFirst(ctx.req.getRequestURI(), "/api", "")); + String uri = ReposiliteUtils.normalizeUri(rewritePathsEnabled, repositoryService, StringUtils.replaceFirst(context.uri(), "/api", "")); if (StringUtils.isEmpty(uri) || "/".equals(uri)) { - return ctx.json(lookupService.findAvailableRepositories(ctx.headerMap())); + return ctx.json(lookupService.findAvailableRepositories(context.headers())); } - Result, ErrorDto> result = repositoryAuthenticator.authRepository(ctx.headerMap(), ctx.req.getRequestURI(), uri); + Result, ErrorDto> result = repositoryAuthenticator.authRepository(context.headers(), uri); if (result.containsError()) { return ResponseUtils.errorResponse(ctx, result.getError().getStatus(), result.getError().getMessage()); diff --git a/reposilite-backend/src/main/java/org/panda_lang/reposilite/repository/RepositoryAuthenticator.java b/reposilite-backend/src/main/java/org/panda_lang/reposilite/repository/RepositoryAuthenticator.java index dc6ca0fb1..94987e82b 100644 --- a/reposilite-backend/src/main/java/org/panda_lang/reposilite/repository/RepositoryAuthenticator.java +++ b/reposilite-backend/src/main/java/org/panda_lang/reposilite/repository/RepositoryAuthenticator.java @@ -41,10 +41,10 @@ public RepositoryAuthenticator(boolean rewritePathsEnabled, Authenticator authen } public Result, ErrorDto> authDefaultRepository(Map headers, String uri) { - return authRepository(headers, uri, ReposiliteUtils.normalizeUri(rewritePathsEnabled, repositoryService, uri)); + return authRepository(headers, ReposiliteUtils.normalizeUri(rewritePathsEnabled, repositoryService, uri)); } - public Result, ErrorDto> authRepository(Map headers, String uri, String normalizedUri) { + public Result, ErrorDto> authRepository(Map headers, String normalizedUri) { String[] path = StringUtils.split(normalizedUri, "/"); String repositoryName = path[0]; @@ -60,7 +60,7 @@ public Result, ErrorDto> authRepository(Map