1

我想将 Spring Security 属性加载到变量中。

变量:

  • edit正文中提供的布尔值POST(加载正常)
  • 如果用户具有角色主管,则布尔值isSupervisor应该为真(我不知道如何将其加载到可访问的变量中。我尝试了许多不同的方法,但没有奏效。)

代码:

//set somehow the isSupervisor variable
//var isSupervisor = hasRole('ROLE_SUPERVISOR')    
<c:if test="${edit} and not isSupervisor">
... do something
</c:if>
4

2 回答 2

5

我找到了这个解决方案:

<!-- Boolean isSupervisor -->
<!-- needed for creating the boolean: !isSupervisor -->
<c:set var="isSupervisor" value="false" />
<sec:authorize ifAllGranted="ROLE_SUPERVISOR">
    <c:set var="isSupervisor" value="true" />
</sec:authorize>


<c:if test="${!edit || (edit && !isSupervisor)}">
    // do some opertations...
</c:if>
于 2012-07-18T07:43:33.537 回答
0

看看Spring Security JSP Taglib Reference

它提供了以下示例:

<sec:authorize access="hasRole('supervisor')">

  This content will only be visible to users who have
  the "supervisor" authority in their list of <tt>GrantedAuthority</tt>s.

</sec:authorize>
于 2012-07-17T06:30:01.040 回答