浏览代码

LogoutWebFilter supports anonymous users

Fixes gh-4540
Rob Winch 8 年之前
父节点
当前提交
5fd84a62b5

+ 7 - 1
webflux/src/main/java/org/springframework/security/web/server/authentication/logout/LogoutWebFiter.java

@@ -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);
+	}
 }