具有动态权限检查的Spring安全性

时间:2019-03-08 06:56:48

标签: spring-security thymeleaf

<div xmlns:th="http://www.w3.org/1999/xhtml" xmlns:sec="http://www.w3.org/1999/xhtml">
 <span sec:authorize="hasAnyRole(${p})">
<button>Save</button>
</span>
</div>

我有这段代码可以检查访问“保存”按钮的权限。

model.addAttribute(“ p”,p);在控制器处添加了p作为逗号分隔的特权。因此,如何检查用户是否具有给定角色。

1 个答案:

答案 0 :(得分:0)

请考虑使用 Preprocessing 功能。您可以按照以下步骤进行操作:

<div xmlns:th="http://www.w3.org/1999/xhtml" xmlns:sec="http://www.w3.org/1999/xhtml">
 <span sec:authorize="hasAnyRole(__${p}__)">
<button>Save</button>
</span>
</div>

请注意使用双下划线开头和结尾字符,百里香首先在此表达式之前先评估此表达式。

相关问题