如何在Mustache中使用Spring Security? [英] How to use Spring Security with Mustache?

查看:69
本文介绍了如何在Mustache中使用Spring Security?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在遵循Spring Security参考,并且已经重定向到自定义登录页面,其工作方式如

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}}

...但是它们不起作用(而且我没想到他们真的可以).如何在Moustache中获得CSRF令牌?

...but they don't work (and I didn't really expect them to). How can I get the CSRF token in Mustache?

我还想知道:我可以在代码中的哪里设置断点,以查看Spring Security作为模型发送到自定义登录视图的内容?

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?)

推荐答案

将此添加到您的application.properties:

spring.mustache.expose-request-attributes=true

然后,您可以访问模板中的_csrf请求属性.

Then you have access to the _csrf request attribute in your template.

这篇关于如何在Mustache中使用Spring Security?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆