假設我有一個配置文件頁面,其中有一個'編輯您的配置文件'鏈接。所有用戶都可以查看配置文件頁面,但編輯鏈接按鈕應僅對登錄的用戶查看其配置文件而非其他用戶的配置文件可見。Spring Security - 顯示特定於登錄用戶的內容
截至目前,我有這樣的代碼,
<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()"/>
一個班輪。
在此先感謝。 :)
您不應該需要sec:authorize標記,如果用戶未登錄,主體對象將爲空,並且c:if測試將失敗。不完全是你想要的,但它會把它清理一點。 – dardo
不錯。但是,如果沒有sec:auth標記,這將無法正常工作。它會拋出一個異常。 – shazinltc
好的,這是跛腳 – dardo