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

The following examples show how to use org.jboss.as.server.deployment.Attachments. 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 (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 #2
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 #3
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 #4
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 #5
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 #6
Source File: CamelContextDescriptorsProcessor.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
public boolean addConditionally(DeploymentUnit depUnit, CamelDeploymentSettings.Builder depSettingsBuilder, URL fileURL) {

        boolean skipResource = false;
        CompositeIndex index = depUnit.getAttachment(Attachments.COMPOSITE_ANNOTATION_INDEX);

        // [#1215] Add support for Spring based CamelContext injection
        for (AnnotationInstance aninst : index.getAnnotations(DotName.createSimple("org.apache.camel.cdi.ImportResource"))) {
            for (String resname : aninst.value().asStringArray()) {
                skipResource |= fileURL.getPath().endsWith(resname);
            }
        }

        if (skipResource == false) {
            depSettingsBuilder.camelContextUrl(fileURL);
            return true;
        }
        return false;
    }
 
Example #7
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 #8
Source File: ManifestClassPathProcessor.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Creates a {@link ResourceRoot} for the passed {@link VirtualFile file} and adds it to the list of {@link ResourceRoot}s
 * in the {@link DeploymentUnit deploymentUnit}
 *
 *
 * @param file           The file for which the resource root will be created
 * @return Returns the created {@link ResourceRoot}
 * @throws java.io.IOException
 */
private synchronized ResourceRoot createResourceRoot(final VirtualFile file, final DeploymentUnit deploymentUnit, final VirtualFile deploymentRoot) throws DeploymentUnitProcessingException {
    try {
        Map<String, MountedDeploymentOverlay> overlays = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_OVERLAY_LOCATIONS);

        String relativeName = file.getPathNameRelativeTo(deploymentRoot);
        MountedDeploymentOverlay overlay = overlays.get(relativeName);
        Closeable closable = null;
        if(overlay != null) {
            overlay.remountAsZip(false);
        } else if(file.isFile()) {
            closable = VFS.mountZip(file, file, TempFileProviderService.provider());
        }
        final MountHandle mountHandle = MountHandle.create(closable);
        final ResourceRoot resourceRoot = new ResourceRoot(file, mountHandle);
        ModuleRootMarker.mark(resourceRoot);
        ResourceRootIndexer.indexResourceRoot(resourceRoot);
        return resourceRoot;
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
Example #9
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 #10
Source File: ManifestClassPathProcessor.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void handlingExistingClassPathEntry(final ArrayDeque<RootEntry> resourceRoots, final DeploymentUnit topLevelDeployment, final VirtualFile topLevelRoot, final Map<VirtualFile, ResourceRoot> subDeployments, final Map<VirtualFile, AdditionalModuleSpecification> additionalModules, final Set<VirtualFile> existingAccessibleRoots, final ResourceRoot resourceRoot, final Attachable target, final VirtualFile classPathFile) throws DeploymentUnitProcessingException {
    if (existingAccessibleRoots.contains(classPathFile)) {
        ServerLogger.DEPLOYMENT_LOGGER.debugf("Class-Path entry %s in %s ignored, as target is already accessible", classPathFile, resourceRoot.getRoot());
    } else if (additionalModules.containsKey(classPathFile)) {
        final AdditionalModuleSpecification moduleSpecification = additionalModules.get(classPathFile);
        //as class path entries are exported, transitive dependencies will also be available
        target.addToAttachmentList(Attachments.CLASS_PATH_ENTRIES, moduleSpecification.getModuleIdentifier());
    } else if (subDeployments.containsKey(classPathFile)) {
        //now we need to calculate the sub deployment module identifier
        //unfortunately the sub deployment has not been setup yet, so we cannot just
        //get it from the sub deployment directly
        final ResourceRoot otherRoot = subDeployments.get(classPathFile);
        target.addToAttachmentList(Attachments.CLASS_PATH_ENTRIES, ModuleIdentifierProcessor.createModuleIdentifier(otherRoot.getRootName(), otherRoot, topLevelDeployment, topLevelRoot, false));
    } else {
        ModuleIdentifier identifier = createAdditionalModule(resourceRoot, topLevelDeployment, topLevelRoot, additionalModules, classPathFile, resourceRoots);
        target.addToAttachmentList(Attachments.CLASS_PATH_ENTRIES, identifier);
    }
}
 
Example #11
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 #12
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 #13
Source File: CompositeIndexProcessor.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Loops through all resource roots that have been made available transitively via Class-Path entries, and
 * adds them to the list of roots to be processed.
 */
private Collection<? extends ResourceRoot> handleClassPathItems(final DeploymentUnit deploymentUnit) {
    final Set<ResourceRoot> additionalRoots = new HashSet<ResourceRoot>();
    final ArrayDeque<ResourceRoot> toProcess = new ArrayDeque<ResourceRoot>();
    final List<ResourceRoot> resourceRoots = DeploymentUtils.allResourceRoots(deploymentUnit);
    toProcess.addAll(resourceRoots);
    final Set<ResourceRoot> processed = new HashSet<ResourceRoot>(resourceRoots);

    while (!toProcess.isEmpty()) {
        final ResourceRoot root = toProcess.pop();
        final List<ResourceRoot> classPathRoots = root.getAttachmentList(Attachments.CLASS_PATH_RESOURCE_ROOTS);
        for(ResourceRoot cpRoot : classPathRoots) {
            if(!processed.contains(cpRoot)) {
                additionalRoots.add(cpRoot);
                toProcess.add(cpRoot);
                processed.add(cpRoot);
            }
        }
    }
    return additionalRoots;
}
 
Example #14
Source File: CompositeIndexProcessor.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private Map<ModuleIdentifier, DeploymentUnit> buildSubdeploymentDependencyMap(DeploymentUnit deploymentUnit) {
    Set<ModuleIdentifier> depModuleIdentifiers = new HashSet<>();
    for (ModuleDependency dep: deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION).getAllDependencies()) {
        depModuleIdentifiers.add(dep.getIdentifier());
    }

    DeploymentUnit top = deploymentUnit.getParent()==null?deploymentUnit:deploymentUnit.getParent();
    Map<ModuleIdentifier, DeploymentUnit> res = new HashMap<>();
    AttachmentList<DeploymentUnit> subDeployments = top.getAttachment(Attachments.SUB_DEPLOYMENTS);
    if (subDeployments != null) {
        for (DeploymentUnit subDeployment : subDeployments) {
            ModuleIdentifier moduleIdentifier = subDeployment.getAttachment(Attachments.MODULE_IDENTIFIER);
            if (depModuleIdentifiers.contains(moduleIdentifier)) {
                res.put(moduleIdentifier, subDeployment);
            }
        }
    }
    return res;
}
 
Example #15
Source File: AnnotationIndexUtils.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static Map<ResourceRoot, Index> getAnnotationIndexes(final DeploymentUnit deploymentUnit) {
    final List<ResourceRoot> allResourceRoots = new ArrayList<ResourceRoot>();
    allResourceRoots.addAll(deploymentUnit.getAttachmentList(Attachments.RESOURCE_ROOTS));
    allResourceRoots.add(deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT));
    Map<ResourceRoot, Index> indexes = new HashMap<ResourceRoot, Index>();
    for (ResourceRoot resourceRoot : allResourceRoots) {
        if (resourceRoot == null)
            continue;

        Index index = resourceRoot.getAttachment(Attachments.ANNOTATION_INDEX);
        if (index != null) {
            indexes.put(resourceRoot, index);
        }
    }
    return indexes;
}
 
Example #16
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 #17
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 #18
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 #19
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 #20
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 #21
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 #22
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 undeploy(final DeploymentUnit context) {
    // don't process sub-deployments as they are processed by processing methods
    final ResourceRoot root = context.getAttachment(Attachments.DEPLOYMENT_ROOT);
    if (SubDeploymentMarker.isSubDeployment(root)) return;
    // Remove any log context selector references
    final Module module = context.getAttachment(Attachments.MODULE);
    // Remove either the default log context or a defined log context. It's safe to attempt to remove a
    // nonexistent context.
    unregisterLogContext(context, DEFAULT_LOG_CONTEXT_KEY, module);
    unregisterLogContext(context, LOG_CONTEXT_KEY, module);
    // Unregister all sub-deployments
    final List<DeploymentUnit> subDeployments = getSubDeployments(context);
    for (DeploymentUnit subDeployment : subDeployments) {
        final Module subDeploymentModule = subDeployment.getAttachment(Attachments.MODULE);
        // Sub-deployment should never have a default log context
        unregisterLogContext(subDeployment, LOG_CONTEXT_KEY, subDeploymentModule);
    }
}
 
Example #23
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 #24
Source File: KeycloakServerDeploymentProcessor.java    From keycloak with Apache License 2.0 5 votes vote down vote up
private void addInfinispanCaches(DeploymentPhaseContext context) {
    ServiceTarget st = context.getServiceTarget();
    CapabilityServiceSupport support = context.getDeploymentUnit().getAttachment(Attachments.CAPABILITY_SERVICE_SUPPORT);
    for (String c : CACHES) {
        ServiceName sn = support.getCapabilityServiceName("org.wildfly.clustering.infinispan.cache", "keycloak", c);
        st.addDependency(sn);
    }
}
 
Example #25
Source File: DeploymentDependenciesProcessor.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void processDependencies(final DeploymentPhaseContext phaseContext, final DeploymentUnit deploymentUnit) {
    final DeploymentDependencies deps = deploymentUnit.getAttachment(DeploymentDependencies.ATTACHMENT_KEY);
    if (!deps.getDependencies().isEmpty()) {
        for (final String deployment : deps.getDependencies()) {
            final ServiceName name =  DeploymentCompleteServiceProcessor.serviceName(Services.deploymentUnitName(deployment));
            phaseContext.addToAttachmentList(Attachments.NEXT_PHASE_DEPS, name);
        }
    }
}
 
Example #26
Source File: JBossAllXMLParsingProcessor.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final ResourceRoot root = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT);

    VirtualFile descriptor = null;
    for (final String loc : DEPLOYMENT_STRUCTURE_DESCRIPTOR_LOCATIONS) {
        final VirtualFile file = root.getRoot().getChild(loc);
        if (file.exists()) {
            descriptor = file;
            break;
        }
    }
    if(descriptor == null) {
        return;
    }
    final XMLMapper mapper = XMLMapper.Factory.create();
    final Map<QName, AttachmentKey<?>> namespaceAttachments = new HashMap<QName, AttachmentKey<?>>();
    for(final JBossAllXMLParserDescription<?> parser : deploymentUnit.getAttachmentList(JBossAllXMLParserDescription.ATTACHMENT_KEY)) {
        namespaceAttachments.put(parser.getRootElement(), parser.getAttachmentKey());
        mapper.registerRootElement(parser.getRootElement(), new JBossAllXMLElementReader(parser));
    }
    mapper.registerRootElement(new QName(Namespace.JBOSS_1_0.getUriString(), JBOSS), Parser.INSTANCE);
    mapper.registerRootElement(new QName(Namespace.NONE.getUriString(), JBOSS), Parser.INSTANCE);

    final JBossAllXmlParseContext context = new JBossAllXmlParseContext(deploymentUnit);
    parse(descriptor, mapper, context);

    //we use this map to detect the presence of two different but functionally equivalent namespaces
    final Map<AttachmentKey<?>, QName> usedNamespaces = new HashMap<AttachmentKey<?>, QName>();
    for(Map.Entry<QName, Object> entry : context.getParseResults().entrySet()) {
        final AttachmentKey attachmentKey = namespaceAttachments.get(entry.getKey());
        if(usedNamespaces.containsKey(attachmentKey)) {
            throw ServerLogger.ROOT_LOGGER.equivalentNamespacesInJBossXml(entry.getKey(), usedNamespaces.get(attachmentKey));
        }
        usedNamespaces.put(attachmentKey, entry.getKey());
        deploymentUnit.putAttachment(attachmentKey, entry.getValue());
    }
}
 
Example #27
Source File: ManifestAttachmentProcessor.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static Manifest getManifest(ResourceRoot resourceRoot) throws DeploymentUnitProcessingException {
    Manifest manifest = resourceRoot.getAttachment(Attachments.MANIFEST);
    if (manifest == null) {
        final VirtualFile deploymentRoot = resourceRoot.getRoot();
        try {
            manifest = VFSUtils.getManifest(deploymentRoot);
        } catch (IOException e) {
            throw ServerLogger.ROOT_LOGGER.failedToGetManifest(deploymentRoot, e);
        }
    }
    return manifest;
}
 
Example #28
Source File: ServiceActivatorDependencyProcessor.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Add the dependencies if the deployment contains a service activator loader entry.
 * @param phaseContext the deployment unit context
 * @throws DeploymentUnitProcessingException
 */
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final ResourceRoot deploymentRoot = phaseContext.getDeploymentUnit().getAttachment(Attachments.DEPLOYMENT_ROOT);
    final ModuleSpecification moduleSpecification = phaseContext.getDeploymentUnit().getAttachment(
            Attachments.MODULE_SPECIFICATION);
    if(deploymentRoot == null)
        return;
    final ServicesAttachment servicesAttachments = phaseContext.getDeploymentUnit().getAttachment(Attachments.SERVICES);
    if(servicesAttachments != null && !servicesAttachments.getServiceImplementations(ServiceActivator.class.getName()).isEmpty()) {
        moduleSpecification.addSystemDependency(MSC_DEP);
    }
}
 
Example #29
Source File: ManifestAttachmentProcessor.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void undeploy(final DeploymentUnit context) {
    List<ResourceRoot> resourceRoots = DeploymentUtils.allResourceRoots(context);
    for (ResourceRoot resourceRoot : resourceRoots) {
        resourceRoot.removeAttachment(Attachments.MANIFEST);
    }
}
 
Example #30
Source File: EESecurityDependencyProcessor.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void deploy(DeploymentPhaseContext phaseContext) {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final ModuleLoader moduleLoader = Module.getBootModuleLoader();
    final ModuleSpecification moduleSpecification = deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION);

    moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, JACC_API, false, false, true, false));
    moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, AUTH_MESSAGE_API, false, false, true, false));
}