Search in sources :

Example 11 with SSLContextParameters

use of org.apache.camel.util.jsse.SSLContextParameters in project camel by apache.

the class WebsocketComponent method createEndpoint.

@Override
protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
    // TODO cmueller: remove the "sslContextParametersRef" look up in Camel 3.0
    SSLContextParameters sslContextParameters = resolveAndRemoveReferenceParameter(parameters, "sslContextParametersRef", SSLContextParameters.class);
    if (sslContextParameters == null) {
        sslContextParameters = resolveAndRemoveReferenceParameter(parameters, "sslContextParameters", SSLContextParameters.class);
    }
    Boolean enableJmx = getAndRemoveParameter(parameters, "enableJmx", Boolean.class);
    String staticResources = getAndRemoveParameter(parameters, "staticResources", String.class);
    int port = extractPortNumber(remaining);
    String host = extractHostName(remaining);
    WebsocketEndpoint endpoint = new WebsocketEndpoint(this, uri, remaining, parameters);
    if (enableJmx != null) {
        endpoint.setEnableJmx(enableJmx);
    } else {
        endpoint.setEnableJmx(isEnableJmx());
    }
    // prefer to use endpoint configured over component configured
    if (sslContextParameters == null) {
        // fallback to component configured
        sslContextParameters = getSslContextParameters();
    }
    if (sslContextParameters != null) {
        endpoint.setSslContextParameters(sslContextParameters);
    }
    // prefer to use endpoint configured over component configured
    if (staticResources == null) {
        // fallback to component configured
        staticResources = getStaticResources();
    }
    if (staticResources != null) {
        endpoint.setStaticResources(staticResources);
    }
    endpoint.setSslContextParameters(sslContextParameters);
    endpoint.setPort(port);
    endpoint.setHost(host);
    setProperties(endpoint, parameters);
    return endpoint;
}
Also used : Endpoint(org.apache.camel.Endpoint) SSLContextParameters(org.apache.camel.util.jsse.SSLContextParameters)

Example 12 with SSLContextParameters

use of org.apache.camel.util.jsse.SSLContextParameters in project camel by apache.

the class WebsocketSSLContextInUriRouteExampleTest method createAsyncHttpSSLClient.

protected AsyncHttpClient createAsyncHttpSSLClient() throws IOException, GeneralSecurityException {
    AsyncHttpClient c;
    AsyncHttpClientConfig config;
    DefaultAsyncHttpClientConfig.Builder builder = new DefaultAsyncHttpClientConfig.Builder();
    SSLContext sslContext = new SSLContextParameters().createSSLContext(context());
    JdkSslContext ssl = new JdkSslContext(sslContext, true, ClientAuth.REQUIRE);
    builder.setSslContext(ssl);
    builder.setAcceptAnyCertificate(true);
    config = builder.build();
    c = new DefaultAsyncHttpClient(config);
    return c;
}
Also used : JdkSslContext(io.netty.handler.ssl.JdkSslContext) RouteBuilder(org.apache.camel.builder.RouteBuilder) AsyncHttpClientConfig(org.asynchttpclient.AsyncHttpClientConfig) DefaultAsyncHttpClientConfig(org.asynchttpclient.DefaultAsyncHttpClientConfig) DefaultAsyncHttpClientConfig(org.asynchttpclient.DefaultAsyncHttpClientConfig) DefaultAsyncHttpClient(org.asynchttpclient.DefaultAsyncHttpClient) SSLContext(javax.net.ssl.SSLContext) AsyncHttpClient(org.asynchttpclient.AsyncHttpClient) DefaultAsyncHttpClient(org.asynchttpclient.DefaultAsyncHttpClient) SSLContextParameters(org.apache.camel.util.jsse.SSLContextParameters)

Example 13 with SSLContextParameters

use of org.apache.camel.util.jsse.SSLContextParameters in project camel by apache.

the class WebsocketSSLRouteExampleTest method createAsyncHttpSSLClient.

protected AsyncHttpClient createAsyncHttpSSLClient() throws IOException, GeneralSecurityException {
    AsyncHttpClient c;
    AsyncHttpClientConfig config;
    DefaultAsyncHttpClientConfig.Builder builder = new DefaultAsyncHttpClientConfig.Builder();
    SSLContext sslContext = new SSLContextParameters().createSSLContext(context());
    JdkSslContext ssl = new JdkSslContext(sslContext, true, ClientAuth.REQUIRE);
    builder.setSslContext(ssl);
    builder.setAcceptAnyCertificate(true);
    config = builder.build();
    c = new DefaultAsyncHttpClient(config);
    return c;
}
Also used : JdkSslContext(io.netty.handler.ssl.JdkSslContext) RouteBuilder(org.apache.camel.builder.RouteBuilder) AsyncHttpClientConfig(org.asynchttpclient.AsyncHttpClientConfig) DefaultAsyncHttpClientConfig(org.asynchttpclient.DefaultAsyncHttpClientConfig) DefaultAsyncHttpClientConfig(org.asynchttpclient.DefaultAsyncHttpClientConfig) DefaultAsyncHttpClient(org.asynchttpclient.DefaultAsyncHttpClient) SSLContext(javax.net.ssl.SSLContext) AsyncHttpClient(org.asynchttpclient.AsyncHttpClient) DefaultAsyncHttpClient(org.asynchttpclient.DefaultAsyncHttpClient) SSLContextParameters(org.apache.camel.util.jsse.SSLContextParameters)

Example 14 with SSLContextParameters

use of org.apache.camel.util.jsse.SSLContextParameters in project camel by apache.

the class SalesforceComponentVerifier method verifyConnectivity.

// *********************************
// Connectivity validation
// *********************************
@Override
protected Result verifyConnectivity(Map<String, Object> parameters) {
    // Default is success
    ResultBuilder builder = ResultBuilder.withStatusAndScope(Result.Status.OK, Scope.CONNECTIVITY);
    try {
        SalesforceEndpointConfig configuration = new SalesforceEndpointConfig();
        setProperties(configuration, parameters);
        SalesforceLoginConfig loginConfig = new SalesforceLoginConfig();
        setProperties(loginConfig, parameters);
        // Create a dummy SslContextFactory which is needed by SalesforceHttpClient
        // or the underlying jetty client fails with a NPE
        SSLContextParameters contextParameters = new SSLContextParameters();
        SslContextFactory sslContextFactory = new SslContextFactory();
        sslContextFactory.setSslContext(contextParameters.createSSLContext(getCamelContext()));
        SalesforceHttpClient httpClient = new SalesforceHttpClient(sslContextFactory);
        httpClient.setConnectTimeout(SalesforceComponent.CONNECTION_TIMEOUT);
        configureHttpProxy(httpClient, parameters);
        SalesforceSession session = new SalesforceSession(getCamelContext(), httpClient, httpClient.getTimeout(), loginConfig);
        DefaultRestClient client = new DefaultRestClient(httpClient, configuration.getApiVersion(), configuration.getFormat(), session);
        httpClient.setSession(session);
        httpClient.start();
        // For authentication check is is enough to use
        session.start();
        client.start();
        client.getVersions((response, exception) -> processSalesforceException(builder, Optional.ofNullable(exception)));
        client.stop();
        session.stop();
        httpClient.stop();
        httpClient.destroy();
    } catch (NoSuchOptionException e) {
        builder.error(ResultErrorBuilder.withMissingOption(e.getOptionName()).build());
    } catch (SalesforceException e) {
        processSalesforceException(builder, Optional.of(e));
    } catch (Exception e) {
        builder.error(ResultErrorBuilder.withException(e).build());
        throw new RuntimeException(e);
    }
    return builder.build();
}
Also used : ResultBuilder(org.apache.camel.impl.verifier.ResultBuilder) SalesforceException(org.apache.camel.component.salesforce.api.SalesforceException) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) NoSuchOptionException(org.apache.camel.NoSuchOptionException) SalesforceSession(org.apache.camel.component.salesforce.internal.SalesforceSession) DefaultRestClient(org.apache.camel.component.salesforce.internal.client.DefaultRestClient) URISyntaxException(java.net.URISyntaxException) NoSuchOptionException(org.apache.camel.NoSuchOptionException) SalesforceException(org.apache.camel.component.salesforce.api.SalesforceException) SSLContextParameters(org.apache.camel.util.jsse.SSLContextParameters)

Example 15 with SSLContextParameters

use of org.apache.camel.util.jsse.SSLContextParameters in project camel by apache.

the class HttpsTwoComponentsSslContextParametersGetTest method createRegistry.

@Override
protected JndiRegistry createRegistry() throws Exception {
    JndiRegistry registry = super.createRegistry();
    registry.bind("x509HostnameVerifier", new AllowAllHostnameVerifier());
    registry.bind("sslContextParameters", new SSLContextParameters());
    registry.bind("sslContextParameters2", new SSLContextParameters());
    registry.bind("http4s-foo", new HttpComponent());
    registry.bind("http4s-bar", new HttpComponent());
    return registry;
}
Also used : JndiRegistry(org.apache.camel.impl.JndiRegistry) AllowAllHostnameVerifier(org.apache.http.conn.ssl.AllowAllHostnameVerifier) SSLContextParameters(org.apache.camel.util.jsse.SSLContextParameters)

Aggregations

SSLContextParameters (org.apache.camel.util.jsse.SSLContextParameters)59 KeyStoreParameters (org.apache.camel.util.jsse.KeyStoreParameters)35 KeyManagersParameters (org.apache.camel.util.jsse.KeyManagersParameters)28 TrustManagersParameters (org.apache.camel.util.jsse.TrustManagersParameters)27 JndiRegistry (org.apache.camel.impl.JndiRegistry)19 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)8 IOException (java.io.IOException)7 GeneralSecurityException (java.security.GeneralSecurityException)7 SSLContextServerParameters (org.apache.camel.util.jsse.SSLContextServerParameters)7 RouteBuilder (org.apache.camel.builder.RouteBuilder)6 SSLContext (javax.net.ssl.SSLContext)5 Test (org.junit.Test)4 URI (java.net.URI)3 SalesforceException (org.apache.camel.component.salesforce.api.SalesforceException)3 SalesforceSession (org.apache.camel.component.salesforce.internal.SalesforceSession)3 HttpClient (org.eclipse.jetty.client.HttpClient)3 JdkSslContext (io.netty.handler.ssl.JdkSslContext)2 URISyntaxException (java.net.URISyntaxException)2 CertificateException (java.security.cert.CertificateException)2 X509Certificate (java.security.cert.X509Certificate)2