From 2719875aa539988c83befd95271d88dd49408518 Mon Sep 17 00:00:00 2001 From: Sergey Beryozkin Date: Tue, 15 Jun 2021 18:13:04 +0100 Subject: [PATCH] Update OidcClientImpl to throw ISE if the client is closed --- .../oidc/client/runtime/OidcClientImpl.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/extensions/oidc-client/runtime/src/main/java/io/quarkus/oidc/client/runtime/OidcClientImpl.java b/extensions/oidc-client/runtime/src/main/java/io/quarkus/oidc/client/runtime/OidcClientImpl.java index cbeeb1f177009..de8fa0f2ec87f 100644 --- a/extensions/oidc-client/runtime/src/main/java/io/quarkus/oidc/client/runtime/OidcClientImpl.java +++ b/extensions/oidc-client/runtime/src/main/java/io/quarkus/oidc/client/runtime/OidcClientImpl.java @@ -42,6 +42,7 @@ public class OidcClientImpl implements OidcClient { private final String clientSecretBasicAuthScheme; private final Key clientJwtKey; private final OidcClientConfig oidcConfig; + private volatile boolean closed; public OidcClientImpl(WebClient client, String tokenRequestUri, String grantType, MultiMap tokenGrantParams, MultiMap commonRefreshGrantParams, OidcClientConfig oidcClientConfig) { @@ -57,6 +58,7 @@ public OidcClientImpl(WebClient client, String tokenRequestUri, String grantType @Override public Uni getTokens(Map additionalGrantParameters) { + checkClosed(); if (tokenGrantParams == null) { throw new OidcClientException( "Only 'refresh_token' grant is supported, please call OidcClient#refreshTokens method instead"); @@ -66,6 +68,7 @@ public Uni getTokens(Map additionalGrantParameters) { @Override public Uni refreshTokens(String refreshToken) { + checkClosed(); if (refreshToken == null) { throw new OidcClientException("Refresh token is null"); } @@ -169,6 +172,15 @@ private static MultiMap copyMultiMap(MultiMap oldMap) { @Override public void close() throws IOException { - client.close(); + if (!closed) { + client.close(); + closed = true; + } + } + + private void checkClosed() { + if (closed) { + throw new IllegalStateException("OidcClient " + oidcConfig.getId().get() + " is closed"); + } } }