cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1381307 - in /cxf/trunk: api/src/main/java/org/apache/cxf/configuration/jsse/ systests/transports/src/test/java/org/apache/cxf/systest/http/
Date Wed, 05 Sep 2012 19:17:06 GMT
Author: dkulp
Date: Wed Sep  5 19:17:05 2012
New Revision: 1381307

URL: http://svn.apache.org/viewvc?rev=1381307&view=rev
Log:
Add hashCode/equals methods to the TLS stuff so it can be used as part of the keys for the
connection pools

Modified:
    cxf/trunk/api/src/main/java/org/apache/cxf/configuration/jsse/TLSClientParameters.java
    cxf/trunk/api/src/main/java/org/apache/cxf/configuration/jsse/TLSParameterBase.java
    cxf/trunk/systests/transports/src/test/java/org/apache/cxf/systest/http/HTTPConduitTest.java

Modified: cxf/trunk/api/src/main/java/org/apache/cxf/configuration/jsse/TLSClientParameters.java
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/configuration/jsse/TLSClientParameters.java?rev=1381307&r1=1381306&r2=1381307&view=diff
==============================================================================
--- cxf/trunk/api/src/main/java/org/apache/cxf/configuration/jsse/TLSClientParameters.java
(original)
+++ cxf/trunk/api/src/main/java/org/apache/cxf/configuration/jsse/TLSClientParameters.java
Wed Sep  5 19:17:05 2012
@@ -18,6 +18,8 @@
  */
 package org.apache.cxf.configuration.jsse;
 
+import java.util.List;
+
 import javax.net.ssl.SSLSocketFactory;
 
 /**
@@ -122,4 +124,115 @@ public class TLSClientParameters extends
                       boolean useHttpsURLConnectionDefaultHostnameVerifier) {
         this.useHttpsURLConnectionDefaultHostnameVerifier = useHttpsURLConnectionDefaultHostnameVerifier;
     }
+    
+    public int hashCode() {
+        int hash = disableCNCheck ? 37 : 17;
+        hash = hash(hash, sslCacheTimeout);
+        hash = hash(hash, secureRandom);
+        hash = hash(hash, protocol);
+        hash = hash(hash, certAlias);
+        hash = hash(hash, provider);
+        for (String cs : ciphersuites) {
+            hash = hash(hash, cs);
+        }
+        hash = hash(hash, keyManagers);
+        hash = hash(hash, trustManagers);
+        if (cipherSuiteFilters != null) {
+            hash = hash(hash, cipherSuiteFilters.getInclude());
+            hash = hash(hash, cipherSuiteFilters.getExclude());
+        }
+        if (certConstraints != null) {
+            hash = hash(hash, certConstraints.getIssuerDNConstraints());
+            hash = hash(hash, certConstraints.getSubjectDNConstraints());
+        }
+        return hash;
+    }
+    private int hash(int i, Object o) {
+        if (o != null) {
+            i = i * 37 + o.hashCode();
+        }
+        return i;
+    }
+    private int hash(int i, Object[] os) {
+        if (os == null) {
+            return i;
+        }
+        for (Object o: os) {
+            i = hash(i, o);
+        }
+        return i;
+    }
+    
+    public boolean equals(Object o) {
+        if (o == this) {
+            return true;
+        }
+        if (o instanceof TLSClientParameters) {
+            TLSClientParameters that = (TLSClientParameters)o;
+            boolean eq = disableCNCheck == that.disableCNCheck;
+            eq |= sslCacheTimeout == that.sslCacheTimeout;
+            eq |= secureRandom == that.secureRandom;
+            eq |= equals(certAlias, that.certAlias);
+            eq |= equals(protocol, that.protocol);
+            eq |= equals(provider, that.provider);
+            eq |= equals(ciphersuites, that.ciphersuites);
+            eq |= equals(keyManagers, that.keyManagers);
+            eq |= equals(trustManagers, that.trustManagers);
+            if (cipherSuiteFilters != null) {
+                if (that.cipherSuiteFilters != null) {
+                    eq |= equals(cipherSuiteFilters.getExclude(), that.cipherSuiteFilters.getExclude());
+                    eq |= equals(cipherSuiteFilters.getInclude(), that.cipherSuiteFilters.getInclude());
+                } else {
+                    eq = false;
+                }
+            } else {
+                eq |= that.cipherSuiteFilters == null;
+            }
+            if (certConstraints != null) {
+                if (that.certConstraints != null) {
+                    eq |= equals(certConstraints.getIssuerDNConstraints(), 
+                                 that.certConstraints.getIssuerDNConstraints());
+                    eq |= equals(certConstraints.getSubjectDNConstraints(),
+                                 that.certConstraints.getSubjectDNConstraints());
+                } else {
+                    eq = false;
+                }
+            } else {
+                eq |= that.certConstraints == null;
+            }
+            return eq;
+        }
+        return false;
+    }
+    
+    private static boolean equals(final List<?> obj1, final List<?> obj2) {
+        if (obj1.size() == obj2.size()) {
+            for (int x = 0; x < obj1.size(); x++) {
+                if (!equals(obj1.get(x), obj2.get(x))) {
+                    return false;
+                }
+            }
+            return true;
+        }
+        return false;
+    }
+    private static boolean equals(final Object obj1, final Object obj2) {
+        return obj1 == null ? obj2 == null : obj1.equals(obj2);
+    }
+    private static boolean equals(final Object[] a1, final Object[] a2) {
+        if (a1 == null) {
+            return a2 == null;
+        } else {
+            if (a2 != null && a1.length == a2.length) {
+                for (int i = 0; i < a1.length; i++) {
+                    if (!equals(a1[i], a2[i])) {
+                        return false;
+                    }
+                }
+                return true;
+            } else {
+                return false;
+            }
+        }
+    }
 }

Modified: cxf/trunk/api/src/main/java/org/apache/cxf/configuration/jsse/TLSParameterBase.java
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/configuration/jsse/TLSParameterBase.java?rev=1381307&r1=1381306&r2=1381307&view=diff
==============================================================================
--- cxf/trunk/api/src/main/java/org/apache/cxf/configuration/jsse/TLSParameterBase.java (original)
+++ cxf/trunk/api/src/main/java/org/apache/cxf/configuration/jsse/TLSParameterBase.java Wed
Sep  5 19:17:05 2012
@@ -33,15 +33,15 @@ import org.apache.cxf.configuration.secu
  * to both client and server sides.
  */
 public class TLSParameterBase {
-    private KeyManager[]    keyManagers;
-    private TrustManager[]  trustManagers;
-    private String          provider;
-    private List<String>    ciphersuites = new ArrayList<String>();
-    private FiltersType     cipherSuiteFilters;
-    private CertificateConstraintsType certConstraints;
-    private SecureRandom    secureRandom;
-    private String          protocol;
-    private String          certAlias;
+    protected KeyManager[]    keyManagers;
+    protected TrustManager[]  trustManagers;
+    protected String          provider;
+    protected List<String>    ciphersuites = new ArrayList<String>();
+    protected FiltersType     cipherSuiteFilters;
+    protected CertificateConstraintsType certConstraints;
+    protected SecureRandom    secureRandom;
+    protected String          protocol;
+    protected String          certAlias;
     /**
      * Set the JSSE provider. If not set,
      * it uses system default.

Modified: cxf/trunk/systests/transports/src/test/java/org/apache/cxf/systest/http/HTTPConduitTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/transports/src/test/java/org/apache/cxf/systest/http/HTTPConduitTest.java?rev=1381307&r1=1381306&r2=1381307&view=diff
==============================================================================
--- cxf/trunk/systests/transports/src/test/java/org/apache/cxf/systest/http/HTTPConduitTest.java
(original)
+++ cxf/trunk/systests/transports/src/test/java/org/apache/cxf/systest/http/HTTPConduitTest.java
Wed Sep  5 19:17:05 2012
@@ -505,6 +505,10 @@ public class HTTPConduitTest extends Abs
         assertEquals("Set the wrong pass word form the configuration",
                      "password", authPolicy.getPassword());
         String answer = bethal.sayHi();
+        answer = bethal.sayHi();
+        answer = bethal.sayHi();
+        answer = bethal.sayHi();
+        answer = bethal.sayHi();
         assertTrue("Unexpected answer: " + answer, 
                 "Bonjour from Bethal".equals(answer));
     }



Mime
View raw message