camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dhira...@apache.org
Subject [3/5] git commit: CAMEL-7954: Updated Camel-box to use SSLContextParameters
Date Fri, 24 Oct 2014 21:43:00 GMT
CAMEL-7954: Updated Camel-box to use SSLContextParameters


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/bfa2388b
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/bfa2388b
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/bfa2388b

Branch: refs/heads/camel-2.14.x
Commit: bfa2388b3bab07e0110faf7846af2bd44dda99b4
Parents: 90f42ed
Author: Dhiraj Bokde <dhirajsb@yahoo.com>
Authored: Fri Oct 24 13:32:01 2014 -0700
Committer: Dhiraj Bokde <dhirajsb@yahoo.com>
Committed: Fri Oct 24 14:42:28 2014 -0700

----------------------------------------------------------------------
 .../camel/component/box/BoxConfiguration.java   | 12 +++++++++++
 .../component/box/internal/BoxClientHelper.java | 22 ++++++++++++++++++++
 .../component/box/internal/LoginAuthFlowUI.java | 15 +++++++++++++
 3 files changed, 49 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/bfa2388b/components/camel-box/src/main/java/org/apache/camel/component/box/BoxConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-box/src/main/java/org/apache/camel/component/box/BoxConfiguration.java
b/components/camel-box/src/main/java/org/apache/camel/component/box/BoxConfiguration.java
index 0fdac6d..2fabf7f 100644
--- a/components/camel-box/src/main/java/org/apache/camel/component/box/BoxConfiguration.java
+++ b/components/camel-box/src/main/java/org/apache/camel/component/box/BoxConfiguration.java
@@ -24,6 +24,7 @@ import com.box.boxjavalibv2.authorization.IAuthSecureStorage;
 import com.box.boxjavalibv2.authorization.OAuthRefreshListener;
 import org.apache.camel.spi.UriParam;
 import org.apache.camel.spi.UriParams;
+import org.apache.camel.util.jsse.SSLContextParameters;
 
 /**
  * Component configuration for Box component.
@@ -67,6 +68,9 @@ public class BoxConfiguration {
     @UriParam
     private Map<String, Object> httpParams;
 
+    @UriParam
+    private SSLContextParameters sslContextParameters;
+
     /**
      * Box.com login timeout in seconds, defaults to 30.
      */
@@ -169,6 +173,14 @@ public class BoxConfiguration {
         this.httpParams = httpParams;
     }
 
+    public SSLContextParameters getSslContextParameters() {
+        return sslContextParameters;
+    }
+
+    public void setSslContextParameters(SSLContextParameters sslContextParameters) {
+        this.sslContextParameters = sslContextParameters;
+    }
+
     public int getLoginTimeout() {
         return loginTimeout;
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/bfa2388b/components/camel-box/src/main/java/org/apache/camel/component/box/internal/BoxClientHelper.java
----------------------------------------------------------------------
diff --git a/components/camel-box/src/main/java/org/apache/camel/component/box/internal/BoxClientHelper.java
b/components/camel-box/src/main/java/org/apache/camel/component/box/internal/BoxClientHelper.java
index 0f94aec..54c3e49 100644
--- a/components/camel-box/src/main/java/org/apache/camel/component/box/internal/BoxClientHelper.java
+++ b/components/camel-box/src/main/java/org/apache/camel/component/box/internal/BoxClientHelper.java
@@ -16,6 +16,8 @@
  */
 package org.apache.camel.component.box.internal;
 
+import java.io.IOException;
+import java.security.GeneralSecurityException;
 import java.util.Map;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
@@ -29,11 +31,16 @@ import com.box.boxjavalibv2.exceptions.AuthFatalFailureException;
 import com.box.boxjavalibv2.exceptions.BoxServerException;
 import com.box.restclientv2.IBoxRESTClient;
 import com.box.restclientv2.exceptions.BoxRestException;
+
 import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.component.box.BoxConfiguration;
 import org.apache.camel.util.ObjectHelper;
+import org.apache.camel.util.jsse.SSLContextParameters;
 import org.apache.http.client.HttpClient;
 import org.apache.http.conn.ClientConnectionManager;
+import org.apache.http.conn.scheme.Scheme;
+import org.apache.http.conn.scheme.SchemeRegistry;
+import org.apache.http.conn.ssl.SSLSocketFactory;
 import org.apache.http.params.HttpParams;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -79,6 +86,21 @@ public final class BoxClientHelper {
             public HttpClient getRawHttpClient() {
                 final HttpClient httpClient = super.getRawHttpClient();
                 clientConnectionManager[0] = httpClient.getConnectionManager();
+                final SchemeRegistry schemeRegistry = clientConnectionManager[0].getSchemeRegistry();
+                SSLContextParameters sslContextParameters = configuration.getSslContextParameters();
+                if (sslContextParameters == null) {
+                    sslContextParameters = new SSLContextParameters();
+                }
+                try {
+                    final SSLSocketFactory socketFactory = new SSLSocketFactory(
+                        sslContextParameters.createSSLContext(),
+                        SSLSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
+                    schemeRegistry.register(new Scheme("https", socketFactory, 443));
+                } catch (GeneralSecurityException e) {
+                    throw ObjectHelper.wrapRuntimeCamelException(e);
+                } catch (IOException e) {
+                    throw ObjectHelper.wrapRuntimeCamelException(e);
+                }
 
                 // set custom HTTP params
                 final Map<String, Object> configParams = configuration.getHttpParams();

http://git-wip-us.apache.org/repos/asf/camel/blob/bfa2388b/components/camel-box/src/main/java/org/apache/camel/component/box/internal/LoginAuthFlowUI.java
----------------------------------------------------------------------
diff --git a/components/camel-box/src/main/java/org/apache/camel/component/box/internal/LoginAuthFlowUI.java
b/components/camel-box/src/main/java/org/apache/camel/component/box/internal/LoginAuthFlowUI.java
index 568d27c..0568ad9 100644
--- a/components/camel-box/src/main/java/org/apache/camel/component/box/internal/LoginAuthFlowUI.java
+++ b/components/camel-box/src/main/java/org/apache/camel/component/box/internal/LoginAuthFlowUI.java
@@ -16,12 +16,16 @@
  */
 package org.apache.camel.component.box.internal;
 
+import java.io.IOException;
+import java.security.GeneralSecurityException;
 import java.security.SecureRandom;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
+import javax.net.ssl.SSLContext;
+
 import com.box.boxjavalibv2.BoxClient;
 import com.box.boxjavalibv2.authorization.IAuthFlowListener;
 import com.box.boxjavalibv2.authorization.IAuthFlowUI;
@@ -43,6 +47,8 @@ import com.gargoylesoftware.htmlunit.html.HtmlPasswordInput;
 import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;
 import com.gargoylesoftware.htmlunit.html.HtmlTextInput;
 import org.apache.camel.component.box.BoxConfiguration;
+import org.apache.camel.util.ObjectHelper;
+import org.apache.camel.util.jsse.SSLContextParameters;
 import org.apache.http.HttpHost;
 import org.apache.http.HttpStatus;
 import org.apache.http.conn.params.ConnRoutePNames;
@@ -81,6 +87,15 @@ public final class LoginAuthFlowUI implements IAuthFlowUI {
         options.setThrowExceptionOnFailingStatusCode(true);
         options.setThrowExceptionOnScriptError(true);
         options.setPrintContentOnFailingStatusCode(LOG.isDebugEnabled());
+        try {
+            // use default SSP to create supported non-SSL protocols list
+            final SSLContext sslContext = new SSLContextParameters().createSSLContext();
+            options.setSSLClientProtocols(sslContext.createSSLEngine().getEnabledProtocols());
+        } catch (GeneralSecurityException e) {
+            throw ObjectHelper.wrapRuntimeCamelException(e);
+        } catch (IOException e) {
+            throw ObjectHelper.wrapRuntimeCamelException(e);
+        }
 
         // add HTTP proxy if set
         final Map<String, Object> httpParams = configuration.getHttpParams();


Mime
View raw message