Skip to content
Snippets Groups Projects
Commit 94dffcf0 authored by kfilippopolitis's avatar kfilippopolitis
Browse files

Added global variables for pathologies url and disabledAlgorithms.

parent 1705e121
No related branches found
No related tags found
1 merge request!19Feat/186 experiment refactor
......@@ -76,3 +76,9 @@ services:
keycloak:
keycloakUrl: {{ .Env.KEYCLOAK_URL }}
pathologies:
pathologiesUrl: "file:/opt/portal/api/pathologies.json"
algorithms:
disabledAlgorithmsUrl: "file:/opt/portal/api/disabledAlgorithms.json"
\ No newline at end of file
......@@ -268,6 +268,14 @@
<include>**/*.yml</include> <!-- Only for development -->
</includes>
<filtering>true</filtering>
</resource>
<resource>
<directory>config</directory>
<includes>
<include>*.json</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
......
......@@ -6,6 +6,7 @@ import eu.hbp.mip.utils.CustomLoginUrlAuthenticationEntryPoint;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.security.oauth2.resource.AuthoritiesExtractor;
import org.springframework.boot.autoconfigure.security.oauth2.resource.ResourceServerProperties;
......@@ -70,6 +71,7 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
private static final Logger LOGGER = LoggerFactory.getLogger(SecurityConfiguration.class);
@Qualifier("oauth2ClientContext")
@Autowired
private OAuth2ClientContext oauth2ClientContext;
......
......@@ -17,6 +17,7 @@ import eu.hbp.mip.utils.Logging;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;
import org.springframework.http.ResponseEntity;
......@@ -41,6 +42,7 @@ public class AlgorithmsApi {
private static final Gson gson = new Gson();
@Qualifier("userInfo")
@Autowired
private UserInfo userInfo;
......@@ -53,6 +55,9 @@ public class AlgorithmsApi {
@Value("#{'${services.galaxy.galaxyApiKey}'}")
private String galaxyApiKey;
@Value("#{'${services.algorithms.disabledAlgorithmsUrl}'}")
private String disabledAlgorithmsUrl;
@ApiOperation(value = "List all algorithms", response = String.class)
@RequestMapping(method = RequestMethod.GET)
public ResponseEntity<List<AlgorithmDTO>> getAlgorithms() {
......@@ -195,7 +200,7 @@ public class AlgorithmsApi {
*/
List<String> getDisabledAlgorithms() throws IOException {
Resource resource = resourceLoader.getResource("file:/opt/portal/api/disabledAlgorithms.json");
Resource resource = resourceLoader.getResource(disabledAlgorithmsUrl);
List<String> response = gson.fromJson(convertInputStreamToString(
resource.getInputStream()),
......
......@@ -15,6 +15,7 @@ import eu.hbp.mip.utils.InputStreamConverter;
import eu.hbp.mip.utils.Logging;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;
import org.springframework.http.ResponseEntity;
......@@ -35,6 +36,7 @@ public class PathologiesApi {
private static final Gson gson = new Gson();
@Qualifier("userInfo")
@Autowired
private UserInfo userInfo;
......@@ -42,32 +44,37 @@ public class PathologiesApi {
@Value("#{'${hbp.authentication.enabled:1}'}")
private boolean authenticationIsEnabled;
@Value("#{'${services.pathologies.pathologiesUrl}'}")
private String pathologiesUrl;
@Autowired
private CustomResourceLoader resourceLoader;
@RequestMapping(name = "/pathologies", method = RequestMethod.GET)
public ResponseEntity<String> getPathologies(Authentication authentication) {
Logging.LogUserAction(userInfo.getUser().getUsername(), "(GET) /pathologies", "Loading pathologies ...");
String endpoint = "(GET) /pathologies";
String username = userInfo.getUser().getUsername();
Logging.LogUserAction(username, endpoint, "Loading pathologies ...");
// Load pathologies from file
Resource resource = resourceLoader.getResource("file:/opt/portal/api/pathologies.json");
Resource resource = resourceLoader.getResource(pathologiesUrl);
List<PathologyDTO> allPathologies;
try {
allPathologies = gson.fromJson(InputStreamConverter.convertInputStreamToString(resource.getInputStream()), new TypeToken<List<PathologyDTO>>() {
}.getType());
} catch (IOException e) {
Logging.LogUserAction(userInfo.getUser().getUsername(), "(GET) /pathologies", "Unable to load pathologies");
Logging.LogUserAction(username, endpoint, "Unable to load pathologies");
throw new BadRequestException("The pathologies could not be loaded.");
}
// If authentication is disabled return everything
if (!authenticationIsEnabled) {
Logging.LogUserAction(userInfo.getUser().getUsername(), "(GET) /pathologies", "Successfully loaded " + allPathologies.size() + " pathologies");
Logging.LogUserAction(username, endpoint, "Successfully loaded " + allPathologies.size() + " pathologies");
return ResponseEntity.ok().body(gson.toJson(allPathologies));
}
Logging.LogUserAction(userInfo.getUser().getUsername(), "(GET) /pathologies", "Successfully loaded all authorized pathologies");
Logging.LogUserAction(username, endpoint, "Successfully loaded all authorized pathologies");
return ResponseEntity.ok().body(ClaimUtils.getAuthorizedPathologies(
userInfo.getUser().getUsername(), authentication.getAuthorities(), allPathologies));
username, authentication.getAuthorities(), allPathologies));
}
}
......@@ -21,7 +21,7 @@ spring:
# HBP OAUTH2 LOGIN
hbp:
authentication:
enabled: true
enabled: 0
client:
clientId: "MIP"
clientSecret: "dae83a6b-c769-4186-8383-f0984c6edf05"
......@@ -71,5 +71,11 @@ services:
galaxyUsername: "admin"
galaxyPassword: "password"
keycloak:
keycloakUrl: 127.0.0.1
\ No newline at end of file
keycloak:
keycloakUrl: "127.0.0.1"
pathologies:
pathologiesUrl: "classPath:/pathologies.json"
algorithms:
disabledAlgorithmsUrl: "classPath:/disableAlgorithms.json"
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment