Spring Security Key in JSTL tags
Is there a way to convert form jsp code
<security:authorize access="hasRole('ROLE_USER')">You're an user</security:authorize>
<security:authorize access="hasRole('ROLE_ADMIN')">You're an admin</security:authorize>
<security:authorize access="hasRole('ROLE_SADMIN')">You're a superadmin</security:authorize>
to another form similar to the following (doesn't work)?
<c:choose>
<c:when test="hasRole('ROLE_USER')">
You're an user
</c:when>
<c:when test="hasRole('ROLE_ADMIN')">
You're an admin
</c:when>
<c:when test="hasRole('ROLE_SADMIN')">
You're a superadmin
</c:when>
<c:otherwise>
You have no relevant role
</c:otherwise>
</c:choose>
More precisely, is there a way to replace this Spring security taglib functionality with JSTL tags?
You can use the vartag attribute <security:authorize/>that will create:
A variable of the area in which the logical result of the tag is located will be written a score, allowing you to reuse the same condition subsequently on the page without reevaluation.
<security:authorize access="hasRole('ROLE_USER')" var="isUser" />
<security:authorize access="hasRole('ROLE_ADMIN')" var="isAdmin" />
<security:authorize access="hasRole('ROLE_SADMIN')" var="isSuperUser" />
<c:choose>
<c:when test="${isSuperUser}">
You're a superadmin
</c:when>
<c:when test="${isAdmin}">
You're an admin
</c:when>
<c:when test="${isUser}">
You're an user
</c:when>
<c:otherwise>
You have no relevant role
</c:otherwise>
</c:choose>