Search in sources :

Example 1 with SupplierReactiveJwtDecoder

use of org.springframework.security.oauth2.jwt.SupplierReactiveJwtDecoder in project spring-boot by spring-projects.

the class ReactiveOAuth2ResourceServerAutoConfigurationTests method autoConfigurationShouldConfigureResourceServerUsingOidcIssuerUri.

@Test
@SuppressWarnings("unchecked")
void autoConfigurationShouldConfigureResourceServerUsingOidcIssuerUri() throws IOException {
    this.server = new MockWebServer();
    this.server.start();
    String path = "test";
    String issuer = this.server.url(path).toString();
    String cleanIssuerPath = cleanIssuerPath(issuer);
    setupMockResponse(cleanIssuerPath);
    this.contextRunner.withPropertyValues("spring.security.oauth2.resourceserver.jwt.issuer-uri=http://" + this.server.getHostName() + ":" + this.server.getPort() + "/" + path).run((context) -> {
        assertThat(context).hasSingleBean(SupplierReactiveJwtDecoder.class);
        assertFilterConfiguredWithJwtAuthenticationManager(context);
        assertThat(context.containsBean("jwtDecoderByIssuerUri")).isTrue();
        SupplierReactiveJwtDecoder supplierReactiveJwtDecoder = context.getBean(SupplierReactiveJwtDecoder.class);
        Mono<ReactiveJwtDecoder> reactiveJwtDecoderSupplier = (Mono<ReactiveJwtDecoder>) ReflectionTestUtils.getField(supplierReactiveJwtDecoder, "jwtDecoderMono");
        ReactiveJwtDecoder reactiveJwtDecoder = reactiveJwtDecoderSupplier.block();
    });
    // The last request is to the JWK Set endpoint to look up the algorithm
    assertThat(this.server.getRequestCount()).isEqualTo(1);
}
Also used : NimbusReactiveJwtDecoder(org.springframework.security.oauth2.jwt.NimbusReactiveJwtDecoder) ReactiveJwtDecoder(org.springframework.security.oauth2.jwt.ReactiveJwtDecoder) SupplierReactiveJwtDecoder(org.springframework.security.oauth2.jwt.SupplierReactiveJwtDecoder) Mono(reactor.core.publisher.Mono) MockWebServer(okhttp3.mockwebserver.MockWebServer) SupplierReactiveJwtDecoder(org.springframework.security.oauth2.jwt.SupplierReactiveJwtDecoder) Test(org.junit.jupiter.api.Test)

Example 2 with SupplierReactiveJwtDecoder

use of org.springframework.security.oauth2.jwt.SupplierReactiveJwtDecoder in project spring-boot by spring-projects.

the class ReactiveOAuth2ResourceServerAutoConfigurationTests method autoConfigurationShouldConfigureResourceServerUsingOidcRfc8414IssuerUri.

@Test
@SuppressWarnings("unchecked")
void autoConfigurationShouldConfigureResourceServerUsingOidcRfc8414IssuerUri() throws Exception {
    this.server = new MockWebServer();
    this.server.start();
    String issuer = this.server.url("").toString();
    String cleanIssuerPath = cleanIssuerPath(issuer);
    setupMockResponsesWithErrors(cleanIssuerPath, 1);
    this.contextRunner.withPropertyValues("spring.security.oauth2.resourceserver.jwt.issuer-uri=http://" + this.server.getHostName() + ":" + this.server.getPort()).run((context) -> {
        assertThat(context).hasSingleBean(SupplierReactiveJwtDecoder.class);
        assertFilterConfiguredWithJwtAuthenticationManager(context);
        assertThat(context.containsBean("jwtDecoderByIssuerUri")).isTrue();
        SupplierReactiveJwtDecoder supplierReactiveJwtDecoder = context.getBean(SupplierReactiveJwtDecoder.class);
        Mono<ReactiveJwtDecoder> reactiveJwtDecoderSupplier = (Mono<ReactiveJwtDecoder>) ReflectionTestUtils.getField(supplierReactiveJwtDecoder, "jwtDecoderMono");
        ReactiveJwtDecoder reactiveJwtDecoder = reactiveJwtDecoderSupplier.block();
    });
    // The last request is to the JWK Set endpoint to look up the algorithm
    assertThat(this.server.getRequestCount()).isEqualTo(2);
}
Also used : NimbusReactiveJwtDecoder(org.springframework.security.oauth2.jwt.NimbusReactiveJwtDecoder) ReactiveJwtDecoder(org.springframework.security.oauth2.jwt.ReactiveJwtDecoder) SupplierReactiveJwtDecoder(org.springframework.security.oauth2.jwt.SupplierReactiveJwtDecoder) Mono(reactor.core.publisher.Mono) MockWebServer(okhttp3.mockwebserver.MockWebServer) SupplierReactiveJwtDecoder(org.springframework.security.oauth2.jwt.SupplierReactiveJwtDecoder) Test(org.junit.jupiter.api.Test)

Example 3 with SupplierReactiveJwtDecoder

use of org.springframework.security.oauth2.jwt.SupplierReactiveJwtDecoder in project spring-boot by spring-projects.

the class ReactiveOAuth2ResourceServerAutoConfigurationTests method autoConfigurationShouldConfigureResourceServerUsingOAuthIssuerUri.

@Test
@SuppressWarnings("unchecked")
void autoConfigurationShouldConfigureResourceServerUsingOAuthIssuerUri() throws Exception {
    this.server = new MockWebServer();
    this.server.start();
    String issuer = this.server.url("").toString();
    String cleanIssuerPath = cleanIssuerPath(issuer);
    setupMockResponsesWithErrors(cleanIssuerPath, 2);
    this.contextRunner.withPropertyValues("spring.security.oauth2.resourceserver.jwt.issuer-uri=http://" + this.server.getHostName() + ":" + this.server.getPort()).run((context) -> {
        assertThat(context).hasSingleBean(SupplierReactiveJwtDecoder.class);
        assertFilterConfiguredWithJwtAuthenticationManager(context);
        assertThat(context.containsBean("jwtDecoderByIssuerUri")).isTrue();
        SupplierReactiveJwtDecoder supplierReactiveJwtDecoder = context.getBean(SupplierReactiveJwtDecoder.class);
        Mono<ReactiveJwtDecoder> reactiveJwtDecoderSupplier = (Mono<ReactiveJwtDecoder>) ReflectionTestUtils.getField(supplierReactiveJwtDecoder, "jwtDecoderMono");
        ReactiveJwtDecoder reactiveJwtDecoder = reactiveJwtDecoderSupplier.block();
    });
    // The last request is to the JWK Set endpoint to look up the algorithm
    assertThat(this.server.getRequestCount()).isEqualTo(3);
}
Also used : NimbusReactiveJwtDecoder(org.springframework.security.oauth2.jwt.NimbusReactiveJwtDecoder) ReactiveJwtDecoder(org.springframework.security.oauth2.jwt.ReactiveJwtDecoder) SupplierReactiveJwtDecoder(org.springframework.security.oauth2.jwt.SupplierReactiveJwtDecoder) Mono(reactor.core.publisher.Mono) MockWebServer(okhttp3.mockwebserver.MockWebServer) SupplierReactiveJwtDecoder(org.springframework.security.oauth2.jwt.SupplierReactiveJwtDecoder) Test(org.junit.jupiter.api.Test)

Aggregations

MockWebServer (okhttp3.mockwebserver.MockWebServer)3 Test (org.junit.jupiter.api.Test)3 NimbusReactiveJwtDecoder (org.springframework.security.oauth2.jwt.NimbusReactiveJwtDecoder)3 ReactiveJwtDecoder (org.springframework.security.oauth2.jwt.ReactiveJwtDecoder)3 SupplierReactiveJwtDecoder (org.springframework.security.oauth2.jwt.SupplierReactiveJwtDecoder)3 Mono (reactor.core.publisher.Mono)3