Skip to content
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
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package org.cbioportal.legacy.service;

import org.springframework.security.core.Authentication;

import java.util.Map;

public interface FrontendPropertiesService {

String getFrontendProperty(FrontendPropertiesServiceImpl.FrontendProperty property);

Map<String, String> getFrontendProperties();
Map<String,String> getFrontendProperties(Authentication authentication);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
package org.cbioportal.legacy.service;

import jakarta.annotation.PostConstruct;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.stereotype.Service;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
Expand Down Expand Up @@ -291,9 +300,11 @@ public String getFrontendProperty(FrontendProperty property) {
return serverConfigProperties.get(property.getFrontendName());
}

public Map<String, String> getFrontendProperties() {
// Make sure that requests work on individual instances of this data.
return cloneProperties();
public Map<String, String> getFrontendProperties(Authentication authentication) {
// Make sure that requests work on individual instances of this data.
Map<String,String> properties = cloneProperties();
updateShowDownloadButtonProperties(properties, authentication);
return properties;
}

private Map<String, String> cloneProperties() {
Expand All @@ -304,6 +315,16 @@ private Map<String, String> cloneProperties() {
HashMap::putAll);
}

private void updateShowDownloadButtonProperties(Map<String,String> properties, Authentication authentication) {
String downloadGroup = "ROLE_" + env.getProperty("download_group", "");
if(authentication != null && StringUtils.isNotEmpty(downloadGroup)) {
boolean userHasDownloadRole = authentication.getAuthorities().contains(new SimpleGrantedAuthority(downloadGroup));
if(userHasDownloadRole) {
properties.put("skin_hide_download_controls", "show");
}
}
}

/**
* Find the file, either on the file system or in a .jar, and return as an InputStream.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private Map<String, Object> getFrontendProperties(
String baseUrl = requestUtils.getBaseUrl(request);
Map<String, Object> properties = new HashMap<>();

Map<String, String> originalProperties = frontendPropertiesService.getFrontendProperties();
Map<String, String> originalProperties = frontendPropertiesService.getFrontendProperties(authentication);

for (Map.Entry<String, String> entry : originalProperties.entrySet()) {
String value = entry.getValue();
Expand Down