2012-07-16 37 views
1

我想將Spring Security屬性加載到變量中。將Spring安全屬性加載到JSP變量中

變量:

  • 布爾editPOST體(負載正常工作),如果用戶具有角色的主管(我不知道如何將其加載到
  • 布爾isSupervisor應該是真實的提供。可訪問的變量,我嘗試了許多不同的方法,它不工作)

代碼:

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

可能相關的問題:HTTPS://jira.springsource .ORG /瀏覽/ SEC-1611 – 2012-07-16 09:11:33

回答

4

,我發現這個解決方案:

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