From 4eb3f362e34820e86fe8b403e05f8aab6861e3f4 Mon Sep 17 00:00:00 2001 From: Ryan Amari Date: Tue, 5 Nov 2024 14:52:15 -0500 Subject: [PATCH] ALS-7712: Add redirect handler for signed urls --- .../edu/harvard/dbmi/avillach/PicsureRS.java | 10 ++++++++++ .../avillach/service/PicsureQueryService.java | 19 +++++++++++++++---- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/pic-sure-api-war/src/main/java/edu/harvard/dbmi/avillach/PicsureRS.java b/pic-sure-api-war/src/main/java/edu/harvard/dbmi/avillach/PicsureRS.java index 49bdb337..cd079227 100644 --- a/pic-sure-api-war/src/main/java/edu/harvard/dbmi/avillach/PicsureRS.java +++ b/pic-sure-api-war/src/main/java/edu/harvard/dbmi/avillach/PicsureRS.java @@ -245,4 +245,14 @@ public Response getProxy( return proxyWebClient.getProxy(containerId, request, uriInfo.getQueryParameters(), headers); } + @GET + @Path("/query/{queryId}/signed-redirect") + public Response getSignedRedirect( + @PathParam("queryId") UUID queryId, + @QueryParam("target") String target, + @Parameter QueryRequest credentialsQueryRequest, + @Context HttpHeaders headers) { + return queryService.getSignedRedirect(queryId, credentialsQueryRequest, headers, target); + } + } diff --git a/pic-sure-api-war/src/main/java/edu/harvard/dbmi/avillach/service/PicsureQueryService.java b/pic-sure-api-war/src/main/java/edu/harvard/dbmi/avillach/service/PicsureQueryService.java index 74945080..982574f4 100644 --- a/pic-sure-api-war/src/main/java/edu/harvard/dbmi/avillach/service/PicsureQueryService.java +++ b/pic-sure-api-war/src/main/java/edu/harvard/dbmi/avillach/service/PicsureQueryService.java @@ -7,10 +7,7 @@ import edu.harvard.dbmi.avillach.data.entity.Resource; import edu.harvard.dbmi.avillach.data.repository.QueryRepository; import edu.harvard.dbmi.avillach.data.repository.ResourceRepository; -import edu.harvard.dbmi.avillach.domain.FederatedQueryRequest; -import edu.harvard.dbmi.avillach.domain.GeneralQueryRequest; -import edu.harvard.dbmi.avillach.domain.QueryRequest; -import edu.harvard.dbmi.avillach.domain.QueryStatus; +import edu.harvard.dbmi.avillach.domain.*; import edu.harvard.dbmi.avillach.security.JWTFilter; import edu.harvard.dbmi.avillach.util.Utilities; import edu.harvard.dbmi.avillach.util.exception.ApplicationException; @@ -22,6 +19,8 @@ import javax.transaction.Transactional; import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.Response; +import java.net.URI; +import java.net.URLEncoder; import java.nio.charset.StandardCharsets; import java.sql.Date; import java.util.*; @@ -431,5 +430,17 @@ private Resource verifyQueryRequest(QueryRequest dataQueryRequest, HttpHeaders h ); return resource; } + + public Response getSignedRedirect(UUID queryId, QueryRequest credentialsQueryRequest, HttpHeaders headers, String target) { + Response response = this.queryResultSignedUrl(queryId, credentialsQueryRequest, headers); + String responseString = response.getEntity().toString(); + try { + SignedUrlResponse signedUrlResponse = mapper.readValue(responseString, SignedUrlResponse.class); + String formattedString = String.format(target, URLEncoder.encode(signedUrlResponse.getSignedUrl(), StandardCharsets.UTF_8)); + return Response.status(Response.Status.FOUND).location(URI.create(formattedString)).build(); + } catch (JsonProcessingException e) { + throw new RuntimeException(e); + } + } }