Repository: nifi
Updated Branches:
  refs/heads/0.x de7ecd719 -> 714a90bbd


NIFI-1907 Moving lazy init of SSLContext to StandardSiteToSiteClientConfig 
rather than the builder

This closes #457.


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

Branch: refs/heads/0.x
Commit: 714a90bbde5b985e400cc6f274a0128defc9ed6c
Parents: de7ecd7
Author: Bryan Bende <[email protected]>
Authored: Fri May 20 11:15:36 2016 -0400
Committer: Bryan Bende <[email protected]>
Committed: Tue May 24 09:49:35 2016 -0400

----------------------------------------------------------------------
 .../nifi/remote/client/SiteToSiteClient.java    | 106 +++++++++----------
 .../remote/client/SiteToSiteClientConfig.java   |   1 +
 2 files changed, 54 insertions(+), 53 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/nifi/blob/714a90bb/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/client/SiteToSiteClient.java
----------------------------------------------------------------------
diff --git 
a/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/client/SiteToSiteClient.java
 
b/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/client/SiteToSiteClient.java
index 2b04df9..d982cc4 100644
--- 
a/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/client/SiteToSiteClient.java
+++ 
b/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/client/SiteToSiteClient.java
@@ -572,58 +572,7 @@ public interface SiteToSiteClient extends Closeable {
          * @return the SSL Context that is configured for this builder
          */
         public SSLContext getSslContext() {
-            if (sslContext != null) {
-                return sslContext;
-            }
-
-            final KeyManagerFactory keyManagerFactory;
-            if (keystoreFilename != null && keystorePass != null && 
keystoreType != null) {
-                try {
-                    // prepare the keystore
-                    final KeyStore keyStore = 
KeyStore.getInstance(getKeystoreType().name());
-                    try (final InputStream keyStoreStream = new 
FileInputStream(new File(getKeystoreFilename()))) {
-                        keyStore.load(keyStoreStream, 
getKeystorePass().toCharArray());
-                    }
-                    keyManagerFactory = 
KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
-                    keyManagerFactory.init(keyStore, 
getKeystorePass().toCharArray());
-                } catch (final Exception e) {
-                    throw new RuntimeException("Failed to load Keystore", e);
-                }
-            } else {
-                keyManagerFactory = null;
-            }
-
-            final TrustManagerFactory trustManagerFactory;
-            if (truststoreFilename != null && truststorePass != null && 
truststoreType != null) {
-                try {
-                    // prepare the truststore
-                    final KeyStore trustStore = 
KeyStore.getInstance(getTruststoreType().name());
-                    try (final InputStream trustStoreStream = new 
FileInputStream(new File(getTruststoreFilename()))) {
-                        trustStore.load(trustStoreStream, 
getTruststorePass().toCharArray());
-                    }
-                    trustManagerFactory = 
TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
-                    trustManagerFactory.init(trustStore);
-                } catch (final Exception e) {
-                    throw new RuntimeException("Failed to load Truststore", e);
-                }
-            } else {
-                trustManagerFactory = null;
-            }
-
-            if (keyManagerFactory != null && trustManagerFactory != null) {
-                try {
-                    // initialize the ssl context
-                    final SSLContext sslContext = 
SSLContext.getInstance("TLS");
-                    sslContext.init(keyManagerFactory.getKeyManagers(), 
trustManagerFactory.getTrustManagers(), new SecureRandom());
-                    
sslContext.getDefaultSSLParameters().setNeedClientAuth(true);
-
-                    return sslContext;
-                } catch (final Exception e) {
-                    throw new RuntimeException("Created keystore and 
truststore but failed to initialize SSLContext");
-                }
-            } else {
-                return null;
-            }
+            return sslContext;
         }
 
         /**
@@ -758,7 +707,58 @@ public interface SiteToSiteClient extends Closeable {
 
         @Override
         public SSLContext getSslContext() {
-            return sslContext;
+            if (sslContext != null) {
+                return sslContext;
+            }
+
+            final KeyManagerFactory keyManagerFactory;
+            if (keystoreFilename != null && keystorePass != null && 
keystoreType != null) {
+                try {
+                    // prepare the keystore
+                    final KeyStore keyStore = 
KeyStore.getInstance(getKeystoreType().name());
+                    try (final InputStream keyStoreStream = new 
FileInputStream(new File(getKeystoreFilename()))) {
+                        keyStore.load(keyStoreStream, 
keystorePass.toCharArray());
+                    }
+                    keyManagerFactory = 
KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
+                    keyManagerFactory.init(keyStore, 
keystorePass.toCharArray());
+                } catch (final Exception e) {
+                    throw new IllegalStateException("Failed to load Keystore", 
e);
+                }
+            } else {
+                keyManagerFactory = null;
+            }
+
+            final TrustManagerFactory trustManagerFactory;
+            if (truststoreFilename != null && truststorePass != null && 
truststoreType != null) {
+                try {
+                    // prepare the truststore
+                    final KeyStore trustStore = 
KeyStore.getInstance(getTruststoreType().name());
+                    try (final InputStream trustStoreStream = new 
FileInputStream(new File(getTruststoreFilename()))) {
+                        trustStore.load(trustStoreStream, 
truststorePass.toCharArray());
+                    }
+                    trustManagerFactory = 
TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
+                    trustManagerFactory.init(trustStore);
+                } catch (final Exception e) {
+                    throw new IllegalStateException("Failed to load 
Truststore", e);
+                }
+            } else {
+                trustManagerFactory = null;
+            }
+
+            if (keyManagerFactory != null && trustManagerFactory != null) {
+                try {
+                    // initialize the ssl context
+                    final SSLContext sslContext = 
SSLContext.getInstance("TLS");
+                    sslContext.init(keyManagerFactory.getKeyManagers(), 
trustManagerFactory.getTrustManagers(), new SecureRandom());
+                    
sslContext.getDefaultSSLParameters().setNeedClientAuth(true);
+
+                    return sslContext;
+                } catch (final Exception e) {
+                    throw new IllegalStateException("Created keystore and 
truststore but failed to initialize SSLContext", e);
+                }
+            } else {
+                return null;
+            }
         }
 
         @Override

http://git-wip-us.apache.org/repos/asf/nifi/blob/714a90bb/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/client/SiteToSiteClientConfig.java
----------------------------------------------------------------------
diff --git 
a/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/client/SiteToSiteClientConfig.java
 
b/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/client/SiteToSiteClientConfig.java
index 8962c71..59891f0 100644
--- 
a/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/client/SiteToSiteClientConfig.java
+++ 
b/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/client/SiteToSiteClientConfig.java
@@ -54,6 +54,7 @@ public interface SiteToSiteClientConfig extends Serializable {
 
     /**
      * @return the SSL Context that is configured for this builder
+     * @throws IllegalStateException if an SSLContext is being constructed and 
an error occurs doing so
      */
     SSLContext getSslContext();
 

Reply via email to