@ -52,7 +52,6 @@ public class AuthenticationWebFilter implements WebFilter {
@@ -52,7 +52,6 @@ public class AuthenticationWebFilter implements WebFilter {
private ServerSecurityContextRepository serverSecurityContextRepository = new ServerWebExchangeAttributeServerSecurityContextRepository ( ) ;
private ServerWebExchangeMatcher requiresAuthenticationMatcher = ServerWebExchangeMatchers . anyExchange ( ) ;
public AuthenticationWebFilter ( ReactiveAuthenticationManager authenticationManager ) {
Assert . notNull ( authenticationManager , "authenticationManager cannot be null" ) ;
this . authenticationManager = authenticationManager ;
@ -60,21 +59,16 @@ public class AuthenticationWebFilter implements WebFilter {
@@ -60,21 +59,16 @@ public class AuthenticationWebFilter implements WebFilter {
@Override
public Mono < Void > filter ( ServerWebExchange exchange , WebFilterChain chain ) {
ServerWebExchange wrappedExchange = new SecurityContextRepositoryServerWebExchange ( exchange , this . serverSecurityContextRepository ) ;
return filterInternal ( wrappedExchange , chain ) ;
}
private Mono < Void > filterInternal ( ServerWebExchange wrappedExchange , WebFilterChain chain ) {
return this . requiresAuthenticationMatcher . matches ( wrappedExchange )
return this . requiresAuthenticationMatcher . matches ( exchange )
. filter ( matchResult - > matchResult . isMatch ( ) )
. flatMap ( matchResult - > this . authenticationConverter . apply ( wrapp edE xchange) )
. switchIfEmpty ( chain . filter ( wrapp edE xchange) . then ( Mono . empty ( ) ) )
. flatMap ( token - > authenticate ( wrapp edE xchange, chain , token ) ) ;
. flatMap ( matchResult - > this . authenticationConverter . apply ( exchange ) )
. switchIfEmpty ( chain . filter ( exchange ) . then ( Mono . empty ( ) ) )
. flatMap ( token - > authenticate ( exchange , chain , token ) ) ;
}
private Mono < Void > authenticate ( ServerWebExchange wrapp edE xchange,
private Mono < Void > authenticate ( ServerWebExchange exchange ,
WebFilterChain chain , Authentication token ) {
WebFilterExchange webFilterExchange = new WebFilterExchange ( wrapp edE xchange, chain ) ;
WebFilterExchange webFilterExchange = new WebFilterExchange ( exchange , chain ) ;
return this . authenticationManager . authenticate ( token )
. flatMap ( authentication - > onAuthenticationSuccess ( authentication , webFilterExchange ) )
. onErrorResume ( AuthenticationException . class , e - > this . serverAuthenticationFailureHandler