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?)
Mustache is a simple web template system. It is available for many programming languages including Java. Mustache is described as a logic-less because it does not have any explicit control flow statements, such as if and else conditionals or for loops.
Mustache is a logic-less templating system. It permits you to use pre-written text files with placeholders that will be replaced at run-time with values particular to a given request.
Add this to yourapplication.properties
:
spring.mustache.expose-request-attributes=true
Then you have access to the _csrf
request attribute in your template.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With