@Override
 public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
     throws BeansException {
   beanFactory.setBeanClassLoader(beanClassLoader);
   beanFactory.addBeanPostProcessor(new PluginClassLoaderBeanPostProcessor(beanClassLoader));
   beanFactory.addBeanPostProcessor(new FlywayBeanPostProcessor(pluginRegistry));
   super.postProcessBeanFactory(beanFactory);
 }
 @Override
 public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry)
     throws BeansException {
   pluginRegistry = loadPlugins();
   processImplementations(registry, pluginRegistry);
   processResources(pluginRegistry);
   setBeanClassLoader(beanClassLoader);
   super.postProcessBeanDefinitionRegistry(registry);
 }
  @Override
  public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
      throws BeansException {
    LOGGER.info("Loading Management providers {}", Provider.class.getSimpleName());

    Set<String> providers =
        new HashSet<>(
            SpringFactoriesLoader.loadFactoryNames(
                Provider.class, beanFactory.getBeanClassLoader()));

    LOGGER.info(
        "\tFound {} {} implementation(s)", providers.size(), Provider.class.getSimpleName());

    DefaultListableBeanFactory defaultListableBeanFactory =
        (DefaultListableBeanFactory) beanFactory;
    environment = beanFactory.getBean(Environment.class);

    List<String> getSecurityProviders = getSecurityProviders();

    for (String provider : providers) {
      try {
        Class<?> instanceClass = ClassUtils.forName(provider, beanFactory.getBeanClassLoader());
        Assert.isAssignable(Provider.class, instanceClass);

        Provider providerInstance = createInstance((Class<Provider>) instanceClass);

        if (getSecurityProviders.contains(providerInstance.type())) {
          LOGGER.info(
              "Registering a provider {} [{}]",
              instanceClass.getSimpleName(),
              providerInstance.type());

          if (providerInstance.authenticationManager() != null) {
            defaultListableBeanFactory.registerBeanDefinition(
                providerInstance.authenticationManager().getName(),
                new RootBeanDefinition(providerInstance.authenticationManager().getName()));
          }

          if (providerInstance.identityManager() != null) {
            defaultListableBeanFactory.registerBeanDefinition(
                providerInstance.identityManager().getName(),
                new RootBeanDefinition(providerInstance.identityManager().getName()));
          }

          Class<?> extension = providerInstance.configuration();
          if (extension != null) {
            LOGGER.info("\tRegistering provider extension: {}", extension.getName());
            defaultListableBeanFactory.registerBeanDefinition(
                extension.getName(), new RootBeanDefinition(extension.getName()));

            LOGGER.info("\tLoading @Configuration from previous extension {}", extension.getName());
            configurationClassPostProcessor.processConfigBeanDefinitions(
                defaultListableBeanFactory);
          }
        }
      } catch (Exception ex) {
        LOGGER.error("Unable to instantiate provider: {}", ex);
        throw new IllegalStateException("Unable to instantiate provider: " + provider, ex);
      }
    }
  }