Search in sources :

Example 1 with XnioSsl

use of org.xnio.ssl.XnioSsl in project wildfly by wildfly.

the class ModClusterService method start.

@Override
public synchronized void start(StartContext context) throws StartException {
    super.start(context);
    SSLContext sslContext = this.sslContext.getOptionalValue();
    if (sslContext == null) {
        SecurityRealm realm = securityRealm.getOptionalValue();
        if (realm != null) {
            sslContext = realm.getSSLContext();
        }
    }
    //TODO: SSL support for the client
    //TODO: wire up idle timeout when new version of undertow arrives
    final ModCluster.Builder modClusterBuilder;
    final XnioWorker worker = workerInjectedValue.getValue();
    if (sslContext == null) {
        modClusterBuilder = ModCluster.builder(worker);
    } else {
        OptionMap.Builder builder = OptionMap.builder();
        builder.set(Options.USE_DIRECT_BUFFERS, true);
        OptionMap combined = builder.getMap();
        XnioSsl xnioSsl = new UndertowXnioSsl(worker.getXnio(), combined, sslContext);
        modClusterBuilder = ModCluster.builder(worker, UndertowClient.getInstance(), xnioSsl);
    }
    modClusterBuilder.setMaxRetries(maxRetries).setClientOptions(clientOptions).setHealthCheckInterval(healthCheckInterval).setMaxRequestTime(maxRequestTime).setCacheConnections(cachedConnections).setQueueNewRequests(requestQueueSize > 0).setRequestQueueSize(requestQueueSize).setRemoveBrokenNodes(removeBrokenNodes).setTtl(connectionIdleTimeout).setMaxConnections(connectionsPerThread).setUseAlias(useAlias);
    if (FailoverStrategy.DETERMINISTIC.equals(failoverStrategy)) {
        modClusterBuilder.setDeterministicFailover(true);
    }
    modCluster = modClusterBuilder.build();
    MCMPConfig.Builder builder = MCMPConfig.builder();
    final SocketBinding advertiseBinding = advertiseSocketBinding.getOptionalValue();
    if (advertiseBinding != null) {
        InetAddress multicastAddress = advertiseBinding.getMulticastAddress();
        if (multicastAddress == null) {
            throw UndertowLogger.ROOT_LOGGER.advertiseSocketBindingRequiresMulticastAddress();
        }
        if (advertiseFrequency > 0) {
            builder.enableAdvertise().setAdvertiseAddress(advertiseBinding.getSocketAddress().getAddress().getHostAddress()).setAdvertiseGroup(multicastAddress.getHostAddress()).setAdvertisePort(advertiseBinding.getMulticastPort()).setAdvertiseFrequency(advertiseFrequency).setPath(advertisePath).setProtocol(advertiseProtocol).setSecurityKey(securityKey);
        }
    }
    builder.setManagementHost(managementSocketBinding.getValue().getSocketAddress().getHostString());
    builder.setManagementPort(managementSocketBinding.getValue().getSocketAddress().getPort());
    config = builder.build();
    if (advertiseBinding != null && advertiseFrequency > 0) {
        try {
            modCluster.advertise(config);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
    modCluster.start();
}
Also used : SocketBinding(org.jboss.as.network.SocketBinding) XnioSsl(org.xnio.ssl.XnioSsl) UndertowXnioSsl(io.undertow.protocols.ssl.UndertowXnioSsl) XnioWorker(org.xnio.XnioWorker) SecurityRealm(org.jboss.as.domain.management.SecurityRealm) MCMPConfig(io.undertow.server.handlers.proxy.mod_cluster.MCMPConfig) SSLContext(javax.net.ssl.SSLContext) IOException(java.io.IOException) ModCluster(io.undertow.server.handlers.proxy.mod_cluster.ModCluster) OptionMap(org.xnio.OptionMap) UndertowXnioSsl(io.undertow.protocols.ssl.UndertowXnioSsl) InetAddress(java.net.InetAddress)

Example 2 with XnioSsl

use of org.xnio.ssl.XnioSsl in project undertow by undertow-io.

the class HttpClientTestCase method testSsl.

@Test
public void testSsl() throws Exception {
    //
    DefaultServer.setRootHandler(SIMPLE_MESSAGE_HANDLER);
    final UndertowClient client = createClient();
    final List<ClientResponse> responses = new CopyOnWriteArrayList<>();
    final CountDownLatch latch = new CountDownLatch(10);
    DefaultServer.startSSLServer();
    SSLContext context = DefaultServer.getClientSSLContext();
    XnioSsl ssl = new UndertowXnioSsl(DefaultServer.getWorker().getXnio(), OptionMap.EMPTY, DefaultServer.SSL_BUFFER_POOL, context);
    final ClientConnection connection = client.connect(new URI(DefaultServer.getDefaultServerSSLAddress()), worker, ssl, DefaultServer.getBufferPool(), OptionMap.EMPTY).get();
    try {
        connection.getIoThread().execute(new Runnable() {

            @Override
            public void run() {
                for (int i = 0; i < 10; i++) {
                    final ClientRequest request = new ClientRequest().setMethod(Methods.GET).setPath("/");
                    request.getRequestHeaders().put(Headers.HOST, DefaultServer.getHostAddress());
                    connection.sendRequest(request, createClientCallback(responses, latch));
                }
            }
        });
        latch.await(10, TimeUnit.SECONDS);
        Assert.assertEquals(10, responses.size());
        for (final ClientResponse response : responses) {
            Assert.assertEquals(message, response.getAttachment(RESPONSE_BODY));
        }
    } finally {
        connection.getIoThread().execute(new Runnable() {

            @Override
            public void run() {
                IoUtils.safeClose(connection);
            }
        });
        DefaultServer.stopSSLServer();
    }
}
Also used : ClientResponse(io.undertow.client.ClientResponse) XnioSsl(org.xnio.ssl.XnioSsl) UndertowXnioSsl(io.undertow.protocols.ssl.UndertowXnioSsl) UndertowClient(io.undertow.client.UndertowClient) SSLContext(javax.net.ssl.SSLContext) CountDownLatch(java.util.concurrent.CountDownLatch) URI(java.net.URI) ClientConnection(io.undertow.client.ClientConnection) UndertowXnioSsl(io.undertow.protocols.ssl.UndertowXnioSsl) ClientRequest(io.undertow.client.ClientRequest) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Test(org.junit.Test)

Example 3 with XnioSsl

use of org.xnio.ssl.XnioSsl in project undertow by undertow-io.

the class DefaultWebSocketClientSslProvider method getSsl.

@Override
public XnioSsl getSsl(XnioWorker worker, Endpoint endpoint, ClientEndpointConfig cec, URI uri) {
    XnioSsl ssl = getThreadLocalSsl(worker);
    if (ssl != null) {
        return ssl;
    }
    //look for some SSL config
    SSLContext sslContext = (SSLContext) cec.getUserProperties().get(SSL_CONTEXT);
    if (sslContext != null) {
        return new UndertowXnioSsl(worker.getXnio(), OptionMap.EMPTY, sslContext);
    }
    return null;
}
Also used : XnioSsl(org.xnio.ssl.XnioSsl) UndertowXnioSsl(io.undertow.protocols.ssl.UndertowXnioSsl) SSLContext(javax.net.ssl.SSLContext) UndertowXnioSsl(io.undertow.protocols.ssl.UndertowXnioSsl)

Example 4 with XnioSsl

use of org.xnio.ssl.XnioSsl in project undertow by undertow-io.

the class ServerWebSocketContainer method connectToServer.

@Override
public Session connectToServer(final Object annotatedEndpointInstance, final URI path) throws DeploymentException, IOException {
    if (closed) {
        throw new ClosedChannelException();
    }
    ConfiguredClientEndpoint config = getClientEndpoint(annotatedEndpointInstance.getClass(), false);
    if (config == null) {
        throw JsrWebSocketMessages.MESSAGES.notAValidClientEndpointType(annotatedEndpointInstance.getClass());
    }
    Endpoint instance = config.getFactory().createInstance(new ImmediateInstanceHandle<>(annotatedEndpointInstance));
    XnioSsl ssl = null;
    for (WebsocketClientSslProvider provider : clientSslProviders) {
        ssl = provider.getSsl(xnioWorker, annotatedEndpointInstance, path);
        if (ssl != null) {
            break;
        }
    }
    return connectToServerInternal(instance, ssl, config, path);
}
Also used : ClosedChannelException(java.nio.channels.ClosedChannelException) Endpoint(javax.websocket.Endpoint) ServerEndpoint(javax.websocket.server.ServerEndpoint) ClientEndpoint(javax.websocket.ClientEndpoint) XnioSsl(org.xnio.ssl.XnioSsl)

Example 5 with XnioSsl

use of org.xnio.ssl.XnioSsl in project undertow by undertow-io.

the class ServerWebSocketContainer method connectToServer.

@Override
public Session connectToServer(Class<?> aClass, URI uri) throws DeploymentException, IOException {
    if (closed) {
        throw new ClosedChannelException();
    }
    ConfiguredClientEndpoint config = getClientEndpoint(aClass, true);
    if (config == null) {
        throw JsrWebSocketMessages.MESSAGES.notAValidClientEndpointType(aClass);
    }
    try {
        AnnotatedEndpointFactory factory = config.getFactory();
        InstanceHandle<?> instance = config.getInstanceFactory().createInstance();
        XnioSsl ssl = null;
        for (WebsocketClientSslProvider provider : clientSslProviders) {
            ssl = provider.getSsl(xnioWorker, aClass, uri);
            if (ssl != null) {
                break;
            }
        }
        return connectToServerInternal(factory.createInstance(instance), ssl, config, uri);
    } catch (InstantiationException e) {
        throw new RuntimeException(e);
    }
}
Also used : ClosedChannelException(java.nio.channels.ClosedChannelException) AnnotatedEndpointFactory(io.undertow.websockets.jsr.annotated.AnnotatedEndpointFactory) XnioSsl(org.xnio.ssl.XnioSsl)

Aggregations

XnioSsl (org.xnio.ssl.XnioSsl)10 UndertowXnioSsl (io.undertow.protocols.ssl.UndertowXnioSsl)6 SSLContext (javax.net.ssl.SSLContext)5 OptionMap (org.xnio.OptionMap)4 InetSocketAddress (java.net.InetSocketAddress)3 URI (java.net.URI)3 ClosedChannelException (java.nio.channels.ClosedChannelException)3 AjpOpenListener (io.undertow.server.protocol.ajp.AjpOpenListener)2 AlpnOpenListener (io.undertow.server.protocol.http.AlpnOpenListener)2 HttpOpenListener (io.undertow.server.protocol.http.HttpOpenListener)2 Http2OpenListener (io.undertow.server.protocol.http2.Http2OpenListener)2 IOException (java.io.IOException)2 ChannelListener (org.xnio.ChannelListener)2 ClientConnection (io.undertow.client.ClientConnection)1 ClientRequest (io.undertow.client.ClientRequest)1 ClientResponse (io.undertow.client.ClientResponse)1 UndertowClient (io.undertow.client.UndertowClient)1 ByteBufferPool (io.undertow.connector.ByteBufferPool)1 DefaultByteBufferPool (io.undertow.server.DefaultByteBufferPool)1 HttpHandler (io.undertow.server.HttpHandler)1