From 0995bc0d7f8e5a910d8ccedd7e1867b3da501fe3 Mon Sep 17 00:00:00 2001 From: SravanThotakura05 <83568543+SravanThotakura05@users.noreply.github.com> Date: Tue, 14 May 2024 17:56:07 +0530 Subject: [PATCH] Added token refresh api timeout to avoid buffer overflow of requests. --- docs/modules/ROOT/pages/index.adoc | 2 ++ .../java/com/solace/quarkus/runtime/OidcProvider.java | 9 +++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/docs/modules/ROOT/pages/index.adoc b/docs/modules/ROOT/pages/index.adoc index c4f59fa..f224e78 100644 --- a/docs/modules/ROOT/pages/index.adoc +++ b/docs/modules/ROOT/pages/index.adoc @@ -123,6 +123,7 @@ quarkus.solace.vpn=default quarkus.solace.authentication.scheme=AUTHENTICATION_SCHEME_OAUTH2 quarkus.solace.oidc.client-name=solace // client name provided in oidc client config below quarkus.solace.oidc.refresh.interval=50s // Refresh interval should be less than access token expiry time. Otherwise extension will fail to update access token in solace session. +quarkus.solace.oidc.refresh.timeout=10s // Token Refresh API timeout. Default is set to 10 seconds. quarkus.oidc-client.solace.auth-server-url=http://localhost:7777/auth/realms/master quarkus.oidc-client.solace.client-id= @@ -142,6 +143,7 @@ quarkus.solace.tls.trust-store-type= quarkus.solace.tls.trust-store-password= quarkus.solace.oidc.client-name=solace // client name provided in oidc client config below quarkus.solace.oidc.refresh.interval=50s // Refresh interval should be less than access token expiry time. Otherwise extension will fail to update access token in solace session. +quarkus.solace.oidc.refresh.timeout=10s // Token Refresh API timeout. Default is set to 10 seconds. quarkus.oidc-client.solace.auth-server-url=http://localhost:7777/auth/realms/master quarkus.oidc-client.solace.client-id= diff --git a/quarkus-solace-client/runtime/src/main/java/com/solace/quarkus/runtime/OidcProvider.java b/quarkus-solace-client/runtime/src/main/java/com/solace/quarkus/runtime/OidcProvider.java index 34ea8f8..2bd369d 100644 --- a/quarkus-solace-client/runtime/src/main/java/com/solace/quarkus/runtime/OidcProvider.java +++ b/quarkus-solace-client/runtime/src/main/java/com/solace/quarkus/runtime/OidcProvider.java @@ -25,6 +25,9 @@ public class OidcProvider { @ConfigProperty(name = "quarkus.solace.oidc.refresh.interval", defaultValue = "60s") Duration duration; + @ConfigProperty(name = "quarkus.solace.oidc.refresh.timeout", defaultValue = "10s") + Duration refreshTimeout; + @ConfigProperty(name = "quarkus.solace.oidc.client-name") Optional oidcClientName; @@ -43,15 +46,17 @@ Tokens getToken() { void init(MessagingService service) { OidcClient client = getClient(); Multi.createFrom().ticks().every(duration) + .onOverflow().drop() .emitOn(Infrastructure.getDefaultWorkerPool()) .call(() -> { if (lastToken != null && lastToken.getRefreshToken() != null && lastToken.isAccessTokenWithinRefreshInterval()) { Log.info("Refreshing access token for Solace connection"); - return client.refreshTokens(lastToken.getRefreshToken()).invoke(tokens -> lastToken = tokens); + return client.refreshTokens(lastToken.getRefreshToken()).invoke(tokens -> lastToken = tokens).ifNoItem() + .after(refreshTimeout).fail(); } else { Log.info("Acquiring access token for Solace connection"); - return client.getTokens().invoke(tokens -> lastToken = tokens); + return client.getTokens().invoke(tokens -> lastToken = tokens).ifNoItem().after(refreshTimeout).fail(); } }) .onFailure().call(t -> {