Sunday, May 16, 2021

POST call forbidden (403) in Spring Boot application

If you are getting status code 403 (forbidden) error for a POST call in Spring Boot application and if you are fine with disabling CSRF (cross site request forgery), you can disable CSRF to continue your POST call.
Here is the code snippet to do this:


@EnableWebSecurity

public class WebSecurityConfig extends WebSecurityConfigurerAdapter {


    @Override

    protected void configure(HttpSecurity http) throws Exception {

        http.csrf().disable();

    }

}



References:

  1. https://github.com/pyav/restful-web-services/blob/main/src/main/java/com/pyav/rest/webservices/restfulwebservices/WebSecurityConfig.java