Ejemplo n.º 1
0
 @Override
 public void merge(LoginScreenConfig src, LoginScreenConfig dst) {
   dst.merge(src);
 }
  @Override
  public void registerContribution(
      Object contribution, String extensionPoint, ComponentInstance contributor) {

    if (extensionPoint.equals(EP_AUTHENTICATOR)) {
      AuthenticationPluginDescriptor descriptor = (AuthenticationPluginDescriptor) contribution;
      if (authenticatorsDescriptors.containsKey(descriptor.getName())) {
        mergeDescriptors(descriptor);
        log.debug("merged AuthenticationPluginDescriptor: " + descriptor.getName());
      } else {
        authenticatorsDescriptors.put(descriptor.getName(), descriptor);
        log.debug("registered AuthenticationPluginDescriptor: " + descriptor.getName());
      }

      // create the new instance
      AuthenticationPluginDescriptor actualDescriptor =
          authenticatorsDescriptors.get(descriptor.getName());
      try {
        NuxeoAuthenticationPlugin authPlugin = actualDescriptor.getClassName().newInstance();
        authPlugin.initPlugin(actualDescriptor.getParameters());
        authenticators.put(actualDescriptor.getName(), authPlugin);
      } catch (InstantiationException e) {
        log.error(
            "Unable to create AuthPlugin for : "
                + actualDescriptor.getName()
                + "Error : "
                + e.getMessage(),
            e);
      } catch (IllegalAccessException e) {
        log.error(
            "Unable to create AuthPlugin for : "
                + actualDescriptor.getName()
                + "Error : "
                + e.getMessage(),
            e);
      }

    } else if (extensionPoint.equals(EP_CHAIN)) {
      AuthenticationChainDescriptor chainContrib = (AuthenticationChainDescriptor) contribution;
      log.debug("New authentication chain powered by " + contributor.getName());
      authChain.clear();
      authChain.addAll(chainContrib.getPluginsNames());
    } else if (extensionPoint.equals(EP_OPENURL)) {
      OpenUrlDescriptor openUrlContrib = (OpenUrlDescriptor) contribution;
      openUrls.add(openUrlContrib);
    } else if (extensionPoint.equals(EP_STARTURL)) {
      StartURLPatternDescriptor startupURLContrib = (StartURLPatternDescriptor) contribution;
      startupURLs.addAll(startupURLContrib.getStartURLPatterns());
    } else if (extensionPoint.equals(EP_PROPAGATOR)) {
      AuthenticationPropagatorDescriptor propagationContrib =
          (AuthenticationPropagatorDescriptor) contribution;

      // create the new instance
      try {
        propagator = propagationContrib.getClassName().newInstance();
      } catch (InstantiationException e) {
        log.error("Unable to create propagator", e);
      } catch (IllegalAccessException e) {
        log.error("Unable to create propagator", e);
      }
    } else if (extensionPoint.equals(EP_CBFACTORY)) {
      CallbackHandlerFactoryDescriptor cbhfContrib =
          (CallbackHandlerFactoryDescriptor) contribution;

      // create the new instance
      try {
        cbhFactory = cbhfContrib.getClassName().newInstance();
      } catch (InstantiationException e) {
        log.error("Unable to create callback handler factory", e);
      } catch (IllegalAccessException e) {
        log.error("Unable to create callback handler factory", e);
      }
    } else if (extensionPoint.equals(EP_SESSIONMANAGER)) {
      SessionManagerDescriptor smContrib = (SessionManagerDescriptor) contribution;
      if (smContrib.enabled) {
        try {
          NuxeoAuthenticationSessionManager sm = smContrib.getClassName().newInstance();
          sessionManagers.put(smContrib.getName(), sm);
        } catch (Exception e) {
          log.error("Unable to create session manager", e);
        }
      } else {
        sessionManagers.remove(smContrib.getName());
      }
    } else if (extensionPoint.equals(EP_SPECIFIC_CHAINS)) {
      SpecificAuthChainDescriptor desc = (SpecificAuthChainDescriptor) contribution;
      specificAuthChains.put(desc.name, desc);
    } else if (extensionPoint.equals(EP_PREFILTER)) {
      AuthPreFilterDescriptor desc = (AuthPreFilterDescriptor) contribution;
      if (preFiltersDesc == null) {
        preFiltersDesc = new HashMap<String, AuthPreFilterDescriptor>();
      }
      preFiltersDesc.put(desc.getName(), desc);
    } else if (extensionPoint.equals(EP_LOGINSCREEN)) {
      LoginScreenConfig newConfig = (LoginScreenConfig) contribution;
      loginScreenConfig.merge(newConfig);
    }
  }