JavaSpring:为什么调用/logout会重定向到/login
我正在创建一个无状态webapp后端,它提供了一系列restapi端点。扩展JavaSpring:为什么调用/logout会重定向到/login,java,spring,Java,Spring,我正在创建一个无状态webapp后端,它提供了一系列restapi端点。扩展WebSecurityConfig适配器的WebSecurityConfig类如下所示: @Override protected void configure(HttpSecurity http) throws Exception { http .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
WebSecurityConfig适配器的WebSecurityConfig
类如下所示:
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.csrf().disable()
.authorizeRequests()
.anyRequest().authenticated()
.and()
.addFilterBefore(
new JWTAuthenticationFilter(userDetailsServiceBean()),
UsernamePasswordAuthenticationFilter.class);
}
当我调用/logout
端点时,我希望在响应中得到拒绝访问
和403 http状态代码,但我得到以下结果:
{
"timestamp": 1495012033216,
"status": 405,
"error": "Method Not Allowed",
"exception": "org.springframework.web.HttpRequestMethodNotSupportedException",
"message": "Request method 'GET' not supported",
"path": "/login"
}
这就是我在头中包含或不包含身份验证JWT时得到的结果。为什么?我没有任何特定于/logout
的内容,为什么会发生这种情况
在login?logout
获得相同行为之前,我看到了一些问题,但与/logout
无关。我应该如何重写此行为并使其与任何其他Rest端点一样
这种默认行为的好处是什么 您是否可以共享控制器和请求注销端点没有控制器。我的请求是对/logout端点的简单POST调用。您正在请求/logout,而您没有到/logout的映射url?是。我使用/somethingtheatdoesntextist
执行此操作,它返回拒绝访问
响应,因为所有请求都必须经过身份验证。是的,您清楚地表明所有请求都在配置中经过身份验证。anyRequest().authenticated()