Search in sources :

Example 26 with WARArchive

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

the class OpenApiDeploymentProcessor method process.

/**
 * Process the deployment in order to produce an OpenAPI document.
 *
 * @see org.wildfly.swarm.spi.api.DeploymentProcessor#process()
 */
@Override
public void process() throws Exception {
    try {
        // First register OpenApiServletContextListener which triggers the final init
        WARArchive warArchive = archive.as(WARArchive.class);
        warArchive.findWebXmlAsset().addListener(LISTENER_CLASS);
    } catch (Exception e) {
        throw new RuntimeException("Failed to register OpenAPI listener", e);
    }
    // Set models from annotations and static file
    OpenApiDocument openApiDocument = OpenApiDocument.INSTANCE;
    openApiDocument.config(config);
    openApiDocument.modelFromStaticFile(modelFromStaticFile());
    openApiDocument.modelFromAnnotations(modelFromAnnotations());
}
Also used : OpenApiDocument(org.wildfly.swarm.microprofile.openapi.api.OpenApiDocument) WARArchive(org.wildfly.swarm.undertow.WARArchive) IOException(java.io.IOException)

Example 27 with WARArchive

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

the class Main method main.

public static void main(String[] args) throws Exception {
    /*BEGIN:custom main:JAR_WITH_MAIN*/
    swarm = new Swarm();
    WARArchive war = ShrinkWrap.create(WARArchive.class).addPackage(Main.class.getPackage()).addAsWebInfResource(new ClassLoaderAsset("web.xml", Main.class.getClassLoader()), WebXmlAsset.NAME);
    swarm.start().deploy(war);
    /*END:custom main:JAR_WITH_MAIN*/
    /*BEGIN:custom main:WAR_WITH_MAIN*/
    swarm2 = new Swarm().start().deploy();
/*END:custom main:WAR_WITH_MAIN*/
}
Also used : Swarm(org.wildfly.swarm.Swarm) ClassLoaderAsset(org.jboss.shrinkwrap.api.asset.ClassLoaderAsset) WARArchive(org.wildfly.swarm.undertow.WARArchive)

Example 28 with WARArchive

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

the class JAXRSArchiveTest method testDetectJAXRSness_classAnnotation.

@Test
public void testDetectJAXRSness_classAnnotation() {
    WARArchive archive = ShrinkWrap.create(WARArchive.class);
    archive.addClass(MyResource.class);
    assertThat(JAXRSArchive.isJAXRS(archive)).isTrue();
}
Also used : WARArchive(org.wildfly.swarm.undertow.WARArchive) Test(org.junit.Test)

Example 29 with WARArchive

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

the class ManagementConsoleDeploymentProducer method managementConsoleWar.

@Produces
public Archive managementConsoleWar() throws Exception {
    // Load the management-ui webjars.
    WARArchive war = ShrinkWrap.create(WARArchive.class, "management-console-ui.war");
    Module module = Module.getBootModuleLoader().loadModule("org.jboss.as.console");
    Iterator<Resource> resources = module.globResources("*");
    while (resources.hasNext()) {
        Resource each = resources.next();
        war.add(new UrlAsset(each.getURL()), each.getName());
    }
    war.setContextRoot(this.fraction.contextRoot());
    return war;
}
Also used : Resource(org.jboss.modules.Resource) Module(org.jboss.modules.Module) WARArchive(org.wildfly.swarm.undertow.WARArchive) UrlAsset(org.jboss.shrinkwrap.api.asset.UrlAsset) Produces(javax.enterprise.inject.Produces)

Example 30 with WARArchive

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

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