Java Code Examples for org.jboss.as.server.deployment.DeploymentUnit#getName()

The following examples show how to use org.jboss.as.server.deployment.DeploymentUnit#getName() . 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: 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 2
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 3
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 4
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 5
Source File: Configuration.java    From keycloak with Apache License 2.0 6 votes vote down vote up
private String preferredDeploymentName(DeploymentUnit deploymentUnit) {
    String deploymentName = deploymentUnit.getName();
    WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
    if (warMetaData == null) {
        return deploymentName;
    }
    
    JBossWebMetaData webMetaData = warMetaData.getMergedJBossWebMetaData();
    if (webMetaData == null) {
        return deploymentName;
    }
    
    String moduleName = webMetaData.getModuleName();
    if (moduleName != null) return moduleName + ".war";
    
    return deploymentName;
}
 
Example 6
Source File: Configuration.java    From keycloak with Apache License 2.0 6 votes vote down vote up
private String preferredDeploymentName(DeploymentUnit deploymentUnit) {
    String deploymentName = deploymentUnit.getName();
    WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
    if (warMetaData == null) {
        return deploymentName;
    }
    
    JBossWebMetaData webMetaData = warMetaData.getMergedJBossWebMetaData();
    if (webMetaData == null) {
        return deploymentName;
    }
    
    String moduleName = webMetaData.getModuleName();
    if (moduleName != null) return moduleName + ".war";
    
    return deploymentName;
}
 
Example 7
Source File: KeycloakAdapterConfigService.java    From keycloak with Apache License 2.0 6 votes vote down vote up
private String preferredDeploymentName(DeploymentUnit deploymentUnit) {
    String deploymentName = deploymentUnit.getName();
    WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
    if (warMetaData == null) {
        return deploymentName;
    }
    
    JBossWebMetaData webMetaData = warMetaData.getMergedJBossWebMetaData();
    if (webMetaData == null) {
        return deploymentName;
    }
    
    String moduleName = webMetaData.getModuleName();
    if (moduleName != null) return moduleName + ".war";
    
    return deploymentName;
}
 
Example 8
Source File: KeycloakAdapterConfigService.java    From keycloak with Apache License 2.0 6 votes vote down vote up
private String preferredDeploymentName(DeploymentUnit deploymentUnit) {
    String deploymentName = deploymentUnit.getName();
    WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
    if (warMetaData == null) {
        return deploymentName;
    }
    
    JBossWebMetaData webMetaData = warMetaData.getMergedJBossWebMetaData();
    if (webMetaData == null) {
        return deploymentName;
    }
    
    String moduleName = webMetaData.getModuleName();
    if (moduleName != null) return moduleName + ".war";
    
    return deploymentName;
}
 
Example 9
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 10
Source File: CamelDeploymentSettingsBuilderProcessor.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
private boolean isDeploymentValid(final DeploymentUnit depUnit) {

        boolean result = true;

        // Skip wiring wfc for hawtio and resource adapter deployments
        String runtimeName = depUnit.getName();
        if (runtimeName.startsWith("hawtio") && runtimeName.endsWith(".war") || runtimeName.endsWith(".rar")) {
            result = false;
        }

        return result;
    }
 
Example 11
Source File: KeycloakAdapterConfigDeploymentProcessor.java    From keycloak with Apache License 2.0 5 votes vote down vote up
private void addKeycloakSamlAuthData(DeploymentPhaseContext phaseContext) 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.");
    }

    try {
        addXMLData(getXML(deploymentUnit), warMetaData);
    } catch (Exception e) {
        throw new DeploymentUnitProcessingException("Failed to configure KeycloakSamlExtension from subsystem model", e);
    }
    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-SAML");

    KeycloakLogger.ROOT_LOGGER.deploymentSecured(deploymentUnit.getName());
}
 
Example 12
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 13
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 14
Source File: DeploymentRootMountProcessor.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    if(deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT) != null) {
        return;
    }
    final DeploymentMountProvider deploymentMountProvider = deploymentUnit.getAttachment(Attachments.SERVER_DEPLOYMENT_REPOSITORY);
    if(deploymentMountProvider == null) {
        throw ServerLogger.ROOT_LOGGER.noDeploymentRepositoryAvailable();
    }

    final String deploymentName = deploymentUnit.getName();
    final VirtualFile deploymentContents = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_CONTENTS);

    // internal deployments do not have any contents, so there is nothing to mount
    if (deploymentContents == null)
        return;

    final VirtualFile deploymentRoot;
    final MountHandle mountHandle;
    if (deploymentContents.isDirectory()) {
        // use the contents directly
        deploymentRoot = deploymentContents;
        // nothing was mounted
        mountHandle = null;
        ExplodedDeploymentMarker.markAsExplodedDeployment(deploymentUnit);

    } else {
        // The mount point we will use for the repository file
        deploymentRoot = VFS.getChild("content/" + deploymentName);

        boolean failed = false;
        Closeable handle = null;
        try {
            final boolean mountExploded = MountExplodedMarker.isMountExploded(deploymentUnit);
            final MountType type;
            if(mountExploded) {
                type = MountType.EXPANDED;
            } else if (deploymentName.endsWith(".xml")) {
                type = MountType.REAL;
            } else {
                type = MountType.ZIP;
            }
            handle = deploymentMountProvider.mountDeploymentContent(deploymentContents, deploymentRoot, type);
            mountHandle = MountHandle.create(handle);
        } catch (IOException e) {
            failed = true;
            throw ServerLogger.ROOT_LOGGER.deploymentMountFailed(e);
        } finally {
            if(failed) {
                VFSUtils.safeClose(handle);
            }
        }
    }
    final ResourceRoot resourceRoot = new ResourceRoot(deploymentRoot, mountHandle);
    ModuleRootMarker.mark(resourceRoot);
    deploymentUnit.putAttachment(Attachments.DEPLOYMENT_ROOT, resourceRoot);
    deploymentUnit.putAttachment(Attachments.MODULE_SPECIFICATION, new ModuleSpecification());
}
 
Example 15
Source File: KeycloakClusteredSsoDeploymentProcessor.java    From keycloak with Apache License 2.0 4 votes vote down vote up
private void addSamlReplicationConfiguration(DeploymentUnit deploymentUnit, DeploymentPhaseContext context) {
        WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
        if (warMetaData == null) {
            return;
        }

        JBossWebMetaData webMetaData = warMetaData.getMergedJBossWebMetaData();
        if (webMetaData == null) {
            webMetaData = new JBossWebMetaData();
            warMetaData.setMergedJBossWebMetaData(webMetaData);
        }

        // Find out default names of cache container and cache
        String cacheContainer = DEFAULT_CACHE_CONTAINER;
        String deploymentSessionCacheName =
          (deploymentUnit.getParent() == null
              ? ""
              : deploymentUnit.getParent().getName() + ".")
          + deploymentUnit.getName();

        // Update names from jboss-web.xml's <replicationConfig>
        if (webMetaData.getReplicationConfig() != null && webMetaData.getReplicationConfig().getCacheName() != null) {
            ServiceName sn = ServiceName.parse(webMetaData.getReplicationConfig().getCacheName());
            cacheContainer = (sn.length() > 1) ? sn.getParent().getSimpleName() : sn.getSimpleName();
            deploymentSessionCacheName = sn.getSimpleName();
        }
        String ssoCacheName = deploymentSessionCacheName + ".ssoCache";

        // Override if they were set in the context parameters
        List<ParamValueMetaData> contextParams = webMetaData.getContextParams();
        if (contextParams == null) {
            contextParams = new ArrayList<>();
        }
        for (ParamValueMetaData contextParam : contextParams) {
            if (Objects.equals(contextParam.getParamName(), SSO_CACHE_CONTAINER_NAME_PARAM_NAME)) {
                cacheContainer = contextParam.getParamValue();
            } else if (Objects.equals(contextParam.getParamName(), SSO_CACHE_NAME_PARAM_NAME)) {
                ssoCacheName = contextParam.getParamValue();
            }
        }

        LOG.debugv("Determined SSO cache container configuration: container: {0}, cache: {1}", cacheContainer, ssoCacheName);
//        addCacheDependency(context, deploymentUnit, cacheContainer, cacheName);

        // Set context parameters for SSO cache container/name
        ParamValueMetaData paramContainer = new ParamValueMetaData();
        paramContainer.setParamName(AdapterConstants.REPLICATION_CONFIG_CONTAINER_PARAM_NAME);
        paramContainer.setParamValue(cacheContainer);
        contextParams.add(paramContainer);

        ParamValueMetaData paramSsoCache = new ParamValueMetaData();
        paramSsoCache.setParamName(AdapterConstants.REPLICATION_CONFIG_SSO_CACHE_PARAM_NAME);
        paramSsoCache.setParamValue(ssoCacheName);
        contextParams.add(paramSsoCache);

        webMetaData.setContextParams(contextParams);
    }
 
Example 16
Source File: KeycloakClusteredSsoDeploymentProcessor.java    From keycloak with Apache License 2.0 4 votes vote down vote up
private void addSamlReplicationConfiguration(DeploymentUnit deploymentUnit, DeploymentPhaseContext context) {
    WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
    if (warMetaData == null) {
        return;
    }

    JBossWebMetaData webMetaData = warMetaData.getMergedJBossWebMetaData();
    if (webMetaData == null) {
        webMetaData = new JBossWebMetaData();
        warMetaData.setMergedJBossWebMetaData(webMetaData);
    }

    // Find out default names of cache container and cache
    String cacheContainer = DEFAULT_CACHE_CONTAINER;
    String deploymentSessionCacheName =
      (deploymentUnit.getParent() == null
          ? ""
          : deploymentUnit.getParent().getName() + ".")
      + deploymentUnit.getName();

    // Update names from jboss-web.xml's <replicationConfig>
    if (webMetaData.getReplicationConfig() != null && webMetaData.getReplicationConfig().getCacheName() != null) {
        ServiceName sn = ServiceName.parse(webMetaData.getReplicationConfig().getCacheName());
        cacheContainer = (sn.length() > 1) ? sn.getParent().getSimpleName() : sn.getSimpleName();
        deploymentSessionCacheName = sn.getSimpleName();
    }
    String ssoCacheName = deploymentSessionCacheName + ".ssoCache";

    // Override if they were set in the context parameters
    List<ParamValueMetaData> contextParams = webMetaData.getContextParams();
    if (contextParams == null) {
        contextParams = new ArrayList<>();
    }
    for (ParamValueMetaData contextParam : contextParams) {
        if (Objects.equals(contextParam.getParamName(), SSO_CACHE_CONTAINER_NAME_PARAM_NAME)) {
            cacheContainer = contextParam.getParamValue();
        } else if (Objects.equals(contextParam.getParamName(), SSO_CACHE_NAME_PARAM_NAME)) {
            ssoCacheName = contextParam.getParamValue();
        }
    }

    LOG.debugv("Determined SSO cache container configuration: container: {0}, cache: {1}", cacheContainer, ssoCacheName);
    addCacheDependency(context, deploymentUnit, cacheContainer, ssoCacheName);

    // Set context parameters for SSO cache container/name
    ParamValueMetaData paramContainer = new ParamValueMetaData();
    paramContainer.setParamName(AdapterConstants.REPLICATION_CONFIG_CONTAINER_PARAM_NAME);
    paramContainer.setParamValue(cacheContainer);
    contextParams.add(paramContainer);

    ParamValueMetaData paramSsoCache = new ParamValueMetaData();
    paramSsoCache.setParamName(AdapterConstants.REPLICATION_CONFIG_SSO_CACHE_PARAM_NAME);
    paramSsoCache.setParamValue(ssoCacheName);
    contextParams.add(paramSsoCache);

    webMetaData.setContextParams(contextParams);
}
 
Example 17
Source File: CamelDeploymentSettingsBuilderProcessor.java    From wildfly-camel with Apache License 2.0 4 votes vote down vote up
public static String getDeploymentName(final DeploymentUnit depUnit) {
    DeploymentUnit parent = depUnit.getParent();
    return parent != null ? parent.getName() + "." + depUnit.getName() : depUnit.getName();
}