【问题标题】:Spring security with dynamic privilege checking具有动态权限检查的 Spring 安全性
【发布时间】:2019-03-09 20:07:49
【问题描述】:
<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 作为逗号分隔的权限。那么如何检查用户是否具有任何给定的角色。

【问题讨论】:

    标签: spring-security thymeleaf


    【解决方案1】:

    请考虑使用 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>
    

    注意使用双下划线开始和结束字符,其中 thymeleaf 先评估此表达式。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-12-01
      • 2017-02-14
      • 2012-06-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-10
      • 1970-01-01
      相关资源
      最近更新 更多