spring 接入 Shiro 框架

说明: 记录spring 接入Shiro 框架的步骤

参考:layui_template 项目

参考:https://www.w3cschool.cn/shiro/co4m1if2.html

参考:https://zhuanlan.zhihu.com/p/54176956

步骤简要

  • 继承 AuthorizingRealm 类,实现数据源

    1. 重写 doGetAuthorizationInfo 接口
    2. 重写 doGetAuthenticationInfo 方法
  • 创建 shiro 相关的其他配置

    1. 创建 SecurityManage 对象,
      并将第一步 实现 AuthorizingRealm接口的实现类 设置到 SecurityManager 绑定的Realm上,同时设置 缓存管理器 或 其他设置

    2. 如果是web项目,还可以设置 ShiroFilter ,通过设置 ShiroFilterFactoryBean 对象

方法权限设置

  • 注解支持的方式
    通过在具体的需要授权的方法上加 @RequiresPermissions 注解