spring-boot – 我可以在spring-data-rest存储库中专门禁用PATCH吗?

我们API的客户端不使用补丁,我想避免它用于维护开销.我不想禁用POST或PUT. 最佳答案 它可以在安全级别处理,方法是扩展WebSecurityConfigurerAdapter(在
spring-security-config中可用)并覆盖configure(HttpSecurity http)以拒绝对目标URL的PATCH请求:

@Configuration
@EnableWebSecurity
public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests()
                .antMatchers(HttpMethod.PATCH, "/path_to_target_url").denyAll();
    }

}

任何PATCH到目标URL的尝试都将失败,并显示401 Unauthorized错误.

点赞