diff --git a/adapters/oidc/adapter-core/src/main/java/org/keycloak/adapters/KeycloakDeployment.java b/adapters/oidc/adapter-core/src/main/java/org/keycloak/adapters/KeycloakDeployment.java index 0127decdb6..873e595090 100755 --- a/adapters/oidc/adapter-core/src/main/java/org/keycloak/adapters/KeycloakDeployment.java +++ b/adapters/oidc/adapter-core/src/main/java/org/keycloak/adapters/KeycloakDeployment.java @@ -20,6 +20,7 @@ package org.keycloak.adapters; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; +import org.apache.http.util.EntityUtils; import org.jboss.logging.Logger; import org.keycloak.adapters.authentication.ClientCredentialsProvider; import org.keycloak.adapters.authorization.PolicyEnforcer; @@ -216,12 +217,16 @@ public class KeycloakDeployment { HttpGet request = new HttpGet(discoveryUrl); request.addHeader("accept", "application/json"); - HttpResponse response = getClient().execute(request); - if (response.getStatusLine().getStatusCode() != 200) { - throw new Exception(response.getStatusLine().getReasonPhrase()); + try { + HttpResponse response = getClient().execute(request); + if (response.getStatusLine().getStatusCode() != 200) { + EntityUtils.consumeQuietly(response.getEntity()); + throw new Exception(response.getStatusLine().getReasonPhrase()); + } + return JsonSerialization.readValue(response.getEntity().getContent(), OIDCConfigurationRepresentation.class); + } finally { + request.releaseConnection(); } - - return JsonSerialization.readValue(response.getEntity().getContent(), OIDCConfigurationRepresentation.class); } public RelativeUrlsUsed getRelativeUrls() {