1

「プロフィールの編集」リンクがあるプロフィール ページがあるとします。プロファイル ページはすべてのユーザーが表示できますが、リンクの編集ボタンは、別のユーザーのプロファイルではなく、自分のプロファイルを表示しているログイン ユーザーに対してのみ表示される必要があります。

今のところ、私はこのコードを持っています、

<sec:authorize access="isAuthenticated()">
<sec:authentication property="principal.username" var="principal"/>
<c:if test="${profile_username eq principal}">   <!--profile_username is the username of the viewed profile  -->
<!-- edit your profile link -->
</c:if>
</sec:authorize>    

これを行うよりクリーンな方法はありますか?? のようなワンライナーかもしれません

<sec:authorize access="isTheSamePerson()"/>.

前もって感謝します。:)

4

1 に答える 1

1

実際のドメイン オブジェクトを考慮に入れる必要があります。これらの目的のために、Spring Security には特別なACL機能があります。それを設定して、対応するaccesscontrollistタグを使用できます。

<sec:accesscontrollist hasPermission="2" domainObject="${profile}">
    <!-- Your edit link goes here -->
    <!-- "2" means write permission -->
    <!-- Be sure that you use Spring Security >= 3.1.2. This syntax may not works for smaller versions due to bugs  -->
</sec:accesscontrollist>

このような状況が 1 つしかない場合は、やり過ぎかもしれません。

オプション番号 2. カスタム Web セキュリティ式を定義できます。

<sec:authorize access="isOwner(#profile)"/>.

それほど単純ではありません。

カスタム JSP タグ (タグ ファイル) が最も簡単な解決策になると思います。

<customtags:authorizeeditaccount account="${profile}"/> 

このタグは同じことを行います。それはずっと良く見えるでしょう。

于 2013-01-22T15:10:05.350 に答える