Spring Boot WebSecurityConfig LogoutSuccessURL

我正在开发一个 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");

    }


有人可以帮我解决这个问题吗?


蝴蝶不菲
浏览 77回答 1
1回答

白衣非少年

所以我最终想通了。它正在重定向,/?sessionexpired因为在注销时我通过将其设置为 true 来使Session失效。我应该将其设置为 false,然后用于.deleteCookies("JSESSIONID")使会话无效。这样它就会正确重定向。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java