thymeleaf-extras-springsecurity
モジュールを使用すると、式ユーティリティオブジェクトを使用して、th:if
の中にSpringセキュリティの認証式を使用できます。実際に
<div th:if="${#authorization.expression('hasRole(''ROLE_ADMIN'')') and #authorization.expression('...') }">
This will only be displayed if authenticated user has role ROLE_ADMIN.
</div>
あなたはタグライブラリを使用しているかのようにあなたがsec:authentication
とsec:authorize
を使用できるように、この新しいモジュールによって追加の方言は、デフォルトの接頭辞としてsec
を使用しています。
<div sec:authorize="hasRole('ROLE_ADMIN')">
This will only be displayed if authenticated user has role ROLE_ADMIN.
</div>
<div sec:authentication="name">
The value of the "name" property of the authentication object should appear here.
</div>
は、あなたがしなければならないのは、私は感謝、探していたまさにあなたのテンプレートエンジンの設定
<bean id="templateEngine" class="org.thymeleaf.spring3.SpringTemplateEngine">
...
<property name="additionalDialects">
<set>
<!-- Note the package would change to 'springsecurity3' if you are using that version -->
<bean class="org.thymeleaf.extras.springsecurity4.dialect.SpringSecurityDialect"/>
</set>
</property>
...
</bean>
をする方言を追加することです! – DiegoSahagun
@Bnrdo Javaクラスを使って同じことを行う方法は? –