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");
}
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");
}
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);
}
}
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();
}
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");
}
Aggregations