Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Extract correct values for user email and use configuration property for user displayed name #11351

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions src/main/java/org/cbioportal/web/IndexPageController.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.Authentication;
import org.springframework.security.oauth2.core.OAuth2AuthenticatedPrincipal;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
Expand Down Expand Up @@ -47,6 +48,9 @@ public class IndexPageController {
@Value("${msk.whole.slide.viewer.secret.key:}")
private String wholeSlideViewerKey;

@Value("${skin.user_display_name:email}")
private String userDisplayNameAttribute;

private final ObjectMapper mapper = new ObjectMapper();

private Map<String, Object> getFrontendProperties(HttpServletRequest request, Authentication authentication) {
Expand All @@ -64,14 +68,23 @@ private Map<String, Object> getFrontendProperties(HttpServletRequest request, Au
}
}
properties.put("base_url", baseUrl);
properties.put("user_email_address", authentication != null ? authentication.getName(): "anonymousUser");
// TODO: Support skin.user_display_name
properties.put("user_display_name", authentication != null ? authentication.getName(): "anonymousUser");
properties.put("user_email_address", getPrincipalAttribute(authentication, "email"));
properties.put("user_display_name", getPrincipalAttribute(authentication, userDisplayNameAttribute));
// Set MSK slide viewer token at runtime
properties.put("mskWholeSlideViewerToken", getMskWholeSlideViewerToken(wholeSlideViewerKey, authentication));
return properties;
}


private String getPrincipalAttribute(Authentication authentication, String attributeName) {
if (authentication != null) {
return switch (authentication.getPrincipal()) {
case OAuth2AuthenticatedPrincipal principal -> principal.getAttribute(attributeName);
default -> authentication.getName();
};
}
return "anonymousUser";
}

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
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/application.properties.EXAMPLE
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ skin.study_view.link_text=To build your own case set, try out our enhanced Study
## setting controlling whether Download tabs and download/copy-to-clipboard controls should be shown
# skin.hide_download_controls=false

## setting controlling which name should be used to display the authenticated user (email, or username)
## setting controlling which name should be used to display the authenticated user (email, name or username)
# skin.user_display_name=email

## enable and set this property to specify a study group to be used to identify public studies for which no specific authorization entries are needed in the `authorities` table
Expand Down