Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I specifically disable PATCH in spring-data-rest repository?

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.

like image 918
utkarsh dubey Avatar asked Oct 17 '22 20:10

utkarsh dubey


1 Answers

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.

like image 182
Marc Tarin Avatar answered Oct 20 '22 23:10

Marc Tarin