Skip to content

Commit 4370bb7

Browse files
committed
Merge branch 'develop' into 11733-api-get-file-citation-format
2 parents acbf825 + 6a144ac commit 4370bb7

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;
@@ -444,7 +445,7 @@ private Response processDatafileWithGuestbookResponse(ContainerRequestContext cr
444445

445446
// Handle Guestbook Responses
446447
String displayName = "";
447-
String gbrids = "";
448+
String gbrids = null;
448449
Long datasetId = null;
449450
try {
450451
// 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
@@ -509,8 +510,15 @@ private Response returnSignedUrl(ContainerRequestContext crc, UriInfo uriInfo, U
509510
if (user != null && user instanceof AuthenticatedUser) {
510511
AuthenticatedUser requestor = (AuthenticatedUser) user;
511512
userIdentifier = requestor.getUserIdentifier();
513+
// Find the latest token: Use for signing
514+
// Could be null if no token was generated: Generate one to be used for signing (expire in 1 minute to match timeout in signedUrl)
515+
// Could be expired: The user was already authenticated (possible by bearer token). Only used for signing so we don't care
512516
ApiToken apiToken = authSvc.findApiTokenByUser(requestor);
513-
if (apiToken != null && !apiToken.isExpired() && !apiToken.isDisabled()) {
517+
if (apiToken == null) {
518+
logger.fine("Generating temporary API token for user " + userIdentifier);
519+
apiToken = authSvc.generateApiTokenForUser(requestor, AuthenticationServiceBean.INTERVAL.MINUTES, 1);
520+
}
521+
if (apiToken != null) {
514522
key = apiToken.getTokenString();
515523
}
516524
} else {
@@ -521,7 +529,9 @@ private Response returnSignedUrl(ContainerRequestContext crc, UriInfo uriInfo, U
521529

522530
UriBuilder builder = UriBuilder.fromUri(uriInfo.getRequestUri());
523531
builder.replaceQueryParam("gbrecs", true);
524-
builder.replaceQueryParam("gbrids", gbrids);
532+
if (gbrids != null && !gbrids.isEmpty()) {
533+
builder.replaceQueryParam("gbrids", gbrids);
534+
}
525535
builder.replaceQueryParam("persistentId", null); // remove this as a parm and add the id to the path
526536
crc.setProperty("gbrids", gbrids);
527537
String baseUrlEncoded = builder.build().toString();

0 commit comments

Comments
 (0)