Is there a way to implement control statement with Spring Security taglibs?
Currently we can only check if a user has a role...
<security:authorize access="hasRole('ROLE_ADMIN')">
// display something
</security:authorize>
How about else?
Spring Security has its own taglib which provides basic support for accessing security information and applying security constraints in JSPs.
Authorize Tag This tag is used for authorization purpose. This tag evaluates and check whether the request is authorized or not. It uses two attributes access and URL to check request authorization.
In Spring MVC applications using JSP, we can use the Spring Security tags for applying security constraints as well as for accessing security information. Spring Security Tag library provides basic support for such operations.
The question is old, but anyway..
You can store the result of tag evaluation into variable (at least at version 3.1) and then use it within standard if/else
construction. I think this is more useful solution than previous one.
<security:authorize access="hasRole('ROLE_ADMIN')" var="isAdmin" />
<c:choose>
<c:when test="${isAdmin}">superuser</c:when>
<c:otherwise>ordinary user</c:otherwise>
</c:choose>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With