Mat*_*llo 8 java spring spring-security
我刚刚在我的 Spring Boot 项目类路径中添加了 Spring Security。我没有做 Java 配置或 XML 配置。
问题是,当我向资源localhost:8080/users发送请求时,我的第一个请求通常会得到身份验证(通过基本身份验证),但后续请求不需要任何身份验证标头。即使我重新启动服务器,请求仍在进行身份验证而无需输入任何凭据。
我想关闭这个“缓存”。
我尝试了很多客户。Postman, SOAP-UI, browsers..Already read this , but not works
Mat*_* Ke 13
您必须将会话创建策略设置为 STATELESS。否则 Spring 安全将使用 cookie。
(您可以在 Postman 中发送按钮下方的 cookie 菜单中删除 cookie。)
示例配置:
@Configuration
@EnableWebSecurity(debug = true)
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.sessionManagement().sessionCreationPolicy(
SessionCreationPolicy.STATELESS)
.and()
.authorizeRequests()
.anyRequest().authenticated()
.and()
.httpBasic();
}
...
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6280 次 |
| 最近记录: |