Search in sources :

Example 1 with SupplierJwtDecoder

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

the class OAuth2ResourceServerAutoConfigurationTests method autoConfigurationShouldConfigureResourceServerUsingOidcRfc8414IssuerUri.

@Test
@SuppressWarnings("unchecked")
void autoConfigurationShouldConfigureResourceServerUsingOidcRfc8414IssuerUri() throws Exception {
    this.server = new MockWebServer();
    this.server.start();
    String path = "test";
    String issuer = this.server.url(path).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() + "/" + path).run((context) -> {
        assertThat(context).hasSingleBean(SupplierJwtDecoder.class);
        assertThat(context.containsBean("jwtDecoderByIssuerUri")).isTrue();
        SupplierJwtDecoder supplierJwtDecoderBean = context.getBean(SupplierJwtDecoder.class);
        Supplier<JwtDecoder> jwtDecoderSupplier = (Supplier<JwtDecoder>) ReflectionTestUtils.getField(supplierJwtDecoderBean, "jwtDecoderSupplier");
        JwtDecoder jwtDecoder = jwtDecoderSupplier.get();
    });
    // The last request is to the JWK Set endpoint to look up the algorithm
    assertThat(this.server.getRequestCount()).isEqualTo(3);
}
Also used : SupplierJwtDecoder(org.springframework.security.oauth2.jwt.SupplierJwtDecoder) JwtDecoder(org.springframework.security.oauth2.jwt.JwtDecoder) MockWebServer(okhttp3.mockwebserver.MockWebServer) Supplier(java.util.function.Supplier) SupplierJwtDecoder(org.springframework.security.oauth2.jwt.SupplierJwtDecoder) Test(org.junit.jupiter.api.Test)

Example 2 with SupplierJwtDecoder

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

the class OAuth2ResourceServerAutoConfigurationTests method autoConfigurationShouldConfigureResourceServerUsingOAuthIssuerUri.

@Test
@SuppressWarnings("unchecked")
void autoConfigurationShouldConfigureResourceServerUsingOAuthIssuerUri() throws Exception {
    this.server = new MockWebServer();
    this.server.start();
    String path = "test";
    String issuer = this.server.url(path).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() + "/" + path).run((context) -> {
        assertThat(context).hasSingleBean(SupplierJwtDecoder.class);
        assertThat(context.containsBean("jwtDecoderByIssuerUri")).isTrue();
        SupplierJwtDecoder supplierJwtDecoderBean = context.getBean(SupplierJwtDecoder.class);
        Supplier<JwtDecoder> jwtDecoderSupplier = (Supplier<JwtDecoder>) ReflectionTestUtils.getField(supplierJwtDecoderBean, "jwtDecoderSupplier");
        JwtDecoder jwtDecoder = jwtDecoderSupplier.get();
    });
    // The last request is to the JWK Set endpoint to look up the algorithm
    assertThat(this.server.getRequestCount()).isEqualTo(4);
}
Also used : SupplierJwtDecoder(org.springframework.security.oauth2.jwt.SupplierJwtDecoder) JwtDecoder(org.springframework.security.oauth2.jwt.JwtDecoder) MockWebServer(okhttp3.mockwebserver.MockWebServer) Supplier(java.util.function.Supplier) SupplierJwtDecoder(org.springframework.security.oauth2.jwt.SupplierJwtDecoder) Test(org.junit.jupiter.api.Test)

Example 3 with SupplierJwtDecoder

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

the class OAuth2ResourceServerAutoConfigurationTests method autoConfigurationShouldConfigureResourceServerUsingOidcIssuerUri.

@Test
@SuppressWarnings("unchecked")
void autoConfigurationShouldConfigureResourceServerUsingOidcIssuerUri() throws Exception {
    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(SupplierJwtDecoder.class);
        assertThat(context.containsBean("jwtDecoderByIssuerUri")).isTrue();
        SupplierJwtDecoder supplierJwtDecoderBean = context.getBean(SupplierJwtDecoder.class);
        Supplier<JwtDecoder> jwtDecoderSupplier = (Supplier<JwtDecoder>) ReflectionTestUtils.getField(supplierJwtDecoderBean, "jwtDecoderSupplier");
        JwtDecoder jwtDecoder = jwtDecoderSupplier.get();
    });
    // The last request is to the JWK Set endpoint to look up the algorithm
    assertThat(this.server.getRequestCount()).isEqualTo(2);
}
Also used : SupplierJwtDecoder(org.springframework.security.oauth2.jwt.SupplierJwtDecoder) JwtDecoder(org.springframework.security.oauth2.jwt.JwtDecoder) MockWebServer(okhttp3.mockwebserver.MockWebServer) Supplier(java.util.function.Supplier) SupplierJwtDecoder(org.springframework.security.oauth2.jwt.SupplierJwtDecoder) Test(org.junit.jupiter.api.Test)

Aggregations

Supplier (java.util.function.Supplier)3 MockWebServer (okhttp3.mockwebserver.MockWebServer)3 Test (org.junit.jupiter.api.Test)3 JwtDecoder (org.springframework.security.oauth2.jwt.JwtDecoder)3 SupplierJwtDecoder (org.springframework.security.oauth2.jwt.SupplierJwtDecoder)3