spring-security - 具有动态权限检查的 Spring 安全性
问题描述
<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 作为逗号分隔的权限。那么如何检查用户是否具有任何给定的角色。
解决方案
请考虑使用预处理功能。你可以这样做:
<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 先评估此表达式。
推荐阅读
- openssl - 使用 Windows 将 MQTT AWS 桥接到本地 Mosquitto。有人有工作设置吗?
- wordpress - Wordpress .. 如何将网站限制为 IP 或登录
- debugging - 如何查找 VC++/MFC-App 的内存消耗
- php - 正则表达式如何找到行首和行尾
- makefile - 是什么在下面的代码中使 makefile 错误?
- android - 画布drawBitmap不显示位图
- ionic-framework - 如何在 ionic 4 中为桌面视图创建切换侧边栏
- windows - 在 Windows 上的窗口之间切换时,如何禁用自动选择保存到字段(和类似字段)上的输入文本?
- angular - 将我的 @angular/compiler-cli 版本从 8.2.13 降级到 6.1.10
- graphql - @connection 上的 Appsync 过滤列表