要想使用thymeleaf为SpringSecurity提供的标签属性,首先需要引入thymeleaf-extras-springsecurity4依赖支持。
<!--Spring Security和thymeleaf的整合依赖-->
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity4</artifactId>
</dependency>
目前了解到的有关SpringSecurity的标签属性有以下几个:
sec:authorize="isAuthenticated()"
判断用户是否已经登陆认证,引号内的参数必须是isAuthenticated()。
sec:authentication=“name”
获得当前用户的用户名,引号内的参数必须是name。
sec:authorize=“hasRole(‘role’)”
判断当前用户是否拥有指定的权限。引号内的参数为权限的名称。
sec:authentication="principal.authorities"
获得当前用户的全部角色,引号内的参数必须是principal.authorities。