zoukankan      html  css  js  c++  java
  • shiro和Spring整合使用注解时没有执行realm的doGetAuthorizationInfo回调方法的解决(XML配置)

    在使用Shiro框架进行项目整合时,使用注解在使用Shiro框架进行项目整合时,使用注解在使用Shiro框架进行项目整合时,使用注解@RequiresPermissions为方法提供是需要的权限,但是根本没有进行验证,后面发现在自己的Realm中只执行了doGetAuthenticationInfo(登录验证)方法而没有执行doGetAuthorizationInfo(权限验证)的方法。

    查看相关资料后发现是因为在Springmvc的配置文件中(我的名字是spring-servlet.xml)没有加入

    <aop:config proxy-target-class="true"/>

    <!-- 开启shiro注解 -->
    <bean class="org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor">
        <property name="securityManager" ref="securityManager" />
    </bean>

    加入后解决问题.

    也可以使用:

    <!-- 支持Shiro对Controller的方法级AOP安全控制 begin-->
    <bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator" depends-on="lifecycleBeanPostProcessor">
      <property name="proxyTargetClass" value="true" />
    </bean>

    <bean class="org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor">
        <property name="securityManager" ref="securityManager" />
    </bean>
    <!-- 保证实现了Shiro内部lifecycle函数的bean执行 -->
    <bean id="lifecycleBeanPostProcessor" class="org.apache.shiro.spring.LifecycleBeanPostProcessor"/>

    但是一定要记住是把以下配置放在SpringMvc的配置文件中。

    <aop:config proxy-target-class="true"/>

    <bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator" depends-on="lifecycleBeanPostProcessor">
      <property name="proxyTargetClass" value="true" />
    </bean>

  • 相关阅读:
    CF293E Close Vertice
    [SCOI2016]幸运数字
    [NOI2003]逃学的小孩
    0302读后感
    1231递归下降语法分析
    1210-有穷自动机
    11.12 评论汇总
    1029语言文法
    0921 词法分析
    0909开启编译原理之路
  • 原文地址:https://www.cnblogs.com/onlymate/p/8784882.html
Copyright © 2011-2022 走看看