Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
dippindots committed Feb 6, 2024
1 parent 001086f commit 848f3ce
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 36 deletions.
25 changes: 22 additions & 3 deletions src/main/java/org/cbioportal/web/IndexPageController.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
import com.fasterxml.jackson.databind.module.SimpleModule;
import jakarta.servlet.http.HttpServletRequest;
import org.cbioportal.service.FrontendPropertiesService;
import org.cbioportal.service.util.MskWholeSlideViewerTokenGenerator;
import org.cbioportal.web.util.HttpRequestUtils;
import org.cbioportal.web.util.TokenUtils;
import org.json.simple.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Controller;
Expand All @@ -38,7 +39,7 @@ public class IndexPageController {
private HttpRequestUtils requestUtils;

@Autowired
private TokenUtils tokenUtils;
private Environment env;

@Value("${authenticate}")
private String[] authenticate;
Expand All @@ -56,9 +57,27 @@ private Map<String, String> getFrontendProperties(HttpServletRequest request, Au
// TODO: Support skin.user_display_name
properties.put("user_display_name", authentication != null ? authentication.getName(): "anonymousUser");
// Set MSK slide viewer token at runtime
properties.put("mskWholeSlideViewerToken", tokenUtils.getMskWholeSlideViewerToken());
properties.put("mskWholeSlideViewerToken", getMskWholeSlideViewerToken(env.getProperty("msk.whole.slide.viewer.secret.key"), authentication));
return properties;
}

private String getMskWholeSlideViewerToken(String secretKey, Authentication authentication) {
// this token is for the msk portal
// the token is generated based on users' timestamp to let the slide viewer know whether the token is expired and then decide whether to allow the user to login the viewer
// every time when we refresh the page or goto the new page, a new token should be generated
if (secretKey != null)
secretKey = secretKey.trim();
String timeStamp = String.valueOf(System.currentTimeMillis());

if (authentication != null && authentication.isAuthenticated() && secretKey != null &&
!secretKey.isEmpty()) {
return "{ \"token\":\"" + MskWholeSlideViewerTokenGenerator.generateTokenByHmacSHA256(
authentication.getName(), secretKey, timeStamp) + "\", \"time\":\"" + timeStamp +
"\"}";
} else {
return null;
}
}

@RequestMapping({"/", "/index", "/index.html", "/study/summary", "/results" })
public String showIndexPage(HttpServletRequest request, Authentication authentication, Model model)
Expand Down
33 changes: 0 additions & 33 deletions src/main/java/org/cbioportal/web/util/TokenUtils.java

This file was deleted.

0 comments on commit 848f3ce

Please sign in to comment.