跳到主要内容
版本:7.0.2

登出

DeepSeek V3 中英对照 Logout

Spring Security 默认提供登出端点。登录后,你可以通过 GET /logout 查看默认的登出确认页面,也可以通过 POST /logout 发起登出操作。这将:

  • 清除 ServerCsrfTokenRepositoryServerSecurityContextRepository,并

  • 重定向回登录页面

通常,在登出时你也会希望使会话失效。为此,你可以在登出配置中添加 WebSessionServerLogoutHandler,如下所示:

@Bean
SecurityWebFilterChain http(ServerHttpSecurity http) throws Exception {
DelegatingServerLogoutHandler logoutHandler = new DelegatingServerLogoutHandler(
new SecurityContextServerLogoutHandler(), new WebSessionServerLogoutHandler()
);

http
.authorizeExchange((authorize) -> authorize.anyExchange().authenticated())
.logout((logout) -> logout.logoutHandler(logoutHandler));

return http.build();
}