Exemplo n.º 1
0
 @Override
 public int getApplicationStartedOrder() {
   ComponentInstance repositoryComponent =
       (ComponentInstance)
           Framework.getRuntime()
               .getComponentInstance("org.nuxeo.ecm.core.repository.RepositoryServiceComponent");
   if (repositoryComponent == null) {
     return super.getApplicationStartedOrder();
   }
   return ((DefaultComponent) repositoryComponent.getInstance()).getApplicationStartedOrder() - 5;
 }
 @Override
 public void unregisterContribution(
     Object contribution, String extensionPoint, ComponentInstance contributor) throws Exception {
   if (GUARD_XP.equals(extensionPoint)) {
     GuardDescriptor gd = (GuardDescriptor) contribution;
     PermissionService.getInstance().unregisterGuard(gd.getId());
   } else if (BINDING_XP.equals(extensionPoint)) {
     WebObjectBindingDescriptor binding = (WebObjectBindingDescriptor) contribution;
     engine.unregisterBinding(binding.type);
   } else if (APP_MAPPING_XP.equals(extensionPoint)) {
     engine.removeApplicationMapping((WebApplicationMapping) contribution);
   } else if (extensionPoint.equals(RENDERING_EXTENSION_XP)) {
     RenderingExtensionDescriptor fed = (RenderingExtensionDescriptor) contribution;
     engine.unregisterRenderingExtension(fed.name);
   } else if (extensionPoint.equals(INSTALL_XP)) {
     Installer installer = (Installer) contribution;
     installer.uninstall(contributor.getContext(), engine.getRootDirectory());
   } else if (extensionPoint.equals(CONFIG_XP)) {
     ConfigurationFileDescriptor cfg = (ConfigurationFileDescriptor) contribution;
     if (cfg.path != null) {
       unloadConfiguration(new File(engine.getRootDirectory(), cfg.path));
     } else if (cfg.entry != null) {
       throw new UnsupportedOperationException("Entry is not supported for now");
     } else {
       log.error(
           "Neither path neither entry attribute was defined in the configuration extension. Ignoring");
     }
   }
 }
  @Test
  public void testContributions() {
    RuntimeService runtime = Framework.getRuntime();
    ComponentManager mgr = runtime.getComponentManager();
    assertTrue(mgr.size() > 0);

    ComponentInstance co = runtime.getComponentInstance("service:my.comp1");
    assertNotNull(co);
    assertEquals(co.getName(), new ComponentName("service:my.comp1"));

    co = runtime.getComponentInstance("service:my.comp2");
    assertNotNull(co);
    assertEquals(co.getName(), new ComponentName("service:my.comp2"));

    mgr.unregister(new ComponentName("service:my.comp2"));
    co = runtime.getComponentInstance("service:my.comp2");
    assertNull(co);
    co = runtime.getComponentInstance("service:my.comp1");
    assertNotNull(co);
  }
 @Override
 public void registerContribution(
     Object contribution, String extensionPoint, ComponentInstance contributor) throws Exception {
   if (GUARD_XP.equals(extensionPoint)) {
     GuardDescriptor gd = (GuardDescriptor) contribution;
     PermissionService.getInstance().registerGuard(gd.getId(), gd.getGuard());
   } else if (BINDING_XP.equals(extensionPoint)) {
     WebObjectBindingDescriptor binding = (WebObjectBindingDescriptor) contribution;
     engine.registerBinding(binding.type, binding.objectId);
   } else if (APP_MAPPING_XP.equals(extensionPoint)) {
     engine.addApplicationMapping((WebApplicationMapping) contribution);
   } else if (extensionPoint.equals(RENDERING_EXTENSION_XP)) {
     RenderingExtensionDescriptor fed = (RenderingExtensionDescriptor) contribution;
     try {
       engine.registerRenderingExtension(fed.name, fed.newInstance());
     } catch (Exception e) {
       throw new RuntimeServiceException(
           "Deployment Error. Failed to contribute freemarker template extension: " + fed.name);
     }
   } else if (extensionPoint.equals(INSTALL_XP)) {
     Installer installer = (Installer) contribution;
     installer.install(contributor.getContext(), engine.getRootDirectory());
   } else if (extensionPoint.equals(CONFIG_XP)) {
     ConfigurationFileDescriptor cfg = (ConfigurationFileDescriptor) contribution;
     if (cfg.path != null) {
       loadConfiguration(
           contributor.getContext(),
           new File(engine.getRootDirectory(), cfg.path),
           cfg.trackChanges);
     } else if (cfg.entry != null) {
       throw new UnsupportedOperationException("Entry is not supported for now");
     } else {
       log.error(
           "Neither path neither entry attribute was defined in the configuration extension. Ignoring");
     }
   }
 }
Exemplo n.º 5
0
 @Override
 public void registerContribution(
     Object contribution, String extensionPoint, ComponentInstance contributor) {
   if (contribution instanceof FlavorDescriptor) {
     FlavorDescriptor flavor = (FlavorDescriptor) contribution;
     log.info(String.format("Register flavor '%s'", flavor.getName()));
     registerFlavor(flavor, contributor.getContext());
     log.info(String.format("Done registering flavor '%s'", flavor.getName()));
   } else if (contribution instanceof SimpleStyle) {
     SimpleStyle style = (SimpleStyle) contribution;
     log.info(String.format("Register style '%s'", style.getName()));
     String message =
         String.format(
             "Style '%s' on component %s should now be contributed to extension "
                 + "point '%s': a compatibility registration was performed but it may not be "
                 + "accurate. Note that the 'flavor' processor should be used with this resource.",
             style.getName(), contributor.getName(), WR_EX);
     DeprecationLogger.log(message, "7.4");
     Framework.getRuntime().getWarnings().add(message);
     ResourceDescriptor resource = getResourceFromStyle(style);
     registerResource(resource, contributor.getContext());
     log.info(String.format("Done registering style '%s'", style.getName()));
   } else if (contribution instanceof PageDescriptor) {
     PageDescriptor page = (PageDescriptor) contribution;
     log.info(String.format("Register page '%s'", page.getName()));
     if (page.hasResources()) {
       // automatically register a bundle for page resources
       WebResourceManager wrm = Framework.getService(WebResourceManager.class);
       wrm.registerResourceBundle(page.getComputedResourceBundle());
     }
     pageReg.addContribution(page);
     log.info(String.format("Done registering page '%s'", page.getName()));
   } else if (contribution instanceof ResourceDescriptor) {
     ResourceDescriptor resource = (ResourceDescriptor) contribution;
     log.info(String.format("Register resource '%s'", resource.getName()));
     String message =
         String.format(
             "Resource '%s' on component %s should now be contributed to extension "
                 + "point '%s': a compatibility registration was performed but it may not be accurate.",
             resource.getName(), contributor.getName(), WR_EX);
     DeprecationLogger.log(message, "7.4");
     Framework.getRuntime().getWarnings().add(message);
     // ensure path is absolute, consider that resource is in the war, and if not, user will have
     // to declare it
     // directly to the WRM endpoint
     String path = resource.getPath();
     if (path != null && !path.startsWith("/")) {
       resource.setUri("/" + path);
     }
     registerResource(resource, contributor.getContext());
     log.info(String.format("Done registering resource '%s'", resource.getName()));
   } else if (contribution instanceof NegotiationDescriptor) {
     NegotiationDescriptor neg = (NegotiationDescriptor) contribution;
     log.info(String.format("Register negotiation for '%s'", neg.getTarget()));
     negReg.addContribution(neg);
     log.info(String.format("Done registering negotiation for '%s'", neg.getTarget()));
   } else {
     log.error(
         String.format(
             "Unknown contribution to the theme " + "styling service, extension point '%s': '%s",
             extensionPoint, contribution));
   }
 }
  @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);
    }
  }