Skip to content

Commit bf43d37

Browse files
authored
Add new configuration item: azure.activedirectory.jwk-set-cache-refresh-time
1 parent 9215dcc commit bf43d37

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

sdk/spring/azure-spring-boot/src/main/java/com/azure/spring/autoconfigure/aad/AADAuthenticationFilterAutoConfiguration.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ public ResourceRetriever getJWTResourceRetriever() {
109109
@ConditionalOnMissingBean(JWKSetCache.class)
110110
public JWKSetCache getJWKSetCache() {
111111
long lifespan = aadAuthenticationProperties.getJwkSetCacheLifespan();
112-
return new DefaultJWKSetCache(lifespan, lifespan, TimeUnit.MILLISECONDS);
112+
long refreshTime = aadAuthenticationProperties.getJwkSetCacheRefreshTime();
113+
return new DefaultJWKSetCache(lifespan, refreshTime, TimeUnit.MILLISECONDS);
113114
}
114115

115116
@PostConstruct

sdk/spring/azure-spring-boot/src/main/java/com/azure/spring/autoconfigure/aad/AADAuthenticationProperties.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public class AADAuthenticationProperties {
3333
private static final Logger LOGGER = LoggerFactory.getLogger(AADAuthenticationProperties.class);
3434
private static final String DEFAULT_SERVICE_ENVIRONMENT = "global";
3535
private static final long DEFAULT_JWK_SET_CACHE_LIFESPAN = TimeUnit.MINUTES.toMillis(5);
36+
private static final long DEFAULT_JWK_SET_CACHE_REFRESH_TIME = DEFAULT_JWK_SET_CACHE_LIFESPAN;
3637
private static final String GROUP_RELATIONSHIP_DIRECT = "direct";
3738
private static final String GROUP_RELATIONSHIP_TRANSITIVE = "transitive";
3839

@@ -101,6 +102,11 @@ public class AADAuthenticationProperties {
101102
*/
102103
private long jwkSetCacheLifespan = DEFAULT_JWK_SET_CACHE_LIFESPAN;
103104

105+
/**
106+
* The refresh time of the cached JWK set before it expires, default is 5 minutes.
107+
*/
108+
private long jwkSetCacheRefreshTime = DEFAULT_JWK_SET_CACHE_REFRESH_TIME;
109+
104110
/**
105111
* Azure Tenant ID.
106112
*/
@@ -388,6 +394,14 @@ public void setJwkSetCacheLifespan(long jwkSetCacheLifespan) {
388394
this.jwkSetCacheLifespan = jwkSetCacheLifespan;
389395
}
390396

397+
public long getJwkSetCacheRefreshTime() {
398+
return jwkSetCacheRefreshTime;
399+
}
400+
401+
public void setJwkSetCacheRefreshTime(long jwkSetCacheRefreshTime) {
402+
this.jwkSetCacheRefreshTime = jwkSetCacheRefreshTime;
403+
}
404+
391405
public String getTenantId() {
392406
return tenantId;
393407
}

0 commit comments

Comments
 (0)