1

Spring Security 属性を変数にロードしたいと思います。

変数:

  • edit本体で提供されるブール値POST(読み込みは正常に機能します)
  • ユーザーがスーパーバイザーの役割を持っている場合、ブール値isSupervisorは true になるはずです (アクセス可能な変数にロードする方法がわかりません。さまざまなアプローチを試しましたが、うまくいきませんでした。)

コード:

//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 リファレンスをご覧ください

次の例を提供します。

<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 に答える