Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

403 forbidden error when using Spring boot - security

I'm getting 403 forbidden error when using Spring boot security for basic authentication. I get this error when using the POST method.

My main class code is as follows,

@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) 
    {
       return builder.sources(MyContext.class);
    }

Please suggest a solution for this. Thanks

like image 547
Supriya Avatar asked Oct 19 '25 01:10

Supriya


1 Answers

I get this error using Post method.

Above line gives hint that the issue is due to CSRF protection. If users will not be using your application in a web browser, then it is safe to disable CSRF protection. Otherwise you should ensure to include the CSRF token in the request.

To disable CSRF protection you can use the following:

@Override
protected void configure(HttpSecurity http) throws Exception {
     http
     // ...
     .csrf().disable();
}

Refer spring-security-csrf

like image 111
Alien Avatar answered Oct 21 '25 03:10

Alien