spring security 动态配置登出页面

在配置信息中添加logoutSuccessHandler

//重写WebSecurityConfigurerAdapter的config()方法;
http.logout()
        .logoutUrl("/mgmt/logout") //配置登出请求路径
        .logoutSuccessHandler(new LogoutSuccessHandler() {
            @Override
            public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
                //获取用户登录名,根据登录名获取用户信息
                String name = authentication.getName();
                //根据用户信息设置不同的登录页面
                String url = "";
                //访问对应的请求
                response.sendRedirect(url);
            }
        }).and().csrf().disable();

  

posted @ 2020-09-09 13:52  TYD  阅读(334)  评论(0编辑  收藏  举报