camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dhira...@apache.org
Subject [2/5] git commit: CAMEL-7933: Updated Camel-apns to use SSLContextParameters
Date Fri, 24 Oct 2014 21:42:59 GMT
CAMEL-7933: Updated Camel-apns 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/90f42ed5
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/90f42ed5
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/90f42ed5

Branch: refs/heads/camel-2.14.x
Commit: 90f42ed5fefbbbae633288a2f307cd2c77cdc9df
Parents: 9b54104
Author: Dhiraj Bokde <dhirajsb@yahoo.com>
Authored: Fri Oct 24 13:36:01 2014 -0700
Committer: Dhiraj Bokde <dhirajsb@yahoo.com>
Committed: Fri Oct 24 14:42:27 2014 -0700

----------------------------------------------------------------------
 .../apns/factory/ApnsServiceFactory.java        | 21 ++++---
 .../apns/factory/ApnsServiceFactoryTest.java    |  2 +-
 .../ConfiguredApnsServiceFactoryTest.java       |  5 +-
 .../camel/component/apns/util/ApnsUtils.java    | 60 +++++++++++++-------
 .../spring/SpringApnsConsumerTest-context.xml   |  4 +-
 5 files changed, 56 insertions(+), 36 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/90f42ed5/components/camel-apns/src/main/java/org/apache/camel/component/apns/factory/ApnsServiceFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-apns/src/main/java/org/apache/camel/component/apns/factory/ApnsServiceFactory.java
b/components/camel-apns/src/main/java/org/apache/camel/component/apns/factory/ApnsServiceFactory.java
index 0debdd1..0557d2c 100644
--- a/components/camel-apns/src/main/java/org/apache/camel/component/apns/factory/ApnsServiceFactory.java
+++ b/components/camel-apns/src/main/java/org/apache/camel/component/apns/factory/ApnsServiceFactory.java
@@ -18,7 +18,7 @@ package org.apache.camel.component.apns.factory;
 
 import java.io.IOException;
 import java.io.InputStream;
-import javax.net.ssl.SSLContext;
+import java.security.GeneralSecurityException;
 
 import com.notnoop.apns.APNS;
 import com.notnoop.apns.ApnsDelegate;
@@ -36,6 +36,7 @@ import org.apache.camel.component.apns.util.ParamUtils;
 import org.apache.camel.component.apns.util.ResourceUtils;
 import org.apache.camel.util.ObjectHelper;
 import org.apache.camel.util.ResourceHelper;
+import org.apache.camel.util.jsse.SSLContextParameters;
 
 public class ApnsServiceFactory implements CamelContextAware {
 
@@ -48,7 +49,7 @@ public class ApnsServiceFactory implements CamelContextAware {
     private String certificatePassword;
     private ConnectionStrategy connectionStrategy;
     private ReconnectionPolicy reconnectionPolicy;
-    private SSLContext sslContext;
+    private SSLContextParameters sslContextParameters;
     private int poolSize = DEFAULT_POOL_SIZE;
     private String gatewayHost;
     private int gatewayPort;
@@ -149,12 +150,12 @@ public class ApnsServiceFactory implements CamelContextAware {
         this.connectionStrategy = connectionStrategy;
     }
 
-    public SSLContext getSslContext() {
-        return sslContext;
+    public SSLContextParameters getSslContextParameters() {
+        return sslContextParameters;
     }
 
-    public void setSslContext(SSLContext sslContext) {
-        this.sslContext = sslContext;
+    public void setSslContextParameters(SSLContextParameters sslContextParameters) {
+        this.sslContextParameters = sslContextParameters;
     }
 
     public ApnsDelegate getApnsDelegate() {
@@ -177,6 +178,8 @@ public class ApnsServiceFactory implements CamelContextAware {
             configureApnsCertificate(builder);
         } catch (IOException e) {
             throw ObjectHelper.wrapRuntimeCamelException(e);
+        } catch (GeneralSecurityException e) {
+            throw ObjectHelper.wrapRuntimeCamelException(e);
         }
 
         ApnsService apnsService = builder.build();
@@ -187,9 +190,9 @@ public class ApnsServiceFactory implements CamelContextAware {
         return serviceBuilder;
     }
 
-    private void configureApnsCertificate(ApnsServiceBuilder builder) throws IOException
{
-        if (getSslContext() != null) {
-            builder.withSSLContext(getSslContext());
+    private void configureApnsCertificate(ApnsServiceBuilder builder) throws IOException,
GeneralSecurityException {
+        if (getSslContextParameters() != null) {
+            builder.withSSLContext(getSslContextParameters().createSSLContext());
             return;
         }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/90f42ed5/components/camel-apns/src/test/java/org/apache/camel/component/apns/factory/ApnsServiceFactoryTest.java
----------------------------------------------------------------------
diff --git a/components/camel-apns/src/test/java/org/apache/camel/component/apns/factory/ApnsServiceFactoryTest.java
b/components/camel-apns/src/test/java/org/apache/camel/component/apns/factory/ApnsServiceFactoryTest.java
index a784ee7..84361e1 100644
--- a/components/camel-apns/src/test/java/org/apache/camel/component/apns/factory/ApnsServiceFactoryTest.java
+++ b/components/camel-apns/src/test/java/org/apache/camel/component/apns/factory/ApnsServiceFactoryTest.java
@@ -64,7 +64,7 @@ public class ApnsServiceFactoryTest {
         apnsServiceFactory.setFeedbackPort(FixedCertificates.TEST_FEEDBACK_PORT);
         apnsServiceFactory.setGatewayHost(FixedCertificates.TEST_HOST);
         apnsServiceFactory.setGatewayPort(FixedCertificates.TEST_GATEWAY_PORT);
-        apnsServiceFactory.setSslContext(ApnsUtils.clientContext());
+        apnsServiceFactory.setSslContextParameters(ApnsUtils.clientContext());
 
         return apnsServiceFactory;
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/90f42ed5/components/camel-apns/src/test/java/org/apache/camel/component/apns/factory/ConfiguredApnsServiceFactoryTest.java
----------------------------------------------------------------------
diff --git a/components/camel-apns/src/test/java/org/apache/camel/component/apns/factory/ConfiguredApnsServiceFactoryTest.java
b/components/camel-apns/src/test/java/org/apache/camel/component/apns/factory/ConfiguredApnsServiceFactoryTest.java
index c48c6c0..f3fc60f 100644
--- a/components/camel-apns/src/test/java/org/apache/camel/component/apns/factory/ConfiguredApnsServiceFactoryTest.java
+++ b/components/camel-apns/src/test/java/org/apache/camel/component/apns/factory/ConfiguredApnsServiceFactoryTest.java
@@ -17,9 +17,10 @@
 package org.apache.camel.component.apns.factory;
 
 import java.io.IOException;
-import javax.net.ssl.SSLContext;
 
 import com.notnoop.apns.ApnsServiceBuilder;
+
+import org.apache.camel.util.jsse.SSLContextParameters;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -42,7 +43,7 @@ public class ConfiguredApnsServiceFactoryTest {
 
     @Before
     public void setUp() throws IOException {
-        apnsServiceFactory.setSslContext(mock(SSLContext.class));
+        apnsServiceFactory.setSslContextParameters(mock(SSLContextParameters.class));
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/camel/blob/90f42ed5/components/camel-apns/src/test/java/org/apache/camel/component/apns/util/ApnsUtils.java
----------------------------------------------------------------------
diff --git a/components/camel-apns/src/test/java/org/apache/camel/component/apns/util/ApnsUtils.java
b/components/camel-apns/src/test/java/org/apache/camel/component/apns/util/ApnsUtils.java
index 177f74b..74f090d 100644
--- a/components/camel-apns/src/test/java/org/apache/camel/component/apns/util/ApnsUtils.java
+++ b/components/camel-apns/src/test/java/org/apache/camel/component/apns/util/ApnsUtils.java
@@ -16,17 +16,17 @@
  */
 package org.apache.camel.component.apns.util;
 
+import java.io.IOException;
 import java.io.InputStream;
+import java.security.GeneralSecurityException;
 import java.security.Provider;
 import java.security.Provider.Service;
-import java.security.SecureRandom;
 import java.security.Security;
 import java.security.cert.CertificateException;
 import java.security.cert.X509Certificate;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Random;
-
 import javax.net.ssl.SSLContext;
 import javax.net.ssl.TrustManager;
 import javax.net.ssl.X509TrustManager;
@@ -38,6 +38,10 @@ import com.notnoop.apns.utils.FixedCertificates;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.component.apns.factory.ApnsServiceFactory;
+import org.apache.camel.util.jsse.KeyManagersParameters;
+import org.apache.camel.util.jsse.KeyStoreParameters;
+import org.apache.camel.util.jsse.SSLContextParameters;
+import org.apache.camel.util.jsse.TrustManagersParameters;
 
 public final class ApnsUtils {
 
@@ -90,27 +94,39 @@ public final class ApnsUtils {
         return keys.get(0);
     }
     
-    public static SSLContext clientContext() throws Exception {
-        InputStream stream = ClassLoader.getSystemResourceAsStream(FixedCertificates.CLIENT_STORE);
-        SSLContext context = Utilities.newSSLContext(stream, 
-                                                     FixedCertificates.CLIENT_PASSWD,
-                                                     "PKCS12",
-                                                     getAlgorithm());
-        context.init(null, new TrustManager[] {new X509TrustManager() {
-            public void checkClientTrusted(X509Certificate[] chain, String authType)
-                throws CertificateException {
-            }
-
-            public void checkServerTrusted(X509Certificate[] chain, String authType)
-                throws CertificateException {
+    public static SSLContextParameters clientContext() throws Exception {
+        final KeyStoreParameters ksp = new KeyStoreParameters();
+        ksp.setResource(ClassLoader.getSystemResource(FixedCertificates.CLIENT_STORE).toString());
+        ksp.setType("PKCS12");
+
+        final KeyManagersParameters kmp = new KeyManagersParameters();
+        kmp.setKeyStore(ksp);
+        kmp.setKeyPassword(FixedCertificates.CLIENT_PASSWD);
+        kmp.setAlgorithm(getAlgorithm());
+
+        final SSLContextParameters contextParameters = new SSLContextParameters();
+        contextParameters.setKeyManagers(kmp);
+        contextParameters.setTrustManagers(new TrustManagersParameters() {
+            @Override
+            public TrustManager[] createTrustManagers() throws GeneralSecurityException,
IOException {
+                return new TrustManager[] {new X509TrustManager() {
+                    public void checkClientTrusted(X509Certificate[] chain, String authType)
+                        throws CertificateException {
+                    }
+
+                    public void checkServerTrusted(X509Certificate[] chain, String authType)
+                        throws CertificateException {
+                    }
+
+                    public X509Certificate[] getAcceptedIssuers() {
+                        return new X509Certificate[0];
+                    }
+
+                }};
             }
+        });
 
-            public X509Certificate[] getAcceptedIssuers() {
-                return null;
-            }
-            
-        }}, new SecureRandom());
-        return context;
+        return contextParameters;
     }
     
     public static ApnsServiceFactory createDefaultTestConfiguration(CamelContext camelContext)

@@ -124,7 +140,7 @@ public final class ApnsUtils {
         // apnsServiceFactory.setCertificatePath("classpath:/" +
         // FixedCertificates.CLIENT_STORE);
         // apnsServiceFactory.setCertificatePassword(FixedCertificates.CLIENT_PASSWD);
-        apnsServiceFactory.setSslContext(clientContext());
+        apnsServiceFactory.setSslContextParameters(clientContext());
         return apnsServiceFactory;
     }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/90f42ed5/components/camel-apns/src/test/resources/org/apache/camel/component/apns/spring/SpringApnsConsumerTest-context.xml
----------------------------------------------------------------------
diff --git a/components/camel-apns/src/test/resources/org/apache/camel/component/apns/spring/SpringApnsConsumerTest-context.xml
b/components/camel-apns/src/test/resources/org/apache/camel/component/apns/spring/SpringApnsConsumerTest-context.xml
index 712ba84..cd0c9fd 100644
--- a/components/camel-apns/src/test/resources/org/apache/camel/component/apns/spring/SpringApnsConsumerTest-context.xml
+++ b/components/camel-apns/src/test/resources/org/apache/camel/component/apns/spring/SpringApnsConsumerTest-context.xml
@@ -31,12 +31,12 @@
     <property name="feedbackPort" value="7843"/>
     <property name="gatewayHost" value="localhost"/>
     <property name="gatewayPort" value="7654"/>
-    <property name="sslContext" ref="sslContext"/>
+    <property name="sslContextParameters" ref="sslContextParameters"/>
   </bean>
 
   <bean id="apnsService" factory-bean="apnsServiceFactory" factory-method="getApnsService"/>
 
-  <bean id="sslContext" class="org.apache.camel.component.apns.util.ApnsUtils" factory-method="clientContext"/>
+  <bean id="sslContextParameters" class="org.apache.camel.component.apns.util.ApnsUtils"
factory-method="clientContext"/>
 
   <bean id="apns" class="org.apache.camel.component.apns.ApnsComponent">
     <property name="apnsService" ref="apnsService"/>


Mime
View raw message