gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 20:33:03 24 4
gpt4 key购买 nike

我们 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();
}

}

任何对目标 URL 进行 PATCH 的尝试都将失败并返回 401 Unauthorized错误。

关于spring-boot - 我可以在 spring-data-rest 存储库中专门禁用 PATCH 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41345847/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com