zoukankan      html  css  js  c++  java
  • Spring Security之注销登录

    Spring Security支持在继承WebSecurityConfigurerAdapter的配置类中配置注销登录:

    HttpSecurity内的logout()方法以一个LogoutConfigurer作为配置基础,创建一个用于注销登录的过滤器:
    HttpSecurity:

    public LogoutConfigurer<HttpSecurity> logout() throws Exception {
           return (LogoutConfigurer)this.getOrApply(new LogoutConfigurer());
       }
    
       public HttpSecurity logout(Customizer<LogoutConfigurer<HttpSecurity>> logoutCustomizer) throws Exception {
           logoutCustomizer.customize(this.getOrApply(new LogoutConfigurer()));
           return this;
       }
    

    LogoutConfigurer:

        public void configure(H http) throws Exception {
            LogoutFilter logoutFilter = this.createLogoutFilter(http);
            http.addFilter(logoutFilter);
        }
    
    
        private LogoutFilter createLogoutFilter(H http) {
            this.logoutHandlers.add(this.contextLogoutHandler);
            this.logoutHandlers.add(this.postProcess(new LogoutSuccessEventPublishingLogoutHandler()));
            LogoutHandler[] handlers = (LogoutHandler[])this.logoutHandlers.toArray(new LogoutHandler[0]);
            LogoutFilter result = new LogoutFilter(this.getLogoutSuccessHandler(), handlers);
            result.setLogoutRequestMatcher(this.getLogoutRequestMatcher(http));
            result = (LogoutFilter)this.postProcess(result);
            return result;
        }
    

    它默认注册了一个/logout路由,用户通过访问该路由可以安全地注销其登录状态,包括使HttpSession失效、清空已配置的Remember-me验证,以及清空SecurityContextHolder,并在注销成功之后重定向到/login?logout页面。

    如有必要,还可以重新配置:

  • 相关阅读:
    Asp中JSON的使用
    POJ 3243 Clever Y Extended-Baby-Step-Giant-Step
    [Java开发之路](16)学习log4j日志
    【剑指Offer学习】【面试题49:把字符串转换成整数】
    负载均衡器&amp;http正向代理
    Android应用开发经常使用知识
    java8_api_nio
    李洪强经典面试题25(选择题)
    李洪强经典面试题24
    李洪强经典面试题23
  • 原文地址:https://www.cnblogs.com/hanlk/p/13194118.html
Copyright © 2011-2022 走看看