diff --git a/docker/config/application.tmpl b/docker/config/application.tmpl index 6588e210aff0957a01ba66c4c436ae4dd9b7a163..f2587889371ac5ddd7f6bbad5b2f5574d303e07e 100644 --- a/docker/config/application.tmpl +++ b/docker/config/application.tmpl @@ -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 diff --git a/pom.xml b/pom.xml index f9c84d85d6d01e7dd02f56fbf4c52db6d87b908f..b64596e794adb4c824a7a6a59d932cb6e6ebaddf 100644 --- a/pom.xml +++ b/pom.xml @@ -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> diff --git a/src/main/java/eu/hbp/mip/configuration/SecurityConfiguration.java b/src/main/java/eu/hbp/mip/configuration/SecurityConfiguration.java index ff28602a1b33e541fd89858d4a6f9d0bf9787605..81afa6418383a2a9817bdf0770f4a0b90a08af25 100644 --- a/src/main/java/eu/hbp/mip/configuration/SecurityConfiguration.java +++ b/src/main/java/eu/hbp/mip/configuration/SecurityConfiguration.java @@ -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; diff --git a/src/main/java/eu/hbp/mip/controllers/AlgorithmsApi.java b/src/main/java/eu/hbp/mip/controllers/AlgorithmsApi.java index d5dca19ae3b3503876b884dabdf48e7a2d808898..07ab6ef291b4dcb32123e4c66f26a625e8b99261 100644 --- a/src/main/java/eu/hbp/mip/controllers/AlgorithmsApi.java +++ b/src/main/java/eu/hbp/mip/controllers/AlgorithmsApi.java @@ -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()), diff --git a/src/main/java/eu/hbp/mip/controllers/PathologiesApi.java b/src/main/java/eu/hbp/mip/controllers/PathologiesApi.java index 4ec7c8e36d421f0ead08e15bf05b13328f63d72c..a6979e70ccae284adeed66bdf125f83e256987e9 100644 --- a/src/main/java/eu/hbp/mip/controllers/PathologiesApi.java +++ b/src/main/java/eu/hbp/mip/controllers/PathologiesApi.java @@ -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)); } } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 825692ef70c731e54d1061293ec06d4dc8d1ab61..a4c205725b44f860118b7f8417fb14ef9f88f555 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -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