在我的 Spring Boot 应用程序中,我配置了以下 OAuth2 ResourceServer
:
@Override
public void configure(HttpSecurity http) throws Exception {
// @formatter:off
http
.antMatcher("/api/**").authorizeRequests()
.antMatchers("/api/v1.0/users").permitAll()
.anyRequest().authenticated()
.and()
.csrf().disable()
.sessionManagement().sessionCreationPolicy(STATELESS);
// @formatter:on
}
在我的 REST API UserController
中,我有两种不同的请求处理程序方法 - 用于 POST 和 GET http 方法。现在上面配置中的两个都是公开的。
我想保护 POST 方法的安全,并将 GET 设为公开,即使对于匿名用户也是如此
如何更改上述配置以支持此功能?
最佳答案
只需在匹配器中添加方法即可
antMatchers(HttpMethod.POST, "/api/v1.0/users")
关于java - 基于不同http方法的Spring Security配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39809333/