From 25fff8468b5b0382f775aba1cd68844b6c493c6b Mon Sep 17 00:00:00 2001
From: Manuel Spuhler <manuel.spuhler@chuv.ch>
Date: Wed, 30 Oct 2019 19:23:22 +0100
Subject: [PATCH] Reworked Galaxy config

---
 docker/config/application.tmpl                |  1 +
 .../eu/hbp/mip/controllers/SecurityApi.java   | 17 +++++++++++----
 .../eu/hbp/mip/model/StringDtoResponse.java   | 21 -------------------
 3 files changed, 14 insertions(+), 25 deletions(-)
 delete mode 100644 src/main/java/eu/hbp/mip/model/StringDtoResponse.java

diff --git a/docker/config/application.tmpl b/docker/config/application.tmpl
index 3321fea84..e3a624a13 100644
--- a/docker/config/application.tmpl
+++ b/docker/config/application.tmpl
@@ -85,4 +85,5 @@ services:
   galaxy:
     galaxyUsername:  {{ default .Env.GALAXY_USERNAME "admin" }}
     galaxyPassword:  {{ default .Env.GALAXY_PASSWORD "password" }}
+    galaxyContext:  {{ default .Env.GALAXY_CONTEXT "nativeGalaxy" }}
 
diff --git a/src/main/java/eu/hbp/mip/controllers/SecurityApi.java b/src/main/java/eu/hbp/mip/controllers/SecurityApi.java
index f949f16ac..1f073a270 100644
--- a/src/main/java/eu/hbp/mip/controllers/SecurityApi.java
+++ b/src/main/java/eu/hbp/mip/controllers/SecurityApi.java
@@ -3,11 +3,11 @@ package eu.hbp.mip.controllers;
 import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.google.gson.Gson;
+import com.google.gson.JsonObject;
 import eu.hbp.mip.configuration.SecurityConfiguration;
 import org.springframework.beans.factory.annotation.Value;
 import eu.hbp.mip.model.User;
 import eu.hbp.mip.model.UserInfo;
-import eu.hbp.mip.model.StringDtoResponse;
 import eu.hbp.mip.repositories.UserRepository;
 import io.swagger.annotations.ApiParam;
 import org.slf4j.Logger;
@@ -31,6 +31,8 @@ public class SecurityApi {
 
     private static final Logger LOGGER = LoggerFactory.getLogger(SecurityApi.class);
 
+    private static final Gson gson = new Gson();
+
     @Autowired
     private UserInfo userInfo;
 
@@ -90,17 +92,24 @@ public class SecurityApi {
     @Value("#{'${services.galaxy.galaxyPassword:password}'}")
     private String galaxyPassword;
 
+    @Value("#{'${services.galaxy.galaxyContext:nativeGalaxy}'}")
+    private String galaxyContext;
+
     /**
      * Get Galaxy Reverse Proxy basic access token.
      *
      * @return Return a @{@link ResponseEntity} with the token.
      */
 
-    @RequestMapping(path = "/galaxy/token", method = RequestMethod.GET, produces = "application/json")
+    @RequestMapping(path = "/galaxy", method = RequestMethod.GET, produces = "application/json")
     @ResponseStatus(value = HttpStatus.OK)
-    public ResponseEntity getGalaxyBasicAccessToken(){
+    public ResponseEntity getGalaxyConfiguration(){
         String stringEncoded = Base64.getEncoder().encodeToString((galaxyUsername + ":" + galaxyPassword).getBytes());
-        return ResponseEntity.ok(new StringDtoResponse(stringEncoded));
+        JsonObject object = new JsonObject();
+        object.addProperty("authorization", "Basic " + stringEncoded);
+        object.addProperty("context", galaxyContext);
+
+        return ResponseEntity.ok(gson.toJson(object));
     }
 
 }
diff --git a/src/main/java/eu/hbp/mip/model/StringDtoResponse.java b/src/main/java/eu/hbp/mip/model/StringDtoResponse.java
deleted file mode 100644
index 272174d69..000000000
--- a/src/main/java/eu/hbp/mip/model/StringDtoResponse.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package eu.hbp.mip.model;
-
-public class StringDtoResponse {
-
-    private String response;
-
-    public StringDtoResponse() {
-    }
-
-    public StringDtoResponse(String response) {
-        this.response = response;
-    }
-
-    public String getResponse() {
-        return response;
-    }
-
-    public void setResponse(String response) {
-        this.response = response;
-    }
-}
-- 
GitLab