Java Code Examples for org.jboss.shrinkwrap.api.Archive#add()

The following examples show how to use org.jboss.shrinkwrap.api.Archive#add() . 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: EAP6DeploymentArchiveProcessor.java    From keycloak with Apache License 2.0 6 votes vote down vote up
private void modifyWebXML(Archive<?> archive, TestClass testClass) {
    if (!archive.contains(DeploymentArchiveProcessorUtils.WEBXML_PATH)) return;
    if (testClass.getJavaClass().isAnnotationPresent(UseServletFilter.class) &&
            archive.contains(DeploymentArchiveProcessorUtils.JBOSS_DEPLOYMENT_XML_PATH)) {
        log.debug("Modifying WEB.XML in " + archive.getName() + " for Servlet Filter.");
        DeploymentArchiveProcessorUtils.modifyWebXMLForServletFilter(archive, testClass);
        DeploymentArchiveProcessorUtils.addFilterDependencies(archive, testClass);
    }

    try {
        Document webXmlDoc = IOUtil.loadXML(archive.get(DeploymentArchiveProcessorUtils.WEBXML_PATH).getAsset().openStream());

        IOUtil.modifyDocElementValue(webXmlDoc, "param-value", ".*infinispan\\.InfinispanSessionCacheIdMapperUpdater", 
            "org.keycloak.adapters.saml.jbossweb.infinispan.InfinispanSessionCacheIdMapperUpdater");

        archive.add(new StringAsset((IOUtil.documentToString(webXmlDoc))), WEBXML_PATH);
    } catch (IllegalArgumentException ex) {
        throw new RuntimeException("Error when processing " + archive.getName(), ex);
    }
}
 
Example 2
Source File: Tomcat7DeploymentArchiveProcessor.java    From keycloak with Apache License 2.0 6 votes vote down vote up
@Override
public void process(Archive<?> archive, TestClass testClass) {
    super.process(archive, testClass);
    if (DeploymentArchiveProcessorUtils.checkRunOnServerDeployment(archive)) return;

    Set<Class<?>> configClasses = TomcatDeploymentArchiveProcessorUtils.getApplicationConfigClasses(archive);

    if (!configClasses.isEmpty()) {
        // Tomcat 7 doesn't work with resteasy-servlet-initializer therefore we need to configure Tomcat the old way
        // jax-rs docs: http://docs.jboss.org/resteasy/docs/3.6.1.Final/userguide/html_single/#d4e161
        Document webXmlDoc;
        try {
            webXmlDoc = IOUtil.loadXML(
                    archive.get(WEBXML_PATH).getAsset().openStream());
        } catch (Exception ex) {
            throw new RuntimeException("Error when processing " + archive.getName(), ex);
        }

        addContextParam(webXmlDoc);
        addServlet(webXmlDoc, configClasses.iterator().next().getName());
        addServletMapping(webXmlDoc);

        archive.add(new StringAsset((documentToString(webXmlDoc))), DeploymentArchiveProcessorUtils.WEBXML_PATH);
    }
}
 
Example 3
Source File: DeploymentArchiveProcessor.java    From keycloak with Apache License 2.0 6 votes vote down vote up
public void addFilterDependencies(Archive<?> archive, TestClass testClass) {
    TestContext testContext = testContextProducer.get();
    if (testContext.getAppServerInfo().isUndertow()) {
        return;
    }

    Node jbossDeploymentStructureXml = archive.get(JBOSS_DEPLOYMENT_XML_PATH);
    if (jbossDeploymentStructureXml == null) {
        log.debug("Archive doesn't contain " + JBOSS_DEPLOYMENT_XML_PATH);
        return;
    }

    log.info("Adding filter dependencies to " + archive.getName());
    
    String dependency = testClass.getAnnotation(UseServletFilter.class).filterDependency();
    ((WebArchive) archive).addAsLibraries(KeycloakDependenciesResolver.resolveDependencies((dependency + ":" + System.getProperty("project.version"))));

    Document jbossXmlDoc = loadXML(jbossDeploymentStructureXml.getAsset().openStream());
    removeNodeByAttributeValue(jbossXmlDoc, "dependencies", "module", "name", "org.keycloak.keycloak-saml-core");
    removeNodeByAttributeValue(jbossXmlDoc, "dependencies", "module", "name", "org.keycloak.keycloak-adapter-spi");
    archive.add(new StringAsset((documentToString(jbossXmlDoc))), JBOSS_DEPLOYMENT_XML_PATH);

}
 
Example 4
Source File: FaultToleranceApplicationArchiveProcessor.java    From smallrye-fault-tolerance with Apache License 2.0 5 votes vote down vote up
@Override
public void process(Archive<?> applicationArchive, TestClass testClass) {
    if (!(applicationArchive instanceof ClassContainer)) {
        LOGGER.warning(
                "Unable to add additional classes - not a class/resource container: "
                        + applicationArchive);
        return;
    }
    ClassContainer<?> classContainer = (ClassContainer<?>) applicationArchive;

    if (applicationArchive instanceof LibraryContainer) {
        JavaArchive additionalBeanArchive = ShrinkWrap.create(JavaArchive.class);
        additionalBeanArchive.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
        ((LibraryContainer<?>) applicationArchive).addAsLibrary(additionalBeanArchive);
    } else {
        classContainer.addAsResource(EmptyAsset.INSTANCE, "META-INF/beans.xml");
    }

    if (!applicationArchive.contains("META-INF/beans.xml")) {
        applicationArchive.add(EmptyAsset.INSTANCE, "META-INF/beans.xml");
    }

    String config;
    if (!applicationArchive.contains(MP_CONFIG_PATH)) {
        config = MAX_THREADS_OVERRIDE;
    } else {
        ByteArrayOutputStream output = readCurrentConfig(applicationArchive);
        applicationArchive.delete(MP_CONFIG_PATH);
        config = output.toString() + "\n" + MAX_THREADS_OVERRIDE;
    }
    classContainer.addAsResource(new StringAsset(config), MP_CONFIG_PATH);

    LOGGER.info("Added additional resources to " + applicationArchive.toString(true));
}
 
Example 5
Source File: TomcatDeploymentArchiveProcessorUtils.java    From keycloak with Apache License 2.0 5 votes vote down vote up
public static void replaceOIDCValveWithSAMLValve(Archive<?> archive) {
    try {
        String contextXmlContent = IOUtils.toString(archive.get(CONTEXT_PATH).getAsset().openStream(), "UTF-8")
                .replace(OIDC_VALVE_CLASS, SAML_VALVE_CLASS);
        archive.add(new StringAsset(contextXmlContent), CONTEXT_PATH);
    } catch (IOException ex) {
        throw new RuntimeException(ex);
    }
}
 
Example 6
Source File: TomcatDeploymentArchiveProcessorUtils.java    From keycloak with Apache License 2.0 5 votes vote down vote up
public static void removeServletConfigurationInWebXML(Archive<?> archive) {
    if (!archive.contains(DeploymentArchiveProcessorUtils.WEBXML_PATH)) return;

    try {
        Document webXmlDoc = loadXML(archive.get(DeploymentArchiveProcessorUtils.WEBXML_PATH).getAsset().openStream());

        LOG.debug("Removing web.xml servlet configuration for " + archive.getName());
        removeElementFromDoc(webXmlDoc, "web-app/servlet");
        removeElementFromDoc(webXmlDoc, "web-app/servlet-mapping");

        archive.add(new StringAsset((documentToString(webXmlDoc))), DeploymentArchiveProcessorUtils.WEBXML_PATH);
    } catch (IllegalArgumentException ex) {
        throw new RuntimeException("Error when processing " + archive.getName(), ex);
    }
}
 
Example 7
Source File: TomcatDeploymentArchiveProcessorUtils.java    From keycloak with Apache License 2.0 5 votes vote down vote up
public static void replaceKEYCLOAKMethodWithBASIC(Archive<?> archive) {
    if (!archive.contains(DeploymentArchiveProcessorUtils.WEBXML_PATH)) return;

    try {
        Document webXmlDoc = loadXML(archive.get(DeploymentArchiveProcessorUtils.WEBXML_PATH).getAsset().openStream());

        LOG.debug("Setting BASIC as auth-method in WEB.XML for " + archive.getName());
        modifyDocElementValue(webXmlDoc, "auth-method", "KEYCLOAK-SAML", "BASIC");
        modifyDocElementValue(webXmlDoc, "auth-method", "KEYCLOAK", "BASIC");

        archive.add(new StringAsset((documentToString(webXmlDoc))), DeploymentArchiveProcessorUtils.WEBXML_PATH);
    } catch (IllegalArgumentException ex) {
        throw new RuntimeException("Error when processing " + archive.getName(), ex);
    }
}
 
Example 8
Source File: DeploymentArchiveProcessorUtils.java    From keycloak with Apache License 2.0 5 votes vote down vote up
public static void modifySAMLAdapterConfig(Archive<?> archive, String adapterConfigPath) {
    Document doc = IOUtil.loadXML(archive.get(adapterConfigPath).getAsset().openStream());

    if (AUTH_SERVER_SSL_REQUIRED) {
        IOUtil.modifyDocElementAttribute(doc, "SingleSignOnService", "bindingUrl", "8080", System.getProperty("auth.server.https.port"));
        IOUtil.modifyDocElementAttribute(doc, "SingleSignOnService", "bindingUrl", "http", "https");
        IOUtil.modifyDocElementAttribute(doc, "SingleLogoutService", "postBindingUrl", "8080", System.getProperty("auth.server.https.port"));
        IOUtil.modifyDocElementAttribute(doc, "SingleLogoutService", "postBindingUrl", "http", "https");
        IOUtil.modifyDocElementAttribute(doc, "SingleLogoutService", "redirectBindingUrl", "8080", System.getProperty("auth.server.https.port"));
        IOUtil.modifyDocElementAttribute(doc, "SingleLogoutService", "redirectBindingUrl", "http", "https");
    } else {
        IOUtil.modifyDocElementAttribute(doc, "SingleSignOnService", "bindingUrl", "8080", System.getProperty("auth.server.http.port"));
        IOUtil.modifyDocElementAttribute(doc, "SingleLogoutService", "postBindingUrl", "8080", System.getProperty("auth.server.http.port"));
        IOUtil.modifyDocElementAttribute(doc, "SingleLogoutService", "redirectBindingUrl", "8080", System.getProperty("auth.server.http.port"));
    }

    if (APP_SERVER_SSL_REQUIRED) {
        IOUtil.modifyDocElementAttribute(doc, "SP", "logoutPage", "8080", System.getProperty("app.server.https.port"));
        IOUtil.modifyDocElementAttribute(doc, "SP", "logoutPage", "http", "https");
        IOUtil.modifyDocElementAttribute(doc, "SingleSignOnService", "assertionConsumerServiceUrl", "8080", System.getProperty("app.server.https.port"));
        IOUtil.modifyDocElementAttribute(doc, "SingleSignOnService", "assertionConsumerServiceUrl", "http", "https");
    } else {
        IOUtil.modifyDocElementAttribute(doc, "SP", "logoutPage", "8080", System.getProperty("app.server.http.port"));
        IOUtil.modifyDocElementAttribute(doc, "SingleSignOnService", "assertionConsumerServiceUrl", "8080", System.getProperty("app.server.http.port"));
    }

    archive.add(new StringAsset(IOUtil.documentToString(doc)), adapterConfigPath);

    ((WebArchive) archive).addAsResource(new File(DeploymentArchiveProcessorUtils.class.getResource("/keystore/keycloak.truststore").getFile()));
}
 
Example 9
Source File: DeploymentArchiveProcessorUtils.java    From keycloak with Apache License 2.0 5 votes vote down vote up
public static void modifyOIDCAdapterConfig(Archive<?> archive, String adapterConfigPath) {
    try {
        AdapterConfig adapterConfig = IOUtil.loadJson(archive.get(adapterConfigPath)
                .getAsset().openStream(), AdapterConfig.class);

        adapterConfig.setAuthServerUrl(getAuthServerUrl());

        if (APP_SERVER_SSL_REQUIRED) {
            adapterConfig.setSslRequired("all");
        }

        if (AUTH_SERVER_SSL_REQUIRED) {
            String trustStorePathInDeployment = "keycloak.truststore";
            if (adapterConfigPath.contains("WEB-INF")) {
                // This is a Java adapter, we can use classpath
                trustStorePathInDeployment = "classpath:keycloak.truststore";
            }
            adapterConfig.setTruststore(trustStorePathInDeployment);
            adapterConfig.setTruststorePassword(TRUSTSTORE_PASSWORD);
            File truststorePath = new File(DeploymentArchiveProcessorUtils.class.getResource("/keystore/keycloak.truststore").getFile());
            ((WebArchive) archive).addAsResource(truststorePath);
            log.debugf("Adding Truststore to the deployment, path %s, password %s, adapter path %s", truststorePath.getAbsolutePath(), TRUSTSTORE_PASSWORD, trustStorePathInDeployment);
        }

        archive.add(new StringAsset(JsonSerialization.writeValueAsPrettyString(adapterConfig)),
                        adapterConfigPath);
    } catch (IOException ex) {
        log.error("Cannot serialize adapter config to JSON.", ex);
    }
}
 
Example 10
Source File: DeploymentArchiveProcessorUtils.java    From keycloak with Apache License 2.0 5 votes vote down vote up
public static void addFilterDependencies(Archive<?> archive, TestClass testClass) {
    log.info("Adding filter dependencies to " + archive.getName());
    
    String dependency = testClass.getAnnotation(UseServletFilter.class).filterDependency();
    ((WebArchive) archive).addAsLibraries(KeycloakDependenciesResolver.resolveDependencies((dependency + ":" + System.getProperty("project.version"))));

    Document jbossXmlDoc = IOUtil.loadXML(archive.get(JBOSS_DEPLOYMENT_XML_PATH).getAsset().openStream());
    IOUtil.removeNodeByAttributeValue(jbossXmlDoc, "dependencies", "module", "name", "org.keycloak.keycloak-saml-core");
    IOUtil.removeNodeByAttributeValue(jbossXmlDoc, "dependencies", "module", "name", "org.keycloak.keycloak-adapter-spi");

    archive.add(new StringAsset((IOUtil.documentToString(jbossXmlDoc))), JBOSS_DEPLOYMENT_XML_PATH);
}
 
Example 11
Source File: AdapterServletDeployment.java    From keycloak with Apache License 2.0 5 votes vote down vote up
public static void addContextXml(Archive archive, String contextPath) {
    // hardcoded for now
    try {
        String contextXmlContent = IOUtils.toString(tomcatContext.openStream())
                .replace("%CONTEXT_PATH%", contextPath);
        archive.add(new StringAsset(contextXmlContent), "/META-INF/context.xml");
    } catch (IOException ex) {
        throw new RuntimeException(ex);
    }
}
 
Example 12
Source File: AbstractAdapterTest.java    From keycloak with Apache License 2.0 5 votes vote down vote up
public static void addContextXml(Archive archive, String contextPath) {
    try {
        String contextXmlContent = IOUtils.toString(tomcatContext.openStream(), "UTF-8")
                .replace("%CONTEXT_PATH%", contextPath);
        archive.add(new StringAsset(contextXmlContent), "/META-INF/context.xml");
    } catch (IOException ex) {
        throw new RuntimeException(ex);
    }
}
 
Example 13
Source File: TomEEContainer.java    From tomee with Apache License 2.0 5 votes vote down vote up
protected Assignable archiveWithTestInfo(final Archive<?> archive) {
    String name = archive.getName();
    if (name.endsWith(".war") || name.endsWith(".ear")) {
        name = name.substring(0, name.length() - ".war".length());
    }
    return archive.add(
            new StringAsset(testClass.get().getJavaClass().getName() + '#' + name),
            ArchivePaths.create("arquillian-tomee-info.txt"));
}
 
Example 14
Source File: MockArtifactResolver.java    From thorntail with Apache License 2.0 5 votes vote down vote up
public void add(ArtifactSpec spec, Consumer<Entry> config) {
    Archive archive = ShrinkWrap.create(JavaArchive.class);
    archive.add(EmptyAsset.INSTANCE, "nothing");

    Entry entry = new Entry(spec);
    config.accept(entry);

    this.entries.put(spec, entry);
    this.artifacts.put(spec, archive);
}
 
Example 15
Source File: MockArtifactResolver.java    From thorntail with Apache License 2.0 5 votes vote down vote up
public void add(ArtifactSpec spec) {
    Archive archive = ShrinkWrap.create(JavaArchive.class);
    archive.add(EmptyAsset.INSTANCE, "nothing");

    Entry entry = new Entry(spec);

    this.entries.put(spec, entry);
    this.artifacts.put(spec, archive);
}
 
Example 16
Source File: TestDeploymentPackager.java    From camel-spring-boot with Apache License 2.0 5 votes vote down vote up
@Override
public Archive<?> generateDeployment(TestDeployment testDeployment, Collection<ProtocolArchiveProcessor> collection) {
    Archive<?> applicationArchive = testDeployment.getApplicationArchive();
    boolean isClassPath = ClassPath.isRepresentedBy(applicationArchive);
    for (Archive<?> auxiliaryArchive : testDeployment.getAuxiliaryArchives()) {
        if (isClassPath) {
            applicationArchive.add(auxiliaryArchive, ClassPath.ROOT_ARCHIVE_PATH, ZipExporter.class);
        } else {
            applicationArchive.merge(auxiliaryArchive);
        }
    }
    return applicationArchive;
}
 
Example 17
Source File: DeploymentArchiveProcessor.java    From keycloak with Apache License 2.0 4 votes vote down vote up
protected void modifyAdapterConfig(Archive<?> archive, String adapterConfigPath, boolean relative) {
    if (archive.contains(adapterConfigPath)) {
        log.info("Modifying adapter config " + adapterConfigPath + " in " + archive.getName());
        if (adapterConfigPath.endsWith(".xml")) { // SAML adapter config
            log.info("Modifying saml adapter config in " + archive.getName());

            Document doc = loadXML(archive.get(adapterConfigPath).getAsset().openStream());
            if (AUTH_SERVER_SSL_REQUIRED) {
                modifyDocElementAttribute(doc, "SingleSignOnService", "bindingUrl", "8080", System.getProperty("auth.server.https.port"));
                modifyDocElementAttribute(doc, "SingleSignOnService", "bindingUrl", "http", "https");
                modifyDocElementAttribute(doc, "SingleSignOnService", "assertionConsumerServiceUrl", "8080", System.getProperty("app.server.https.port"));
                modifyDocElementAttribute(doc, "SingleSignOnService", "assertionConsumerServiceUrl", "http", "https");
                modifyDocElementAttribute(doc, "SingleLogoutService", "postBindingUrl", "8080", System.getProperty("auth.server.https.port"));
                modifyDocElementAttribute(doc, "SingleLogoutService", "postBindingUrl", "http", "https");
                modifyDocElementAttribute(doc, "SingleLogoutService", "redirectBindingUrl", "8080", System.getProperty("auth.server.https.port"));
                modifyDocElementAttribute(doc, "SingleLogoutService", "redirectBindingUrl", "http", "https");
                modifyDocElementAttribute(doc, "SP", "logoutPage", "8080", System.getProperty("app.server.https.port"));
                modifyDocElementAttribute(doc, "SP", "logoutPage", "http", "https");
            } else {
                modifyDocElementAttribute(doc, "SingleSignOnService", "bindingUrl", "8080", System.getProperty("auth.server.http.port"));
                modifyDocElementAttribute(doc, "SingleSignOnService", "assertionConsumerServiceUrl", "8080", System.getProperty("app.server.http.port"));
                modifyDocElementAttribute(doc, "SingleLogoutService", "postBindingUrl", "8080", System.getProperty("auth.server.http.port"));
                modifyDocElementAttribute(doc, "SingleLogoutService", "redirectBindingUrl", "8080", System.getProperty("auth.server.http.port"));
                modifyDocElementAttribute(doc, "SP", "logoutPage", "8080", System.getProperty("app.server.http.port"));
            }

            archive.add(new StringAsset(IOUtil.documentToString(doc)), adapterConfigPath);

            ((WebArchive) archive).addAsResource(new File(DeploymentArchiveProcessor.class.getResource("/keystore/keycloak.truststore").getFile()));

            // For running SAML tests it is necessary to have few dependencies on app-server side.
            // Few of them are not in adapter zip so we need to add them manually here
        } else { // OIDC adapter config
            try {
                AdapterConfig adapterConfig = loadJson(archive.get(adapterConfigPath)
                        .getAsset().openStream(), AdapterConfig.class);

                adapterConfig.setAuthServerUrl(getAuthServerContextRoot() + "/auth");

                if (APP_SERVER_SSL_REQUIRED) {
                    adapterConfig.setSslRequired("all");
                }

                archive.add(new StringAsset(JsonSerialization.writeValueAsPrettyString(adapterConfig)),
                        adapterConfigPath);

            } catch (IOException ex) {
                log.error("Cannot serialize adapter config to JSON.", ex);
            }
        }
    }
}
 
Example 18
Source File: Mvn.java    From tomee with Apache License 2.0 4 votes vote down vote up
public void update(final Archive<?> archive) {
    for (final Map.Entry<ArchivePath, Asset> r : paths.entrySet()) {
        archive.add(r.getValue(), prefix + r.getKey().get());
    }
}
 
Example 19
Source File: ModulesHelper.java    From hibernate-ogm-ignite with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static void addModulesDependencyDeclaration(Archive<?> archive, String dependencies) {
	archive.add( manifest( injectVariables( dependencies ) ), "META-INF/MANIFEST.MF" );
}
 
Example 20
Source File: DependencyManager.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 3 votes vote down vote up
public void addArtifactToArchiveMavenRepository(Archive archive, ArtifactSpec artifact) throws Exception {

        if (artifact.gathered) {
            return;
        }
        artifact = resolveArtifact(artifact);

        StringBuilder artifactPath = new StringBuilder("m2repo/");
        artifactPath.append(artifact.repoPath(true));

        archive.add(new FileAsset(artifact.file), artifactPath.toString());

        artifact.gathered = true;

    }