如何使用 Thymeleaf 配置 SpringBoot 并使用 sec:authentication 标签 [英] How can I configure SpringBoot with Thymeleaf and use sec:authentication tag
问题描述
我的应用程序使用 spring-boot 1.2.5 + thymeleaf + spring security.
我需要在我的网站上显示用户名,经过一些研究后,我似乎应该使用如下代码:
的name"属性的值认证对象应该出现在这里.
但是我没有让 Thymeleaf 解析那个标签.请我需要一些帮助:(
您需要在您的项目中添加 Spring Security 3 集成模块.这些模块是相当于 Spring 安全标签库的 Thymeleaf 方言.这些是 thymeleaf 额外模块,不是 Thymeleaf 核心的一部分.
在您的模板引擎中只需添加集成模块方言.
...<属性名称="additionalDialects"><设置><bean class="org.thymeleaf.extras.springsecurity4.dialect.SpringSecurityDialect"/></set></属性>...</bean>
添加模块后,您可以使用以下代码:
的name"属性的值身份验证对象应出现在此处.
Thymeleaf 等效模块可以在此处找到.另外,请参阅此 ThemeLeaf 的分步教程
更新:
如果您使用的是 Spring Boot,您只需要在 pom.xml 中添加依赖项或在您的项目中添加 jars.
Im using spring-boot 1.2.5 + thymeleaf + spring security for my application.
I need to display the username in my website, after doing some research seems that I should use code something like:
<div sec:authentication="name">The value of the "name" property of
the authentication object should appear here.</div>
However I don't get Thymeleaf to parse that tag. Please I need some help :(
You need to add Spring Security 3 integration module in your project. These module are Thymeleaf dialect equivalent to Spring security tag lib. These are thymeleaf extra modules and are not a part of the Thymeleaf core.
In your Template Engine Just add the integration module dialect.
<bean id="templateEngine" class="org.thymeleaf.spring3.SpringTemplateEngine">
...
<property name="additionalDialects">
<set>
<bean class="org.thymeleaf.extras.springsecurity4.dialect.SpringSecurityDialect"/>
</set>
</property>
...
</bean>
After adding the modules, you can use your following code:
<div sec:authentication="name">The value of the "name" property of
the authentication object should appear here.</div>
Thymeleaf equivalent modules can be found here. Also, refer this Step by Step tutorial of TheymeLeaf
UPDATE:
If you are using Spring Boot, You just need add the dependency in the pom.xml or add the jars in your project.
这篇关于如何使用 Thymeleaf 配置 SpringBoot 并使用 sec:authentication 标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!