Fix authenticationFailureHandler customization tests
Issue gh-12132
This commit is contained in:
parent
c7b9b33cd1
commit
72c25332a5
|
@ -32,10 +32,12 @@ import org.springframework.security.config.annotation.web.reactive.EnableWebFlux
|
|||
import org.springframework.security.config.test.SpringTestContext
|
||||
import org.springframework.security.config.test.SpringTestContextExtension
|
||||
import org.springframework.security.core.Authentication
|
||||
import org.springframework.security.core.AuthenticationException
|
||||
import org.springframework.security.core.userdetails.MapReactiveUserDetailsService
|
||||
import org.springframework.security.core.userdetails.User
|
||||
import org.springframework.security.web.server.SecurityWebFilterChain
|
||||
import org.springframework.security.web.server.ServerAuthenticationEntryPoint
|
||||
import org.springframework.security.web.server.WebFilterExchange
|
||||
import org.springframework.security.web.server.authentication.HttpStatusServerEntryPoint
|
||||
import org.springframework.security.web.server.authentication.ServerAuthenticationFailureHandler
|
||||
import org.springframework.security.web.server.context.ServerSecurityContextRepository
|
||||
|
@ -250,7 +252,7 @@ class ServerHttpBasicDslTests {
|
|||
open class CustomAuthenticationFailureHandlerConfig {
|
||||
|
||||
companion object {
|
||||
val FAILURE_HANDLER: ServerAuthenticationFailureHandler = ServerAuthenticationFailureHandler { _, _ -> Mono.empty() }
|
||||
val FAILURE_HANDLER: ServerAuthenticationFailureHandler = MockServerAuthenticationFailureHandler()
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
@ -266,6 +268,16 @@ class ServerHttpBasicDslTests {
|
|||
}
|
||||
}
|
||||
|
||||
open class MockServerAuthenticationFailureHandler: ServerAuthenticationFailureHandler {
|
||||
override fun onAuthenticationFailure(
|
||||
webFilterExchange: WebFilterExchange?,
|
||||
exception: AuthenticationException?
|
||||
): Mono<Void> {
|
||||
return Mono.empty()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Configuration
|
||||
open class UserDetailsConfig {
|
||||
@Bean
|
||||
|
|
|
@ -30,9 +30,11 @@ import org.springframework.security.authentication.ReactiveAuthenticationManager
|
|||
import org.springframework.security.config.annotation.web.reactive.EnableWebFluxSecurity
|
||||
import org.springframework.security.config.test.SpringTestContext
|
||||
import org.springframework.security.config.test.SpringTestContextExtension
|
||||
import org.springframework.security.core.AuthenticationException
|
||||
import org.springframework.security.oauth2.server.resource.authentication.JwtIssuerReactiveAuthenticationManagerResolver
|
||||
import org.springframework.security.oauth2.server.resource.web.server.authentication.ServerBearerTokenAuthenticationConverter
|
||||
import org.springframework.security.web.server.SecurityWebFilterChain
|
||||
import org.springframework.security.web.server.WebFilterExchange
|
||||
import org.springframework.security.web.server.authentication.HttpStatusServerEntryPoint
|
||||
import org.springframework.security.web.server.authentication.ServerAuthenticationFailureHandler
|
||||
import org.springframework.security.web.server.authorization.HttpStatusServerAccessDeniedHandler
|
||||
|
@ -152,7 +154,7 @@ class ServerOAuth2ResourceServerDslTests {
|
|||
open class AuthenticationFailureHandlerConfig {
|
||||
|
||||
companion object {
|
||||
val FAILURE_HANDLER: ServerAuthenticationFailureHandler = ServerAuthenticationFailureHandler { _, _ -> Mono.empty() }
|
||||
val FAILURE_HANDLER: ServerAuthenticationFailureHandler = MockServerAuthenticationFailureHandler()
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
@ -171,6 +173,16 @@ class ServerOAuth2ResourceServerDslTests {
|
|||
}
|
||||
}
|
||||
|
||||
open class MockServerAuthenticationFailureHandler: ServerAuthenticationFailureHandler {
|
||||
override fun onAuthenticationFailure(
|
||||
webFilterExchange: WebFilterExchange?,
|
||||
exception: AuthenticationException?
|
||||
): Mono<Void> {
|
||||
return Mono.empty()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `request when custom bearer token converter configured then custom converter used`() {
|
||||
this.spring.register(BearerTokenConverterConfig::class.java).autowire()
|
||||
|
|
Loading…
Reference in New Issue