【发布时间】:2017-01-22 14:42:21
【问题描述】:
我有一个使用 Spring Boot 和 Spring Security 构建的 REST API。我从文档中读到 Spring Security 在请求/logout 时默认将当前用户注销。但是,我似乎无法让它工作。
这是我的安全配置:
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
@Configuration
class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.anyRequest().fullyAuthenticated()
.and()
.httpBasic()
.and()
.csrf().disable();
}
}
但是,当我向/logout 发出请求时,我收到以下错误:
{
"timestamp": 1485096094269,
"status": 404,
"error": "Not Found",
"message": "No message available",
"path": "/login"
}
【问题讨论】:
-
你不提供
.logout();参见例如spring.io/guides/gs/securing-web。你提出什么要求? -
我实际上尝试添加 .logout();从我见过的几个不同的例子中,但没有效果。您如何建议更改上述示例以启用注销?我发出的请求是对“/logout”的 GET 请求。
-
是的,配置肯定被调用了。我添加了“.logout.permitAll()”,我尝试使用 POST 方法来“/logout”,但仍然是相同的消息并且没有注销。其他人使用什么作为配置方法?
-
在使用基本身份验证时尝试注销也不起作用,下一个请求仍然发送身份验证标头,用户将再次登录。注销和基本身份验证不能同时使用。
-
我明白了,我不知道。那么你会推荐使用摘要身份验证吗?或者我是否需要使用带有“/logout”请求映射的自定义方法手动使会话无效?
标签: java spring-boot spring-security