NorwegianDeveloper005
NorwegianDeveloper005

Reputation: 31

Problem with Spring Boot Security and CORS when it comes to POST requests

I want to secure a REST service for personal use and used as a backed for an Angular app using method to method security like this.

    @PreAuthorize("hasPermission(#id, 'Player', 'expenseReport.allowed')")
    @GetMapping(value = "editplayer")
    @CrossOrigin(origins = crossorg)
    public Player getEditPlayerAuthorize(@RequestParam Long id){
        return fetcher.fetchPlayer(id);
    }

The @CrossOrigin annotation works perfectly where, but when I try the same on a POST request it fails because of CORS:

    @PostMapping(value = "login", produces = "application/json")
    @CrossOrigin(origins = crossorg)
    public Login attemptLogin(@RequestBody Login payload) {        
        return handler.attemptLogin(payload);
    }

So I guess Spring Boot security is somehow interfering in this, but I see no solution why this should affect only POST requests? They worked fine before I added Spring Boot Security.

Upvotes: 0

Views: 279

Answers (1)

Naveen Chikkamath
Naveen Chikkamath

Reputation: 11

  1. Add the proper url for @CrossOrigin? (For eg. localhost url of front end).

  2. default enabled csrf may have to be disabled.

refer this How to Solve 403 Error in Spring Boot Post Request

Request Experts to help resolve this.

Upvotes: 1

Related Questions