Search in sources :

Example 1 with Server

use of org.wildfly.swarm.config.undertow.Server in project wildfly-swarm by wildfly-swarm.

the class HTTP2CustomizerTest method testHTTP2Enabled.

@Test
public void testHTTP2Enabled() {
    HTTP2Customizer customizer = new HTTP2Customizer();
    customizer.undertow = new UndertowFraction().applyDefaults();
    Server server = customizer.undertow.subresources().server(UndertowProperties.DEFAULT_SERVER);
    AtomicReference<HttpsListener> listener = new AtomicReference<>();
    server.httpsListener("default-https", (config) -> {
        listener.set(config);
    });
    assertThat(listener.get()).isNotNull();
    assertThat(listener.get().enableHttp2()).isNull();
    customizer.customize();
    assertThat(listener.get().enableHttp2()).isTrue();
}
Also used : UndertowFraction(org.wildfly.swarm.undertow.UndertowFraction) Server(org.wildfly.swarm.config.undertow.Server) AtomicReference(java.util.concurrent.atomic.AtomicReference) HttpsListener(org.wildfly.swarm.config.undertow.server.HttpsListener) Test(org.junit.Test)

Example 2 with Server

use of org.wildfly.swarm.config.undertow.Server 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");
                    });
                }
            }
        }
    }
}
Also used : Server(org.wildfly.swarm.config.undertow.Server) ManagementCoreService(org.wildfly.swarm.config.ManagementCoreService)

Example 3 with Server

use of org.wildfly.swarm.config.undertow.Server in project wildfly-swarm by wildfly-swarm.

the class TopologyProxiedServiceCustomizer method customize.

public void customize() {
    Map<String, String> mappings = this.fraction.proxiedServiceMappings();
    if (!mappings.isEmpty()) {
        HandlerConfiguration handlerConfig = undertow.subresources().handlerConfiguration();
        for (String serviceName : mappings.keySet()) {
            ReverseProxy<?> proxy = new ReverseProxy<>(proxyHandlerName(serviceName)).hosts(Collections.emptyList());
            handlerConfig.reverseProxy(proxy);
            String contextPath = mappings.get(serviceName);
            for (Server server : undertow.subresources().servers()) {
                Location location = new Location(contextPath).handler(proxyHandlerName(serviceName));
                for (Host host : server.subresources().hosts()) {
                    host.location(location);
                }
            }
        }
    }
}
Also used : HandlerConfiguration(org.wildfly.swarm.config.undertow.HandlerConfiguration) Server(org.wildfly.swarm.config.undertow.Server) Host(org.wildfly.swarm.config.undertow.server.Host) Location(org.wildfly.swarm.config.undertow.server.host.Location)

Example 4 with Server

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

Example 5 with Server

use of org.wildfly.swarm.config.undertow.Server in project wildfly-swarm by wildfly-swarm.

the class HTTPSCustomizerTest method testWithoutManagementFraction.

@Test
public void testWithoutManagementFraction() {
    HTTPSCustomizer customizer = new HTTPSCustomizer();
    customizer.undertow = new UndertowFraction();
    customizer.undertow.applyDefaults();
    customizer.certInfo = CertInfo.INVALID;
    customizer.managementCoreService = new MockInstance<>(null);
    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()).isEmpty();
}
Also used : UndertowFraction(org.wildfly.swarm.undertow.UndertowFraction) Server(org.wildfly.swarm.config.undertow.Server) Test(org.junit.Test)

Aggregations

Server (org.wildfly.swarm.config.undertow.Server)5 Test (org.junit.Test)3 UndertowFraction (org.wildfly.swarm.undertow.UndertowFraction)3 ManagementCoreService (org.wildfly.swarm.config.ManagementCoreService)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 SecurityRealm (org.wildfly.swarm.config.management.SecurityRealm)1 HandlerConfiguration (org.wildfly.swarm.config.undertow.HandlerConfiguration)1 Host (org.wildfly.swarm.config.undertow.server.Host)1 HttpsListener (org.wildfly.swarm.config.undertow.server.HttpsListener)1 Location (org.wildfly.swarm.config.undertow.server.host.Location)1 CertInfo (org.wildfly.swarm.undertow.descriptors.CertInfo)1