Search in sources :

Example 1 with WebXmlAsset

use of org.wildfly.swarm.undertow.descriptors.WebXmlAsset in project wildfly-swarm by wildfly-swarm.

the class WebXmlAssetTest method testInvalidLoginAuthMethod.

@Test
public void testInvalidLoginAuthMethod() throws Exception {
    WebXmlAsset asset = new WebXmlAsset();
    assertThat(asset.getLoginRealm(null)).isNull();
    assertThat(asset.getLoginRealm("")).isNull();
    assertThat(asset.getLoginRealm("  ")).isNull();
}
Also used : WebXmlAsset(org.wildfly.swarm.undertow.descriptors.WebXmlAsset) Test(org.junit.Test)

Example 2 with WebXmlAsset

use of org.wildfly.swarm.undertow.descriptors.WebXmlAsset in project wildfly-swarm by wildfly-swarm.

the class MPJWTAuthExtensionArchivePreparer method process.

@Override
public void process() throws Exception {
    WARArchive war = archive.as(WARArchive.class);
    // Check for LoginConfig annotation
    Collection<AnnotationInstance> lcAnnotations = index.getAnnotations(LOGIN_CONFIG);
    for (AnnotationInstance lc : lcAnnotations) {
        AnnotationValue authMethod = lc.value("authMethod");
        AnnotationValue realmName = lc.value("realmName");
        String realm = realmName != null ? realmName.asString() : "";
        // Set the web.xml login-config auth-method and jboss-web.xml security domain
        if (authMethod != null) {
            WebXmlAsset webXml = war.findWebXmlAsset();
            webXml.setLoginConfig(authMethod.asString(), realm);
        }
        if (realm.length() > 0) {
            JBossWebAsset jBossWeb = war.findJbossWebAsset();
            jBossWeb.setSecurityDomain(realm);
        }
    }
    // Get the @ApplicationPath setting
    WebXmlAsset webXml = war.findWebXmlAsset();
    String appPath = "/";
    Collection<AnnotationInstance> appPaths = index.getAnnotations(APP_PATH);
    if (!appPaths.isEmpty()) {
        appPath = appPaths.iterator().next().value().asString();
    }
    // Process the @RolesAllowed, @PermitAll and @DenyAll annotations
    Collection<AnnotationInstance> rolesAnnotations = index.getAnnotations(ROLES_ALLOWED);
    for (AnnotationInstance annotation : rolesAnnotations) {
        if (annotation.target().kind() == AnnotationTarget.Kind.CLASS) {
            // Process the root resource
            String[] roles = annotation.value().asStringArray();
            ClassInfo classInfo = annotation.target().asClass();
            if (!scannedClasses.contains(classInfo.name())) {
                generateSecurityConstraints(webXml, classInfo, roles, appPath);
            }
        } else if (annotation.target().kind() == AnnotationTarget.Kind.METHOD) {
            // Process the containing root resource if it has not been already
            MethodInfo methodInfo = annotation.target().asMethod();
            ClassInfo classInfo = methodInfo.declaringClass();
            if (!scannedClasses.contains(classInfo.name())) {
                String[] roles = {};
                generateSecurityConstraints(webXml, classInfo, roles, appPath);
            }
        }
    }
    // Handle the verification configuration on the fraction
    if (fraction.getTokenIssuer().isPresent()) {
        log.debugf("Issuer: %s", fraction.getTokenIssuer().get());
        war.addAsManifestResource(new StringAsset(fraction.getTokenIssuer().get()), "MP-JWT-ISSUER");
    }
    if (fraction.getPublicKey() != null) {
        log.debugf("PublicKey: %s", fraction.getPublicKey());
        war.addAsManifestResource(new StringAsset(fraction.getPublicKey()), "MP-JWT-SIGNER");
    }
    if (log.isTraceEnabled()) {
        log.trace("war: " + war.toString(true));
    }
}
Also used : JBossWebAsset(org.wildfly.swarm.undertow.descriptors.JBossWebAsset) StringAsset(org.jboss.shrinkwrap.api.asset.StringAsset) WebXmlAsset(org.wildfly.swarm.undertow.descriptors.WebXmlAsset) AnnotationValue(org.jboss.jandex.AnnotationValue) MethodInfo(org.jboss.jandex.MethodInfo) WARArchive(org.wildfly.swarm.undertow.WARArchive) AnnotationInstance(org.jboss.jandex.AnnotationInstance) ClassInfo(org.jboss.jandex.ClassInfo)

Example 3 with WebXmlAsset

use of org.wildfly.swarm.undertow.descriptors.WebXmlAsset in project wildfly-swarm by wildfly-swarm.

the class FlywayMigrationArchivePreparer method process.

@Override
public void process() {
    if (archive.getName().endsWith(".war")) {
        WARArchive webArchive = archive.as(WARArchive.class);
        WebXmlAsset webXml = webArchive.findWebXmlAsset();
        webXml.addListener("org.wildfly.swarm.flyway.deployment.FlywayMigrationServletContextListener");
        FlywayFraction flywayFraction = flywayFractionInstance.get();
        if (flywayFraction.usePrimaryDataSource()) {
            String dataSourceJndi = getDatasourceNameJndi();
            webXml.setContextParam(FlywayMigrationServletContextListener.FLYWAY_JNDI_DATASOURCE, dataSourceJndi);
        } else {
            webXml.setContextParam(FlywayMigrationServletContextListener.FLYWAY_JDBC_URL, flywayFraction.jdbcUrl());
            webXml.setContextParam(FlywayMigrationServletContextListener.FLYWAY_JDBC_USER, flywayFraction.jdbcUser());
            webXml.setContextParam(FlywayMigrationServletContextListener.FLYWAY_JDBC_PASSWORD, flywayFraction.jdbcPassword());
        }
    }
}
Also used : WebXmlAsset(org.wildfly.swarm.undertow.descriptors.WebXmlAsset) FlywayFraction(org.wildfly.swarm.flyway.FlywayFraction) WARArchive(org.wildfly.swarm.undertow.WARArchive)

Example 4 with WebXmlAsset

use of org.wildfly.swarm.undertow.descriptors.WebXmlAsset in project wildfly-swarm by wildfly-swarm.

the class JaegerInstaller method process.

@Override
public void process() throws Exception {
    JaegerFraction fraction = jaegerFractionInstance.get();
    logger.info("Determining whether to install Jaeger integration or not.");
    logger.info("JaegerFraction instance: " + fraction);
    if (archive.getName().endsWith(".war")) {
        logger.logf(Logger.Level.INFO, "Installing the Jaeger 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.jaeger.deployment.JaegerInitializer");
        webXml.addListener("org.wildfly.swarm.jaeger.deployment.JaegerInitializer");
        setContextParamIfNotNull(webXml, JAEGER_SERVICE_NAME, fraction.getServiceName());
        setContextParamIfNotNull(webXml, JAEGER_SERVICE_NAME, fraction.getServiceName());
        setContextParamIfNotNull(webXml, JAEGER_SAMPLER_TYPE, fraction.getSamplerType());
        setContextParamIfNotNull(webXml, JAEGER_SAMPLER_PARAM, fraction.getSamplerParameter());
        setContextParamIfNotNull(webXml, JAEGER_SAMPLER_MANAGER_HOST_PORT, fraction.getSamplerManagerHost());
        setContextParamIfNotNull(webXml, JAEGER_REPORTER_LOG_SPANS, fraction.getReporterLogSpans());
        setContextParamIfNotNull(webXml, JAEGER_AGENT_HOST, fraction.getAgentHost());
        setContextParamIfNotNull(webXml, JAEGER_AGENT_PORT, fraction.getAgentPort());
        setContextParamIfNotNull(webXml, JAEGER_REPORTER_FLUSH_INTERVAL, fraction.getReporterFlushInterval());
        setContextParamIfNotNull(webXml, JAEGER_REPORTER_MAX_QUEUE_SIZE, fraction.getReporterMaxQueueSize());
        webXml.setContextParam("skipOpenTracingResolver", "true");
    }
}
Also used : WebXmlAsset(org.wildfly.swarm.undertow.descriptors.WebXmlAsset) WARArchive(org.wildfly.swarm.undertow.WARArchive) JaegerFraction(org.wildfly.swarm.jaeger.JaegerFraction)

Example 5 with WebXmlAsset

use of org.wildfly.swarm.undertow.descriptors.WebXmlAsset 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)

Aggregations

WebXmlAsset (org.wildfly.swarm.undertow.descriptors.WebXmlAsset)14 Test (org.junit.Test)9 WARArchive (org.wildfly.swarm.undertow.WARArchive)5 JBossWebAsset (org.wildfly.swarm.undertow.descriptors.JBossWebAsset)2 SecurityConstraint (org.wildfly.swarm.undertow.descriptors.SecurityConstraint)2 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Inject (javax.inject.Inject)1 AnnotationInstance (org.jboss.jandex.AnnotationInstance)1 AnnotationValue (org.jboss.jandex.AnnotationValue)1 ClassInfo (org.jboss.jandex.ClassInfo)1 MethodInfo (org.jboss.jandex.MethodInfo)1 Logger (org.jboss.logging.Logger)1 Archive (org.jboss.shrinkwrap.api.Archive)1 StringAsset (org.jboss.shrinkwrap.api.asset.StringAsset)1 AttributeDocumentation (org.wildfly.swarm.config.runtime.AttributeDocumentation)1