security + oauth2 @PreAuthorize 动态配置接口角色权限

编程入门 行业动态 更新时间:2024-10-23 07:25:23

security + oauth2 @PreAuthorize 动态配置<a href=https://www.elefans.com/category/jswz/34/1771365.html style=接口角色权限"/>

security + oauth2 @PreAuthorize 动态配置接口角色权限

使用@PreAuthorize(“hasRole(‘ROLE_ADMIN’)”)配置接口角色权限时,角色是写死的,无法根据我资源授权动态配置,通过参考.pc_aggpage_search_result.none-task-blog-2aggregatepagefirst_rank_ecpm_v1~rank_v31_ecpm-1-115370515.pc_agg_new_rank&utm_term=preauthorize%E6%B3%A8%E8%A7%A3%E6%80%8E%E4%B9%88%E5%85%B3%E8%81%94%E6%9D%83%E9%99%90%E7%9A%84&spm=1000.2123.3001.4430
发现@PreAuthorize传入的方法可以自定义,于是便想到了实现这一个功能的方案:

public class CustomMethodSecurityExpressionRoot extends SecurityExpressionRoot implements MethodSecurityExpressionOperations {private Object filterObject;private Object returnObject;private Object target;CustomMethodSecurityExpressionRoot(Authentication a) {super(a);}public void setFilterObject(Object filterObject) {this.filterObject = filterObject;}public Object getFilterObject() {return this.filterObject;}</

更多推荐

security + oauth2 @PreAuthorize 动态配置接口角色权限

本文发布于:2024-03-10 21:28:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1729081.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:接口   角色   权限   动态   security

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!