I'm following the Spring Security reference, and I've got redirection to a custom login page working as described in section 3.3. However, I'm not sure how to get the CSRF token in Mustache (all the examples use JSP). I've tried a few naïve things like this...
{{#_csrf}}
<input type="hidden" name="{{parameterName}}" value="{{token}}"/>
{{/_csrf}}
...and this...
{{#CsrfToken}}
<input type="hidden" name="{{parameterName}}" value="{{token}}"/>
{{/CsrfToken}}
...but they don't work (and I didn't really expect them to). How can I get the CSRF token in Mustache?
I'm also wondering: Where could I set a breakpoint in my code to see what Spring Security is sending as the model to my custom login view?)
DispatcherServlet
. If you're going to use a template engine such as Mustache that doesn't have out-of-the-box integration, you'll need to look up the CSRF token in your controller and add it to the model yourself. – AlpacaHttpServletRequest
argument to my@RequestMapping
handler method and got an instance ofCsrfToken
from the "_csrf" attribute. If you add an answer, I'll accept it. – Symmetrize