Search in sources :

Example 1 with TrustedIssuerJwtAuthenticationManagerResolver

use of org.springframework.security.oauth2.server.resource.authentication.JwtIssuerAuthenticationManagerResolver.TrustedIssuerJwtAuthenticationManagerResolver in project spring-security by spring-projects.

the class JwtIssuerReactiveAuthenticationManagerResolverTests method resolveWhenUsingSameIssuerThenReturnsSameAuthenticationManager.

@Test
public void resolveWhenUsingSameIssuerThenReturnsSameAuthenticationManager() throws Exception {
    try (MockWebServer server = new MockWebServer()) {
        String issuer = server.url("").toString();
        server.enqueue(new MockResponse().setResponseCode(200).setHeader("Content-Type", "application/json").setBody(String.format(DEFAULT_RESPONSE_TEMPLATE, issuer, issuer)));
        server.enqueue(new MockResponse().setResponseCode(200).setHeader("Content-Type", "application/json").setBody(JWK_SET));
        TrustedIssuerJwtAuthenticationManagerResolver resolver = new TrustedIssuerJwtAuthenticationManagerResolver((iss) -> iss.equals(issuer));
        ReactiveAuthenticationManager authenticationManager = resolver.resolve(issuer).block();
        ReactiveAuthenticationManager cachedAuthenticationManager = resolver.resolve(issuer).block();
        assertThat(authenticationManager).isSameAs(cachedAuthenticationManager);
    }
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) ReactiveAuthenticationManager(org.springframework.security.authentication.ReactiveAuthenticationManager) MockWebServer(okhttp3.mockwebserver.MockWebServer) TrustedIssuerJwtAuthenticationManagerResolver(org.springframework.security.oauth2.server.resource.authentication.JwtIssuerReactiveAuthenticationManagerResolver.TrustedIssuerJwtAuthenticationManagerResolver) Test(org.junit.jupiter.api.Test)

Example 2 with TrustedIssuerJwtAuthenticationManagerResolver

use of org.springframework.security.oauth2.server.resource.authentication.JwtIssuerAuthenticationManagerResolver.TrustedIssuerJwtAuthenticationManagerResolver in project spring-security by spring-projects.

the class JwtIssuerAuthenticationManagerResolverTests method resolveWhenUsingSameIssuerThenReturnsSameAuthenticationManager.

@Test
public void resolveWhenUsingSameIssuerThenReturnsSameAuthenticationManager() throws Exception {
    try (MockWebServer server = new MockWebServer()) {
        String issuer = server.url("").toString();
        server.enqueue(new MockResponse().setResponseCode(200).setHeader("Content-Type", "application/json").setBody(String.format(DEFAULT_RESPONSE_TEMPLATE, issuer, issuer)));
        server.enqueue(new MockResponse().setResponseCode(200).setHeader("Content-Type", "application/json").setBody(JWK_SET));
        TrustedIssuerJwtAuthenticationManagerResolver resolver = new TrustedIssuerJwtAuthenticationManagerResolver((iss) -> iss.equals(issuer));
        AuthenticationManager authenticationManager = resolver.resolve(issuer);
        AuthenticationManager cachedAuthenticationManager = resolver.resolve(issuer);
        assertThat(authenticationManager).isSameAs(cachedAuthenticationManager);
    }
}
Also used : AuthenticationManager(org.springframework.security.authentication.AuthenticationManager) MockResponse(okhttp3.mockwebserver.MockResponse) MockWebServer(okhttp3.mockwebserver.MockWebServer) TrustedIssuerJwtAuthenticationManagerResolver(org.springframework.security.oauth2.server.resource.authentication.JwtIssuerAuthenticationManagerResolver.TrustedIssuerJwtAuthenticationManagerResolver) Test(org.junit.jupiter.api.Test)

Aggregations

MockResponse (okhttp3.mockwebserver.MockResponse)2 MockWebServer (okhttp3.mockwebserver.MockWebServer)2 Test (org.junit.jupiter.api.Test)2 AuthenticationManager (org.springframework.security.authentication.AuthenticationManager)1 ReactiveAuthenticationManager (org.springframework.security.authentication.ReactiveAuthenticationManager)1 TrustedIssuerJwtAuthenticationManagerResolver (org.springframework.security.oauth2.server.resource.authentication.JwtIssuerAuthenticationManagerResolver.TrustedIssuerJwtAuthenticationManagerResolver)1 TrustedIssuerJwtAuthenticationManagerResolver (org.springframework.security.oauth2.server.resource.authentication.JwtIssuerReactiveAuthenticationManagerResolver.TrustedIssuerJwtAuthenticationManagerResolver)1