Search in sources :

Example 1 with CertInfo

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

the class CertInfoProducerTest method testGenerateWithDefaults.

@Test
@Category(CommunityOnly.class)
public void testGenerateWithDefaults() {
    CertInfoProducer producer = new CertInfoProducer();
    producer.undertow = new UndertowFraction();
    producer.generateSelfCertificate.set(true);
    CertInfo certInfo = producer.produceCertInfo();
    assertThat(certInfo).isNotNull();
    assertThat(certInfo.generateSelfSignedCertificateHost()).isEqualTo("localhost");
}
Also used : CertInfo(org.wildfly.swarm.undertow.descriptors.CertInfo) UndertowFraction(org.wildfly.swarm.undertow.UndertowFraction) Category(org.junit.experimental.categories.Category) Test(org.junit.Test)

Example 2 with CertInfo

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

the class CertInfoProducerTest method testGenerateWithExplicitHost.

@Test
@Category(CommunityOnly.class)
public void testGenerateWithExplicitHost() {
    CertInfoProducer producer = new CertInfoProducer();
    producer.undertow = new UndertowFraction();
    producer.generateSelfCertificate.set(true);
    producer.selfCertificateHost.set("www.mycorp.com");
    CertInfo certInfo = producer.produceCertInfo();
    assertThat(certInfo).isNotNull();
    assertThat(certInfo.generateSelfSignedCertificateHost()).isEqualTo("www.mycorp.com");
}
Also used : CertInfo(org.wildfly.swarm.undertow.descriptors.CertInfo) UndertowFraction(org.wildfly.swarm.undertow.UndertowFraction) Category(org.junit.experimental.categories.Category) Test(org.junit.Test)

Example 3 with CertInfo

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

the class CertInfoProducer method produceCertInfo.

@Produces
@Singleton
public CertInfo produceCertInfo() {
    if (generateSelfCertificate.get()) {
        if (SwarmInfo.isProduct()) {
            throw SwarmMessages.MESSAGES.generateSelfSignedCertificateNotSupported();
        }
        checkDataDir();
        return new CertInfo(selfCertificateHost.get(), JBOSS_DATA_DIR);
    } else {
        String keystorePath = undertow.keystorePath();
        if (embeddedKeystore.get()) {
            checkDataDir();
            Path dataDir = Paths.get(System.getProperty(JBOSS_DATA_DIR));
            Path certDestination = dataDir.resolve(keystorePath);
            try {
                URL jks = ClassLoader.getSystemClassLoader().getResource(keystorePath);
                if (jks == null) {
                    Module appModule = Module.getCallerModuleLoader().loadModule("swarm.application");
                    jks = appModule.getClassLoader().getResource(keystorePath);
                }
                if (jks == null) {
                    throw new RuntimeException(String.format("Unable to locate embedded keystore %s in classpath", keystorePath));
                }
                Files.copy(jks.openStream(), certDestination);
                keystorePath = certDestination.toString();
            } catch (Exception ie) {
                throw new RuntimeException("Error copying embedded certificate", ie);
            }
        }
        String keystorePassword = undertow.keystorePassword();
        String keyPassword = undertow.keyPassword();
        String keystoreAlias = undertow.alias();
        return new CertInfo(keystorePath, keystorePassword, keyPassword, keystoreAlias);
    }
}
Also used : CertInfo(org.wildfly.swarm.undertow.descriptors.CertInfo) Path(java.nio.file.Path) Module(org.jboss.modules.Module) URL(java.net.URL) IOException(java.io.IOException) Produces(javax.enterprise.inject.Produces) Singleton(javax.inject.Singleton)

Example 4 with CertInfo

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

the class CertInfoProducerTest method testDefaults.

@Test
public void testDefaults() {
    CertInfoProducer producer = new CertInfoProducer();
    producer.undertow = new UndertowFraction();
    CertInfo certInfo = producer.produceCertInfo();
    assertThat(certInfo).isNotNull();
    assertThat(certInfo.generateSelfSignedCertificateHost()).isNull();
}
Also used : CertInfo(org.wildfly.swarm.undertow.descriptors.CertInfo) UndertowFraction(org.wildfly.swarm.undertow.UndertowFraction) Test(org.junit.Test)

Example 5 with CertInfo

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

the class HTTPSCustomizerTest method testWithManagementFraction.

@Test
public void testWithManagementFraction() throws Exception {
    HTTPSCustomizer customizer = new HTTPSCustomizer();
    customizer.undertow = new UndertowFraction();
    customizer.undertow.applyDefaults();
    customizer.certInfo = new CertInfo("myhost.com", "./my/path");
    customizer.managementCoreService = new MockInstance<>(new ManagementCoreService());
    customizer.customize();
    Server server = customizer.undertow.subresources().server("default-server");
    assertThat(server).isNotNull();
    assertThat(server.subresources().httpListeners()).hasSize(1);
    assertThat(server.subresources().httpListener("default")).isNotNull();
    assertThat(server.subresources().httpsListeners()).hasSize(1);
    assertThat(server.subresources().httpsListener("default-https")).isNotNull();
    SecurityRealm realm = customizer.managementCoreService.get().subresources().securityRealm("SSLRealm");
    assertThat(realm).isNotNull();
    assertThat(realm.subresources().sslServerIdentity().keystoreRelativeTo()).isEqualTo("./my/path");
    assertSelfSignedCertificate(realm.subresources().sslServerIdentity(), "myhost.com");
}
Also used : CertInfo(org.wildfly.swarm.undertow.descriptors.CertInfo) UndertowFraction(org.wildfly.swarm.undertow.UndertowFraction) Server(org.wildfly.swarm.config.undertow.Server) SecurityRealm(org.wildfly.swarm.config.management.SecurityRealm) ManagementCoreService(org.wildfly.swarm.config.ManagementCoreService) Test(org.junit.Test)

Aggregations

CertInfo (org.wildfly.swarm.undertow.descriptors.CertInfo)5 Test (org.junit.Test)4 UndertowFraction (org.wildfly.swarm.undertow.UndertowFraction)4 Category (org.junit.experimental.categories.Category)2 IOException (java.io.IOException)1 URL (java.net.URL)1 Path (java.nio.file.Path)1 Produces (javax.enterprise.inject.Produces)1 Singleton (javax.inject.Singleton)1 Module (org.jboss.modules.Module)1 ManagementCoreService (org.wildfly.swarm.config.ManagementCoreService)1 SecurityRealm (org.wildfly.swarm.config.management.SecurityRealm)1 Server (org.wildfly.swarm.config.undertow.Server)1