我正在使用spring-boot-starter-security'版本:'2.0.0来保护REST API . 另外,我正在登录LDAP服务器 . 我的登录工作正常,当我将 endpoints 与身份验证配置放在一起时,浏览器会询问用户/通过 . 问题是当我执行注销时,我可以重新进入需要身份验证的 endpoints ,我的意思是,如果请求是安全 endpoints ,则需要用户/传递 . 如果我登录正常,API会显示 endpoints 的结果,但是如果我执行注销,则注销会显示我已成功并且我再次请求安全 endpoints ,但结果显示没有登录 . 此外,我配置了2个最大会话,当我执行两次注销时,我无法再次登录,因为我收到了最大会话错误 . 所以在某种程度上,我的注销效果不佳 .
这是我的代码:
@Configuration
@EnableWebSecurity公共类SecurityConfig扩展了WebSecurityConfigurerAdapter {
@Override protected void configure(HttpSecurity http)抛出Exception {
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")
;
}
1 回答
我找到了不同的理论,最常见的是那个说你不能用“基本”配置执行有效注销的理论:
因此,解决方案是使用表单页面来提供身份验证或Spring提供的
.formLogin()
.