我正在使用带有 REST 的 Spring Security,并且我正在使用 URL (/logout
) 作为我的注销方法的端点。但是调用这个方法后,它把我重定向到(/login?logout
),我知道这是spring logOutSuccessUrl
。我想摆脱重定向。这是我的代码:
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/login").permitAll()
.anyRequest().fullyAuthenticated()
.and().requiresChannel().anyRequest().requiresSecure()
.and().httpBasic().disable().logout()
.disable()
// .logoutSuccessHandler(new HttpStatusReturningLogoutSuccessHandler(HttpStatus.OK))
.csrf().disable();
}
我尝试使用 HttpStatusReturningLogoutSuccessHandler
但它不起作用,甚至设置 logoutSuccessUrl()
也没有任何改变。
您知道如何禁用此重定向吗?
最佳答案
以下代码对我有用(注意它没有 logout().disable()
)
http.logout().permitAll();
http.logout().logoutSuccessHandler((new HttpStatusReturningLogoutSuccessHandler(HttpStatus.OK)));
https://stackoverflow.com/questions/36354405/