I'm looking for the function to verify if the user logged belongs to a role. is maybe the following?
pageContext.request.userPrincipal.roles
How should I use it properly along with JSTL to test if the user belong to ADMIN group?
You can use Method expression 'request.isUserInRole' in JSP to check whether current authenticated user has a role.
Test this:
<c:if test="${not empty pageContext.request.userPrincipal}">
<c:if test="${pageContext.request.isUserInRole('ADMIN')}">
User ${pageContext.request.userPrincipal.name} in ADMIN Group
</c:if>
</c:if>
Note that: Calling method with/without parameters in EL expression is only supported from JavaEE6 (JSP 2.2 & EL 2.2).
来源:https://stackoverflow.com/questions/24170824/which-is-the-right-function-to-call-in-a-jsp-page-to-verify-the-logged-user-is-i