Spring Boot集成Shiro 登录后访问请求不执行Realm的授权doGetAuthorizationInfo方法

springboot集成shiro的时候在注解方法访问没有经过授权的校验:aop:config在shiro权限注解中发挥的作用

 产生的原因是:授权的注解没有进行生效
 需要改正:
 1.注入通知器: com.sml.shiro.config.ShiroConfig
     /**
          * 注入AuthorizationAttributeSourceAdvisor 实现了MethodMatcher接口 通知器 可以进行对注解权限校验
          * shiro认证注解可以正常work:
             会扫描配置文件中的所有advisor,并为其创建代理
             AuthorizationAttributeSourceAdvisor匹配所有类,匹配所有加了认证注解的方法
          * @param securityManager
          * @return
          */
         @Bean
         public AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor(SecurityManager securityManager) {
             AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor = new AuthorizationAttributeSourceAdvisor();
             authorizationAttributeSourceAdvisor.setSecurityManager(securityManager);
             return authorizationAttributeSourceAdvisor;
         }
 2.当注解的内容跟当前用户的权限不匹配的时候,则会报500的错误
   返回的错误日志为:
   org.apache.shiro.authz.AuthorizationException: Not authorized to invoke method: java.lang.String com.sml.controller.sys.UserController.add(org.springframework.ui.Model)
   	at org.apache.shiro.authz.aop.AuthorizingAnnotationMethodInterceptor.assertAuthorized(AuthorizingAnnotationMethodInterceptor.java:90)
   	at org.apache.shiro.authz.aop.AnnotationsAuthorizingMethodInterceptor.assertAuthorized(AnnotationsAuthorizingMethodInterceptor.java:100)
   	at org.apache.shiro.authz.aop.AuthorizingMethodInterceptor.invoke(AuthorizingMethodInterceptor.java:38)
   	at org.apache.shiro.spring.security.interceptor.AopAllianceAnnotationsAuthorizingMethodInterceptor.invoke(AopAllianceAnnotationsAuthorizingMethodInterceptor.java:115)
   	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)        
 
 PS:源码类的快捷键(Ctrl + N)
     org.apache.shiro.authz.ModularRealmAuthorizer             
     applyPermissionResolverToRealms
     【查找的对象为空,并没有调试的作用】
     

你可能感兴趣的:(shiro)