Uploaded image for project: 'Shiro'
  1. Shiro
  2. SHIRO-829

beanPostProcessor and FactoryBean cause aop to fail in the same Configuration

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Resolved
    • 1.7.1
    • 1.9.0
    • Integration: Spring
    • None
    • springboot:1.5.21.RELEASE
      spring:4.3.24.RELEASE

    Description

      When LifecycleBeanPostProcessor and ShiroFilterFactoryBean are defined in the same configuration class, Realm's dependency aop (@Transactional and cache) is invalidated. Please look below:

      @Configuration
      public class ShiroConfig {
          @Bean("lifecycleBeanPostProcessor")
          public LifecycleBeanPostProcessor lifecycleBeanPostProcessor() {
              return new LifecycleBeanPostProcessor();
          }
          @Bean("securityManager")
          public SecurityManager securityManager(OAuth2Realm oAuth2Realm) {
              DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager();
              securityManager.setRealm(oAuth2Realm);
              securityManager.setRememberMeManager(null);
              return securityManager;
          }
          @Bean("shiroFilter")
          public ShiroFilterFactoryBean shiroFilter(SecurityManager securityManager) {
              return shiroFilter;
          }
          @Bean
          public AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor(SecurityManager securityManager) {
              AuthorizationAttributeSourceAdvisor advisor = new AuthorizationAttributeSourceAdvisor();
              advisor.setSecurityManager(securityManager);
              return advisor;
          }
      }
      
      @Slf4j
      @Component
      public class OAuth2Realm extends AuthorizingRealm {
          @Autowired
          private ISysSsoService sysSsoService;
      
          ......
      }
      
      

      When the ISysSsoService method is annotated by @Transactional, @Transactional will become invalid.

      I can fix it like this

      @Configuration
      public class ShiroConfig {
          public static class LifecycleBeanPostProcessorConfiguration {
              @Bean("lifecycleBeanPostProcessor")
              public LifecycleBeanPostProcessor lifecycleBeanPostProcessor() {
                  return new LifecycleBeanPostProcessor();
              }
          }
          ......
      }

      But I think this is a bug

      see spring-beans-4.3.24.RELEASE.jar org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory#getTypeForFactoryBean

      At 1 in the figure, we want to parse the return type of the FactoryBean, and enter the logic of Figure 2 when it cannot be parsed according to the signature. Because LifecycleBeanPostProcessor is initialized earlier than the ordinary bean, the Configuration class already exists as a FactoryBean, so that the dependent instantiation will continue.

      I have found a solution to change the signature of ShiroFilterFactoryBean to

      public class ShiroFilterFactoryBean implements FactoryBean<AbstractShiroFilter>, BeanPostProcessor 

       

      Attachments

        1. build.log
          17 kB
          chenzhi.xu
        2. image-2021-08-03-18-24-02-370.png
          127 kB
          chenzhi.xu
        3. image-2021-08-05-15-55-50-006.png
          0.3 kB
          chenzhi.xu
        4. screenshot-1.png
          64 kB
          chenzhi.xu
        5. screenshot-2.png
          80 kB
          chenzhi.xu
        6. screenshot-3.png
          150 kB
          chenzhi.xu

        Issue Links

          Activity

            People

              fpapon Francois Papon
              xcz chenzhi.xu
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 4h 20m
                  4h 20m