Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/release-notes/12340-timing-issue-guestbook-response.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
## BUG
Timing issue fixed where user only had a few seconds instead of a minute to call the File download API after POSTing the guestbook response
7 changes: 4 additions & 3 deletions src/main/java/edu/harvard/iq/dataverse/api/Access.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ public class Access extends AbstractApiBean {
DataverseFeaturedItemServiceBean dataverseFeaturedItemServiceBean;

private static final String DEFAULT_BUNDLE_NAME = "dataverse_files.zip";
private static final int GUESTBOOK_RESPONSE_SIGNEDURL_TIMEOUT_MINUTES = 1;
//@EJB

// TODO:
Expand Down Expand Up @@ -495,7 +496,7 @@ private Response returnSignedUrl(ContainerRequestContext crc, UriInfo uriInfo, U
ApiToken apiToken = authSvc.findApiTokenByUser(requestor);
if (apiToken == null) {
logger.fine("Generating temporary API token for user " + userIdentifier);
apiToken = authSvc.generateApiTokenForUser(requestor, AuthenticationServiceBean.INTERVAL.MINUTES, 1);
apiToken = authSvc.generateApiTokenForUser(requestor, AuthenticationServiceBean.INTERVAL.MINUTES, GUESTBOOK_RESPONSE_SIGNEDURL_TIMEOUT_MINUTES);
}
if (apiToken != null) {
key = apiToken.getTokenString();
Expand All @@ -517,7 +518,7 @@ private Response returnSignedUrl(ContainerRequestContext crc, UriInfo uriInfo, U
String baseUrl = URLDecoder.decode(baseUrlEncoded, StandardCharsets.UTF_8);
baseUrl = baseUrl.replace(":persistentId", id);
key = JvmSettings.API_SIGNING_SECRET.lookupOptional().orElse("") + key;
String signedUrl = UrlSignerUtil.signUrl(baseUrl, 1, userIdentifier, "GET", key);
String signedUrl = UrlSignerUtil.signUrl(baseUrl, GUESTBOOK_RESPONSE_SIGNEDURL_TIMEOUT_MINUTES, userIdentifier, "GET", key);
return ok(Json.createObjectBuilder().add(URLTokenUtil.SIGNED_URL, signedUrl));
}

Expand Down Expand Up @@ -2004,7 +2005,7 @@ private boolean checkGuestbookRequiredResponse(ContainerRequestContext crc, UriI
throw new NotFoundException("GuestbookResponse Not Found for id:" + gbrids);
}
Long delta = Instant.now().toEpochMilli() - gbr.getResponseTime().getTime();
wasWrittenInPost = gbr.getDataset().getId().equals(df.getOwner().getId()) && delta < 10000;
wasWrittenInPost = gbr.getDataset().getId().equals(df.getOwner().getId()) && delta <= (GUESTBOOK_RESPONSE_SIGNEDURL_TIMEOUT_MINUTES * 60000L);
} catch (NumberFormatException | DateTimeParseException ex) {
throw new BadRequestException(ex.getMessage());
}
Expand Down
4 changes: 3 additions & 1 deletion src/test/java/edu/harvard/iq/dataverse/api/UtilIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -1276,7 +1276,9 @@ static Response getDownloadFileUrlWithGuestbookResponse(Integer fileId, String a

static Response downloadFilesUrlWithGuestbookResponse(Integer[] fileIds, String apiToken, String body) {
RequestSpecification requestSpecification = given();
requestSpecification.header(API_TOKEN_HTTP_HEADER, apiToken);
if (apiToken != null) {
requestSpecification.header(API_TOKEN_HTTP_HEADER, apiToken);
}
if (body != null) {
requestSpecification.body(body);
}
Expand Down
Loading