SpringBoot Shiro 权限注解不起作用
最近在学习springboot结合shiro做权限管理时碰到一个问题。
问题如下:
我在userRealm中的doGetAuthorizationInfo方法中给用户添加了权限,然后在Controller中写了下面的代码。其中URL为/listArticle的方法必须要有article:over权限才能通过。我在doGetAuthorizationInfo方法中给该用户添加的权限并没有article:over,但是当前端向该URL发送请求时,@RequiresPermissions注解不起作用,listArticle方法被执行了。而且我在方法内部打印isPermitted("article:over")的输出结果为false。最终通过网上查博客,发现是没有开启Shiro的注解支持的原因。
@RequiresPermissions("article:over")
@RequestMapping(value = "/listArticle", method = RequestMethod.POST)
public JSONObject listArticle(@RequestBody JSONObject request){
System.out.println("---------isPermitted article:over--------" + SecurityUtils.getSubject().isPermitted("article:over"));
CommonTools.paginationConvert(request);
int ArticleNum = articleService.getArticleNum();
List<JSONObject> list = articleService.listArticle(request.getIntValue("offset"), request.getIntValue("pageRow"));
return Result.success(request, list, ArticleNum);
}
解决方法如下:
在ShiroConfig中添加如下一段代码。
//开启对shiro注解的支持
@Bean
public AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor(SecurityManager securityManager) {
AuthorizationAttributeSourceAdvisor advisor = new AuthorizationAttributeSourceAdvisor();
advisor.setSecurityManager(securityManager);
return advisor;
}
//开启aop注解支持
@Bean
public DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator() {
DefaultAdvisorAutoProxyCreator defaultAAP = new DefaultAdvisorAutoProxyCreator();
defaultAAP.setProxyTargetClass(true);
return defaultAAP;
}
添加完这段代码后,我再向该URL发送请求时就会报如下异常,表明该用户没有该权限:
org.apache.shiro.authz.AuthorizationException: Not authorized to invoke method
参考博客:
https://www.cnblogs.com/shiguotao-com/p/10617693.html
https://www.cnblogs.com/tuifeideyouran/p/7696055.html
SpringBoot Shiro 权限注解不起作用的更多相关文章
- Shiro 权限注解
Shiro 权限注解: Shiro 提供了相应的注解用于权限控制,如果使用这些注解就需要使用AOP 的功能来进行 判断,如Spring AOP:Shiro 提供了Spring AOP 集成用于 ...
- 2017.2.13 开涛shiro教程-第十二章-与Spring集成(二)shiro权限注解
原博客地址:http://jinnianshilongnian.iteye.com/blog/2018398 根据下载的pdf学习. 第十二章-与Spring集成(二)shiro权限注解 shiro注 ...
- springboot shiro没有注解解决方案
颓废的悠然 springboot shiro开启注释 shiroconfiguration中增加 1 2 3 4 5 6 7 @Bean public AuthorizationAttri ...
- Shiro权限注解原理
概述 前不久刚学会使用权限注解(),开始思索了一番.最开始猜测实现方式是注解@Aspect,具体实现方式类似如下所示(切面记录审计日志).后来发现并非如此,所以特地分析一下源码. @Component ...
- SpringBoot&Shiro实现权限管理
SpringBoot&Shiro实现权限管理 引言 相信大家前来看这篇文章的时候,是有SpringBoot和Shiro基础的,所以本文只介绍整合的步骤,如果哪里写的不好,恳请大家能指出错误,谢 ...
- Shiro 权限校验不通过时,区分GET和POST请求正确响应对应的方式
引入:https://blog.csdn.net/catoop/article/details/69210140 本文基于Shiro权限注解方式来控制Controller方法是否能够访问. 例如使用到 ...
- SpringBoot整合Shiro权限框架实战
什么是ACL和RBAC ACL Access Control list:访问控制列表 优点:简单易用,开发便捷 缺点:用户和权限直接挂钩,导致在授予时的复杂性,比较分散,不便于管理 例子:常见的文件系 ...
- springboot shiro和freemarker集成之权限控制完全参考手册(跳过认证,登录由三方验证,全网首发)
本文主要考虑单点登录场景,登录由其他系统负责,业务子系统只使用shiro进行菜单和功能权限校验,登录信息通过token从redis取得,这样登录验证和授权就相互解耦了. 用户.角色.权限进行集中式管理 ...
- springboot+shiro+redis(单机redis版)整合教程-续(添加动态角色权限控制)
相关教程: 1. springboot+shiro整合教程 2. springboot+shiro+redis(单机redis版)整合教程 3. springboot+shiro+redis(集群re ...
随机推荐
- 深入理解JavaScript垃圾回收
JavaScript中的垃圾回收是自动进行的,在平常开发中我们可能并不在意,但是深入理解JavaScript中的垃圾回收却是必要的; JavaScript 中主要的内存管理概念是 可达性,简而言之就是 ...
- ::-webkit-scrollbar & hidden scrollbar
::-webkit-scrollbar & hidden scrollbar how to hidden ::-webkit-scrollbar *::-webkit-scrollbar { ...
- Apple Support
Apple Support Send Files to Apple Support https://gigafiles.apple.com/#/customerupload refs 无法截屏 bug ...
- GitHub in depth
GitHub in depth GitHub 高级玩法 / 进阶教程 https://github.com/trending/dart?since=daily https://github.com/t ...
- Cookie 政策
Cookie 政策 合规/隐私协议 https://www.synology.cn/zh-cn/company/legal/cookie_policy Cookie Cookie 政策 生效日期:20 ...
- flat array
flat array 已知如下数组: var arr = [ [1, 2, 2], [3, 4, 5, 5], [6, 7, 8, 9, [11, 12, [12, 13, [14] ] ] ], 1 ...
- TypeScript & Advanced Types
TypeScript & Advanced Types https://www.typescriptlang.org/docs/handbook/advanced-types.html#typ ...
- js destructuring assignment bug
js destructuring assignment bug https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Op ...
- 浅析VAST代币与SPC算力币的释放模式
许多区块链业界分析师认为,2021年的区块链市场或许与2020年的有些许不同.2020年的区块链市场更注重的是DeFi领域,很多公链项目以及资本市场的巨鲸们也是将目光锁定在DeFi领域.而2021年的 ...
- django中间件介绍
在学习django中间件之前,先来认识一下django的生命周期,如下图所示: django生命周期:浏览器发送的请求会先经过wsgiref模块处理解析出request(请求数据)给到中间件,然后通过 ...