容易忽略的地方记录如下:

1.需要引入下面2个依赖,具体版本根据自身环境修改:

<dependency>
<groupId>org.apache.geronimo.bundles</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.6.8_2</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.8.10</version>
</dependency>

2。注入这两个bean:

/**
* 注解访问授权动态拦截,不然不会执行doGetAuthenticationInfo
*
* @param securityManager
* @return
*/
@Bean
public AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor(SecurityManager securityManager) {
AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor = new AuthorizationAttributeSourceAdvisor();
authorizationAttributeSourceAdvisor.setSecurityManager(securityManager);
return authorizationAttributeSourceAdvisor;
} /**
* 授权未通过时(403)错误处理,没有这个不会跳转到403页面
*
* @return
*/
@Bean
public SimpleMappingExceptionResolver getSimpleMappingExceptionResolver() {
SimpleMappingExceptionResolver simpleMappingExceptionResolver = new SimpleMappingExceptionResolver();
Properties mappings = new Properties();
mappings.setProperty("org.apache.shiro.authz.UnauthorizedException", "/error/403");
simpleMappingExceptionResolver.setExceptionMappings(mappings);
return simpleMappingExceptionResolver;
}

完毕!

这个时候执行如下代码,就会跳转到403页面:

@RequiresPermissions("user:test")
@GetMapping("/test")
public String test() {
String strResult = "/test";
return strResult;
}

最新文章

  1. 原创 C++作用域 (二)
  2. new出对象的作用
  3. Jenkins xcodebuild There are no schemes in workspace
  4. Swift字符与字符串
  5. C#复习反射
  6. (hdu)2444 The Accomodation of Students 判断二分图+最大匹配数
  7. codeblock快捷键
  8. GridView动态增加行
  9. C# TextBlock 上标
  10. Golang 网络爬虫框架gocolly/colly 三
  11. Android为TV端助力 eclipse build project 出现major.minor version 52.0的问题
  12. Git和Github入门教程
  13. MATLAB——神经网络train函数
  14. 从Silverlight到ExtJS再到BootStrap,DataTable(DataGrid)的样式格式化原理没变
  15. Excel学习笔记:if({1,0})用法
  16. vue2总结
  17. [LintCode] Binary Tree Level Order Traversal(二叉树的层次遍历)
  18. C#基础知识回顾--串行化与反串行化
  19. UVa 10570 外星人聚会
  20. css !important的作用

热门文章

  1. delphi XE的字符串处理
  2. [转帖] Linux 创建一个简单的私有CA、发证、吊销证书
  3. idea 导入项目后不能执行main方法
  4. js &amp; option keycode
  5. MySql的相关资操作
  6. 【BZOJ1559】[JSOI2009]密码(AC自动机,动态规划,搜索)
  7. 【BZOJ1089】[SCOI2003]严格n元树(高精度,动态规划)
  8. 【codeforces 623E】 Transforming Sequence
  9. 大数据高性能数据库Redis在Windows上的使用教程
  10. Libre 6008 「网络流 24 题」餐巾计划 (网络流,最小费用最大流)