gpt4 book ai didi

spring-boot - Spring Security WebFlux 注销

转载 作者:行者123 更新时间:2023-12-04 15:37:33 26 4
gpt4 key购买 nike

在执行类似于

public class SecurityConfig extends WebSecurityConfigurerAdapter {



@Override
protected void configure(HttpSecurity http) throws Exception
{
http
.httpBasic()
.and()
.logout().clearAuthentication(true)
.logoutSuccessUrl("/")
.deleteCookies("JSESSIONID")
.invalidateHttpSession(true)
.and()
...

最佳答案

除了默认删除 cookie "SESSION"和 WebSession(WebFlux 中的 session 名称)之外,您还可以配置 ServerLogoutSuccessHandler:

    .logout()
.logoutSuccessHandler(new ServerLogoutSuccessHandler() {
@Override
public Mono<Void> onLogoutSuccess(WebFilterExchange exchange, Authentication authentication) {
ServerHttpResponse response = exchange.getExchange().getResponse();
response.setStatusCode(HttpStatus.FOUND);
response.getHeaders().setLocation(URI.create("/login.html?logout"));
response.getCookies().remove("JSESSIONID");
return exchange.getExchange().getSession()
.flatMap(WebSession::invalidate);
}
})

关于spring-boot - Spring Security WebFlux 注销,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59253949/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com