哪个功能可以在jsp页面中调用以验证登录的用户是否在角色中 [英] Which is the right function to call in a jsp page to verify the logged user is in role

查看:85
本文介绍了哪个功能可以在jsp页面中调用以验证登录的用户是否在角色中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种功能来验证登录的用户是否属于某个角色.可能是以下情况?

I'm looking for the function to verify if the user logged belongs to a role. is maybe the following?

pageContext.request.userPrincipal.roles 

如何与JSTL一起正确使用它来测试用户是否属于ADMIN组?

How should I use it properly along with JSTL to test if the user belong to ADMIN group?

推荐答案

您可以在JSP中使用方法表达式' request.isUserInRole '检查当前经过身份验证的用户是否具有角色.

You can use Method expression 'request.isUserInRole' in JSP to check whether current authenticated user has a role.

对此进行测试:

<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>

请注意:仅JavaEE6(JSP 2.2和EL 2.2)支持在EL表达式中使用/不使用参数的调用方法.

Note that: Calling method with/without parameters in EL expression is only supported from JavaEE6 (JSP 2.2 & EL 2.2).

这篇关于哪个功能可以在jsp页面中调用以验证登录的用户是否在角色中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆