@@ -261,6 +261,16 @@ public static SecretKeyJwtDecoderBuilder withSecretKey(SecretKey secretKey) {
261
261
return new SecretKeyJwtDecoderBuilder (secretKey );
262
262
}
263
263
264
+ /**
265
+ * Use the given <a href="https://tools.ietf.org/html/rfc7517#section-5">JWK Set</a>
266
+ * uri.
267
+ * @param jwkSetUri the JWK Set uri to use
268
+ * @return a {@link JwkSetUriJwtDecoderBuilder} for further configurations
269
+ */
270
+ public static JwkSetUriJwtDecoderBuilder withJwkSource (JWKSource <SecurityContext > jwkSetUri ) {
271
+ return new JwkSetUriJwtDecoderBuilder (jwkSetUri );
272
+ }
273
+
264
274
/**
265
275
* A builder for creating {@link NimbusJwtDecoder} instances based on a
266
276
* <a target="_blank" href="https://tools.ietf.org/html/rfc7517#section-5">JWK Set</a>
@@ -274,7 +284,7 @@ public static final class JwkSetUriJwtDecoderBuilder {
274
284
private static final JOSEObjectTypeVerifier <SecurityContext > NO_TYPE_VERIFIER = (header , context ) -> {
275
285
};
276
286
277
- private final Function <RestOperations , String > jwkSetUri ;
287
+ private Function <RestOperations , String > jwkSetUri ;
278
288
279
289
private Function <JWKSource <SecurityContext >, Set <JWSAlgorithm >> defaultAlgorithms = (source ) -> Set
280
290
.of (JWSAlgorithm .RS256 );
@@ -289,6 +299,8 @@ public static final class JwkSetUriJwtDecoderBuilder {
289
299
290
300
private Consumer <ConfigurableJWTProcessor <SecurityContext >> jwtProcessorCustomizer ;
291
301
302
+ private JWKSource <SecurityContext > jwkSource ;
303
+
292
304
private JwkSetUriJwtDecoderBuilder (String jwkSetUri ) {
293
305
Assert .hasText (jwkSetUri , "jwkSetUri cannot be empty" );
294
306
this .jwkSetUri = (rest ) -> jwkSetUri ;
@@ -306,6 +318,13 @@ private JwkSetUriJwtDecoderBuilder(Function<RestOperations, String> jwkSetUri,
306
318
};
307
319
}
308
320
321
+ private JwkSetUriJwtDecoderBuilder (JWKSource <SecurityContext > jwkSource ) {
322
+ Assert .notNull (jwkSource , "jwkSource cannot be null" );
323
+ this .jwkSource = jwkSource ;
324
+ this .jwtProcessorCustomizer = (processor ) -> {
325
+ };
326
+ }
327
+
309
328
/**
310
329
* Whether to use Nimbus's typ header verification. This is {@code true} by
311
330
* default, however it may change to {@code false} in a future major release.
@@ -436,6 +455,9 @@ JWSKeySelector<SecurityContext> jwsKeySelector(JWKSource<SecurityContext> jwkSou
436
455
}
437
456
438
457
JWKSource <SecurityContext > jwkSource () {
458
+ if (jwkSource != null ) {
459
+ return jwkSource ;
460
+ }
439
461
String jwkSetUri = this .jwkSetUri .apply (this .restOperations );
440
462
return JWKSourceBuilder .create (new SpringJWKSource <>(this .restOperations , this .cache , jwkSetUri ))
441
463
.refreshAheadCache (false )
0 commit comments