Skip to content

Commit

Permalink
Update OidcClientImpl to throw ISE if the client is closed
Browse files Browse the repository at this point in the history
  • Loading branch information
sberyozkin committed Jun 16, 2021
1 parent b52a14b commit 2719875
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -57,6 +58,7 @@ public OidcClientImpl(WebClient client, String tokenRequestUri, String grantType

@Override
public Uni<Tokens> getTokens(Map<String, String> additionalGrantParameters) {
checkClosed();
if (tokenGrantParams == null) {
throw new OidcClientException(
"Only 'refresh_token' grant is supported, please call OidcClient#refreshTokens method instead");
Expand All @@ -66,6 +68,7 @@ public Uni<Tokens> getTokens(Map<String, String> additionalGrantParameters) {

@Override
public Uni<Tokens> refreshTokens(String refreshToken) {
checkClosed();
if (refreshToken == null) {
throw new OidcClientException("Refresh token is null");
}
Expand Down Expand Up @@ -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");
}
}
}

0 comments on commit 2719875

Please sign in to comment.