![](/img/trans.png)
[英]Combining namespace based configuration with different authentication methods in spring-security
[英]Spring Security configuration based on different http methods
在我的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")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.