Client of our API's don't use patch and I want to avoid it for maintenance overhead. I don't want to disable POST or PUT.
It can be handled at the security level, by extending WebSecurityConfigurerAdapter (available in spring-security-config) and overriding configure(HttpSecurity http)
to deny PATCH requests to the target url :
@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();
}
}
Any attempt to PATCH to the target URL will fail with a 401 Unauthorized
error.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With