From bf43d379b41fcc37af3dd2f6dc88eceb7bf9acc9 Mon Sep 17 00:00:00 2001 From: Jack Lu Date: Tue, 17 Nov 2020 07:21:39 +0800 Subject: [PATCH] fixes #17567 (#17588) Add new configuration item: azure.activedirectory.jwk-set-cache-refresh-time --- .../AADAuthenticationFilterAutoConfiguration.java | 3 ++- .../aad/AADAuthenticationProperties.java | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/sdk/spring/azure-spring-boot/src/main/java/com/azure/spring/autoconfigure/aad/AADAuthenticationFilterAutoConfiguration.java b/sdk/spring/azure-spring-boot/src/main/java/com/azure/spring/autoconfigure/aad/AADAuthenticationFilterAutoConfiguration.java index 1bc4c26626f27..05489f4fd1f9d 100644 --- a/sdk/spring/azure-spring-boot/src/main/java/com/azure/spring/autoconfigure/aad/AADAuthenticationFilterAutoConfiguration.java +++ b/sdk/spring/azure-spring-boot/src/main/java/com/azure/spring/autoconfigure/aad/AADAuthenticationFilterAutoConfiguration.java @@ -109,7 +109,8 @@ public ResourceRetriever getJWTResourceRetriever() { @ConditionalOnMissingBean(JWKSetCache.class) public JWKSetCache getJWKSetCache() { long lifespan = aadAuthenticationProperties.getJwkSetCacheLifespan(); - return new DefaultJWKSetCache(lifespan, lifespan, TimeUnit.MILLISECONDS); + long refreshTime = aadAuthenticationProperties.getJwkSetCacheRefreshTime(); + return new DefaultJWKSetCache(lifespan, refreshTime, TimeUnit.MILLISECONDS); } @PostConstruct diff --git a/sdk/spring/azure-spring-boot/src/main/java/com/azure/spring/autoconfigure/aad/AADAuthenticationProperties.java b/sdk/spring/azure-spring-boot/src/main/java/com/azure/spring/autoconfigure/aad/AADAuthenticationProperties.java index f1dbcd56948f4..bb3e5d32070e1 100644 --- a/sdk/spring/azure-spring-boot/src/main/java/com/azure/spring/autoconfigure/aad/AADAuthenticationProperties.java +++ b/sdk/spring/azure-spring-boot/src/main/java/com/azure/spring/autoconfigure/aad/AADAuthenticationProperties.java @@ -33,6 +33,7 @@ public class AADAuthenticationProperties { private static final Logger LOGGER = LoggerFactory.getLogger(AADAuthenticationProperties.class); private static final String DEFAULT_SERVICE_ENVIRONMENT = "global"; private static final long DEFAULT_JWK_SET_CACHE_LIFESPAN = TimeUnit.MINUTES.toMillis(5); + private static final long DEFAULT_JWK_SET_CACHE_REFRESH_TIME = DEFAULT_JWK_SET_CACHE_LIFESPAN; private static final String GROUP_RELATIONSHIP_DIRECT = "direct"; private static final String GROUP_RELATIONSHIP_TRANSITIVE = "transitive"; @@ -101,6 +102,11 @@ public class AADAuthenticationProperties { */ private long jwkSetCacheLifespan = DEFAULT_JWK_SET_CACHE_LIFESPAN; + /** + * The refresh time of the cached JWK set before it expires, default is 5 minutes. + */ + private long jwkSetCacheRefreshTime = DEFAULT_JWK_SET_CACHE_REFRESH_TIME; + /** * Azure Tenant ID. */ @@ -388,6 +394,14 @@ public void setJwkSetCacheLifespan(long jwkSetCacheLifespan) { this.jwkSetCacheLifespan = jwkSetCacheLifespan; } + public long getJwkSetCacheRefreshTime() { + return jwkSetCacheRefreshTime; + } + + public void setJwkSetCacheRefreshTime(long jwkSetCacheRefreshTime) { + this.jwkSetCacheRefreshTime = jwkSetCacheRefreshTime; + } + public String getTenantId() { return tenantId; }