Search in sources :

Example 36 with WARArchive

use of org.wildfly.swarm.undertow.WARArchive in project wildfly-swarm by wildfly-swarm.

the class OpenTracingInstaller method process.

@Override
public void process() throws Exception {
    logger.info("Determining whether to install OpenTracing integration or not.");
    if (archive.getName().endsWith(".war")) {
        logger.logf(Logger.Level.INFO, "Installing the OpenTracing integration for the deployment %s", archive.getName());
        WARArchive webArchive = archive.as(WARArchive.class);
        WebXmlAsset webXml = webArchive.findWebXmlAsset();
        logger.logf(Logger.Level.INFO, "Adding the listener org.wildfly.swarm.opentracing.deployment.OpenTracingInitializer");
        webXml.addListener("org.wildfly.swarm.opentracing.deployment.OpenTracingInitializer");
        setContextParamIfNotNull(webXml, TracingFilter.SKIP_PATTERN, fraction.getServletSkipPattern());
    }
}
Also used : WebXmlAsset(org.wildfly.swarm.undertow.descriptors.WebXmlAsset) WARArchive(org.wildfly.swarm.undertow.WARArchive)

Example 37 with WARArchive

use of org.wildfly.swarm.undertow.WARArchive in project wildfly-swarm by wildfly-swarm.

the class ContextPathArchivePreparer method process.

@Override
public void process() {
    WARArchive warArchive = archive.as(WARArchive.class);
    if (warArchive.getContextRoot() == null) {
        warArchive.setContextRoot(contextPath.get());
    }
    UndertowExternalMountsAsset ut = null;
    if (mounts != null) {
        for (String mountPath : mounts) {
            Path staticPath = Paths.get(mountPath);
            if (!staticPath.isAbsolute()) {
                staticPath = Paths.get(System.getProperty("user.dir"), staticPath.toString()).normalize();
            }
            if (ut == null) {
                ut = new UndertowExternalMountsAsset();
            }
            ut.externalMount(staticPath.toString());
        }
    }
    if (ut != null) {
        warArchive.add(ut, WARArchive.EXTERNAL_MOUNT_PATH);
    }
}
Also used : Path(java.nio.file.Path) UndertowExternalMountsAsset(org.wildfly.swarm.undertow.internal.UndertowExternalMountsAsset) WARArchive(org.wildfly.swarm.undertow.WARArchive)

Example 38 with WARArchive

use of org.wildfly.swarm.undertow.WARArchive in project wildfly-swarm by wildfly-swarm.

the class HttpSecurityPreparer method process.

@SuppressWarnings("unchecked")
@Override
public void process() {
    if (deploymentConfigs == null || deploymentConfigs.isEmpty()) {
        return;
    }
    // find a matching archive declaration
    Optional<String> match = deploymentConfigs.keySet().stream().filter(c -> archive.getName().equals(c)).findFirst();
    if (!match.isPresent()) {
        // no matching archive
        return;
    }
    Map<String, Object> matchingConfig = (Map<String, Object>) deploymentConfigs.get(match.get());
    if (!matchingConfig.containsKey("web")) {
        // missing web configuration
        return;
    }
    Map<String, Object> deploymentConfig = (Map<String, Object>) matchingConfig.get("web");
    WARArchive war = archive.as(WARArchive.class);
    WebXmlAsset webXml = war.findWebXmlAsset();
    JBossWebAsset jbossWeb = war.findJbossWebAsset();
    // login-config
    Map<String, Object> loginConfig = (Map<String, Object>) deploymentConfig.get("login-config");
    if (loginConfig != null) {
        String authMethod = (String) loginConfig.getOrDefault("auth-method", "NONE");
        // Setup login-config
        webXml.setLoginConfig(authMethod, "ignored");
        // security domain
        if (loginConfig.containsKey("security-domain")) {
            jbossWeb.setSecurityDomain((String) loginConfig.get("security-domain"));
        }
        // form login
        if (loginConfig.containsKey("form-login-config")) {
            Map<String, Object> formLoginConfig = (Map<String, Object>) loginConfig.get("form-login-config");
            webXml.setFormLoginConfig("Security Realm", (String) formLoginConfig.get("form-login-page"), (String) formLoginConfig.get("form-error-page"));
        }
    }
    // security constraints
    List<Map<String, Object>> securityConstraints = (List<Map<String, Object>>) deploymentConfig.getOrDefault("security-constraints", Collections.EMPTY_LIST);
    for (Map<String, Object> sc : securityConstraints) {
        SecurityConstraint securityConstraint = webXml.protect((String) sc.getOrDefault("url-pattern", "/*"));
        ((List<String>) sc.getOrDefault("methods", Collections.emptyList())).forEach(securityConstraint::withMethod);
        ((List<String>) sc.getOrDefault("roles", Collections.emptyList())).forEach(securityConstraint::withRole);
    }
}
Also used : DeploymentProcessor(org.wildfly.swarm.spi.api.DeploymentProcessor) DeploymentScoped(org.wildfly.swarm.spi.runtime.annotations.DeploymentScoped) Logger(org.jboss.logging.Logger) JBossWebAsset(org.wildfly.swarm.undertow.descriptors.JBossWebAsset) Archive(org.jboss.shrinkwrap.api.Archive) WebXmlAsset(org.wildfly.swarm.undertow.descriptors.WebXmlAsset) SecurityConstraint(org.wildfly.swarm.undertow.descriptors.SecurityConstraint) Inject(javax.inject.Inject) List(java.util.List) Configurable(org.wildfly.swarm.spi.api.annotations.Configurable) Map(java.util.Map) WARArchive(org.wildfly.swarm.undertow.WARArchive) AttributeDocumentation(org.wildfly.swarm.config.runtime.AttributeDocumentation) Optional(java.util.Optional) Collections(java.util.Collections) JBossWebAsset(org.wildfly.swarm.undertow.descriptors.JBossWebAsset) WebXmlAsset(org.wildfly.swarm.undertow.descriptors.WebXmlAsset) WARArchive(org.wildfly.swarm.undertow.WARArchive) SecurityConstraint(org.wildfly.swarm.undertow.descriptors.SecurityConstraint) List(java.util.List) Map(java.util.Map)

Example 39 with WARArchive

use of org.wildfly.swarm.undertow.WARArchive in project wildfly-swarm by wildfly-swarm.

the class DefaultWarDeploymentFactory method archiveFromCurrentApp.

public static WARArchive archiveFromCurrentApp() throws Exception {
    final WARArchive archive = ShrinkWrap.create(WARArchive.class, determineName());
    final DefaultDeploymentFactory factory = new DefaultWarDeploymentFactory();
    factory.setup(archive);
    return archive;
}
Also used : WARArchive(org.wildfly.swarm.undertow.WARArchive) DefaultDeploymentFactory(org.wildfly.swarm.spi.api.DefaultDeploymentFactory)

Aggregations

WARArchive (org.wildfly.swarm.undertow.WARArchive)39 Deployment (org.jboss.arquillian.container.test.api.Deployment)15 Test (org.junit.Test)8 WebXmlAsset (org.wildfly.swarm.undertow.descriptors.WebXmlAsset)5 Produces (javax.enterprise.inject.Produces)4 Node (org.jboss.shrinkwrap.api.Node)4 URL (java.net.URL)3 ClassLoaderAsset (org.jboss.shrinkwrap.api.asset.ClassLoaderAsset)3 MockTracer (io.opentracing.mock.MockTracer)2 BufferedReader (java.io.BufferedReader)2 File (java.io.File)2 InputStreamReader (java.io.InputStreamReader)2 List (java.util.List)2 Map (java.util.Map)2 Module (org.jboss.modules.Module)2 ArchivePath (org.jboss.shrinkwrap.api.ArchivePath)2 Asset (org.jboss.shrinkwrap.api.asset.Asset)2 StringAsset (org.jboss.shrinkwrap.api.asset.StringAsset)2 JBossWebAsset (org.wildfly.swarm.undertow.descriptors.JBossWebAsset)2 UndertowExternalMountsAsset (org.wildfly.swarm.undertow.internal.UndertowExternalMountsAsset)2