Repository: airavata
Updated Branches:
  refs/heads/keycloak-deployment eca907e82 -> 2da77d28c


AIRAVATA-2371 KeyCloakSecurityManager: getting token endpoint for realm


Project: http://git-wip-us.apache.org/repos/asf/airavata/repo
Commit: http://git-wip-us.apache.org/repos/asf/airavata/commit/2da77d28
Tree: http://git-wip-us.apache.org/repos/asf/airavata/tree/2da77d28
Diff: http://git-wip-us.apache.org/repos/asf/airavata/diff/2da77d28

Branch: refs/heads/keycloak-deployment
Commit: 2da77d28c56074d0be58172bc72d0ad02efe891f
Parents: eca907e
Author: Marcus Christie <[email protected]>
Authored: Tue May 2 11:55:02 2017 -0400
Committer: Marcus Christie <[email protected]>
Committed: Tue May 2 11:55:02 2017 -0400

----------------------------------------------------------------------
 .../api/server/security/KeyCloakSecurityManager.java   | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/airavata/blob/2da77d28/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/security/KeyCloakSecurityManager.java
----------------------------------------------------------------------
diff --git 
a/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/security/KeyCloakSecurityManager.java
 
b/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/security/KeyCloakSecurityManager.java
index 43cd696..892a1b4 100644
--- 
a/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/security/KeyCloakSecurityManager.java
+++ 
b/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/security/KeyCloakSecurityManager.java
@@ -214,8 +214,10 @@ public class KeyCloakSecurityManager implements 
AiravataSecurityManager {
         URL url = new URL(urlToRead);
         HttpURLConnection conn = (HttpURLConnection) url.openConnection();
         conn.setRequestMethod("GET");
-        String bearerAuth = "Bearer " + token;
-        conn.setRequestProperty("Authorization", bearerAuth);
+        if (token != null) {
+            String bearerAuth = "Bearer " + token;
+            conn.setRequestProperty("Authorization", bearerAuth);
+        }
         BufferedReader rd = new BufferedReader(new 
InputStreamReader(conn.getInputStream()));
         String line;
         while ((line = rd.readLine()) != null) {
@@ -225,13 +227,16 @@ public class KeyCloakSecurityManager implements 
AiravataSecurityManager {
         return result.toString();
     }
 
-    private String getAdminAccessToken(String gatewayId) throws TException, 
ApplicationSettingsException, IOException {
+    private String getAdminAccessToken(String gatewayId) throws Exception {
         CredentialStoreService.Client csClient = 
getCredentialStoreServiceClient();
         GatewayResourceProfile gwrp = 
getRegistryServiceClient().getGatewayResourceProfile(gatewayId);
+        String identityServerRealm = gwrp.getIdentityServerTenant();
+        String openIdConnectUrl = 
getOpenIDConfigurationUrl(identityServerRealm);
+        JSONObject openIdConnectConfig = new 
JSONObject(getFromUrl(openIdConnectUrl, null));
         PasswordCredential credential = 
csClient.getPasswordCredential(gwrp.getIdentityServerPwdCredToken(), 
gwrp.getGatewayID());
         String username = credential.getLoginUserName();
         String password = credential.getPassword();
-        String urlString = ServerSettings.getRemoteIDPServiceUrl() + 
"/realms/master/protocol/openid-connect/token";
+        String urlString = openIdConnectConfig.getString("token_endpoint");
         StringBuilder result = new StringBuilder();
         URL url = new URL(urlString);
         HttpURLConnection conn = (HttpURLConnection) url.openConnection();

Reply via email to