Skip to content

Commit

Permalink
SAK-46533 T&Q : show secured images on feedback (sakaiproject#10003)
Browse files Browse the repository at this point in the history
  • Loading branch information
bgarciaentornos authored Nov 10, 2021
1 parent 84e60f2 commit 3ebc5ea
Showing 1 changed file with 24 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,8 @@ public void processAction(ActionEvent ae) throws
}
}

generateSecureTokenForAssessment(delivery);

// post event
eventRef = new StringBuffer("publishedAssessmentId=");
eventRef.append(delivery.getAssessmentId());
Expand Down Expand Up @@ -517,25 +519,7 @@ public void processAction(ActionEvent ae) throws
log.debug("****Set begin time " + delivery.getBeginTime());
log.debug("****Set elapsed time " + delivery.getTimeElapse());

// SAK-45537 - Generate a secure token valid only for this exam, site and session.
try {
if (StringUtils.isBlank(delivery.getSecureToken())) {
// Set token validity for the time limit of the exam, if there's no limit make it available for 2 hours.
int timeRemaining = Integer.parseInt(delivery.getTimeLimit()) - Integer.parseInt(delivery.getTimeElapse());
int tokenValiditySeconds = timeRemaining > 0 ? timeRemaining : 7200;
log.debug("Generating secured token for attachments valid for {} seconds.....", tokenValiditySeconds);
String localDateTime = LocalDateTime.now().plusSeconds(tokenValiditySeconds).toString();
String sessionId = sessionManager.getCurrentSession().getId();
String secureTokenString = sessionId+"|"+localDateTime;
log.debug("Encrypting secured token {}", secureTokenString);
String secureToken = URLEncoder.encode(encryptionUtilityService.encrypt(secureTokenString), StandardCharsets.UTF_8.name());
log.debug("Encrypted token with value {}", secureToken);
delivery.setSecureToken(secureToken);
}

} catch (Exception ex) {
log.warn("Cannot generate secured token for assessment {}: {}", delivery.getAssessmentId(), ex.getMessage());
}
generateSecureTokenForAssessment(delivery);

break;

Expand Down Expand Up @@ -612,6 +596,27 @@ public void processAction(ActionEvent ae) throws

}

private void generateSecureTokenForAssessment(DeliveryBean delivery) {
// SAK-45537 - Generate a secure token valid only for this exam, site and session.
try {
if (StringUtils.isBlank(delivery.getSecureToken())) {
// Set token validity for the time limit of the exam, if there's no limit make it available for 2 hours.
int timeRemaining = Integer.parseInt(delivery.getTimeLimit()) - Integer.parseInt(delivery.getTimeElapse());
int tokenValiditySeconds = timeRemaining > 0 ? timeRemaining : 7200;
log.debug("Generating secured token for attachments valid for {} seconds.....", tokenValiditySeconds);
String localDateTime = LocalDateTime.now().plusSeconds(tokenValiditySeconds).toString();
String sessionId = sessionManager.getCurrentSession().getId();
String secureTokenString = sessionId+"|"+localDateTime;
log.debug("Encrypting secured token {}", secureTokenString);
String secureToken = URLEncoder.encode(encryptionUtilityService.encrypt(secureTokenString), StandardCharsets.UTF_8.name());
log.debug("Encrypted token with value {}", secureToken);
delivery.setSecureToken(secureToken);
}
} catch (Exception ex) {
log.warn("Cannot generate secured token for assessment {}: {}", delivery.getAssessmentId(), ex.getMessage());
}
}

/**
* Look up item grading data and set assesment grading data from it or,
* if there is none set null if setNullOK.
Expand Down

0 comments on commit 3ebc5ea

Please sign in to comment.