diff --git a/src/main/java/eu/hbp/mip/configurations/SecurityConfiguration.java b/src/main/java/eu/hbp/mip/configurations/SecurityConfiguration.java index 2b2e549d46dc7f8a71fc981f6c8d000f606630c9..9f583da4ef31205007e7467c63cfaf95645a5f28 100644 --- a/src/main/java/eu/hbp/mip/configurations/SecurityConfiguration.java +++ b/src/main/java/eu/hbp/mip/configurations/SecurityConfiguration.java @@ -56,7 +56,7 @@ public class SecurityConfiguration extends KeycloakWebSecurityConfigurerAdapter "/sso/login", "/v2/api-docs", "/swagger-ui/**", "/swagger-resources/**" // Swagger URLs ).permitAll() - .antMatchers("/galaxy*", "/galaxy/*").hasRole("DATA MANAGER") + .antMatchers("/galaxy*", "/galaxy/*").hasRole("WORKFLOW_ADMIN") .antMatchers("/**").authenticated() .and().csrf().ignoringAntMatchers("/logout").csrfTokenRepository(csrfTokenRepository()) .and().addFilterAfter(csrfHeaderFilter(), CsrfFilter.class); diff --git a/src/main/java/eu/hbp/mip/models/DAOs/ExperimentDAO.java b/src/main/java/eu/hbp/mip/models/DAOs/ExperimentDAO.java index e369e5cf6eff7b2641a4c9815e269eada28b37d9..a696ab52d7c6ff48bd2c1406369d6f7191724d01 100644 --- a/src/main/java/eu/hbp/mip/models/DAOs/ExperimentDAO.java +++ b/src/main/java/eu/hbp/mip/models/DAOs/ExperimentDAO.java @@ -52,7 +52,7 @@ public class ExperimentDAO { @Expose @Column(columnDefinition = "TEXT") - private String result; + private String results; @Expose @Column(columnDefinition = "TIMESTAMP WITHOUT TIME ZONE") @@ -95,6 +95,28 @@ public class ExperimentDAO { */ } + + public String getResults() { + return results; + } + + public void setResults(String result) { + this.results = result; + } + + public class ResultObjectDTO { + + ArrayList<Object> result; + + public ArrayList<Object> getResult() { + return this.result; + } + + public void setResult(ArrayList<Object> results) { + this.result = results; + } + } + public ExperimentDTO convertToDTO(boolean includeResult) { ExperimentDTO experimentDTO = new ExperimentDTO(); @@ -105,7 +127,7 @@ public class ExperimentDAO { experimentDTO.setCreatedBy(this.createdBy.getUsername()); experimentDTO.setName(this.name); if(includeResult){ - experimentDTO.setResult(JsonConverters.convertJsonStringToObject(String.valueOf(this.result), new ArrayList<ExperimentDTO.ResultDTO>().getClass())); + experimentDTO.setResults(JsonConverters.convertJsonStringToObject(this.results, new ArrayList<ArrayList<Object>>().getClass())); } experimentDTO.setStatus(this.status); experimentDTO.setShared(this.shared); diff --git a/src/main/java/eu/hbp/mip/models/DTOs/AlgorithmDTO.java b/src/main/java/eu/hbp/mip/models/DTOs/AlgorithmDTO.java index 1a6d8b99d41b4129c85b2b3591cc6ea3f89c950f..52db979d5ddd7b043572be8fc9255c45fa0e9c98 100644 --- a/src/main/java/eu/hbp/mip/models/DTOs/AlgorithmDTO.java +++ b/src/main/java/eu/hbp/mip/models/DTOs/AlgorithmDTO.java @@ -1,51 +1,15 @@ package eu.hbp.mip.models.DTOs; import com.google.gson.annotations.SerializedName; +import lombok.Getter; +import lombok.Setter; import java.util.List; +@Getter +@Setter public class AlgorithmDTO { - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getDesc() { - return desc; - } - - public void setDesc(String desc) { - this.desc = desc; - } - - public String getLabel() { - return label; - } - - public void setLabel(String label) { - this.label = label; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public List<AlgorithmParamDTO> getParameters() { - return parameters; - } - - public void setParameters(List<AlgorithmParamDTO> parameters) { - this.parameters = parameters; - } - @SerializedName("name") private String name; @@ -61,6 +25,8 @@ public class AlgorithmDTO { @SerializedName("parameters") private List<AlgorithmParamDTO> parameters; + @Getter + @Setter public static class AlgorithmParamDTO { @SerializedName("name") private String name; @@ -103,118 +69,5 @@ public class AlgorithmDTO { @SerializedName("valueEnumerations") private List<String> valueEnumerations; - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getDesc() { - return desc; - } - - public void setDesc(String desc) { - this.desc = desc; - } - - public String getLabel() { - return label; - } - - public void setLabel(String label) { - this.label = label; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public String getColumnValuesSQLType() { - return columnValuesSQLType; - } - - public void setColumnValuesSQLType(String columnValuesSQLType) { - this.columnValuesSQLType = columnValuesSQLType; - } - - public String getColumnValuesIsCategorical() { - return columnValuesIsCategorical; - } - - public void setColumnValuesIsCategorical(String columnValuesIsCategorical) { - this.columnValuesIsCategorical = columnValuesIsCategorical; - } - - public String getValue() { - return value; - } - - public void setValue(String value) { - this.value = value; - } - - public String getDefaultValue() { - return defaultValue; - } - - public void setDefaultValue(String defaultValue) { - this.defaultValue = defaultValue; - } - - public String getValueType() { - return valueType; - } - - public void setValueType(String valueType) { - this.valueType = valueType; - } - - public String getValueNotBlank() { - return valueNotBlank; - } - - public void setValueNotBlank(String valueNotBlank) { - this.valueNotBlank = valueNotBlank; - } - - public String getValueMultiple() { - return valueMultiple; - } - - public void setValueMultiple(String valueMultiple) { - this.valueMultiple = valueMultiple; - } - - public String getValueMin() { - return valueMin; - } - - public void setValueMin(String valueMin) { - this.valueMin = valueMin; - } - - public String getValueMax() { - return valueMax; - } - - public void setValueMax(String valueMax) { - this.valueMax = valueMax; - } - - public List<String> getValueEnumerations() { - return valueEnumerations; - } - - public void setValueEnumerations(List<String> valueEnumerations) { - this.valueEnumerations = valueEnumerations; - } } - } diff --git a/src/main/java/eu/hbp/mip/models/DTOs/ExperimentDTO.java b/src/main/java/eu/hbp/mip/models/DTOs/ExperimentDTO.java index 2840f669fcb507bf7b91b0f604b54ba7440cafc9..34a1bee9c8fda145bbeba5f5413bb19e711fe575 100644 --- a/src/main/java/eu/hbp/mip/models/DTOs/ExperimentDTO.java +++ b/src/main/java/eu/hbp/mip/models/DTOs/ExperimentDTO.java @@ -2,11 +2,15 @@ package eu.hbp.mip.models.DTOs; import com.fasterxml.jackson.annotation.JsonInclude; import eu.hbp.mip.models.DAOs.ExperimentDAO; +import lombok.Getter; +import lombok.Setter; import java.util.Date; import java.util.List; import java.util.UUID; +@Getter +@Setter @JsonInclude(JsonInclude.Include.NON_NULL) public class ExperimentDTO { @@ -18,121 +22,11 @@ public class ExperimentDTO { private Date finished; private Boolean shared; private Boolean viewed; - private List<ExperimentDTO.ResultDTO> result; + private List<List<Object>> results; private ExperimentDAO.Status status; - private AlgorithmDTO algorithm; public ExperimentDTO() { - } - - public AlgorithmDTO getAlgorithm() { - return algorithm; - } - - public void setAlgorithm(AlgorithmDTO algorithm) { - this.algorithm = algorithm; - } - - public UUID getUuid() { - return uuid; - } - - public void setUuid(UUID uuid) { - this.uuid = uuid; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getCreatedBy() { - return createdBy; - } - - public void setCreatedBy(String createdBy) { - this.createdBy = createdBy; - } - - public Date getCreated() { - return created; - } - - public void setCreated(Date created) { - this.created = created; - } - - public Date getUpdated() { - return updated; - } - - public void setUpdated(Date updated) { - this.updated = updated; - } - - public Date getFinished() { - return finished; - } - - public void setFinished(Date finished) { - this.finished = finished; - } - - public Boolean getShared() { - return shared; - } - - public void setShared(Boolean shared) { - this.shared = shared; - } - - public Boolean getViewed() { - return viewed; - } - - public void setViewed(Boolean viewed) { - this.viewed = viewed; - } - - public List<ExperimentDTO.ResultDTO> getResult() { - return result; - } - - public void setResult(List<ExperimentDTO.ResultDTO> result) { - this.result = result; - } - - public ExperimentDAO.Status getStatus() { - return status; - } - - public void setStatus(ExperimentDAO.Status status) { - this.status = status; - } - - public static class ResultDTO { - - private Object data; - private String type; - - public Object getData() { - return this.data; - } - - public void setData(Object data) { - this.data = data; - } - - public String getType() { - return type; - } - public void setType(String type) { - this.type = type; - } } } diff --git a/src/main/java/eu/hbp/mip/models/DTOs/PathologyDTO.java b/src/main/java/eu/hbp/mip/models/DTOs/PathologyDTO.java index 2a8887b5f22a309ecf2befcc69e1191a7c00576c..aa78ef8b0e315a2f71261dc1fed480cb8617ccb2 100644 --- a/src/main/java/eu/hbp/mip/models/DTOs/PathologyDTO.java +++ b/src/main/java/eu/hbp/mip/models/DTOs/PathologyDTO.java @@ -1,43 +1,15 @@ package eu.hbp.mip.models.DTOs; import com.google.gson.annotations.SerializedName; +import lombok.Getter; +import lombok.Setter; import java.util.List; +@Getter +@Setter public class PathologyDTO { - public String getCode() { - return code; - } - - public void setCode(String code) { - this.code = code; - } - - public String getLabel() { - return label; - } - - public void setLabel(String label) { - this.label = label; - } - - public Object getMetadataHierarchy() { - return metadataHierarchy; - } - - public void setMetadataHierarchy(Object metadataHierarchy) { - this.metadataHierarchy = metadataHierarchy; - } - - public List<PathologyDatasetDTO> getDatasets() { - return datasets; - } - - public void setDatasets(List<PathologyDatasetDTO> datasets) { - this.datasets = datasets; - } - @SerializedName("code") private String code; @@ -50,6 +22,8 @@ public class PathologyDTO { @SerializedName("datasets") private List<PathologyDatasetDTO> datasets; + @Getter + @Setter public static class PathologyDatasetDTO { @SerializedName("code") private String code; @@ -57,22 +31,6 @@ public class PathologyDTO { @SerializedName("label") private String label; - public String getCode() { - return code; - } - - public void setCode(String code) { - this.code = code; - } - - public String getLabel() { - return label; - } - - public void setLabel(String label) { - this.label = label; - } - public String toString() { return code; } @@ -81,5 +39,4 @@ public class PathologyDTO { public String toString() { return code; } - } diff --git a/src/main/java/eu/hbp/mip/services/ActiveUserService.java b/src/main/java/eu/hbp/mip/services/ActiveUserService.java index ee65c170ad2b09ebe6d0e602b5af2316cbf82c48..bc3c8ced7fc3a573a8fe67bd87abaf1dcf19246c 100644 --- a/src/main/java/eu/hbp/mip/services/ActiveUserService.java +++ b/src/main/java/eu/hbp/mip/services/ActiveUserService.java @@ -4,15 +4,14 @@ import eu.hbp.mip.models.DAOs.UserDAO; import eu.hbp.mip.repositories.UserRepository; import org.keycloak.KeycloakPrincipal; import org.keycloak.representations.IDToken; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.ScopedProxyMode; -import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.stereotype.Component; import javax.inject.Named; +import java.util.Objects; @Component @Named("ActiveUserService") @@ -44,7 +43,7 @@ public class ActiveUserService { // If Authentication is OFF, create anonymous user with accepted NDA if (!authenticationIsEnabled) { - user = new UserDAO("anonymous", "anonymous", "anonymous@anonymous.com","anonymousId"); + user = new UserDAO("anonymous", "anonymous", "anonymous@anonymous.com", "anonymousId"); user.setAgreeNDA(true); userRepository.save(user); return user; @@ -57,9 +56,20 @@ public class ActiveUserService { user = new UserDAO(idToken.getPreferredUsername(), idToken.getName(), idToken.getEmail(), idToken.getId()); UserDAO userInDatabase = userRepository.findByUsername(user.getUsername()); - if (userInDatabase == null || !userInDatabase.equals(user)) { + if (userInDatabase == null) { userRepository.save(user); + return user; + } + + if (!Objects.equals(user.getEmail(),userInDatabase.getEmail()) + || !Objects.equals(user.getFullname(),userInDatabase.getFullname()) + ) { + userInDatabase.setFullname(user.getFullname()); + userInDatabase.setEmail(user.getEmail()); } + + user = userInDatabase; + userRepository.save(user); return user; } diff --git a/src/main/java/eu/hbp/mip/services/ExperimentService.java b/src/main/java/eu/hbp/mip/services/ExperimentService.java index 2bc16b0f9939df9c015e25fde52c562d496c1c03..1ef7c09d77e864c5199b60743d49a32a64887f32 100644 --- a/src/main/java/eu/hbp/mip/services/ExperimentService.java +++ b/src/main/java/eu/hbp/mip/services/ExperimentService.java @@ -10,6 +10,7 @@ import com.google.gson.Gson; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; +import com.google.gson.internal.LinkedTreeMap; import eu.hbp.mip.controllers.galaxy.retrofit.RetroFitGalaxyClients; import eu.hbp.mip.controllers.galaxy.retrofit.RetrofitClientInstance; import eu.hbp.mip.models.DAOs.ExperimentDAO; @@ -19,6 +20,7 @@ import eu.hbp.mip.models.DTOs.ExperimentDTO; import eu.hbp.mip.models.galaxy.GalaxyWorkflowResult; import eu.hbp.mip.models.galaxy.PostWorkflowToGalaxyDtoResponse; import eu.hbp.mip.repositories.ExperimentRepository; +import eu.hbp.mip.services.Specifications.ExperimentSpecifications; import eu.hbp.mip.utils.ClaimUtils; import eu.hbp.mip.utils.Exceptions.*; import eu.hbp.mip.utils.HTTPUtil; @@ -211,6 +213,14 @@ public class ExperimentService { //Checking if check (POST) /experiments has proper input. checkPostExperimentProperInput(experimentDTO, logger); + // Get the type and name of algorithm + String algorithmType = experimentDTO.getAlgorithm().getType(); + + if(algorithmType == "workflow"){ + logger.LogUserAction("You can not run workflow algorithms transiently."); + throw new BadRequestException("You can not run workflow algorithms transiently."); + } + // Get the parameters List<AlgorithmDTO.AlgorithmParamDTO> algorithmParameters = experimentDTO.getAlgorithm().getParameters(); @@ -236,7 +246,7 @@ public class ExperimentService { logger.LogUserAction("Experiment with uuid: " + experimentDTO.getUuid() + "gave response code: " + exaremeResult.getCode() + " and result: " + exaremeResult.getResults()); - experimentDTO.setResult((exaremeResult.getCode() >= 400) ? null : exaremeResult.getResults()); + experimentDTO.setResults((exaremeResult.getCode() >= 400) ? null : JsonConverters.convertJsonStringToObject(exaremeResult.getResults(), new ArrayList<ArrayList<Object>>().getClass())); experimentDTO.setStatus((exaremeResult.getCode() >= 400) ? ExperimentDAO.Status.error : ExperimentDAO.Status.success); return experimentDTO; @@ -244,10 +254,10 @@ public class ExperimentService { /** * The updateExperiment will update the experiment's properties - * * @param uuid is the id of the experiment to be updated * @param experimentDTO is the experiment information to be updated * @param logger contains username and the endpoint. + * @return */ public ExperimentDTO updateExperiment(String uuid, ExperimentDTO experimentDTO, Logger logger) { ExperimentDAO experimentDAO; @@ -321,7 +331,7 @@ public class ExperimentService { && experimentDTO.getViewed() == null && experimentDTO.getCreated() == null && experimentDTO.getCreatedBy() == null - && experimentDTO.getResult() == null + && experimentDTO.getResults() == null && experimentDTO.getStatus() == null && experimentDTO.getUuid() == null; @@ -362,7 +372,7 @@ public class ExperimentService { throw new BadRequestException("Finished is not editable."); } - if (experimentDTO.getResult() != null) { + if (experimentDTO.getResults() != null) { logger.LogUserAction( "Result is not editable."); throw new BadRequestException("Result is not editable."); } @@ -497,6 +507,50 @@ public class ExperimentService { } } + private String formattingExaremeResult(String result) { + List<LinkedTreeMap<String,Object>> jsonObject = JsonConverters.convertJsonStringToObject(result, new ArrayList<ExperimentDAO.ResultObjectDTO>().getClass()); + LinkedTreeMap<String,Object> firstResult = jsonObject.get(0); + return "[" + JsonConverters.convertObjectToJsonString(firstResult.get("result")) + "]"; + } + + private String formattingGalaxyResult(String result) { + List<LinkedTreeMap<String,Object>> jsonObjects = JsonConverters.convertJsonStringToObject(result, new ArrayList<ExperimentDAO.ResultObjectDTO>().getClass()); + List<Object> objects = new ArrayList<>(); + for (int i = 0; i < jsonObjects.size(); i++) { + LinkedTreeMap<String,Object> k = jsonObjects.get(i); + objects.add(k.get("result")); + } + return JsonConverters.convertObjectToJsonString(objects); + } + + + /** + * The runExaremeExperiment will run to exareme the experiment + * + * @param url is the url that contain the results of the experiment + * @param body is the parameters of the algorithm + * @param experimentDTO is the experiment information to be executed in the exareme + * @return the result of exareme as well as the http status that was retrieved + */ + private ExaremeResult runExaremeExperiment(String url, String body, ExperimentDTO experimentDTO) { + + StringBuilder results = new StringBuilder(); + int code; + try { + code = HTTPUtil.sendPost(url, body, results); + } catch (Exception e) { + throw new InternalServerError("Error occurred : " + e.getMessage()); + } + + String resultToMatchGalaxy = "[" + results + "]"; + String formattedResult = formattingExaremeResult(resultToMatchGalaxy); + Logger.LogExperimentAction(experimentDTO.getName(), experimentDTO.getUuid(), "Algorithm finished with code: " + code + "and result :" + formattedResult); + + return new ExaremeResult(code, formattedResult); + } + + + /* -------------------------------------- EXAREME CALLS ---------------------------------------------------------*/ /** @@ -539,7 +593,7 @@ public class ExperimentService { Logger.LogExperimentAction(experimentDAO.getName(), experimentDAO.getUuid(), "Experiment with uuid: " + experimentDAO.getUuid() + "gave response code: " + exaremeResult.getCode() + " and result: " + exaremeResult.getResults()); - experimentDAO.setResult((exaremeResult.getCode() >= 400) ? null : JsonConverters.convertObjectToJsonString(exaremeResult.getResults())); + experimentDAO.setResults((exaremeResult.getCode() >= 400) ? null : exaremeResult.getResults()); experimentDAO.setStatus((exaremeResult.getCode() >= 400) ? ExperimentDAO.Status.error : ExperimentDAO.Status.success); } catch (Exception e) { Logger.LogExperimentAction(experimentDAO.getName(), experimentDAO.getUuid(), "There was an exception: " + e.getMessage()); @@ -554,32 +608,6 @@ public class ExperimentService { return experimentDTO; } - /** - * The runExaremeExperiment will run to exareme the experiment - * - * @param url is the url that contain the results of the experiment - * @param body is the parameters of the algorithm - * @param experimentDTO is the experiment information to be executed in the exareme - * @return the result of exareme as well as the http status that was retrieved - */ - public ExaremeResult runExaremeExperiment(String url, String body, ExperimentDTO experimentDTO) { - - StringBuilder results = new StringBuilder(); - int code; - try { - code = HTTPUtil.sendPost(url, body, results); - } catch (Exception e) { - throw new InternalServerError("Error occurred : " + e.getMessage()); - } - Logger.LogExperimentAction(experimentDTO.getName(), experimentDTO.getUuid(), "Algorithm finished with code: " + code); - - // Results are stored in the experiment object - ExperimentDTO experimentDTOWithOnlyResult = JsonConverters.convertJsonStringToObject(String.valueOf(results), ExperimentDTO.class); - List<ExperimentDTO.ResultDTO> resultDTOS = experimentDTOWithOnlyResult.getResult(); - return new ExaremeResult(code, resultDTOS); - } - - /* --------------------------------------- GALAXY CALLS ---------------------------------------------------------*/ @@ -718,12 +746,12 @@ public class ExperimentService { Logger.LogExperimentAction(experimentDAO.getName(), experimentDAO.getUuid(), "State is: " + state); switch (state) { - case "running": + case "pending": // Do nothing, when the experiment is created the status is set to running Logger.LogExperimentAction(experimentDAO.getName(), experimentDAO.getUuid(), "Workflow is still running."); break; - case "completed": + case "success": // Get only the job result that is visible List<GalaxyWorkflowResult> workflowJobsResults = getWorkflowResults(experimentDAO); Logger.LogExperimentAction(experimentDAO.getName(), experimentDAO.getUuid(), "Results are: " + workflowJobsResults.toString()); @@ -739,7 +767,7 @@ public class ExperimentService { if (result == null) { experimentDAO.setStatus(ExperimentDAO.Status.error); } else { - experimentDAO.setResult(result); + experimentDAO.setResults(result); experimentDAO.setStatus(ExperimentDAO.Status.success); resultFound = true; } @@ -790,8 +818,8 @@ public class ExperimentService { } // If result exists return - if (experimentDAO.getResult() != null) { - Logger.LogExperimentAction(experimentDAO.getName(), experimentDAO.getUuid(), "ResultDTO exists: " + experimentDAO.getResult()); + if (experimentDAO.getResults() != null) { + Logger.LogExperimentAction(experimentDAO.getName(), experimentDAO.getUuid(), "ResultDTO exists: " + experimentDAO.getResults()); return; } } @@ -801,10 +829,10 @@ public class ExperimentService { /** * @param experimentDAO The experiment of the workflow - * @return "running" -> When the workflow is still running + * @return "pending" -> When the workflow is still running * "internalError" -> When an exception or a bad request occurred * "error" -> When the workflow produced an error - * "completed" -> When the workflow completed successfully + * "success" -> When the workflow completed successfully */ public String getWorkflowStatus(ExperimentDAO experimentDAO) { String historyId = experimentDAO.getWorkflowHistoryId(); @@ -846,14 +874,14 @@ public class ExperimentService { Logger.LogExperimentAction(experimentName, experimentId, " Completed!"); switch (state) { case "ok": - return "completed"; + return "success"; case "error": return "error"; - case "running": + case "pending": case "new": case "waiting": case "queued": - return "running"; + return "pending"; default: return "internalError"; } @@ -919,7 +947,8 @@ public class ExperimentService { + response.code() + "" + " with body: " + (response.errorBody() != null ? response.errorBody().string() : " ")); return null; } - resultJson = new Gson().toJson(response.body()); + + resultJson = gson.toJson(response.body()); Logger.LogExperimentAction(experimentName, experimentId, " ResultDTO: " + resultJson); } catch (IOException e) { @@ -928,8 +957,8 @@ public class ExperimentService { return null; } - Logger.LogExperimentAction(experimentName, experimentId, " Completed!"); - return resultJson; + + return formattingGalaxyResult(resultJson); } @@ -979,9 +1008,9 @@ public class ExperimentService { static class ExaremeResult { private int code; - private List<ExperimentDTO.ResultDTO> results; + private String results; - public ExaremeResult(int code, List<ExperimentDTO.ResultDTO> results) { + public ExaremeResult(int code, String results) { this.code = code; this.results = results; } @@ -990,7 +1019,7 @@ public class ExperimentService { return code; } - public List<ExperimentDTO.ResultDTO> getResults() { + public String getResults() { return results; } } diff --git a/src/main/java/eu/hbp/mip/services/ExperimentSpecifications.java b/src/main/java/eu/hbp/mip/services/Specifications/ExperimentSpecifications.java similarity index 99% rename from src/main/java/eu/hbp/mip/services/ExperimentSpecifications.java rename to src/main/java/eu/hbp/mip/services/Specifications/ExperimentSpecifications.java index e5b51a692e286be347901f7d50d9ab39e248ca8b..c1e6a13acae08d9ac2c516884773b5bf9b4c71b2 100644 --- a/src/main/java/eu/hbp/mip/services/ExperimentSpecifications.java +++ b/src/main/java/eu/hbp/mip/services/Specifications/ExperimentSpecifications.java @@ -1,4 +1,4 @@ -package eu.hbp.mip.services; +package eu.hbp.mip.services.Specifications; import eu.hbp.mip.models.DAOs.ExperimentDAO; import eu.hbp.mip.models.DAOs.UserDAO; diff --git a/src/main/java/eu/hbp/mip/utils/ClaimUtils.java b/src/main/java/eu/hbp/mip/utils/ClaimUtils.java index 902bf9f9fe677e39760e94553b27ff27a57c1c96..f5676b52c130f0b4be1c79d939567f74b752c0db 100644 --- a/src/main/java/eu/hbp/mip/utils/ClaimUtils.java +++ b/src/main/java/eu/hbp/mip/utils/ClaimUtils.java @@ -2,6 +2,7 @@ package eu.hbp.mip.utils; import com.google.gson.Gson; import eu.hbp.mip.models.DTOs.PathologyDTO; +import eu.hbp.mip.utils.Exceptions.InternalServerError; import eu.hbp.mip.utils.Exceptions.UnauthorizedException; import org.keycloak.KeycloakPrincipal; import org.keycloak.adapters.springsecurity.token.KeycloakAuthenticationToken; @@ -29,7 +30,7 @@ public class ClaimUtils { public static void validateAccessRightsOnDatasets(Authentication authentication, String experimentDatasets, Logger logger) { - ArrayList<String> authorities = getKeycloakAuthorities(authentication); + ArrayList<String> authorities = getKeycloakAuthorities(authentication, logger); // Don't check for dataset claims if "super" claim exists allowing everything if (!hasRoleAccess(authorities, ClaimUtils.allDatasetsAllowedClaim(), logger)) { @@ -47,7 +48,7 @@ public class ClaimUtils { public static boolean validateAccessRightsOnExperiments(Authentication authentication, Logger logger) { - ArrayList<String> authorities = getKeycloakAuthorities(authentication); + ArrayList<String> authorities = getKeycloakAuthorities(authentication, logger); // Check for experiment_all claims return hasRoleAccess(authorities, ClaimUtils.allExperimentsAllowedClaim(), logger); @@ -58,7 +59,7 @@ public class ClaimUtils { // --- Providing only the allowed pathologies/datasets to the user --- logger.LogUserAction("Filter out the unauthorised datasets."); - ArrayList<String> authorities = getKeycloakAuthorities(authentication); + ArrayList<String> authorities = getKeycloakAuthorities(authentication, logger); // If the "dataset_all" claim exists then return everything if (hasRoleAccess(authorities, ClaimUtils.allDatasetsAllowedClaim(), logger)) { @@ -100,9 +101,15 @@ public class ClaimUtils { return userClaims.contains(role.toLowerCase()); } - private static ArrayList<String> getKeycloakAuthorities(Authentication authentication){ + private static ArrayList<String> getKeycloakAuthorities(Authentication authentication, Logger logger){ KeycloakAuthenticationToken token = (KeycloakAuthenticationToken) authentication; KeycloakPrincipal keycloakPrincipal = (KeycloakPrincipal) token.getPrincipal(); - return (ArrayList<String>)keycloakPrincipal.getKeycloakSecurityContext().getIdToken().getOtherClaims().get("authorities"); + if(keycloakPrincipal.getKeycloakSecurityContext().getIdToken().getOtherClaims().get("authorities") == null) + { + logger.LogUserAction("Your user has no roles."); + throw new InternalServerError("Your user has no roles."); + } + + return (ArrayList<String>)keycloakPrincipal.getKeycloakSecurityContext().getIdToken().getOtherClaims().get("authorities"); } } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index e77b803581f635159456a423b177b91a4ba2bcf0..58ecf45e12c926af36b3019a8e5d457cbf98f077 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -11,7 +11,7 @@ logging: ### AUTHENTICATION ### authentication: - enabled: true + enabled: false ### DATABASE CONFIGURATION ### @@ -48,14 +48,13 @@ services: ### KEYCLOAK ### keycloak: enabled: true - auth-server-url: "http://127.0.0.1/auth" + auth-server-url: "https://iam.humanbrainproject.eu/auth" realm: "MIP" - resource: "MIP" + resource: "mipfedqa" enable-basic-auth: true credentials: - secret: "dae83a6b-c769-4186-8383-f0984c6edf05" + secret: "492ddb7d-a7c6-4143-89ae-dbfa6f970aca" principal-attribute: "preferred_username" - ssl-required: none ### EXTERNAL FILES ### diff --git a/src/main/resources/db/migration/V7_0__NewDatabaseStructure.sql b/src/main/resources/db/migration/V7_0__NewDatabaseStructure.sql index c39158269bd59362cfd010913c33f17a03e1a4ce..6a3b0c364b2fed6a6456d7eae8a971b9cab7add2 100644 --- a/src/main/resources/db/migration/V7_0__NewDatabaseStructure.sql +++ b/src/main/resources/db/migration/V7_0__NewDatabaseStructure.sql @@ -26,8 +26,8 @@ DROP COLUMN hasservererror, DROP COLUMN validations, DROP COLUMN model_slug; -UPDATE experiment -SET algorithms = REPLACE(algorithms, '"name"', '"id"'); +ALTER TABLE experiment +RENAME result TO results; ALTER TABLE experiment RENAME algorithms TO algorithm; ALTER TABLE experiment @@ -45,7 +45,7 @@ ALTER TABLE experiment ADD COLUMN algorithmId text; UPDATE experiment -SET algorithmId = (algorithm ->> 'id'); +SET algorithmId = (algorithm ->> 'name'); ALTER TABLE experiment ALTER COLUMN algorithm TYPE text;