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 ...
随机推荐
- ARM cache 工作方式
综述 现在的CPU的速度远远高于现代存储器的速度所以出现了cache.按和CPU距离分为L1级和L2级(SM)等.这里主要记录一下自己对cache的工作方式的学习理解. cache工作方式 cahe是 ...
- 快速下载 Visual Studio Code
快速下载 Visual Studio Code https://visualstudio.microsoft.com/zh-hant/downloads/ 切换 cdn https://az76429 ...
- React Hooks: useContext All In One
React Hooks: useContext All In One useContext https://reactjs.org/docs/hooks-reference.html#useconte ...
- javascript nested object merge
javascript nested object merge deep copy Object reference type function namespace(oNamespace, sPacka ...
- css effect all in one
css effect all in one CSS 特效汇总 / 前端特效汇总 图片滑动对比 https://www.fika.io/ https://chrome.google.com/websto ...
- Node.js Learning Paths
Node.js Learning Paths Node.js in Action Node.js Expert situations / scenario Restful API OAuth 2.0 ...
- PPT & order & animation
PPT & order & animation powerpoint order of appearance https://support.office.com/en-us/arti ...
- Redis all in one
Redis all in one Redis: REmote DIctionary Server https://redis.io/topics/quickstart Download, extrac ...
- windwos创建和删除服务
创建 >sc create <service name> type=kernel binpath="C:\hsys.sys" 删除 win+r 输出 regedi ...
- 漫画 | C语言哭了,过年回家,只有我还没对象
C语言回家过年,遇到不少小伙伴. 大家都在外地打拼,一年难得见面,聚到一起吃饭,都非常高兴. 听Java提到TIOBE, 正在喝酒的C语言激动起来. 自己常年在那里排名第二,人类用自己写的程序可真不少 ...