/** * Sets the {@link RestOperations} used when requesting the JSON Web Key (JWK) Set. * * @since 5.1 * @param restOperations the {@link RestOperations} used when requesting the JSON Web Key (JWK) Set */ public final void setRestOperations(RestOperations restOperations) { Assert.notNull(restOperations, "restOperations cannot be null"); this.jwtProcessorBuilder = this.jwtProcessorBuilder.restOperations(restOperations); this.delegate = makeDelegate(); } }
private static JWTProcessor<SecurityContext> withSigning(String jwkResponse) { RestOperations restOperations = mock(RestOperations.class); when(restOperations.exchange(any(RequestEntity.class), eq(String.class))) .thenReturn(new ResponseEntity<>(jwkResponse, HttpStatus.OK)); return withJwkSetUri("http://issuer/.well-known/jwks.json") .restOperations(restOperations) .build(); }
@Test public void processWhenSignedThenOk() throws Exception { RestOperations restOperations = mockJwkSetResponse(JWK_SET); JWTProcessor<SecurityContext> processor = withJwkSetUri(JWK_SET_URI).restOperations(restOperations).build(); assertThat(processor.process(RS256_SIGNED_JWT, null)) .extracting(JWTClaimsSet::getExpirationTime) .isNotNull(); verify(restOperations).exchange(any(RequestEntity.class), eq(String.class)); }
@Test public void restOperationsWhenNullThenThrowsException() { JwtProcessors.JwkSetUriJwtProcessorBuilder builder = withJwkSetUri(JWK_SET_URI); assertThatCode(() -> builder.restOperations(null)).isInstanceOf(IllegalArgumentException.class); }
@Bean NimbusJwtDecoder jwtDecoder() { JWTProcessor<SecurityContext> jwtProcessor = JwtProcessors.withJwkSetUri("https://example.org/.well-known/jwks.json") .restOperations(this.rest).build(); return new NimbusJwtDecoder(jwtProcessor); } }