Skip to content

Commit

Permalink
ALS-7712: Add redirect handler for signed urls
Browse files Browse the repository at this point in the history
  • Loading branch information
ramari16 committed Nov 5, 2024
1 parent dab00d5 commit 4eb3f36
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.*;
Expand Down Expand Up @@ -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);
}
}
}

0 comments on commit 4eb3f36

Please sign in to comment.