Shiro
  1. Shiro
  2. SHIRO-222

Register LifecycleBeanPostProcessor before ShiroFilterFactoryBean [patch included]

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.1.0
    • Fix Version/s: 1.2.0
    • Component/s: Integration: Spring
    • Labels:
      None

      Description

      LifecycleBeanPostProcessor needs to be registred before ShiroFilterFactoryBean because...

      ShiroFilterFactoryBean itself is a BeanPostProcessor, like LifecycleBeanPostProcessor too. So during AbstractApplicationContext.registerBeanPostProcessors() these two beans are created and added to nonOrderedPostProcessors, after then they get registered. At this execution point ShiroFilterFactoryBean is already created with its SecurityManager and defined Realms. So LifecycleBeanPostProcessor will not effect anymore on Realms init.

      http://shiro-user.582556.n2.nabble.com/Shiro-and-Spring-with-ShiroFilterFactoryBean-td5811127.html

        Issue Links

          Activity

          Hide
          Les Hazlewood added a comment -

          Patch applied - thanks very much for the patch!

          Show
          Les Hazlewood added a comment - Patch applied - thanks very much for the patch!
          Hide
          Les Hazlewood added a comment -

          Closing with the 1.2.0 release.

          Show
          Les Hazlewood added a comment - Closing with the 1.2.0 release.
          Hide
          Roman Yaroslavtsev added a comment -

          Hello,

          There is a problem with LifecycleBeanPostPRocessor and spring import configuration.
          I have the following scenario in my project:

          @Configuration
          public class AppConfig {

          @Bean
          public SecurityManager securityManager()

          { //return security manager instance here }

          }

          @Configuration
          @Import(AppConfig.class)
          public class WebConfig {

          @Autowired private AppConfig config;

          @Bean
          public LifecycleBeanPostProcessor lifecycleBeanPostProcessor()

          { return new LifecycleBeanPostProcessor(); }

          @Bean
          public ShiroFilterFactoryBean shiroFilter()

          { //return filter bean here }

          }

          The main point is to separate application configuration from web configuration.

          In this scenario AppConfig is not wired when shifo filter is accessed. This is because LifecycleBeanPostProcessor implements PriorityOrdered and WebConfig configuration bean is instantiated before other priority ordered post processors, such as @Autowired post processor, are registered. Thus WebConfig bean is instantiated without post processing @Import annotation and breaks wiring.

          Possible solution: Implement Ordered instead of PriorityOrdered for LifecycleBeanPostProcessor.

          Thank you.

          Show
          Roman Yaroslavtsev added a comment - Hello, There is a problem with LifecycleBeanPostPRocessor and spring import configuration. I have the following scenario in my project: @Configuration public class AppConfig { @Bean public SecurityManager securityManager() { //return security manager instance here } } @Configuration @Import(AppConfig.class) public class WebConfig { @Autowired private AppConfig config; @Bean public LifecycleBeanPostProcessor lifecycleBeanPostProcessor() { return new LifecycleBeanPostProcessor(); } @Bean public ShiroFilterFactoryBean shiroFilter() { //return filter bean here } } The main point is to separate application configuration from web configuration. In this scenario AppConfig is not wired when shifo filter is accessed. This is because LifecycleBeanPostProcessor implements PriorityOrdered and WebConfig configuration bean is instantiated before other priority ordered post processors, such as @Autowired post processor, are registered. Thus WebConfig bean is instantiated without post processing @Import annotation and breaks wiring. Possible solution: Implement Ordered instead of PriorityOrdered for LifecycleBeanPostProcessor. Thank you.
          Hide
          Roman Yaroslavtsev added a comment -

          Sorry, my suggestion to use Ordered interface was completely incorrect. The simplest solution is to declare LifecycleBeanPostProcessor method as static, to avoid early Configuration bean creation.

          Show
          Roman Yaroslavtsev added a comment - Sorry, my suggestion to use Ordered interface was completely incorrect. The simplest solution is to declare LifecycleBeanPostProcessor method as static, to avoid early Configuration bean creation.

            People

            • Assignee:
              Unassigned
              Reporter:
              manthos
            • Votes:
              1 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development