1 23 24 29 package com.sun.appserv.management.helper; 30 31 import java.io.File ; 32 import java.io.FileInputStream ; 33 import java.io.IOException ; 34 35 import javax.net.ssl.HandshakeCompletedListener; 36 37 import com.sun.appserv.management.base.UploadDownloadMgr; 38 39 import com.sun.appserv.management.DomainRoot; 40 import com.sun.appserv.management.client.TLSParams; 41 import com.sun.appserv.management.client.AppserverConnectionSource; 42 import com.sun.appserv.management.client.HandshakeCompletedListenerImpl; 43 import com.sun.appserv.management.client.TrustStoreTrustManager; 44 45 49 public class Connect 50 { 51 private Connect() {} 52 53 70 public static AppserverConnectionSource 71 connectTLS( 72 final String host, 73 final int port, 74 final String user, 75 final String userPassword, 76 final boolean promptForUnknownCertificate ) 77 throws IOException 78 { 79 final TLSParams tlsParams = createTLSParams( null, promptForUnknownCertificate ); 80 81 return new AppserverConnectionSource( AppserverConnectionSource.PROTOCOL_RMI, 82 host, port, user, userPassword, tlsParams, null); 83 } 84 85 86 public static AppserverConnectionSource 87 connectNoTLS( 88 final String host, 89 final int port, 90 final String user, 91 final String userPassword) 92 throws IOException 93 { 94 return new AppserverConnectionSource( 95 host, port, user, userPassword, null); 96 } 97 98 99 106 public static File 107 getDefaultTrustStore() 108 { 109 final String homeDir = System.getProperty( "user.home" ); 110 final String sep = System.getProperty( "file.separator" ); 111 112 return new File ( homeDir + sep + AppserverConnectionSource.DEFAULT_TRUST_STORE_NAME ); 113 } 114 115 121 public static TLSParams 122 createTLSParams( 123 final String trustStorePassword, 124 final boolean promptForNewCertificate) 125 { 126 return createTLSParams( null, trustStorePassword , promptForNewCertificate); 127 } 128 129 130 144 public static TLSParams 145 createTLSParams( 146 final File trustStore, 147 final String trustStorePasswordIn, 148 final boolean promptForUnknownCertificate ) 149 { 150 final File trustStoreFile = (trustStore == null) ? getDefaultTrustStore() : trustStore; 151 final char[] trustStorePassword = ((trustStorePasswordIn == null) ? 152 AppserverConnectionSource.DEFAULT_TRUST_STORE_PASSWORD : trustStorePasswordIn).toCharArray(); 153 154 final HandshakeCompletedListener handshakeCompletedListener = 155 new HandshakeCompletedListenerImpl(); 156 157 final TrustStoreTrustManager trustMgr = 158 new TrustStoreTrustManager( trustStoreFile, trustStorePassword); 159 160 trustMgr.setPrompt( promptForUnknownCertificate ); 161 162 final TLSParams tlsParams = new TLSParams( trustMgr, handshakeCompletedListener ); 163 164 return( tlsParams ); 165 } 166 } 167 168 169 170 171 172 173 174 | Popular Tags |