I have a problem in my spring boot application with csrf token.
I have a form where I can edit Personality. Man can have
Now imagine that a person has a car, and enter it and save it. Next time he wants to remove this car and introduce another one. I created it so that there is a list of all his cars - he has the ability to remove it from the list. Now I start with these tablets and want to send with the appropriate ID to the POST server. When I try, I get a 403 ban and I have no idea why.
If I switch from POST to GET, it will work.
My JavaScript (taken from this site: http://docs.spring.io/autorepo/docs/spring-security/4.0.0.CI-SNAPSHOT/reference/htmlsingle/#the-csrfmetatags-tag )
var csrfParameter = $("meta[name='_csrf_parameter']").attr("content"); var csrfHeader = $("meta[name='_csrf_header']").attr("content"); var csrfToken = $("meta[name='_csrf']").attr("content"); // using JQuery to send a non-x-www-form-urlencoded request var headers = {}; headers[csrfHeader] = csrfToken; $.ajax({ url: "./delete/car", type: "GET", headers: headers, }); $.ajax({ url: "./delete/car", type: "POST", headers: headers, });
My controller methods:
@RequestMapping(value = "/{login}/delete/car", method = RequestMethod.GET) public ModelAndView delete(@PathVariable("login") final String login) { System.out.println("Stop"); return new ModelAndView("redirect:" + WebSecurityConfig.URL_PERSONS_OVERVIEW); } @RequestMapping(value = "/{login}/delete/car", method = RequestMethod.POST) public ModelAndView deleteInstEmp(@PathVariable("login") final String login) { System.out.println("Stop"); return new ModelAndView("redirect:" + WebSecurityConfig.URL_PERSONS_OVERVIEW); }
Any suggestions?
Thanks in advance.
source share