我正在開發(fā)一個 Spring Boot 項(xiàng)目和用于會話控制的 WebSecurityConfig。問題是,當(dāng)會話過期時,我被重定向到/?sessionexpired我期望它應(yīng)該重定向 o 的時候/?expiredsession。此外,當(dāng)用戶注銷時,頁面會重定向到/?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貢獻(xiàn)1155條經(jīng)驗(yàn) 獲得超0個贊
所以我最終想通了。它正在重定向,/?sessionexpired
因?yàn)樵谧N時我通過將其設(shè)置為 true 來使Session失效。我應(yīng)該將其設(shè)置為 false,然后用于.deleteCookies("JSESSIONID")
使會話無效。這樣它就會正確重定向。
添加回答
舉報
0/150
提交
取消