Add AuthenticationManager to Kotlin ServerHttpSecurityDsl

Closes gh-10053
This commit is contained in:
Eleftheria Stein
2021-07-09 10:34:57 +02:00
parent 2809a3309b
commit 79054093c9
2 changed files with 43 additions and 1 deletions

View File

@@ -16,6 +16,7 @@
package org.springframework.security.config.web.server
import org.springframework.security.authentication.ReactiveAuthenticationManager
import org.springframework.security.oauth2.client.registration.ReactiveClientRegistrationRepository
import org.springframework.security.web.server.SecurityWebFilterChain
import org.springframework.security.web.server.util.matcher.ServerWebExchangeMatcher
@@ -57,10 +58,13 @@ operator fun ServerHttpSecurity.invoke(httpConfiguration: ServerHttpSecurityDsl.
* @author Eleftheria Stein
* @since 5.4
* @param init the configurations to apply to the provided [ServerHttpSecurity]
* @property authenticationManager the default [ReactiveAuthenticationManager] to use
*/
@ServerSecurityMarker
class ServerHttpSecurityDsl(private val http: ServerHttpSecurity, private val init: ServerHttpSecurityDsl.() -> Unit) {
var authenticationManager: ReactiveAuthenticationManager? = null
/**
* Allows configuring the [ServerHttpSecurity] to only be invoked when matching the
* provided [ServerWebExchangeMatcher].
@@ -630,6 +634,7 @@ class ServerHttpSecurityDsl(private val http: ServerHttpSecurity, private val in
*/
internal fun build(): SecurityWebFilterChain {
init()
authenticationManager?.also { this.http.authenticationManager(authenticationManager) }
return this.http.build()
}
}