diff --git a/config/src/test/kotlin/org/springframework/security/config/annotation/web/OAuth2ResourceServerDslTests.kt b/config/src/test/kotlin/org/springframework/security/config/annotation/web/OAuth2ResourceServerDslTests.kt index cb75ba28da8..c0631d162a0 100644 --- a/config/src/test/kotlin/org/springframework/security/config/annotation/web/OAuth2ResourceServerDslTests.kt +++ b/config/src/test/kotlin/org/springframework/security/config/annotation/web/OAuth2ResourceServerDslTests.kt @@ -35,6 +35,7 @@ import org.springframework.security.config.annotation.web.builders.HttpSecurity import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity import org.springframework.security.config.test.SpringTestContext import org.springframework.security.config.test.SpringTestContextExtension +import org.springframework.security.core.Authentication import org.springframework.security.oauth2.core.oidc.IdTokenClaimNames.SUB import org.springframework.security.oauth2.jwt.Jwt import org.springframework.security.oauth2.jwt.JwtDecoder @@ -207,9 +208,7 @@ class OAuth2ResourceServerDslTests { mockkObject(AuthenticationManagerResolverConfig.RESOLVER) every { AuthenticationManagerResolverConfig.RESOLVER.resolve(any()) - } returns AuthenticationManager { - JwtAuthenticationToken(JWT) - } + } returns MockAuthenticationManager(JwtAuthenticationToken(JWT)) this.mockMvc.get("/") { header("Authorization", "Bearer token") @@ -241,6 +240,14 @@ class OAuth2ResourceServerDslTests { } } + class MockAuthenticationManager(var authentication: Authentication) : AuthenticationManager { + + override fun authenticate(authentication: Authentication?): Authentication { + return this.authentication + } + + } + @Test fun `oauth2Resource server when custom authentication manager resolver and opaque then exception`() { Assertions.assertThatExceptionOfType(BeanCreationException::class.java)