Repository: airavata Updated Branches: refs/heads/develop 7d97f7340 -> 269d2aeb7
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/269d2aeb Tree: http://git-wip-us.apache.org/repos/asf/airavata/tree/269d2aeb Diff: http://git-wip-us.apache.org/repos/asf/airavata/diff/269d2aeb Branch: refs/heads/develop Commit: 269d2aeb7923d9edb4f6666bf80a1cc49c398d21 Parents: 7d97f73 Author: Marcus Christie <[email protected]> Authored: Tue May 2 11:55:02 2017 -0400 Committer: Marcus Christie <[email protected]> Committed: Tue May 2 12:02:04 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/269d2aeb/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();
