【问题标题】:Spring Security WebFlux logoutSpring Security WebFlux 注销
【发布时间】:2020-04-02 20:32:28
【问题描述】:

在进行类似于

的注销时,在 WebFlux 中使会话无效和删除 cookie 的等效方法是什么?
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()
...

【问题讨论】:

    标签: spring-boot spring-security spring-webflux


    【解决方案1】:

    除了cookie“SESSION”和WebSession(WebFlux中的会话名)默认被移除之外,你可以配置一个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);
                }
            })
    

    【讨论】:

      猜你喜欢
      • 2017-04-22
      • 2012-10-09
      • 2018-09-02
      • 2011-06-28
      • 2016-07-12
      • 2011-07-19
      • 1970-01-01
      • 2011-03-09
      • 2014-04-23
      相关资源
      最近更新 更多