假设我有一个配置文件页面,其中有一个'编辑您的配置文件'链接。所有用户都可以查看配置文件页面,但编辑链接按钮应仅对登录的用户查看其配置文件而非其他用户的配置文件可见。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