Spring 安全性 w/LDAP 注销无法删除会话

Spring Security w/LDAP Logout can't remove session

我正在使用 spring-boot-starter-security' 版本:'2.0.0 来保护 REST API。 另外,我正在登录 LDAP 服务器。我的登录工作正常,当我将端点与身份验证配置放在一起时,浏览器会询问 user/pass。 问题是当我执行注销时,我可以重新输入需要身份验证的端点,我的意思是,如果请求安全端点,则需要 user/pass。如果我登录正常,API 会显示端点的结果,但如果我执行注销,注销会告诉我成功并且我再次请求安全端点,但结果显示没有登录。 此外,我配置了 2 个最大会话,当我执行两次注销时,我无法再次登录,因为我收到了最大会话的错误。 所以在某种程度上,我的注销效果不佳。

这是我的代码:

@Configuration 

@EnableWebSecurity public class SecurityConfig 扩展 WebSecurityConfigurerAdapter {

@Override protected void configure(HttpSecurity http) 抛出异常 {

    http.
            httpBasic()
            .and().authorizeRequests()
            .antMatchers("/about/**","/hello/**","/logout/**","/logout-success","/login/**").permitAll() //Allow to all to this url
            .anyRequest().fullyAuthenticated()
            .and()
            .requestCache()
            .requestCache(new NullRequestCache())
            .and()
            .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.NEVER)
            .maximumSessions(2).expiredUrl("/login").maxSessionsPreventsLogin(true)
            .and()
    ;

    http.csrf().disable();
    http.headers().frameOptions().disable();

    //logout
    http.logout().deleteCookies("JSESSIONID").invalidateHttpSession(true).logoutUrl("/logout").logoutSuccessUrl("/logout-success");

}

@Override
public void configure(AuthenticationManagerBuilder auth) throws Exception {


    String ldapURL = "ldaps://xxxx";

    auth
            .ldapAuthentication()
            .userSearchFilter("xxx")
            .userSearchBase("xxxx")
            .groupSearchBase("xxxx")
            // .groupSearchFilter("member={0}")
            .contextSource()
            .url(ldapURL)
            .port(xxx)
            .managerDn("xxxx")
            .managerPassword("xxxx")
    ;

}

我发现了关于此的不同理论,最常见的是说您无法使用 "Basic" 配置执行有效注销的理论:

http.httpBasic() 

因此,解决方案是使用表单页面提供身份验证或 .formLogin() 由 Spring 提供。