I have application in SpringMVC with Spring Security. In spring security xml configuration file i enable csrf using <csrf/>
. View in html work properly when i add csrf token to link in form but now i want add Controller and made some rest communication. Controller looks like this:
@Controller
public class RestControllerTest {
@RequestMapping(value = "/rest", method = RequestMethod.POST, produces = "application/json")
@ResponseStatus(value = HttpStatus.OK)
public @ResponseBody void setUser(@RequestBody User user){
System.out.println("Witaj " + user.getFirstname() + "!");
}
}
When i try to send JSon with user (using postman):
{
"firstname": "name",
"lastname": "name"
}
I get 404 not found status in postman and WARN : org.springframework.web.servlet.PageNotFound - Request method 'POST' not supported
in STS. I know that I have to use csrf token but i don't have idea how to do this.