@@ -289,6 +289,8 @@ public static final class JwkSetUriJwtDecoderBuilder {
289
289
290
290
private Consumer <ConfigurableJWTProcessor <SecurityContext >> jwtProcessorCustomizer ;
291
291
292
+ private Consumer <JWKSourceBuilder <SecurityContext >> jwkSourceBuilderCustomizer ;
293
+
292
294
private JwkSetUriJwtDecoderBuilder (String jwkSetUri ) {
293
295
Assert .hasText (jwkSetUri , "jwkSetUri cannot be empty" );
294
296
this .jwkSetUri = (rest ) -> jwkSetUri ;
@@ -423,6 +425,20 @@ public JwkSetUriJwtDecoderBuilder jwtProcessorCustomizer(
423
425
return this ;
424
426
}
425
427
428
+ /**
429
+ * Use the given {@link Consumer} to customize the {@link JWKSourceBuilder} before
430
+ * passing it to the build {@link NimbusJwtDecoder}.
431
+ * @param jwkSourceBuilderCustomizer the callback used to alter the builder
432
+ * @return a {@link JwkSetUriJwtDecoderBuilder} for further configurations
433
+ * @since 6.5
434
+ */
435
+ public JwkSetUriJwtDecoderBuilder jwkSourceBuilderCustomizer (
436
+ Consumer <JWKSourceBuilder <SecurityContext >> jwkSourceBuilderCustomizer ) {
437
+ Assert .notNull (jwkSourceBuilderCustomizer , "jwkSourceBuilderCustomizer cannot be null" );
438
+ this .jwkSourceBuilderCustomizer = jwkSourceBuilderCustomizer ;
439
+ return this ;
440
+ }
441
+
426
442
JWSKeySelector <SecurityContext > jwsKeySelector (JWKSource <SecurityContext > jwkSource ) {
427
443
if (this .signatureAlgorithms .isEmpty ()) {
428
444
return new JWSVerificationKeySelector <>(this .defaultAlgorithms .apply (jwkSource ), jwkSource );
@@ -437,11 +453,17 @@ JWSKeySelector<SecurityContext> jwsKeySelector(JWKSource<SecurityContext> jwkSou
437
453
438
454
JWKSource <SecurityContext > jwkSource () {
439
455
String jwkSetUri = this .jwkSetUri .apply (this .restOperations );
440
- return JWKSourceBuilder .create (new SpringJWKSource <>(this .restOperations , this .cache , jwkSetUri ))
456
+ JWKSourceBuilder <SecurityContext > jwkSourceBuilder = JWKSourceBuilder
457
+ .create (new SpringJWKSource <>(this .restOperations , this .cache , jwkSetUri ))
441
458
.refreshAheadCache (false )
442
459
.rateLimited (false )
443
- .cache (this .cache instanceof NoOpCache )
444
- .build ();
460
+ .cache (this .cache instanceof NoOpCache );
461
+
462
+ if (this .jwkSourceBuilderCustomizer != null ) {
463
+ this .jwkSourceBuilderCustomizer .accept (jwkSourceBuilder );
464
+ }
465
+
466
+ return jwkSourceBuilder .build ();
445
467
}
446
468
447
469
JWTProcessor <SecurityContext > processor () {
0 commit comments