[java-support] 01/02: Enhance TLS socket factory builder so setters return the builder.

Brent Putman putmanb at georgetown.edu
Tue Nov 3 19:41:54 EST 2015


This is an automated email from the git hooks/post-receive script.

putmanb pushed a commit to branch master
in repository java-support.

commit c8f3fb651791730c2ce7c96847025c99b9b0c92d
Author: Brent Putman <putmanb at georgetown.edu>
AuthorDate: Tue Nov 3 18:17:01 2015 -0500

    Enhance TLS socket factory builder so setters return the builder.
    
    Facilitates use in a fluent style.
---
 .../httpclient/TLSSocketFactoryBuilder.java        | 40 +++++++++++++++++-----
 1 file changed, 32 insertions(+), 8 deletions(-)

diff --git a/src/main/java/net/shibboleth/utilities/java/support/httpclient/TLSSocketFactoryBuilder.java b/src/main/java/net/shibboleth/utilities/java/support/httpclient/TLSSocketFactoryBuilder.java
index 53823bf..ef42a48 100644
--- a/src/main/java/net/shibboleth/utilities/java/support/httpclient/TLSSocketFactoryBuilder.java
+++ b/src/main/java/net/shibboleth/utilities/java/support/httpclient/TLSSocketFactoryBuilder.java
@@ -93,9 +93,12 @@ public class TLSSocketFactoryBuilder {
      * <p>If not specified, the value "TLS" will be used.</p>
      * 
      * @param protocol the protocol, may be null
+     * 
+     * @return this builder instance
      */
-    public void setSSLContextProtocol(@Nullable final String protocol) {
+    public TLSSocketFactoryBuilder setSSLContextProtocol(@Nullable final String protocol) {
         sslContextProtocol = StringSupport.trimOrNull(protocol);
+        return this;
     }
 
     /**
@@ -113,9 +116,12 @@ public class TLSSocketFactoryBuilder {
      * via {@link SSLContext#getInstance(String, String)}.
      * 
      * @param provider the provider name, may be null
+     * 
+     * @return this builder instance
      */
-    public void setSSLContextProvider(@Nullable final String provider) {
+    public TLSSocketFactoryBuilder setSSLContextProvider(@Nullable final String provider) {
         sslContextProvider = StringSupport.trimOrNull(provider);
+        return this;
     }
 
     /**
@@ -133,8 +139,10 @@ public class TLSSocketFactoryBuilder {
      * via {@link SSLContext#init(KeyManager[], TrustManager[], SecureRandom)}.
      * 
      * @param managers the list of key managers, or null
+     * 
+     * @return this builder instance
      */
-    public void setKeyManagers(@Nullable final List<KeyManager> managers) {
+    public TLSSocketFactoryBuilder setKeyManagers(@Nullable final List<KeyManager> managers) {
         if (managers == null) {
             keyManagers = null;
         } else {
@@ -143,6 +151,7 @@ public class TLSSocketFactoryBuilder {
                 keyManagers = null;
             }
         }
+        return this;
     }
 
     /**
@@ -160,8 +169,10 @@ public class TLSSocketFactoryBuilder {
      * via {@link SSLContext#init(KeyManager[], TrustManager[], SecureRandom)}.
      * 
      * @param managers the list of trust managers, or null
+     * 
+     * @return this builder instance
      */
-    public void setTrustManagers(@Nullable final List<TrustManager> managers) {
+    public TLSSocketFactoryBuilder setTrustManagers(@Nullable final List<TrustManager> managers) {
         if (managers == null) {
             trustManagers = null;
         } else {
@@ -170,6 +181,7 @@ public class TLSSocketFactoryBuilder {
                 trustManagers = null;
             }
         }
+        return this;
     }
 
     /**
@@ -187,9 +199,12 @@ public class TLSSocketFactoryBuilder {
      * via {@link SSLContext#init(KeyManager[], TrustManager[], SecureRandom)}.
      * 
      * @param random the secure random instance, or null
+     * 
+     * @return this builder instance
      */
-    public void setSecureRandom(@Nullable final SecureRandom random) {
+    public TLSSocketFactoryBuilder setSecureRandom(@Nullable final SecureRandom random) {
         secureRandom = random;
+        return this;
     }
     
     /**
@@ -209,9 +224,12 @@ public class TLSSocketFactoryBuilder {
      * <p>If not specified, defaults to {@link TLSSocketFactory#STRICT_HOSTNAME_VERIFIER}.
      * 
      * @param verifier the hostname verifier, or null
+     * 
+     * @return this builder instance
      */
-    public void setHostnameVerifier(@Nullable final X509HostnameVerifier verifier) {
+    public TLSSocketFactoryBuilder setHostnameVerifier(@Nullable final X509HostnameVerifier verifier) {
         hostnameVerifier = verifier;
+        return this;
     }
 
     /**
@@ -227,12 +245,15 @@ public class TLSSocketFactoryBuilder {
      * Set the list of enabled SSL/TLS protocols on sockets produced by the factory.
      * 
      * @param protocols the list of protocols, or null
+     * 
+     * @return this builder instance
      */
-    public void setEnabledProtocols(@Nullable final List<String> protocols) {
+    public TLSSocketFactoryBuilder setEnabledProtocols(@Nullable final List<String> protocols) {
         enabledProtocols = new ArrayList<>(StringSupport.normalizeStringCollection(protocols));
         if (enabledProtocols.isEmpty()) {
             enabledProtocols = null;
         }
+        return this;
     }
 
     /**
@@ -248,12 +269,15 @@ public class TLSSocketFactoryBuilder {
      * Set the list of enabled SSL/TLS cipher suites on sockets produced by the factory.
      * 
      * @param cipherSuites the list of cipher suites, or null
+     * 
+     * @return this builder instance
      */
-    public void setEnabledCipherSuites(@Nullable final List<String> cipherSuites) {
+    public TLSSocketFactoryBuilder setEnabledCipherSuites(@Nullable final List<String> cipherSuites) {
         enabledCipherSuites = new ArrayList<>(StringSupport.normalizeStringCollection(cipherSuites));
         if (enabledCipherSuites.isEmpty()) {
             enabledCipherSuites = null;
         }
+        return this;
     }
 
     /**

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list