Skip to content

Commit 6a144ac

Browse files
authored
Merge pull request #12279 from IQSS/12267-does-not-save-guestbook-response
Fixes for guestbook edge case errors
2 parents 5dc8b47 + 90a1219 commit 6a144ac

5 files changed

Lines changed: 320 additions & 188 deletions

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
## BUG
2+
Fixes 2 bugs
3+
1. missing "gbrids" in the signed url query parameter list will no longer include "&gbrids=" without a value
4+
2. For SPA, when a user attempting to download files with a guestbook response has no api token but is authenticated by bearer token, a temporary api token will be generated with an expiration of 1 minute which is used for signing and decoding the signed url.

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import edu.harvard.iq.dataverse.*;
1010
import edu.harvard.iq.dataverse.api.auth.AuthRequired;
11+
import edu.harvard.iq.dataverse.authorization.AuthenticationServiceBean;
1112
import edu.harvard.iq.dataverse.authorization.DataverseRole;
1213
import edu.harvard.iq.dataverse.authorization.Permission;
1314
import edu.harvard.iq.dataverse.authorization.RoleAssignee;
@@ -422,7 +423,7 @@ private Response processDatafileWithGuestbookResponse(ContainerRequestContext cr
422423

423424
// Handle Guestbook Responses
424425
String displayName = "";
425-
String gbrids = "";
426+
String gbrids = null;
426427
Long datasetId = null;
427428
try {
428429
// since all files must be in the same Dataset we can generate a Guestbook Response once and just replace the DataFile for each file in the list
@@ -487,8 +488,15 @@ private Response returnSignedUrl(ContainerRequestContext crc, UriInfo uriInfo, U
487488
if (user != null && user instanceof AuthenticatedUser) {
488489
AuthenticatedUser requestor = (AuthenticatedUser) user;
489490
userIdentifier = requestor.getUserIdentifier();
491+
// Find the latest token: Use for signing
492+
// Could be null if no token was generated: Generate one to be used for signing (expire in 1 minute to match timeout in signedUrl)
493+
// Could be expired: The user was already authenticated (possible by bearer token). Only used for signing so we don't care
490494
ApiToken apiToken = authSvc.findApiTokenByUser(requestor);
491-
if (apiToken != null && !apiToken.isExpired() && !apiToken.isDisabled()) {
495+
if (apiToken == null) {
496+
logger.fine("Generating temporary API token for user " + userIdentifier);
497+
apiToken = authSvc.generateApiTokenForUser(requestor, AuthenticationServiceBean.INTERVAL.MINUTES, 1);
498+
}
499+
if (apiToken != null) {
492500
key = apiToken.getTokenString();
493501
}
494502
} else {
@@ -499,7 +507,9 @@ private Response returnSignedUrl(ContainerRequestContext crc, UriInfo uriInfo, U
499507

500508
UriBuilder builder = UriBuilder.fromUri(uriInfo.getRequestUri());
501509
builder.replaceQueryParam("gbrecs", true);
502-
builder.replaceQueryParam("gbrids", gbrids);
510+
if (gbrids != null && !gbrids.isEmpty()) {
511+
builder.replaceQueryParam("gbrids", gbrids);
512+
}
503513
builder.replaceQueryParam("persistentId", null); // remove this as a parm and add the id to the path
504514
crc.setProperty("gbrids", gbrids);
505515
String baseUrlEncoded = builder.build().toString();

0 commit comments

Comments
 (0)