I want to display some content conditionally based on Roles using Spring Security JSP taglibs. But in Spring Security 3.1.x is checking for only one role.
I can use but ifAllGranted is deprecated.
Any help?
I want to display some content conditionally based on Roles using Spring Security JSP taglibs. But in Spring Security 3.1.x is checking for only one role.
I can use but ifAllGranted is deprecated.
Any help?
you can try in this way if you are using thymeleaf
sec:authorize="hasAnyRole('ROLE_ADMIN','ROLE_USER')"
hasAnyRole will return true if the authenticated principal contains at least one of the specified roles,false otherwise.
Please note you have to use sec tag in your html declaration tag like this
<html xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4">
Within Spring Boot 2.4 it is
sec:authorize="hasAnyRole('ROLE_ADMIN')
Ensure that you have
thymeleaf-extras-springsecurity5
in your dependencies. Also make sure that you include the namespace
xmlns:sec="http://www.thymeleaf.org/extras/spring-security"
in your html...