LogoutWebFilter supports anonymous users

Fixes gh-4540
This commit is contained in:
Rob Winch 2017-09-13 17:03:40 -05:00
parent 5baf71f4a0
commit 5fd84a62b5
1 changed files with 7 additions and 1 deletions

View File

@ -47,7 +47,13 @@ public class LogoutWebFiter implements WebFilter {
return this.requiresLogout.matches(exchange)
.filter( result -> result.isMatch())
.switchIfEmpty(chain.filter(exchange).then(Mono.empty()))
.flatMap( result -> exchange.getPrincipal().cast(Authentication.class))
.flatMap( result -> authentication(exchange))
.flatMap( authentication -> this.logoutHandler.logout(new WebFilterExchange(exchange, chain), authentication));
}
private Mono<Authentication> authentication(ServerWebExchange exchange) {
return exchange.getPrincipal()
.cast(Authentication.class)
.defaultIfEmpty(this.anonymousAuthenticationToken);
}
}