use of org.wildfly.swarm.config.ManagementCoreService in project wildfly-swarm by wildfly-swarm.
the class HTTPSCustomizer method customize.
public void customize() {
if (!this.managementCoreService.isUnsatisfied()) {
if (certInfo.isValid()) {
ManagementCoreService management = this.managementCoreService.get();
if (management == null) {
throw SwarmMessages.MESSAGES.httpsRequiresManagementFraction();
}
if (undertow.isOnlyHTTPS()) {
undertow.removeHttpListenersFromDefaultServer();
}
management.securityRealm("SSLRealm", (realm) -> {
realm.sslServerIdentity((identity) -> {
identity.keystorePath(certInfo.keystorePath()).keystoreRelativeTo(certInfo.keystoreRelativeTo()).keystorePassword(certInfo.keystorePassword()).keyPassword(certInfo.keyPassword()).alias(certInfo.keystoreAlias()).alias(certInfo.keystoreAlias());
handleSelfSignedCertificateHost(identity);
});
});
for (Server server : undertow.subresources().servers()) {
if (server.subresources().httpsListeners().isEmpty()) {
server.httpsListener("default-https", (listener) -> {
listener.securityRealm("SSLRealm");
listener.socketBinding("https");
});
}
}
}
}
}
use of org.wildfly.swarm.config.ManagementCoreService 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