spring security customize logout handler

前端 未结 4 2108
谎友^
谎友^ 2020-12-15 05:25

How can I add my own logout handler to LogoutFilter in spring-security ? Thanks!

4条回答
  •  攒了一身酷
    2020-12-15 05:35

    You can use java-config solutions like this.

    
    @Configuration
    @EnableWebSecurity
    
    public class SpringSecurity2Config extends WebSecurityConfigurerAdapter {
    
    
        @Override
        protected void configure(HttpSecurity http) throws Exception {
           //you can set other security config by call http.XXX()
    
            http
                    .logout()
                    .addLogoutHandler(new CustomLogoutHandler())
                    .logoutUrl("/logout")
                    .logoutSuccessHandler(...)
                    .permitAll();
    
        }
    
        static class CustomLogoutHandler implements LogoutHandler {
            @Override
            public void logout(HttpServletRequest request, HttpServletResponse response, Authentication authentication) {
                //...
    
            }
    
        }
    
    }
    

提交回复
热议问题