Skip to content

Commit f8514a4

Browse files
committed
Fix timing issue when posting guestbook response and requesting the download
1 parent 98f448e commit f8514a4

3 files changed

Lines changed: 9 additions & 4 deletions

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
## BUG
2+
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

src/main/java/edu/harvard/iq/dataverse/api/Access.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ public class Access extends AbstractApiBean {
131131
DataverseFeaturedItemServiceBean dataverseFeaturedItemServiceBean;
132132

133133
private static final String DEFAULT_BUNDLE_NAME = "dataverse_files.zip";
134+
private static final int GUESTBOOK_RESPONSE_SIGNEDURL_TIMEOUT_MINUTES = 1;
134135
//@EJB
135136

136137
// TODO:
@@ -495,7 +496,7 @@ private Response returnSignedUrl(ContainerRequestContext crc, UriInfo uriInfo, U
495496
ApiToken apiToken = authSvc.findApiTokenByUser(requestor);
496497
if (apiToken == null) {
497498
logger.fine("Generating temporary API token for user " + userIdentifier);
498-
apiToken = authSvc.generateApiTokenForUser(requestor, AuthenticationServiceBean.INTERVAL.MINUTES, 1);
499+
apiToken = authSvc.generateApiTokenForUser(requestor, AuthenticationServiceBean.INTERVAL.MINUTES, GUESTBOOK_RESPONSE_SIGNEDURL_TIMEOUT_MINUTES);
499500
}
500501
if (apiToken != null) {
501502
key = apiToken.getTokenString();
@@ -517,7 +518,7 @@ private Response returnSignedUrl(ContainerRequestContext crc, UriInfo uriInfo, U
517518
String baseUrl = URLDecoder.decode(baseUrlEncoded, StandardCharsets.UTF_8);
518519
baseUrl = baseUrl.replace(":persistentId", id);
519520
key = JvmSettings.API_SIGNING_SECRET.lookupOptional().orElse("") + key;
520-
String signedUrl = UrlSignerUtil.signUrl(baseUrl, 1, userIdentifier, "GET", key);
521+
String signedUrl = UrlSignerUtil.signUrl(baseUrl, GUESTBOOK_RESPONSE_SIGNEDURL_TIMEOUT_MINUTES, userIdentifier, "GET", key);
521522
return ok(Json.createObjectBuilder().add(URLTokenUtil.SIGNED_URL, signedUrl));
522523
}
523524

@@ -2004,7 +2005,7 @@ private boolean checkGuestbookRequiredResponse(ContainerRequestContext crc, UriI
20042005
throw new NotFoundException("GuestbookResponse Not Found for id:" + gbrids);
20052006
}
20062007
Long delta = Instant.now().toEpochMilli() - gbr.getResponseTime().getTime();
2007-
wasWrittenInPost = gbr.getDataset().getId().equals(df.getOwner().getId()) && delta < 10000;
2008+
wasWrittenInPost = gbr.getDataset().getId().equals(df.getOwner().getId()) && delta <= (GUESTBOOK_RESPONSE_SIGNEDURL_TIMEOUT_MINUTES * 60000L);
20082009
} catch (NumberFormatException | DateTimeParseException ex) {
20092010
throw new BadRequestException(ex.getMessage());
20102011
}

src/test/java/edu/harvard/iq/dataverse/api/UtilIT.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1276,7 +1276,9 @@ static Response getDownloadFileUrlWithGuestbookResponse(Integer fileId, String a
12761276

12771277
static Response downloadFilesUrlWithGuestbookResponse(Integer[] fileIds, String apiToken, String body) {
12781278
RequestSpecification requestSpecification = given();
1279-
requestSpecification.header(API_TOKEN_HTTP_HEADER, apiToken);
1279+
if (apiToken != null) {
1280+
requestSpecification.header(API_TOKEN_HTTP_HEADER, apiToken);
1281+
}
12801282
if (body != null) {
12811283
requestSpecification.body(body);
12821284
}

0 commit comments

Comments
 (0)