i have a secured springboot application with multiple roles (ROLE1,ROLE2). One user has both roles and the other one has only one. On successful login user is sent to the landing page, over there i want to disable element if user has only one role.
I've tried with thymeleaf-extras-springsecurity3 but with no success. This is my code:
Pom.xml
...
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity3</artifactId>
<version>3.0.2.RELEASE</version>
</dependency>
...
landing.html (tried with all of the options)
!${currentUser.user.hasAuthority('ROLE1')}
!${#authorization.expression('hasRole('ROLE1')')}
${#authentication.getPrincipal().getUser().getRoles()}
${#authentication.getPrincipal().getRoles()}
But with no success, i always get null error for that object like this
org.springframework.expression.spel.SpelEvaluationException: EL1011E: Method call: Attempted to call method getPrincipal() on null context object
Any help would be much appreciated! Thanks!