From 4b9b189016dbdeb3b9897bed42ec3bdba989a19c Mon Sep 17 00:00:00 2001 From: mposolda Date: Tue, 25 Sep 2018 21:59:24 +0200 Subject: [PATCH] KEYCLOAK-8008 Ensure InputStream are closed --- .../AuthorizationEndpointRequestParserProcessor.java | 7 ++++--- .../org/keycloak/protocol/oidc/utils/JWKSHttpUtils.java | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/services/src/main/java/org/keycloak/protocol/oidc/endpoints/request/AuthorizationEndpointRequestParserProcessor.java b/services/src/main/java/org/keycloak/protocol/oidc/endpoints/request/AuthorizationEndpointRequestParserProcessor.java index 7b2e058639..74ec64257c 100644 --- a/services/src/main/java/org/keycloak/protocol/oidc/endpoints/request/AuthorizationEndpointRequestParserProcessor.java +++ b/services/src/main/java/org/keycloak/protocol/oidc/endpoints/request/AuthorizationEndpointRequestParserProcessor.java @@ -68,10 +68,11 @@ public class AuthorizationEndpointRequestParserProcessor { if (requestParam != null) { new AuthzEndpointRequestObjectParser(session, requestParam, client).parseRequest(request); } else if (requestUriParam != null) { - InputStream is = session.getProvider(HttpClientProvider.class).get(requestUriParam); - String retrievedRequest = StreamUtil.readString(is); + try (InputStream is = session.getProvider(HttpClientProvider.class).get(requestUriParam)) { + String retrievedRequest = StreamUtil.readString(is); - new AuthzEndpointRequestObjectParser(session, retrievedRequest, client).parseRequest(request); + new AuthzEndpointRequestObjectParser(session, retrievedRequest, client).parseRequest(request); + } } return request; diff --git a/services/src/main/java/org/keycloak/protocol/oidc/utils/JWKSHttpUtils.java b/services/src/main/java/org/keycloak/protocol/oidc/utils/JWKSHttpUtils.java index 8d1e4d641c..803ddcabf3 100644 --- a/services/src/main/java/org/keycloak/protocol/oidc/utils/JWKSHttpUtils.java +++ b/services/src/main/java/org/keycloak/protocol/oidc/utils/JWKSHttpUtils.java @@ -36,8 +36,9 @@ import java.security.PublicKey; public class JWKSHttpUtils { public static JSONWebKeySet sendJwksRequest(KeycloakSession session, String jwksURI) throws IOException { - InputStream is = session.getProvider(HttpClientProvider.class).get(jwksURI); - String keySetString = StreamUtil.readString(is); - return JsonSerialization.readValue(keySetString, JSONWebKeySet.class); + try (InputStream is = session.getProvider(HttpClientProvider.class).get(jwksURI)){ + String keySetString = StreamUtil.readString(is); + return JsonSerialization.readValue(keySetString, JSONWebKeySet.class); + } } }