Cache the content of jwkSetUri in OidcIdTokenDecoderFactory

Viewed 25

I want to cache the content of jwkSetUri, and found it would be feasible to change the private function buildDecoder in OidcIdTokenDecoderFactory like the following.

private CachedNimbusJwtDecoder buildDecoder(ClientRegistration clientRegistration) {
        val jwkSetCache = ConcurrentMapCache(
            "jwkSetCache",
            CacheBuilder.newBuilder()
                .expireAfterWrite(Duration.ofMinutes(jwkCacheTtl.cacheTtlMin))
                .build<Any, Any>().asMap(),
            false
        )
        return NimbusJwtDecoder.withJwkSetUri(jwkSetUri).cache(jwkSetCache).jwsAlgorithm((SignatureAlgorithm) jwsAlgorithm).build();
    }

Ref: https://github.com/spring-projects/spring-security/blob/main/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/oidc/authentication/OidcIdTokenDecoderFactory.java#L167

The issue is I would need to copy the whole content of OidcIdTokenDecoderFactory by implementing JwtDecoderFactory doing this way.

Is there maybe a way to inject a CachedJwtDecoder and let OidcIdTokenDecoderFactory use it?

Any other alternative is also very welcome.

0 Answers
Related