1 23 package com.sun.enterprise.security.ssl; 24 25 import java.util.HashSet ; 26 import java.util.Iterator ; 27 import java.security.cert.CertificateException ; 28 import java.security.cert.X509Certificate ; 29 import javax.net.ssl.X509TrustManager; 30 31 35 public class UnifiedX509TrustManager implements X509TrustManager { 36 private X509TrustManager[] mgrs = null; 37 private X509Certificate [] issuers = {}; 38 39 public UnifiedX509TrustManager(X509TrustManager[] mgrs) { 40 if (mgrs == null) { 41 throw new IllegalArgumentException ("Null array of X509TrustManagers"); 42 } 43 this.mgrs = mgrs; 44 45 HashSet tset = new HashSet (); for (int i = 0; i < mgrs.length; i++) { 47 X509Certificate [] tcerts = mgrs[i].getAcceptedIssuers(); 48 if (tcerts != null && tcerts.length > 0) { 49 for (int j = 0; j < tcerts.length; j++) { 50 tset.add(tcerts[j]); 51 } 52 } 53 } 54 issuers = new X509Certificate [tset.size()]; 55 Iterator iter = tset.iterator(); 56 for (int i = 0; iter.hasNext(); i++) { 57 issuers[i] = (X509Certificate )iter.next(); 58 } 59 } 60 61 public void checkClientTrusted(X509Certificate [] chain, String authType) 63 throws CertificateException { 64 CertificateException cex = null; 65 for (int i = 0; i < mgrs.length; i++) { 66 try { 67 cex = null; mgrs[i].checkClientTrusted(chain, authType); 69 break; 70 } catch(CertificateException ex) { 71 cex = ex; 72 } 73 } 74 if (cex != null) { 75 throw cex; 76 } 77 } 78 79 public void checkServerTrusted(X509Certificate [] chain, String authType) 80 throws CertificateException { 81 CertificateException cex = null; 82 for (int i = 0; i < mgrs.length; i++) { 83 try { 84 cex = null; mgrs[i].checkServerTrusted(chain, authType); 86 break; 87 } catch(CertificateException ex) { 88 cex = ex; 89 } 90 } 91 if (cex != null) { 92 throw cex; 93 } 94 } 95 96 public X509Certificate [] getAcceptedIssuers() { 97 return issuers; 98 } 99 } 100 | Popular Tags |