为了账号安全,请及时绑定邮箱和手机立即绑定

Spring Boot WebSecurityConfig LogoutSuccessURL

Spring Boot WebSecurityConfig LogoutSuccessURL

蝴蝶不菲 2023-09-20 15:20:43
我正在开发一个 Spring Boot 项目和用于会话控制的 WebSecurityConfig。问题是,当会话过期时,我被重定向到/?sessionexpired我期望它应该重定向 o 的时候/?expiredsession。此外,当用户注销时,页面会重定向到/?sessionexpired而不是/?logout.我的配置如下    @Override    protected void configure(HttpSecurity http) throws Exception {        http            .authorizeRequests()                .antMatchers("/thirdparty/**", "/webjars/**", "/sessionerror").permitAll()                .anyRequest().authenticated()                .and()            .formLogin()                .loginPage("/")                .failureUrl("/?error")                .defaultSuccessUrl("/dashboard")                .permitAll()                .and()            .logout()                .logoutUrl("/logout")                .logoutSuccessUrl("/?logout")                .logoutRequestMatcher(new AntPathRequestMatcher("/logout")) // override default of only allowing POST for logout so we can use a GET                .deleteCookies("remove")                .invalidateHttpSession(true)                .permitAll()                .and()            .sessionManagement()                .maximumSessions(1)                .expiredUrl("/?expiredsession")                .maxSessionsPreventsLogin(false)                .and()            .invalidSessionUrl("/?sessionexpired");    }有人可以帮我解决这个问题吗?
查看完整描述

1 回答

?
白衣非少年

TA贡献1155条经验 获得超0个赞

所以我最终想通了。它正在重定向,/?sessionexpired因为在注销时我通过将其设置为 true 来使Session失效。我应该将其设置为 false,然后用于.deleteCookies("JSESSIONID")使会话无效。这样它就会正确重定向。



查看完整回答
反对 回复 2023-09-20
  • 1 回答
  • 0 关注
  • 76 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信