【发布时间】:2018-08-27 13:25:56
【问题描述】:
我正在使用 spring-boot-starter-security' version: '2.0.0 来保护 REST API。 另外,我正在登录 LDAP 服务器。我的登录工作正常,当我放置一个带有身份验证配置的端点时,浏览器会询问用户/密码。 问题是当我执行注销时,我可以重新输入需要身份验证的端点,我的意思是,如果请求安全端点,则需要用户/通行证。如果我登录成功,API 会显示端点的结果,但如果我执行注销,注销会显示成功并且我再次请求安全端点,但结果显示没有登录。 另外,我配置了 2 max session,当我执行两次注销时,我无法再次登录,因为我收到了 max sessions 的错误。 所以在某种程度上,我的注销工作不正常。
这是我的代码:
@Configuration
@EnableWebSecurity 公共类 SecurityConfig 扩展 WebSecurityConfigurerAdapter {
@覆盖 受保护的无效配置(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")
;
}
【问题讨论】:
标签: java spring spring-security ldap logout