示例#1
0
  /**
   * Called by Spring when application events occur. At the moment we handle: ContextClosedEvent
   * ContextRefreshedEvent RequestHandledEvent
   *
   * <p>This is where we inject the job controllers into the application context, each one under
   * it's own key.
   *
   * @param applicationEvent Spring application event
   */
  public void onApplicationEvent(ApplicationEvent applicationEvent) {
    if (applicationEvent instanceof ContextRefreshedEvent) {
      logger.info("Bootstrap init");

      // Inject the metadata farm to handle all source of metadata
      servletContext.setAttribute(Guanxi.CONTEXT_ATTR_IDP_ENTITY_FARM, entityFarm);
    }

    if (applicationEvent instanceof ContextClosedEvent) {
      if (okToUnloadBCProvider) {
        Provider[] providers = Security.getProviders();

        /* Although addProvider() returns the ID of the newly installed provider,
         * we can't rely on this. If another webapp removes a provider from the list of
         * installed providers, all the other providers shuffle up the list by one, thus
         * invalidating the ID we got from addProvider().
         */
        try {
          for (int i = 0; i < providers.length; i++) {
            if (providers[i].getName().equalsIgnoreCase(Guanxi.BOUNCY_CASTLE_PROVIDER_NAME)) {
              Security.removeProvider(Guanxi.BOUNCY_CASTLE_PROVIDER_NAME);
            }
          }

          // Stop the jobs
          scheduler.shutdown();
        } catch (SecurityException se) {
          /* We'll end up here if a security manager is installed and it refuses us
           * permission to remove the BouncyCastle provider
           */
        } catch (SchedulerException se) {
          logger.error("Could not stop jobs", se);
        }
      }
    }

    if (applicationEvent instanceof RequestHandledEvent) {}
  }