【发布时间】:2018-05-21 20:09:38
【问题描述】:
我有一个具有多个角色(ROLE1、ROLE2)的安全 springboot 应用程序。一位用户同时具有两种角色,而另一位用户只有一种。成功登录后,用户将被发送到登录页面,如果用户只有一个角色,我想在那儿禁用元素。
我尝试过 thymeleaf-extras-springsecurity3 但没有成功。这是我的代码:
Pom.xml
...
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity3</artifactId>
<version>3.0.2.RELEASE</version>
</dependency>
...
landing.html(尝试了所有选项)
!${currentUser.user.hasAuthority('ROLE1')}
!${#authorization.expression('hasRole('ROLE1')')}
${#authentication.getPrincipal().getUser().getRoles()}
${#authentication.getPrincipal().getRoles()}
但是没有成功,我总是得到像这样的对象的空错误
org.springframework.expression.spel.SpelEvaluationException: EL1011E: Method call: Attempted to call method getPrincipal() on null context object
任何帮助将不胜感激!谢谢!
【问题讨论】:
标签: java spring spring-security thymeleaf