1 23 24 29 30 package com.sun.enterprise.admin.jmx.remote.https; 31 32 import java.util.logging.Logger ; 33 import java.util.Map ; 34 import javax.management.remote.JMXServiceURL ; 35 36 import com.sun.enterprise.admin.jmx.remote.DefaultConfiguration; 37 import com.sun.enterprise.admin.jmx.remote.UrlConnector; 38 import com.sun.enterprise.admin.jmx.remote.https.SunOneBasicX509TrustManager; 39 import com.sun.enterprise.admin.jmx.remote.https.SunOneBasicHostNameVerifier; 40 41 import java.lang.reflect.Constructor ; 42 import java.security.SecureRandom ; 43 import java.security.GeneralSecurityException ; 44 import javax.net.ssl.HttpsURLConnection; 45 import javax.net.ssl.SSLContext; 46 import javax.net.ssl.SSLSocketFactory; 47 import javax.net.ssl.X509TrustManager; 48 import javax.net.ssl.X509KeyManager; 49 import javax.net.ssl.HostnameVerifier; 50 51 70 71 public class HttpsUrlConnector extends UrlConnector { 72 73 private HostnameVerifier hv = null; 74 private X509TrustManager[] tms = null; 75 private X509KeyManager[] kms = null; 76 private SSLSocketFactory ssf = null; 77 78 public HttpsUrlConnector(JMXServiceURL serviceUrl, Map environment) { 79 super(serviceUrl, environment); 80 81 hv = (HostnameVerifier)environment.get( 82 DefaultConfiguration.HOSTNAME_VERIFIER_PROPERTY_NAME); 83 if (hv == null) 84 hv = new SunOneBasicHostNameVerifier(serviceUrl.getHost()); 85 86 ssf = (SSLSocketFactory)environment.get( 88 DefaultConfiguration.SSL_SOCKET_FACTORY); 89 90 if (ssf == null) { 93 Object tmgr = environment.get(DefaultConfiguration.TRUST_MANAGER_PROPERTY_NAME); 96 if (tmgr instanceof X509TrustManager[]) 97 tms = (X509TrustManager[])tmgr; 98 else if (tmgr instanceof X509TrustManager) 99 tms = new X509TrustManager[] { (X509TrustManager)tmgr }; 100 else if (tmgr == null) { 101 106 tms = new X509TrustManager[] { new SunOneBasicX509TrustManager(serviceUrl, environment) }; 107 } 108 109 Object kmgr = environment.get(DefaultConfiguration.KEY_MANAGER_PROPERTY_NAME); 111 if (kmgr instanceof X509KeyManager[]) 112 kms = (X509KeyManager[])kmgr; 113 else if (kmgr instanceof X509KeyManager) 114 kms = new X509KeyManager[] { (X509KeyManager)kmgr }; 115 } 116 117 initialize(); 118 } 119 120 protected void validateJmxServiceUrl() throws RuntimeException { 121 } 123 124 protected void validateEnvironment() throws RuntimeException { 125 super.validateEnvironment(); 126 } 127 128 private void initialize() { 129 if (ssf == null) { 130 SSLContext sslContext = null; 131 try { 132 sslContext = SSLContext.getInstance("SSLv3"); 133 sslContext.init(kms, tms, new SecureRandom ()); 134 } catch(GeneralSecurityException e) { 135 throw new RuntimeException (e); 136 } 137 138 if( sslContext != null ) 139 HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory()); 140 141 } else HttpsURLConnection.setDefaultSSLSocketFactory(ssf); 142 143 HttpsURLConnection.setDefaultHostnameVerifier( hv ); 144 } 145 } | Popular Tags |