Skip to content

Commit

Permalink
#183, handled token expiry for download by query API
Browse files Browse the repository at this point in the history
  • Loading branch information
Prabhu committed Sep 30, 2021
1 parent 7550b0a commit 917d222
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions api-server/src/main/java/vermillion/http/HttpServerVerticle.java
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,9 @@ private String getFinalTokenFromNormalisedPath(RoutingContext routingContext) {
for (String param: pathParams) {
paramsMap.put(counter++, param);
}
String token, authServer, tokenHash;
authServer = paramsMap.get(3);
tokenHash = paramsMap.get(4);
token = authServer + "/" + tokenHash;
String authServer = paramsMap.get(3);
String tokenHash = paramsMap.get(4);
String token = authServer + "/" + tokenHash;
logger.debug("Final paramsMap: " + paramsMap);
return token;
}
Expand Down Expand Up @@ -1497,9 +1496,6 @@ public void downloadByQuery(RoutingContext context) {

checkAuthorisation(token, READ_SCOPE).flatMap(id -> {
logger.debug("authorised ids of consumer=" + id);
if (id.size() == 0) {
return Single.error(new UnauthorisedThrowable("Unauthorized"));
}
JsonArray authorisedResourceIds = new JsonArray();
Iterator<Object> iterator = id.stream().iterator();
while (iterator.hasNext() && resourceId == null) {
Expand All @@ -1510,6 +1506,7 @@ public void downloadByQuery(RoutingContext context) {
authorisedResourceIds.add(next))));
}
setConsumerEmailDetails(token, emailDetails).subscribe();
isTokenExpired(token).subscribe();

logger.debug("constructed query for download by query API for category/subCategory is: "
+ downloadByQuery.toString());
Expand All @@ -1518,8 +1515,10 @@ public void downloadByQuery(RoutingContext context) {
}).flatMapCompletable(result-> {
logger.debug("Response from search endpoint:" + result.toString());
JsonArray hits = result.getJsonArray("hits");
if (hits.size() == 0) {
return Completable.error(new FileNotFoundThrowable("The requested files are not found"));

logger.debug("tokenExpiredDetails=" + tokenExpiredDetails.toString());
if (tokenExpiredDetails.get("tokenExpiredDetails")) {
return Completable.error(new UnauthorisedThrowable("Unauthorised due to token expiry"));
}

String email = emailDetails.get("email");
Expand All @@ -1528,6 +1527,10 @@ public void downloadByQuery(RoutingContext context) {
return Completable.error(new UnauthorisedThrowable("Email is missing"));
}

if (hits.size() == 0) {
return Completable.error(new FileNotFoundThrowable("The requested files are not found"));
}

SchedulerFactory stdSchedulerFactory = new StdSchedulerFactory();
Scheduler scheduler = stdSchedulerFactory.getScheduler();
scheduler.start();
Expand Down

0 comments on commit 917d222

Please sign in to comment.