[java-oidc-common] branch main updated: JCOMOIDC-80 - RemoteJwkUtils HTTP resource leak

Henri Mikkonen henri.mikkonen at iki.fi
Tue Aug 29 13:11:32 UTC 2023


This is an automated email from the git hooks/post-receive script.

hjmikkon pushed a commit to branch main
in repository java-oidc-common.

View the commit online:
http://git.shibboleth.net/view/?p=java-oidc-common.git;a=commit;h=42b614a1b77830f58fc682e790ec26ca6973ec5f

The following commit(s) were added to refs/heads/main by this push:
     new 42b614a  JCOMOIDC-80 - RemoteJwkUtils HTTP resource leak
42b614a is described below

commit 42b614a1b77830f58fc682e790ec26ca6973ec5f
Author: Henri Mikkonen <henri.mikkonen at iki.fi>
AuthorDate: Tue Aug 29 16:10:58 2023 +0300

    JCOMOIDC-80 - RemoteJwkUtils HTTP resource leak
    
    https://shibboleth.atlassian.net/browse/JCOMOIDC-80
---
 .../oidc/jwk/support/RemoteJwkUtils.java           | 37 ++++++++++------------
 1 file changed, 16 insertions(+), 21 deletions(-)

diff --git a/oidc-common-crypto-api/src/main/java/net/shibboleth/oidc/jwk/support/RemoteJwkUtils.java b/oidc-common-crypto-api/src/main/java/net/shibboleth/oidc/jwk/support/RemoteJwkUtils.java
index 14e0eae..2ab74c9 100644
--- a/oidc-common-crypto-api/src/main/java/net/shibboleth/oidc/jwk/support/RemoteJwkUtils.java
+++ b/oidc-common-crypto-api/src/main/java/net/shibboleth/oidc/jwk/support/RemoteJwkUtils.java
@@ -59,35 +59,30 @@ public final class RemoteJwkUtils {
     public static JWKSet fetchRemoteJwkSet(final String logPrefix, final URI uri, final HttpClient httpClient, 
             final HttpClientSecurityParameters httpClientSecurityParameters) {
         final Logger log = LoggerFactory.getLogger(RemoteJwkUtils.class);
-        final ClassicHttpResponse response;
-        try {
-            final ClassicHttpRequest get = ClassicRequestBuilder.get().setUri(uri).build();
-            final HttpClientContext clientContext = HttpClientContext.create();
-            HttpClientSecuritySupport.marshalSecurityParameters(clientContext, httpClientSecurityParameters, true);
-            HttpClientSecuritySupport.addDefaultTLSTrustEngineCriteria(clientContext, get);
-            response = httpClient.executeOpen(null, get, clientContext);
+        final ClassicHttpRequest get = ClassicRequestBuilder.get().setUri(uri).build();
+        final HttpClientContext clientContext = HttpClientContext.create();
+        HttpClientSecuritySupport.marshalSecurityParameters(clientContext, httpClientSecurityParameters, true);
+        HttpClientSecuritySupport.addDefaultTLSTrustEngineCriteria(clientContext, get);
+        final String output;
+        try (final ClassicHttpResponse response = httpClient.executeOpen(null, get, clientContext)) {
             HttpClientSecuritySupport.checkTLSCredentialEvaluated(clientContext, get.getUri().getScheme());
-        } catch (final IOException e) {
-            log.error("{} Could not get the JWK contents from {}", logPrefix, uri, e);
+            if (response == null) {
+                log.error("{} Could not get the JWK contents from {}", logPrefix, uri);
+                return null;
+            }
+            output = EntityUtils.toString(response.getEntity(), "UTF-8");
+        } catch (final ParseException | IOException e) {
+            log.error("{} Could not parse the JWK contents from {}", logPrefix, uri);
             return null;
         } catch (final URISyntaxException e) {
             log.error("{} Could not build request URI from {}", logPrefix, uri, e);
             return null;
 		}
-        if (response == null) {
-            log.error("{} Could not get the JWK contents from {}", logPrefix, uri);
-            return null;
-        }
-        final String output;
-        try {
-            output = EntityUtils.toString(response.getEntity(), "UTF-8");
-        } catch (final ParseException | IOException e) {
-            log.error("{} Could not parse the JWK contents from {}", logPrefix, uri);
+        log.trace("{} Fetched the following response body: {}", logPrefix, output);
+        if (output == null) {
+            log.trace("{} Empty response body contents from {}", logPrefix, uri);
             return null;
-        } finally {
-            EntityUtils.consumeQuietly(response.getEntity());
         }
-        log.trace("{} Fetched the following response body: {}", logPrefix, output);
         final JWKSet jwkSet;
         try {
             final Map<String, Object> json = JSONObjectUtils.parse(output);

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list