FileDocCategorySizeDatePackage
Connect.javaAPI DocGlassfish v2 API6538Fri May 04 22:30:50 BST 2007com.sun.appserv.management.helper

Connect

public class Connect extends Object
Miscellaneous helper routines for connecting to the Appserver.
since
AppServer 9.0

Fields Summary
Constructors Summary
private Connect()

Methods Summary
public static com.sun.appserv.management.client.AppserverConnectionSourceconnectNoTLS(java.lang.String host, int port, java.lang.String user, java.lang.String userPassword)

		return new AppserverConnectionSource(
				host, port, user, userPassword, null);
	
public static com.sun.appserv.management.client.AppserverConnectionSourceconnectTLS(java.lang.String host, int port, java.lang.String user, java.lang.String userPassword, boolean promptForUnknownCertificate)
Connect to an Appserver using TLS (SSL) using the default TrustStore and default TrustStore password.

If the server certificate is unknown, prompting will occur via System.out if 'promptForNewCertificate' is true; otherwise the connection will be rejected.

If a new server certificate is found, and the user enters "yes", then it is added to the default truststore.

param
host hostname or IP address
param
port port to which to connect
param
user admin user name
param
userPassword password for specified user
param
promptForUnknownCertificate prompts via System.out if the server certificate is unrecognized, otherwise rejects the connection

		final TLSParams	tlsParams	= createTLSParams( null, promptForUnknownCertificate );
		
		return new AppserverConnectionSource( AppserverConnectionSource.PROTOCOL_RMI,
				host, port, user, userPassword, tlsParams, null);
	
public static com.sun.appserv.management.client.TLSParamscreateTLSParams(java.lang.String trustStorePassword, boolean promptForNewCertificate)
Get TLSParams for the default truststore, assuming the default password.

param
trustStorePassword a truststore, or null for the default one
param
promptForNewCertificate

		return createTLSParams( null, trustStorePassword , promptForNewCertificate);
	
public static com.sun.appserv.management.client.TLSParamscreateTLSParams(java.io.File trustStore, java.lang.String trustStorePasswordIn, boolean promptForUnknownCertificate)
Get TLSParams for the specified truststore and password.

A {@link HandshakeCompletedListener} is installed which may be obtained by calling {@link TLSParams#getHandshakeCompletedListener}.

If a new server certificate is found, and the user enters "yes" in response to prompting, then the certificate is added to the truststore.

param
trustStore a truststore, or null for the default one
param
trustStorePasswordIn the truststore password, if null the default one will be used
param
promptForUnknownCertificate prompts via System.out if the server certificate is unrecognized

		final File		trustStoreFile	= (trustStore == null) ? getDefaultTrustStore() : trustStore;
		final char[]	trustStorePassword	= ((trustStorePasswordIn == null) ?
			AppserverConnectionSource.DEFAULT_TRUST_STORE_PASSWORD : trustStorePasswordIn).toCharArray();
					
		final HandshakeCompletedListener	handshakeCompletedListener	=
			new HandshakeCompletedListenerImpl();
			
		final TrustStoreTrustManager trustMgr =
			new TrustStoreTrustManager( trustStoreFile, trustStorePassword);
			
		trustMgr.setPrompt( promptForUnknownCertificate );

		final TLSParams	tlsParams = new TLSParams( trustMgr, handshakeCompletedListener );

		return( tlsParams );
	
public static java.io.FilegetDefaultTrustStore()
The File will use the name {@link AppserverConnectionSource#DEFAULT_TRUST_STORE_NAME} in the user's home directory.

return
a File for the default truststore. May not yet exist.

		final String homeDir = System.getProperty( "user.home" );
		final String sep     = System.getProperty( "file.separator" );
		
		return new File ( homeDir + sep + AppserverConnectionSource.DEFAULT_TRUST_STORE_NAME );