Spring Security - All JQuery Ajax post requests return 404

后端 未结 4 1046
说谎
说谎 2021-02-05 23:14

All my $.ajax, both POST and GET were working fine, but as soon as I integrated Spring security 3.2.6 into my project the

4条回答
  •  不要未来只要你来
    2021-02-06 00:13

    Finally after three agonizing days, I found the problem and boy was it stupid.

    The problem was that I have enabled csrf protection in spring security. And that was causing my post requests to be forbidden which triggers the access-denied-handler error page, since I have not mapped my access-denied-handlerto the "/403" error page as shown below, my http 403/401 was being masked by the http 404

    
    

    So in Short

    1. Map your access-denied-handler error page to a valid url
    2. If you use csrf protection, then always make sure that you pass them in the ajax post request as such

    $.ajax({method :'POST', url : '/ajax',data : {"${_csrf.parameterName}" : "${_csrf.token}"}});

提交回复
热议问题