javax.naming.ldap
Class StartTlsResponse

java.lang.Object sample code for java.lang.Object definition code for java.lang.Object 
  extended by javax.naming.ldap.StartTlsResponse
All Implemented Interfaces:
Serializable sample code for java.io.Serializable definition code for java.io.Serializable , ExtendedResponse sample code for javax.naming.ldap.ExtendedResponse definition code for javax.naming.ldap.ExtendedResponse

public abstract class StartTlsResponse
extends Object sample code for java.lang.Object definition code for java.lang.Object
implements ExtendedResponse sample code for javax.naming.ldap.ExtendedResponse definition code for javax.naming.ldap.ExtendedResponse

This class implements the LDAPv3 Extended Response for StartTLS as defined in Lightweight Directory Access Protocol (v3): Extension for Transport Layer Security The object identifier for StartTLS is 1.3.6.1.4.1.1466.20037 and no extended response value is defined.

The Start TLS extended request and response are used to establish a TLS connection over the existing LDAP connection associated with the JNDI context on which extendedOperation() is invoked. Typically, a JNDI program uses the StartTLS extended request and response classes as follows.

 import javax.naming.ldap.*;
 
 // Open an LDAP association
 LdapContext ctx = new InitialLdapContext();

 // Perform a StartTLS extended operation
 StartTlsResponse tls =
     (StartTlsResponse) ctx.extendedOperation(new StartTlsRequest());

 // Open a TLS connection (over the existing LDAP association) and get details
 // of the negotiated TLS session: cipher suite, peer certificate, ...
 SSLSession session = tls.negotiate();

 // ... use ctx to perform protected LDAP operations

 // Close the TLS connection (revert back to the underlying LDAP association)
 tls.close();

 // ... use ctx to perform unprotected LDAP operations

 // Close the LDAP association
 ctx.close;
 

Since:
1.4
See Also:
StartTlsRequest sample code for javax.naming.ldap.StartTlsRequest definition code for javax.naming.ldap.StartTlsRequest , Serialized Form

Field Summary
static String sample code for java.lang.String definition code for java.lang.String OID sample code for javax.naming.ldap.StartTlsResponse.OID definition code for javax.naming.ldap.StartTlsResponse.OID
          The StartTLS extended response's assigned object identifier is 1.3.6.1.4.1.1466.20037.
 
Constructor Summary
protected StartTlsResponse sample code for javax.naming.ldap.StartTlsResponse.StartTlsResponse() definition code for javax.naming.ldap.StartTlsResponse.StartTlsResponse() ()
          Constructs a StartTLS extended response.
 
Method Summary
abstract  void close sample code for javax.naming.ldap.StartTlsResponse.close() definition code for javax.naming.ldap.StartTlsResponse.close() ()
          Closes the TLS connection gracefully and reverts back to the underlying connection.
 byte[] getEncodedValue sample code for javax.naming.ldap.StartTlsResponse.getEncodedValue() definition code for javax.naming.ldap.StartTlsResponse.getEncodedValue() ()
          Retrieves the StartTLS response's ASN.1 BER encoded value.
 String sample code for java.lang.String definition code for java.lang.String getID sample code for javax.naming.ldap.StartTlsResponse.getID() definition code for javax.naming.ldap.StartTlsResponse.getID() ()
          Retrieves the StartTLS response's object identifier string.
abstract  javax.net.ssl.SSLSession negotiate sample code for javax.naming.ldap.StartTlsResponse.negotiate() definition code for javax.naming.ldap.StartTlsResponse.negotiate() ()
          Negotiates a TLS session using the default SSL socket factory.
abstract  javax.net.ssl.SSLSession negotiate sample code for javax.naming.ldap.StartTlsResponse.negotiate(javax.net.ssl.SSLSocketFactory) definition code for javax.naming.ldap.StartTlsResponse.negotiate(javax.net.ssl.SSLSocketFactory) (javax.net.ssl.SSLSocketFactory factory)
          Negotiates a TLS session using an SSL socket factory.
abstract  void setEnabledCipherSuites sample code for javax.naming.ldap.StartTlsResponse.setEnabledCipherSuites(java.lang.String[]) definition code for javax.naming.ldap.StartTlsResponse.setEnabledCipherSuites(java.lang.String[]) (String sample code for java.lang.String definition code for java.lang.String [] suites)
          Overrides the default list of cipher suites enabled for use on the TLS connection.
abstract  void setHostnameVerifier sample code for javax.naming.ldap.StartTlsResponse.setHostnameVerifier(javax.net.ssl.HostnameVerifier) definition code for javax.naming.ldap.StartTlsResponse.setHostnameVerifier(javax.net.ssl.HostnameVerifier) (javax.net.ssl.HostnameVerifier verifier)
          Sets the hostname verifier used by negotiate() after the TLS handshake has completed and the default hostname verification has failed.
 
Methods inherited from class java.lang.Object sample code for java.lang.Object definition code for java.lang.Object
clone sample code for java.lang.Object.clone() definition code for java.lang.Object.clone() , equals sample code for java.lang.Object.equals(java.lang.Object) definition code for java.lang.Object.equals(java.lang.Object) , finalize sample code for java.lang.Object.finalize() definition code for java.lang.Object.finalize() , getClass sample code for java.lang.Object.getClass() definition code for java.lang.Object.getClass() , hashCode sample code for java.lang.Object.hashCode() definition code for java.lang.Object.hashCode() , notify sample code for java.lang.Object.notify() definition code for java.lang.Object.notify() , notifyAll sample code for java.lang.Object.notifyAll() definition code for java.lang.Object.notifyAll() , toString sample code for java.lang.Object.toString() definition code for java.lang.Object.toString() , wait sample code for java.lang.Object.wait() definition code for java.lang.Object.wait() , wait sample code for java.lang.Object.wait(long) definition code for java.lang.Object.wait(long) , wait sample code for java.lang.Object.wait(long, int) definition code for java.lang.Object.wait(long, int)
 

Field Detail

OID sample code for javax.naming.ldap.StartTlsResponse.OID

public static final String sample code for java.lang.String definition code for java.lang.String  OID
The StartTLS extended response's assigned object identifier is 1.3.6.1.4.1.1466.20037.

See Also:
Constant Field Values
Constructor Detail

StartTlsResponse sample code for javax.naming.ldap.StartTlsResponse() definition code for javax.naming.ldap.StartTlsResponse()

protected StartTlsResponse()
Constructs a StartTLS extended response. A concrete subclass must have a public no-arg constructor.

Method Detail

getID sample code for javax.naming.ldap.StartTlsResponse.getID() definition code for javax.naming.ldap.StartTlsResponse.getID()

public String sample code for java.lang.String definition code for java.lang.String  getID()
Retrieves the StartTLS response's object identifier string.

Specified by:
getID sample code for javax.naming.ldap.ExtendedResponse.getID() definition code for javax.naming.ldap.ExtendedResponse.getID() in interface ExtendedResponse sample code for javax.naming.ldap.ExtendedResponse definition code for javax.naming.ldap.ExtendedResponse
Returns:
The object identifier string, "1.3.6.1.4.1.1466.20037".

getEncodedValue sample code for javax.naming.ldap.StartTlsResponse.getEncodedValue() definition code for javax.naming.ldap.StartTlsResponse.getEncodedValue()

public byte[] getEncodedValue()
Retrieves the StartTLS response's ASN.1 BER encoded value. Since the response has no defined value, null is always returned.

Specified by:
getEncodedValue sample code for javax.naming.ldap.ExtendedResponse.getEncodedValue() definition code for javax.naming.ldap.ExtendedResponse.getEncodedValue() in interface ExtendedResponse sample code for javax.naming.ldap.ExtendedResponse definition code for javax.naming.ldap.ExtendedResponse
Returns:
The null value.

setEnabledCipherSuites sample code for javax.naming.ldap.StartTlsResponse.setEnabledCipherSuites(java.lang.String[]) definition code for javax.naming.ldap.StartTlsResponse.setEnabledCipherSuites(java.lang.String[])

public abstract void setEnabledCipherSuites(String sample code for java.lang.String definition code for java.lang.String [] suites)
Overrides the default list of cipher suites enabled for use on the TLS connection. The cipher suites must have already been listed by SSLSocketFactory.getSupportedCipherSuites() as being supported. Even if a suite has been enabled, it still might not be used because the peer does not support it, or because the requisite certificates (and private keys) are not available.

Parameters:
suites - The non-null list of names of all the cipher suites to enable.
See Also:
negotiate() sample code for javax.naming.ldap.StartTlsResponse.negotiate() definition code for javax.naming.ldap.StartTlsResponse.negotiate()

setHostnameVerifier sample code for javax.naming.ldap.StartTlsResponse.setHostnameVerifier(javax.net.ssl.HostnameVerifier) definition code for javax.naming.ldap.StartTlsResponse.setHostnameVerifier(javax.net.ssl.HostnameVerifier)

public abstract void setHostnameVerifier(javax.net.ssl.HostnameVerifier verifier)
Sets the hostname verifier used by negotiate() after the TLS handshake has completed and the default hostname verification has failed. setHostnameVerifier() must be called before negotiate() is invoked for it to have effect. If called after negotiate(), this method does not do anything.

Parameters:
verifier - The non-null hostname verifier callback.
See Also:
negotiate() sample code for javax.naming.ldap.StartTlsResponse.negotiate() definition code for javax.naming.ldap.StartTlsResponse.negotiate()

negotiate sample code for javax.naming.ldap.StartTlsResponse.negotiate() definition code for javax.naming.ldap.StartTlsResponse.negotiate()

public abstract javax.net.ssl.SSLSession negotiate()
                                            throws IOException sample code for java.io.IOException definition code for java.io.IOException 
Negotiates a TLS session using the default SSL socket factory.

This method is equivalent to negotiate(null).

Returns:
The negotiated SSL session
Throws:
IOException sample code for java.io.IOException definition code for java.io.IOException - If an IO error was encountered while establishing the TLS session.
See Also:
setEnabledCipherSuites(java.lang.String[]) sample code for javax.naming.ldap.StartTlsResponse.setEnabledCipherSuites(java.lang.String[]) definition code for javax.naming.ldap.StartTlsResponse.setEnabledCipherSuites(java.lang.String[]) , setHostnameVerifier(javax.net.ssl.HostnameVerifier) sample code for javax.naming.ldap.StartTlsResponse.setHostnameVerifier(javax.net.ssl.HostnameVerifier) definition code for javax.naming.ldap.StartTlsResponse.setHostnameVerifier(javax.net.ssl.HostnameVerifier)

negotiate sample code for javax.naming.ldap.StartTlsResponse.negotiate(javax.net.ssl.SSLSocketFactory) definition code for javax.naming.ldap.StartTlsResponse.negotiate(javax.net.ssl.SSLSocketFactory)

public abstract javax.net.ssl.SSLSession negotiate(javax.net.ssl.SSLSocketFactory factory)
                                            throws IOException sample code for java.io.IOException definition code for java.io.IOException 
Negotiates a TLS session using an SSL socket factory.

Creates an SSL socket using the supplied SSL socket factory and attaches it to the existing connection. Performs the TLS handshake and returns the negotiated session information.

If cipher suites have been set via setEnabledCipherSuites then they are enabled before the TLS handshake begins.

Hostname verification is performed after the TLS handshake completes. The default hostname verification performs a match of the server's hostname against the hostname information found in the server's certificate. If this verification fails and no callback has been set via setHostnameVerifier then the negotiation fails. If this verification fails and a callback has been set via setHostnameVerifier, then the callback is used to determine whether the negotiation succeeds.

If an error occurs then the SSL socket is closed and an IOException is thrown. The underlying connection remains intact.

Parameters:
factory - The possibly null SSL socket factory to use. If null, the default SSL socket factory is used.
Returns:
The negotiated SSL session
Throws:
IOException sample code for java.io.IOException definition code for java.io.IOException - If an IO error was encountered while establishing the TLS session.
See Also:
setEnabledCipherSuites(java.lang.String[]) sample code for javax.naming.ldap.StartTlsResponse.setEnabledCipherSuites(java.lang.String[]) definition code for javax.naming.ldap.StartTlsResponse.setEnabledCipherSuites(java.lang.String[]) , setHostnameVerifier(javax.net.ssl.HostnameVerifier) sample code for javax.naming.ldap.StartTlsResponse.setHostnameVerifier(javax.net.ssl.HostnameVerifier) definition code for javax.naming.ldap.StartTlsResponse.setHostnameVerifier(javax.net.ssl.HostnameVerifier)

close sample code for javax.naming.ldap.StartTlsResponse.close() definition code for javax.naming.ldap.StartTlsResponse.close()

public abstract void close()
                    throws IOException sample code for java.io.IOException definition code for java.io.IOException 
Closes the TLS connection gracefully and reverts back to the underlying connection.

Throws:
IOException sample code for java.io.IOException definition code for java.io.IOException - If an IO error was encountered while closing the TLS connection