'Spring boot API getting 403 forbidden on POST request

I am running Java Spring Boot app on AWS and using the Nginx proxy to map 8080 PORT. But always getting 403 forbidden error while connecting the API.

Tech: Java/Spring Boot OS: Ubuntu

Here is the Nginx proxy config:

proxy_pass http://localhost:8080/;
port_in_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;

Here is the Spring Security code:

httpSecurity.
            antMatcher("/api/**")
            .cors()
            .and()
            .csrf()
            .disable()
            .sessionManagement()
            .sessionCreationPolicy(SessionCreationPolicy.STATELESS)
            .and()
            .addFilter(filter)
            .addFilterBefore(new ExceptionTranslationFilter(new Http403ForbiddenEntryPoint()), filter.getClass())
            .authorizeRequests()
            .anyRequest()
            .authenticated();

Error getting in console:

"ERROR" dispatch for POST "/error", parameters={}
Using 'application/json', given [*/*]

Spent almost 2 days but nothing find helpful yet.

Thanks in advance.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source