org.jboss.as.server.deployment.DeploymentPhaseContext Java Examples

The following examples show how to use org.jboss.as.server.deployment.DeploymentPhaseContext. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: KeycloakDependencyProcessor.java    From keycloak with Apache License 2.0 6 votes vote down vote up
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    if (!KeycloakAdapterConfigService.getInstance().isSecureDeployment(deploymentUnit)) {
        WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
        if (warMetaData == null) {
            return;
        }
        JBossWebMetaData webMetaData = warMetaData.getMergedJBossWebMetaData();
        if (webMetaData == null) {
            return;
        }
        LoginConfigMetaData loginConfig = webMetaData.getLoginConfig();
        if (loginConfig == null) return;
        if (loginConfig.getAuthMethod() == null) return;
        if (!loginConfig.getAuthMethod().equals("KEYCLOAK")) return;
    }

    final ModuleSpecification moduleSpecification = deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION);
    final ModuleLoader moduleLoader = Module.getBootModuleLoader();
    addCommonModules(moduleSpecification, moduleLoader);
    addPlatformSpecificModules(phaseContext, moduleSpecification, moduleLoader);
}
 
Example #2
Source File: VirtualSecurityDomainProcessor.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    if (deploymentUnit.getParent() != null || !isVirtualDomainRequired(deploymentUnit)) {
        return;  // Only interested in installation if this is really the root deployment.
    }

    ServiceName virtualDomainName = virtualDomainName(deploymentUnit);
    ServiceTarget serviceTarget = phaseContext.getServiceTarget();

    ServiceBuilder<?> serviceBuilder = serviceTarget.addService(virtualDomainName);

    final SecurityDomain virtualDomain = SecurityDomain.builder().build();
    final Consumer<SecurityDomain> consumer = serviceBuilder.provides(virtualDomainName);

    serviceBuilder.setInstance(Service.newInstance(consumer, virtualDomain));
    serviceBuilder.setInitialMode(Mode.ON_DEMAND);
    serviceBuilder.install();
}
 
Example #3
Source File: ProcessApplicationProcessor.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
  final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();    
  final EEModuleDescription eeModuleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
  
  // must be EE Module
  if(eeModuleDescription == null) {
    return;
  }

  // discover user-provided component
  ComponentDescription paComponent = detectExistingComponent(deploymentUnit); 

  if(paComponent != null) {      
    log.log(Level.INFO, "Detected user-provided @"+ProcessApplication.class.getSimpleName()+" component with name '"+paComponent.getComponentName()+"'.");
    
    // mark this to be a process application
    ProcessApplicationAttachments.attachProcessApplicationComponent(deploymentUnit, paComponent);
    ProcessApplicationAttachments.mark(deploymentUnit);
    ProcessApplicationAttachments.markPartOfProcessApplication(deploymentUnit);
  }
}
 
Example #4
Source File: ProcessEngineStartProcessor.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
  
  final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
  
  if(!ProcessApplicationAttachments.isProcessApplication(deploymentUnit)) {
    return;
  }
  
  List<ProcessesXmlWrapper> processesXmls = ProcessApplicationAttachments.getProcessesXmls(deploymentUnit);
  for (ProcessesXmlWrapper wrapper : processesXmls) {            
    for (ProcessEngineXml processEngineXml : wrapper.getProcessesXml().getProcessEngines()) {
      startProcessEngine(processEngineXml, phaseContext);      
    }
  }
  
}
 
Example #5
Source File: AbstractLoggingDeploymentProcessor.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public final void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    // If the log context is already defined, skip the rest of the processing
    if (!hasRegisteredLogContext(deploymentUnit)) {
        if (deploymentUnit.hasAttachment(Attachments.DEPLOYMENT_ROOT)) {
            // don't process sub-deployments as they are processed by processing methods
            final ResourceRoot root = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT);
            if (SubDeploymentMarker.isSubDeployment(root)) return;
            processDeployment(phaseContext, deploymentUnit, root);
            // If we still don't have a context registered on the root deployment, register the current context.
            // This is done to avoid any logging from the root deployment to have access to a sub-deployments log
            // context. For example any library logging from a EAR/lib should use the EAR's configured log context,
            // not a log context from a WAR or EJB library.
            if (!hasRegisteredLogContext(deploymentUnit) && !deploymentUnit.hasAttachment(DEFAULT_LOG_CONTEXT_KEY)) {
                // Register the current log context as this could be an embedded server or overridden another way
                registerLogContext(deploymentUnit, DEFAULT_LOG_CONTEXT_KEY, deploymentUnit.getAttachment(Attachments.MODULE), LogContext.getLogContext());
            }
        }
    }
}
 
Example #6
Source File: KeycloakProviderDependencyProcessor.java    From keycloak with Apache License 2.0 6 votes vote down vote up
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    KeycloakAdapterConfigService config = KeycloakAdapterConfigService.INSTANCE;
    String deploymentName = deploymentUnit.getName();

    if (config.isKeycloakServerDeployment(deploymentName)) {
        return;
    }

    KeycloakDeploymentInfo info = getKeycloakProviderDeploymentInfo(deploymentUnit);
    if (info.hasServices()) {
        final ModuleSpecification moduleSpecification = deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION);
        final ModuleLoader moduleLoader = Module.getBootModuleLoader();
        moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, KEYCLOAK_COMMON, false, false, false, false));
        moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, KEYCLOAK_CORE, false, false, false, false));
        moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, KEYCLOAK_SERVER_SPI, false, false, false, false));
        moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, KEYCLOAK_SERVER_SPI_PRIVATE, false, false, false, false));
        moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, JAXRS, false, false, false, false));
        moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, RESTEASY, false, false, false, false));
        moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, APACHE, false, false, false, false));
        moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, KEYCLOAK_JPA, false, false, false, false));
    }
}
 
Example #7
Source File: KeycloakProviderDeploymentProcessor.java    From keycloak with Apache License 2.0 6 votes vote down vote up
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    KeycloakAdapterConfigService config = KeycloakAdapterConfigService.INSTANCE;
    String deploymentName = deploymentUnit.getName();

    if (config.isKeycloakServerDeployment(deploymentName)) {
        return;
    }

    KeycloakDeploymentInfo info = KeycloakProviderDependencyProcessor.getKeycloakProviderDeploymentInfo(deploymentUnit);
    
    ScriptProviderDeploymentProcessor.deploy(deploymentUnit, info);
    
    if (info.isProvider()) {
        logger.infov("Deploying Keycloak provider: {0}", deploymentUnit.getName());
        final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
        ProviderManager pm = new ProviderManager(info, module.getClassLoader());
        ProviderManagerRegistry.SINGLETON.deploy(pm);
        deploymentUnit.putAttachment(ATTACHMENT_KEY, pm);
    }
}
 
Example #8
Source File: LoggingDependencyDeploymentProcessor.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void deploy(final DeploymentPhaseContext phaseContext) {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final ModuleSpecification moduleSpecification = deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION);
    final ModuleLoader moduleLoader = Module.getBootModuleLoader();
    // Add the logging modules
    for (String moduleId : DUP_INJECTED_LOGGING_MODULES) {
        try {
            LoggingLogger.ROOT_LOGGER.tracef("Adding module '%s' to deployment '%s'", moduleId, deploymentUnit.getName());
            moduleLoader.loadModule(moduleId);
            moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, moduleId, false, false, false, false));
        } catch (ModuleLoadException ex) {
            LoggingLogger.ROOT_LOGGER.debugf("Module not found: %s", moduleId);
        }
    }
}
 
Example #9
Source File: PermissionsValidationProcessor.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final List<PermissionFactory> permissionFactories = deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION).getPermissionFactories();
    final StringBuilder failedPermissions = new StringBuilder();
    for (PermissionFactory factory : permissionFactories) {
        // all permissions granted internally by the container are of type ImmediatePermissionFactory - they should
        // not be considered when validating the permissions granted to deployments via subsystem or deployment
        // descriptors.
        if (!(factory instanceof ImmediatePermissionFactory)) {
            Permission permission = factory.construct();
            boolean implied = this.maxPermissions.implies(permission);
            if (!implied) {
                failedPermissions.append("\n\t\t" + permission);

            }
        }
    }
    if (failedPermissions.length() > 0) {
        throw SecurityManagerLogger.ROOT_LOGGER.invalidDeploymentConfiguration(failedPermissions);
    }
}
 
Example #10
Source File: ProcessEngineStartProcessor.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
  
  final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
  
  if(!ProcessApplicationAttachments.isProcessApplication(deploymentUnit)) {
    return;
  }
  
  List<ProcessesXmlWrapper> processesXmls = ProcessApplicationAttachments.getProcessesXmls(deploymentUnit);
  for (ProcessesXmlWrapper wrapper : processesXmls) {            
    for (ProcessEngineXml processEngineXml : wrapper.getProcessesXml().getProcessEngines()) {
      startProcessEngine(processEngineXml, phaseContext);      
    }
  }
  
}
 
Example #11
Source File: CamelContextBootstrapProcessor.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {

    final DeploymentUnit depUnit = phaseContext.getDeploymentUnit();

    final Module module = depUnit.getAttachment(Attachments.MODULE);
    final String runtimeName = depUnit.getName();

    // Add the camel context bootstraps to the deployment
    CamelDeploymentSettings depSettings = depUnit.getAttachment(CamelDeploymentSettings.ATTACHMENT_KEY);
    for (URL contextURL : depSettings.getCamelContextUrls()) {
        ClassLoader tccl = SecurityActions.getContextClassLoader();
        try {
            SecurityActions.setContextClassLoader(module.getClassLoader());
            SpringCamelContextBootstrap bootstrap = new SpringCamelContextBootstrap(contextURL, module.getClassLoader());
            depUnit.addToAttachmentList(CamelConstants.CAMEL_CONTEXT_BOOTSTRAP_KEY, bootstrap);
        } catch (Exception ex) {
            throw new IllegalStateException("Cannot create camel context: " + runtimeName, ex);
        } finally {
            SecurityActions.setContextClassLoader(tccl);
        }
    }
}
 
Example #12
Source File: KeycloakServerDeploymentProcessor.java    From keycloak with Apache License 2.0 6 votes vote down vote up
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    KeycloakAdapterConfigService configService = KeycloakAdapterConfigService.INSTANCE;
    String deploymentName = deploymentUnit.getName();

    if (!configService.isKeycloakServerDeployment(deploymentName)) {
        return;
    }

    final EEModuleDescription description = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION);
    String webContext = configService.getWebContext();
    if (webContext == null) {
        throw new DeploymentUnitProcessingException("Can't determine web context/module for Keycloak Server");
    }
    description.setModuleName(webContext);

    addInfinispanCaches(phaseContext);
    addConfiguration(deploymentUnit, configService);
}
 
Example #13
Source File: ProcessApplicationProcessor.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
  final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();    
  final EEModuleDescription eeModuleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
  
  // must be EE Module
  if(eeModuleDescription == null) {
    return;
  }

  // discover user-provided component
  ComponentDescription paComponent = detectExistingComponent(deploymentUnit); 

  if(paComponent != null) {      
    log.log(Level.INFO, "Detected user-provided @"+ProcessApplication.class.getSimpleName()+" component with name '"+paComponent.getComponentName()+"'.");
    
    // mark this to be a process application
    ProcessApplicationAttachments.attachProcessApplicationComponent(deploymentUnit, paComponent);
    ProcessApplicationAttachments.mark(deploymentUnit);
    ProcessApplicationAttachments.markPartOfProcessApplication(deploymentUnit);
  }
}
 
Example #14
Source File: CamelDependenciesProcessor.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    DeploymentUnit depUnit = phaseContext.getDeploymentUnit();

    // Only operate on top level deployments
    if (depUnit.getParent() != null) {
        return;
    }

    List<DeploymentUnit> deployments = new ArrayList<>();
    List<DeploymentUnit> subDeployments = depUnit.getAttachmentList(Attachments.SUB_DEPLOYMENTS);
    deployments.add(depUnit);
    deployments.addAll(subDeployments);

    for (DeploymentUnit deployment : deployments) {
        CamelDeploymentSettings depSettings = deployment.getAttachment(CamelDeploymentSettings.ATTACHMENT_KEY);
        if (depSettings.isEnabled()) {
            addDeploymentDependencies(deployment, depSettings);
        }
    }
}
 
Example #15
Source File: CamelEndpointDeploymentSchedulerProcessor.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    CamelDeploymentSettings depSettings = deploymentUnit.getAttachment(CamelDeploymentSettings.ATTACHMENT_KEY);

    if (!depSettings.isEnabled()) {
        return;
    }
    List<DeploymentUnit> subDeployments = deploymentUnit
            .getAttachmentList(org.jboss.as.server.deployment.Attachments.SUB_DEPLOYMENTS);
    if (subDeployments != null && !subDeployments.isEmpty()) {
        /* do not install CamelEndpointDeploymentSchedulerService for ears */
        return;
    }

    final ServiceTarget serviceTarget = phaseContext.getServiceTarget();
    final ServiceController<CamelEndpointDeploymentSchedulerService> serviceController = CamelEndpointDeploymentSchedulerService
            .addService(deploymentUnit.getServiceName(), deploymentUnit.getName(), serviceTarget);
    phaseContext.addDeploymentDependency(serviceController.getName(),
            CamelConstants.CAMEL_ENDPOINT_DEPLOYMENT_SCHEDULER_REGISTRY_KEY);
}
 
Example #16
Source File: DeploymentVisibilityProcessor.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final ModuleSpecification moduleSpec = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE_SPECIFICATION);
    final Map<ModuleIdentifier, DeploymentUnit> deployments = new HashMap<ModuleIdentifier, DeploymentUnit>();
    //local classes are always first
    deploymentUnit.addToAttachmentList(Attachments.ACCESSIBLE_SUB_DEPLOYMENTS, deploymentUnit);
    buildModuleMap(deploymentUnit, deployments);

    for (final ModuleDependency dependency : moduleSpec.getAllDependencies()) {
        final DeploymentUnit sub = deployments.get(dependency.getIdentifier());
        if (sub != null) {
            deploymentUnit.addToAttachmentList(Attachments.ACCESSIBLE_SUB_DEPLOYMENTS, sub);
        }
    }
}
 
Example #17
Source File: CamelDeploymentSettingsProcessor.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {

        final DeploymentUnit depUnit = phaseContext.getDeploymentUnit();

        CamelDeploymentSettings.Builder depSettingsBuilder = depUnit
                .removeAttachment(CamelDeploymentSettings.BUILDER_ATTACHMENT_KEY);
        if (depSettingsBuilder != null && depUnit.getParent() == null) {
            /*
             * We do this only for parentless deployments because for ones that have a parent the build and attachment
             * is done by CamelDeploymentSettings.Builder.build() if the parent
             */
            final CamelDeploymentSettings depSettings = depSettingsBuilder.build();
            depUnit.putAttachment(CamelDeploymentSettings.ATTACHMENT_KEY, depSettings);
        }

    }
 
Example #18
Source File: KeycloakDependencyProcessor.java    From keycloak with Apache License 2.0 6 votes vote down vote up
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();

    if (Configuration.INSTANCE.getSecureDeployment(deploymentUnit) == null) {
        WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
        if (warMetaData == null) {
            return;
        }
        JBossWebMetaData webMetaData = warMetaData.getMergedJBossWebMetaData();
        if (webMetaData == null) {
            return;
        }
        LoginConfigMetaData loginConfig = webMetaData.getLoginConfig();
        if (loginConfig == null) return;
        if (loginConfig.getAuthMethod() == null) return;
        if (!loginConfig.getAuthMethod().equals("KEYCLOAK-SAML")) return;
    }

     // Next phase, need to detect if this is a Keycloak deployment.  If not, don't add the modules.

    final ModuleSpecification moduleSpecification = deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION);
    final ModuleLoader moduleLoader = Module.getBootModuleLoader();
    addCommonModules(moduleSpecification, moduleLoader);
    addPlatformSpecificModules(phaseContext, moduleSpecification, moduleLoader);
}
 
Example #19
Source File: KeycloakDependencyProcessor.java    From keycloak with Apache License 2.0 6 votes vote down vote up
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();

    if (Configuration.INSTANCE.getSecureDeployment(deploymentUnit) == null) {
        WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
        if (warMetaData == null) {
            return;
        }
        JBossWebMetaData webMetaData = warMetaData.getMergedJBossWebMetaData();
        if (webMetaData == null) {
            return;
        }
        LoginConfigMetaData loginConfig = webMetaData.getLoginConfig();
        if (loginConfig == null) return;
        if (loginConfig.getAuthMethod() == null) return;
        if (!loginConfig.getAuthMethod().equals("KEYCLOAK-SAML")) return;
    }

    final ModuleSpecification moduleSpecification = deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION);
    final ModuleLoader moduleLoader = Module.getBootModuleLoader();
    addCommonModules(moduleSpecification, moduleLoader);
    addPlatformSpecificModules(moduleSpecification, moduleLoader);
}
 
Example #20
Source File: DeploymentDependenciesProcessor.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    if (deploymentUnit.hasAttachment(DeploymentDependencies.ATTACHMENT_KEY)) {
        if (deploymentUnit.getParent() != null) {
            ServerLogger.DEPLOYMENT_LOGGER.deploymentDependenciesAreATopLevelElement(deploymentUnit.getName());
        } else {
            processDependencies(phaseContext, deploymentUnit);
        }
    }

    if (deploymentUnit.getParent() != null) {
        DeploymentUnit parent = deploymentUnit.getParent();
        if (parent.hasAttachment(DeploymentDependencies.ATTACHMENT_KEY)) {
            processDependencies(phaseContext, parent);
        }
    }
}
 
Example #21
Source File: ModuleSpecProcessor.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void installAliases(final ModuleSpecification moduleSpecification, final ModuleIdentifier moduleIdentifier, final DeploymentUnit deploymentUnit, final DeploymentPhaseContext phaseContext) {

        ModuleLoader moduleLoader = deploymentUnit.getAttachment(Attachments.SERVICE_MODULE_LOADER);
        for (final ModuleIdentifier alias : moduleSpecification.getAliases()) {
            final ServiceName moduleSpecServiceName = ServiceModuleLoader.moduleSpecServiceName(alias);
            final ModuleSpec spec = ModuleSpec.buildAlias(alias, moduleIdentifier).create();

            HashSet<ModuleDependency> dependencies = new HashSet<>(moduleSpecification.getAllDependencies());
            //we need to add the module we are aliasing as a dependency, to make sure that it will be resolved
            dependencies.add(new ModuleDependency(moduleLoader, moduleIdentifier, false, false, false, false));
            ModuleDefinition moduleDefinition = new ModuleDefinition(alias, dependencies, spec);

            final ValueService<ModuleDefinition> moduleSpecService = new ValueService<>(new ImmediateValue<>(moduleDefinition));
            final ServiceBuilder sb = phaseContext.getServiceTarget().addService(moduleSpecServiceName, moduleSpecService);
            sb.requires(deploymentUnit.getServiceName());
            sb.requires(phaseContext.getPhaseServiceName());
            sb.setInitialMode(Mode.ON_DEMAND);
            sb.install();

            ModuleLoadService.installAliases(phaseContext.getServiceTarget(), alias, Collections.singletonList(moduleIdentifier));

            ModuleResolvePhaseService.installService(phaseContext.getServiceTarget(), moduleDefinition);
        }
    }
 
Example #22
Source File: ClassFileTransformerProcessor.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final DelegatingClassFileTransformer transformer = deploymentUnit.getAttachment(DelegatingClassFileTransformer.ATTACHMENT_KEY);
    final ModuleSpecification moduleSpecification = deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION);
    final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
    if (module == null || transformer == null) {
        return;
    }
    try {
        for (String transformerClassName : moduleSpecification.getClassFileTransformers()) {
            transformer.addTransformer((ClassFileTransformer) module.getClassLoader().loadClass(transformerClassName).newInstance());
        }
        // activate transformer only after all delegate transformers have been added
        // so that transformers themselves are not instrumented
        transformer.setActive(true);
    } catch (Exception e) {
        throw ServerLogger.ROOT_LOGGER.failedToInstantiateClassFileTransformer(ClassFileTransformer.class.getSimpleName(), e);
    }
}
 
Example #23
Source File: KeycloakAdapterConfigDeploymentProcessor.java    From keycloak with Apache License 2.0 6 votes vote down vote up
private void addKeycloakAuthData(DeploymentPhaseContext phaseContext, KeycloakAdapterConfigService service) throws DeploymentUnitProcessingException {
    DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
    if (warMetaData == null) {
        throw new DeploymentUnitProcessingException("WarMetaData not found for " + deploymentUnit.getName() + ".  Make sure you have specified a WAR as your secure-deployment in the Keycloak subsystem.");
    }

    addJSONData(service.getJSON(deploymentUnit), warMetaData);
    JBossWebMetaData webMetaData = warMetaData.getMergedJBossWebMetaData();
    if (webMetaData == null) {
        webMetaData = new JBossWebMetaData();
        warMetaData.setMergedJBossWebMetaData(webMetaData);
    }

    LoginConfigMetaData loginConfig = webMetaData.getLoginConfig();
    if (loginConfig == null) {
        loginConfig = new LoginConfigMetaData();
        webMetaData.setLoginConfig(loginConfig);
    }
    loginConfig.setAuthMethod("KEYCLOAK");
    loginConfig.setRealmName(service.getRealmName(deploymentUnit));
    KeycloakLogger.ROOT_LOGGER.deploymentSecured(deploymentUnit.getName());
}
 
Example #24
Source File: KeycloakAdapterConfigDeploymentProcessor.java    From keycloak with Apache License 2.0 6 votes vote down vote up
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();

    KeycloakAdapterConfigService service = KeycloakAdapterConfigService.getInstance();
    if (service.isSecureDeployment(deploymentUnit) && service.isDeploymentConfigured(deploymentUnit)) {
        addKeycloakAuthData(phaseContext, service);
    }

    addConfigurationListener(phaseContext);

    // FYI, Undertow Extension will find deployments that have auth-method set to KEYCLOAK

    // todo notsure if we need this
    // addSecurityDomain(deploymentUnit, service);
}
 
Example #25
Source File: KeycloakDependencyProcessor.java    From keycloak with Apache License 2.0 6 votes vote down vote up
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();

    if (!KeycloakAdapterConfigService.getInstance().isSecureDeployment(deploymentUnit)) {
        WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
        if (warMetaData == null) {
            return;
        }
        JBossWebMetaData webMetaData = warMetaData.getMergedJBossWebMetaData();
        if (webMetaData == null) {
            return;
        }
        LoginConfigMetaData loginConfig = webMetaData.getLoginConfig();
        if (loginConfig == null) return;
        if (loginConfig.getAuthMethod() == null) return;
        if (!loginConfig.getAuthMethod().equals("KEYCLOAK")) return;
    }

    final ModuleSpecification moduleSpecification = deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION);
    final ModuleLoader moduleLoader = Module.getBootModuleLoader();
    addCommonModules(moduleSpecification, moduleLoader);
    addPlatformSpecificModules(moduleSpecification, moduleLoader);
}
 
Example #26
Source File: DriverDependenciesProcessor.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final ModuleSpecification moduleSpecification = deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION);
    final ModuleLoader moduleLoader = Module.getBootModuleLoader();
    if (deploymentUnit.hasAttachment(Attachments.RESOURCE_ROOTS)) {
        final List<ResourceRoot> resourceRoots = deploymentUnit.getAttachmentList(Attachments.RESOURCE_ROOTS);
        for (ResourceRoot root : resourceRoots) {
            VirtualFile child = root.getRoot().getChild(SERVICE_FILE_NAME);
            if (child.exists()) {
                moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, JTA, false, false, false, false));
                break;
            }
        }
    }
}
 
Example #27
Source File: CamelEndpointDeployerProcessor.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    CamelDeploymentSettings depSettings = deploymentUnit.getAttachment(CamelDeploymentSettings.ATTACHMENT_KEY);

    if (!depSettings.isEnabled()) {
        return;
    }
    final WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
    if (warMetaData == null) {
        /* ignore non-war deployments */
        CamelLogger.LOGGER.debug("{} ignores non-WAR deployment {}",
                CamelEndpointDeployerProcessor.class.getSimpleName(), deploymentUnit.getName());
        return;
    }

    final DeploymentResourceSupport deploymentResourceSupport = deploymentUnit
            .getAttachment(Attachments.DEPLOYMENT_RESOURCE_SUPPORT);
    final ModelNode node = deploymentResourceSupport.getDeploymentSubsystemModel(UndertowExtension.SUBSYSTEM_NAME);
    final String hostName = node.get(DeploymentDefinition.VIRTUAL_HOST.getName()).asString();
    final String serverName = node.get(DeploymentDefinition.SERVER.getName()).asString();
    final String path = node.get(DeploymentDefinition.CONTEXT_ROOT.getName()).asString();

    final ServiceName deploymentServiceName = UndertowService.deploymentServiceName(serverName, hostName, path);
    final ServiceName deploymentInfoServiceName = deploymentServiceName
            .append(UndertowDeploymentInfoService.SERVICE_NAME);
    final ServiceName hostServiceName = UndertowService.virtualHostName(serverName, hostName);

    CamelEndpointDeployerService.addService(deploymentUnit, phaseContext.getServiceTarget(),
            deploymentInfoServiceName, hostServiceName);
}
 
Example #28
Source File: CamelContextDescriptorsProcessor.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {

    final DeploymentUnit depUnit = phaseContext.getDeploymentUnit();
    final String runtimeName = depUnit.getName();

    CamelDeploymentSettings.Builder depSettings = depUnit.getAttachment(CamelDeploymentSettings.BUILDER_ATTACHMENT_KEY);
    if (depSettings.isDisabledByJbossAll() || !depSettings.isDeploymentValid() || runtimeName.endsWith(".ear")) {
        return;
    }

    try {
        boolean addedAny = false;
        if (runtimeName.endsWith(CamelConstants.CAMEL_CONTEXT_FILE_SUFFIX)) {
            URL fileURL = depUnit.getAttachment(Attachments.DEPLOYMENT_CONTENTS).asFileURL();
            addedAny |= addConditionally(depUnit, depSettings, fileURL);
        } else {
            VirtualFileFilter filter = new VirtualFileFilter() {
                public boolean accepts(VirtualFile child) {
                    return child.isFile() && child.getName().endsWith(CamelConstants.CAMEL_CONTEXT_FILE_SUFFIX);
                }
            };
            VirtualFile rootFile = depUnit.getAttachment(Attachments.DEPLOYMENT_ROOT).getRoot();
            for (VirtualFile vfile : rootFile.getChildrenRecursively(filter)) {
                addedAny |= addConditionally(depUnit, depSettings, vfile.asFileURL());
            }
        }

        if (addedAny) {
            LOGGER.info("Camel context descriptors found");
        }
    } catch (IOException ex) {
        throw new IllegalStateException("Cannot create camel context: " + runtimeName, ex);
    }
}
 
Example #29
Source File: CamelContextActivationProcessor.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {

    DeploymentUnit depUnit = phaseContext.getDeploymentUnit();
    CamelDeploymentSettings depSettings = depUnit.getAttachment(CamelDeploymentSettings.ATTACHMENT_KEY);

    if (!depSettings.isEnabled()) {
        return;
    }

    String runtimeName = depUnit.getName();

    ServiceTarget serviceTarget = phaseContext.getServiceTarget();
    ServiceName camelActivationServiceName = depUnit.getServiceName().append(CAMEL_CONTEXT_ACTIVATION_SERVICE_NAME.append(runtimeName));

    List<SpringCamelContextBootstrap> camelctxBootstrapList = depUnit.getAttachmentList(CamelConstants.CAMEL_CONTEXT_BOOTSTRAP_KEY);
    CamelContextActivationService activationService = new CamelContextActivationService(camelctxBootstrapList, runtimeName);
    ServiceBuilder builder = serviceTarget.addService(camelActivationServiceName, activationService);

    // Ensure all camel contexts in the deployment are started before constructing servlets etc
    depUnit.addToAttachmentList(Attachments.WEB_DEPENDENCIES, camelActivationServiceName);

    // Add JNDI binding dependencies to CamelContextActivationService
    for (SpringCamelContextBootstrap bootstrap : camelctxBootstrapList) {
        for (String jndiName : bootstrap.getJndiNames()) {
            if (jndiName.startsWith("${")) {
                // Don't add the binding if it appears to be a Spring property placeholder value
                // these can't be resolved before refresh() has been called on the ApplicationContext
                LOGGER.warn("Skipping JNDI binding dependency for property placeholder value: {}", jndiName);
            } else {
                LOGGER.debug("Add CamelContextActivationService JNDI binding dependency for {}", jndiName);
                installBindingDependency(builder, jndiName);
            }
        }
    }

    builder.install();
}
 
Example #30
Source File: CamelDeploymentSettingsBuilderProcessor.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {

        final DeploymentUnit depUnit = phaseContext.getDeploymentUnit();

        CamelDeploymentSettings.Builder depSettingsBuilder = depUnit.getAttachment(CamelDeploymentSettings.BUILDER_ATTACHMENT_KEY);
        if (depSettingsBuilder == null) {
            depSettingsBuilder = new CamelDeploymentSettings.Builder();
            depUnit.putAttachment(CamelDeploymentSettings.BUILDER_ATTACHMENT_KEY, depSettingsBuilder);
        } else if (depSettingsBuilder.isDisabledByJbossAll()) {
            // Camel is explicitly disabled in jboss-all.xml
            return;
        }

        depSettingsBuilder.deploymentName(getDeploymentName(depUnit));
        depSettingsBuilder.deploymentValid(isDeploymentValid(depUnit));
        depSettingsBuilder.camelActivationAnnotationPresent(hasCamelActivationAnnotations(depUnit));

        final DeploymentUnit parentDepUnit = depUnit.getParent();
        if (parentDepUnit != null) {
            final CamelDeploymentSettings.Builder parentDepSettingsBuilder = parentDepUnit.getAttachment(CamelDeploymentSettings.BUILDER_ATTACHMENT_KEY);
            if (parentDepSettingsBuilder != null) {
                // This consumer is called by CamelDeploymentSettings.Builder.build() right after the child settings are built
                Consumer<CamelDeploymentSettings> consumer = (CamelDeploymentSettings ds) -> {
                    depUnit.removeAttachment(CamelDeploymentSettings.BUILDER_ATTACHMENT_KEY);
                    depUnit.putAttachment(CamelDeploymentSettings.ATTACHMENT_KEY, ds);
                };
                parentDepSettingsBuilder.child(depSettingsBuilder, consumer);
            }
        }
    }