Search in sources :

Example 51 with SSLContextParameters

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

the class JettyHttpsProducerSslContextInUriTest method createRegistry.

@Override
protected JndiRegistry createRegistry() throws Exception {
    KeyStoreParameters ksp = new KeyStoreParameters();
    ksp.setResource(this.getClass().getClassLoader().getResource("jsse/localhost.ks").toString());
    ksp.setPassword(pwd);
    KeyManagersParameters kmp = new KeyManagersParameters();
    kmp.setKeyPassword(pwd);
    kmp.setKeyStore(ksp);
    //TrustManagersParameters tmp = new TrustManagersParameters();
    //tmp.setKeyStore(ksp);
    SSLContextParameters sslContextParameters = new SSLContextParameters();
    sslContextParameters.setKeyManagers(kmp);
    //sslContextParameters.setTrustManagers(tmp);
    JndiRegistry registry = super.createRegistry();
    registry.bind("sslContextParameters", sslContextParameters);
    return registry;
}
Also used : KeyManagersParameters(org.apache.camel.util.jsse.KeyManagersParameters) JndiRegistry(org.apache.camel.impl.JndiRegistry) KeyStoreParameters(org.apache.camel.util.jsse.KeyStoreParameters) SSLContextParameters(org.apache.camel.util.jsse.SSLContextParameters)

Example 52 with SSLContextParameters

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

the class HttpsSslContextParametersGetTest method createRouteBuilder.

@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {

        public void configure() {
            SSLContextParameters params = new SSLContextParameters();
            ProtocolSocketFactory factory = new SSLContextParametersSecureProtocolSocketFactory(params, context);
            Protocol.registerProtocol("https", new Protocol("https", factory, 443));
            from("direct:start").to("https://mail.google.com/mail/").to("mock:results");
        }
    };
}
Also used : ProtocolSocketFactory(org.apache.commons.httpclient.protocol.ProtocolSocketFactory) RouteBuilder(org.apache.camel.builder.RouteBuilder) Protocol(org.apache.commons.httpclient.protocol.Protocol) SSLContextParameters(org.apache.camel.util.jsse.SSLContextParameters)

Example 53 with SSLContextParameters

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

the class IrcsWithSslContextParamsRouteTest method createRegistry.

// TODO This test is disabled until we can find a public SSL enabled IRC 
// server to test against. To use this test, follow the following procedures:
// 1) Download and install UnrealIRCd 3.2.9 from http://www.unrealircd.com/
// 2) Copy the contents of the src/test/unrealircd folder into the installation
//    folder of UnrealIRCd.
// 3) Start UnrealIRCd and execute this test.  Often the test executes quicker than
//    the IRC server responds and the assertion will fail.  In order to get the test to
//    pass reliably, you may need to set a break point in IrcEndpoint#joinChanel in order
//    to slow the route creation down enough for the event listener to be in place
//    when camel-con joins the room.
@Override
protected JndiRegistry createRegistry() throws Exception {
    KeyStoreParameters ksp = new KeyStoreParameters();
    ksp.setResource("localhost.ks");
    ksp.setPassword("changeit");
    TrustManagersParameters tmp = new TrustManagersParameters();
    tmp.setKeyStore(ksp);
    SSLContextParameters sslContextParameters = new SSLContextParameters();
    sslContextParameters.setTrustManagers(tmp);
    JndiRegistry registry = super.createRegistry();
    registry.bind("sslContextParameters", sslContextParameters);
    return registry;
}
Also used : JndiRegistry(org.apache.camel.impl.JndiRegistry) TrustManagersParameters(org.apache.camel.util.jsse.TrustManagersParameters) KeyStoreParameters(org.apache.camel.util.jsse.KeyStoreParameters) SSLContextParameters(org.apache.camel.util.jsse.SSLContextParameters)

Example 54 with SSLContextParameters

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

the class JettyHttpComponent method createEndpoint.

@Override
protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
    // must extract well known parameters before we create the endpoint
    List<Handler> handlerList = resolveAndRemoveReferenceListParameter(parameters, "handlers", Handler.class);
    HttpBinding binding = resolveAndRemoveReferenceParameter(parameters, "httpBindingRef", HttpBinding.class);
    JettyHttpBinding jettyBinding = resolveAndRemoveReferenceParameter(parameters, "jettyHttpBindingRef", JettyHttpBinding.class);
    Boolean enableJmx = getAndRemoveParameter(parameters, "enableJmx", Boolean.class);
    Boolean enableMultipartFilter = getAndRemoveParameter(parameters, "enableMultipartFilter", Boolean.class, true);
    Filter multipartFilter = resolveAndRemoveReferenceParameter(parameters, "multipartFilterRef", Filter.class);
    List<Filter> filters = resolveAndRemoveReferenceListParameter(parameters, "filtersRef", Filter.class);
    Boolean enableCors = getAndRemoveParameter(parameters, "enableCORS", Boolean.class, false);
    HeaderFilterStrategy headerFilterStrategy = resolveAndRemoveReferenceParameter(parameters, "headerFilterStrategy", HeaderFilterStrategy.class);
    UrlRewrite urlRewrite = resolveAndRemoveReferenceParameter(parameters, "urlRewrite", UrlRewrite.class);
    SSLContextParameters sslContextParameters = resolveAndRemoveReferenceParameter(parameters, "sslContextParametersRef", SSLContextParameters.class);
    SSLContextParameters ssl = sslContextParameters != null ? sslContextParameters : this.sslContextParameters;
    String proxyHost = getAndRemoveParameter(parameters, "proxyHost", String.class, getProxyHost());
    Integer proxyPort = getAndRemoveParameter(parameters, "proxyPort", Integer.class, getProxyPort());
    Integer httpClientMinThreads = getAndRemoveParameter(parameters, "httpClientMinThreads", Integer.class, this.httpClientMinThreads);
    Integer httpClientMaxThreads = getAndRemoveParameter(parameters, "httpClientMaxThreads", Integer.class, this.httpClientMaxThreads);
    HttpClient httpClient = resolveAndRemoveReferenceParameter(parameters, "httpClient", HttpClient.class);
    Boolean async = getAndRemoveParameter(parameters, "async", Boolean.class);
    // extract httpClient. parameters
    Map<String, Object> httpClientParameters = IntrospectionSupport.extractProperties(parameters, "httpClient.");
    // extract filterInit. parameters
    Map<String, String> filterInitParameters = IntrospectionSupport.extractStringProperties(IntrospectionSupport.extractProperties(parameters, "filterInit."));
    String address = remaining;
    URI addressUri = new URI(UnsafeUriCharactersEncoder.encodeHttpURI(address));
    URI endpointUri = URISupport.createRemainingURI(addressUri, parameters);
    // need to keep the httpMethodRestrict parameter for the endpointUri
    String httpMethodRestrict = getAndRemoveParameter(parameters, "httpMethodRestrict", String.class);
    // restructure uri to be based on the parameters left as we dont want to include the Camel internal options
    URI httpUri = URISupport.createRemainingURI(addressUri, parameters);
    // create endpoint after all known parameters have been extracted from parameters
    // include component scheme in the uri
    String scheme = ObjectHelper.before(uri, ":");
    endpointUri = new URI(scheme + ":" + endpointUri);
    JettyHttpEndpoint endpoint = createEndpoint(endpointUri, httpUri);
    if (async != null) {
        endpoint.setAsync(async);
    }
    if (headerFilterStrategy != null) {
        endpoint.setHeaderFilterStrategy(headerFilterStrategy);
    } else {
        setEndpointHeaderFilterStrategy(endpoint);
    }
    // setup the proxy host and proxy port
    if (proxyHost != null) {
        endpoint.setProxyHost(proxyHost);
        endpoint.setProxyPort(proxyPort);
    }
    if (urlRewrite != null) {
        // let CamelContext deal with the lifecycle of the url rewrite
        // this ensures its being shutdown when Camel shutdown etc.
        getCamelContext().addService(urlRewrite);
        endpoint.setUrlRewrite(urlRewrite);
    }
    if (httpClientParameters != null && !httpClientParameters.isEmpty()) {
        endpoint.setHttpClientParameters(httpClientParameters);
    }
    if (filterInitParameters != null && !filterInitParameters.isEmpty()) {
        endpoint.setFilterInitParameters(filterInitParameters);
    }
    if (handlerList.size() > 0) {
        endpoint.setHandlers(handlerList);
    }
    // prefer to use endpoint configured over component configured
    if (binding == null) {
        // fallback to component configured
        binding = getHttpBinding();
    }
    if (binding != null) {
        endpoint.setBinding(binding);
    }
    // prefer to use endpoint configured over component configured
    if (jettyBinding == null) {
        // fallback to component configured
        jettyBinding = getJettyHttpBinding();
    }
    if (jettyBinding != null) {
        endpoint.setJettyBinding(jettyBinding);
    }
    if (enableJmx != null) {
        endpoint.setEnableJmx(enableJmx);
    } else {
        // set this option based on setting of JettyHttpComponent
        endpoint.setEnableJmx(isEnableJmx());
    }
    endpoint.setEnableMultipartFilter(enableMultipartFilter);
    if (multipartFilter != null) {
        endpoint.setMultipartFilter(multipartFilter);
        endpoint.setEnableMultipartFilter(true);
    }
    if (enableCors) {
        endpoint.setEnableCORS(enableCors);
        if (filters == null) {
            filters = new ArrayList<Filter>(1);
        }
        filters.add(new CrossOriginFilter());
    }
    if (filters != null) {
        endpoint.setFilters(filters);
    }
    if (httpMethodRestrict != null) {
        endpoint.setHttpMethodRestrict(httpMethodRestrict);
    }
    if (ssl != null) {
        endpoint.setSslContextParameters(ssl);
    }
    if (httpClientMinThreads != null) {
        endpoint.setHttpClientMinThreads(httpClientMinThreads);
    }
    if (httpClientMaxThreads != null) {
        endpoint.setHttpClientMaxThreads(httpClientMaxThreads);
    }
    if (httpClient != null) {
        endpoint.setHttpClient(httpClient);
    }
    endpoint.setSendServerVersion(isSendServerVersion());
    setProperties(endpoint, parameters);
    // re-create http uri after all parameters has been set on the endpoint, as the remainders are for http uri
    httpUri = URISupport.createRemainingURI(addressUri, parameters);
    endpoint.setHttpUri(httpUri);
    return endpoint;
}
Also used : UrlRewrite(org.apache.camel.http.common.UrlRewrite) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) ErrorHandler(org.eclipse.jetty.server.handler.ErrorHandler) Handler(org.eclipse.jetty.server.Handler) SessionHandler(org.eclipse.jetty.server.session.SessionHandler) HeaderFilterStrategy(org.apache.camel.spi.HeaderFilterStrategy) HttpRestHeaderFilterStrategy(org.apache.camel.http.common.HttpRestHeaderFilterStrategy) CrossOriginFilter(org.eclipse.jetty.servlets.CrossOriginFilter) URI(java.net.URI) SSLContextParameters(org.apache.camel.util.jsse.SSLContextParameters) Filter(javax.servlet.Filter) MultiPartFilter(org.eclipse.jetty.servlets.MultiPartFilter) CrossOriginFilter(org.eclipse.jetty.servlets.CrossOriginFilter) HttpClient(org.eclipse.jetty.client.HttpClient) HttpBinding(org.apache.camel.http.common.HttpBinding)

Example 55 with SSLContextParameters

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

the class LumberjackComponentSSLTest method createClientSSLContextParameters.

private SSLContextParameters createClientSSLContextParameters() {
    SSLContextParameters sslContextParameters = new SSLContextParameters();
    TrustManagersParameters trustManagersParameters = new TrustManagersParameters();
    KeyStoreParameters trustStore = new KeyStoreParameters();
    trustStore.setPassword("changeit");
    trustStore.setResource("org/apache/camel/component/lumberjack/keystore.jks");
    trustManagersParameters.setKeyStore(trustStore);
    sslContextParameters.setTrustManagers(trustManagersParameters);
    return sslContextParameters;
}
Also used : TrustManagersParameters(org.apache.camel.util.jsse.TrustManagersParameters) KeyStoreParameters(org.apache.camel.util.jsse.KeyStoreParameters) 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