APIdia Launch Partner
Top Description Inners Fields Constructors Methods
com.sun.jndi.ldap

public final Class Connection

extends Object
implements Runnable
Class Inheritance
All Implemented Interfaces
java.lang.Runnable
Imports
java.io.BufferedInputStream, .BufferedOutputStream, .InterruptedIOException, .IOException, .OutputStream, .InputStream, java.net.InetSocketAddress, .Socket, javax.net.ssl.SSLSocket, .SSLParameters, .HandshakeCompletedEvent, .HandshakeCompletedListener, .SSLPeerUnverifiedException, javax.naming.CommunicationException, .NamingException, .InterruptedNamingException, javax.naming.ldap.Control, java.lang.reflect.Method, .InvocationTargetException, java.security.cert.Certificate, .X509Certificate, java.util.Arrays, java.util.concurrent.CompletableFuture, .ExecutionException, java.util.concurrent.locks.Condition, .ReentrantLock, javax.net.SocketFactory, javax.security.sasl.SaslException, jdk.internal.misc.InnocuousThread

A thread that creates a connection to an LDAP server. After the connection, the thread reads from the connection. A caller can invoke methods on the instance to read LDAP responses and to send LDAP requests.

There is a one-to-one correspondence between an LdapClient and a Connection. Access to Connection and its methods is only via LdapClient with two exceptions: SASL authentication and StartTLS. SASL needs to access Connection's socket IO streams (in order to do encryption of the security layer). StartTLS needs to do replace IO streams and close the IO streams on nonfatal close. The code for SASL authentication can be treated as being the same as from LdapClient because the SASL code is only ever called from LdapClient, from inside LdapClient's synchronized authenticate() method. StartTLS is called directly by the application but should only occur when the underlying connection is quiet.

In terms of synchronization, worry about data structures used by the Connection thread because that usage might contend with calls by the main threads (i.e., those that call LdapClient). Main threads need to worry about contention with each other. Fields that Connection thread uses: inStream - synced access and update; initialized in constructor; referenced outside class unsync'ed (by LdapSasl) only when connection is quiet traceFile, traceTagIn, traceTagOut - no sync; debugging only parent - no sync; initialized in constructor; no updates pendingRequests - sync pauseLock - per-instance lock; paused - sync via pauseLock (pauseReader()) Members used by main threads (LdapClient): host, port - unsync; read-only access for StartTLS and debug messages setBound(), setV3() - no sync; called only by LdapClient.authenticate(), which is a sync method called only when connection is "quiet" getMsgId() - sync writeRequest(), removeRequest(),findRequest(), abandonOutstandingReqs() - access to shared pendingRequests is sync writeRequest(), abandonRequest(), ldapUnbind() - access to outStream sync cleanup() - sync readReply() - access to sock sync unpauseReader() - (indirectly via writeRequest) sync on pauseLock Members used by SASL auth (main thread): inStream, outStream - no sync; used to construct new stream; accessed only when conn is "quiet" and not shared replaceStreams() - sync method Members used by StartTLS: inStream, outStream - no sync; used to record the existing streams; accessed only when conn is "quiet" and not shared replaceStreams() - sync method

Handles anonymous, simple, and SASL bind for v3; anonymous and simple for v2. %%% made public for access by LdapSasl %%%

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class

Field Summary

Modifier and TypeField and Description
private boolean
pack-priv volatile IOException
pack-priv int
private static final boolean
public final String
public InputStream
private static final boolean
private volatile boolean
private final ReentrantLock
private int
public OutputStream
private final LdapClient
private final Condition
private boolean
private final ReentrantLock
private LdapRequest
public final int
pack-priv int
public Socket
pack-priv final ReentrantLock
private volatile Connection.HandshakeListener
private OutputStream
private String
private String
pack-priv volatile boolean
private boolean
private final Thread

Constructor Summary

AccessConstructor and Description
pack-priv
Connection(LdapClient parent, String host, int port, String socketFactory, int connectTimeout, int readTimeout, OutputStream trace)

Method Summary

Modifier and TypeMethod and Description
pack-priv void
pack-priv void
private void
addRequest(LdapRequest ldapRequest)

pack-priv void
cleanup(Control[]
Possibly null request controls that accompanies the abandon and unbind LDAP request.
reqCtls
,
boolean
true means to call parent LdapClient back, notifying it that the connection has been closed; false means not to notify parent. If LdapClient invokes cleanup(), notifyParent should be set to false because LdapClient already knows that it is closing the connection. If Connection invokes cleanup(), notifyParent should be set to true because LdapClient needs to know about the closure.
notifyParent
)

private void
private Socket
createConnectionSocket(String host, int port, SocketFactory factory, int connectTimeout)

private InetSocketAddress
private Socket
createSocket(String host, int port, String socketFactory, int connectTimeout)

pack-priv LdapRequest
findRequest(int msgId)

private void
private InputStream
getInputStream()

Used by Connection thread to read inStream into a local variable.

pack-priv int
private SocketFactory
getSocketFactory(String socketFactoryName)

public X509Certificate
private static boolean
private void
initialSSLHandshake(SSLSocket sslSocket, int connectTimeout)

public boolean
public boolean
private void
ldapUnbind(Control[] reqCtls)

private void
private static byte[]
readFully(InputStream is, int length)

pack-priv BerDecoder
readReply(LdapRequest ldr)

Reads a reply; waits until one is ready.

pack-priv void
public void
public void
replaceStreams(InputStream newIn, OutputStream newOut, boolean isStartTls)

public void
run()

Implements java.lang.Runnable.run.

Runs this operation.

pack-priv void
public void
pack-priv void
setV3(boolean v)

private void
private void
pack-priv LdapRequest
writeRequest(BerEncoder ber, int msgId)

pack-priv LdapRequest
writeRequest(BerEncoder ber, int msgId, boolean pauseAfterReceipt)

pack-priv LdapRequest
writeRequest(BerEncoder ber, int msgId, boolean pauseAfterReceipt, int replyQueueCapacity)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

boundback to summary
private boolean bound
closureReasonback to summary
pack-priv volatile IOException closureReason
connectTimeoutback to summary
pack-priv int connectTimeout
debugback to summary
private static final boolean debug
hostback to summary
public final String host
inStreamback to summary
public InputStream inStream
IS_HOSTNAME_VERIFICATION_DISABLEDback to summary
private static final boolean IS_HOSTNAME_VERIFICATION_DISABLED
isUpgradedToStartTlsback to summary
private volatile boolean isUpgradedToStartTls
lockback to summary
private final ReentrantLock lock
outMsgIdback to summary
private int outMsgId
outStreamback to summary
public OutputStream outStream
parentback to summary
private final LdapClient parent
pauseConditionback to summary
private final Condition pauseCondition
pausedback to summary
private boolean paused
pauseLockback to summary
private final ReentrantLock pauseLock
pendingRequestsback to summary
private LdapRequest pendingRequests
portback to summary
public final int port
readTimeoutback to summary
pack-priv int readTimeout
sockback to summary
public Socket sock
startTlsLockback to summary
pack-priv final ReentrantLock startTlsLock
tlsHandshakeListenerback to summary
private volatile Connection.HandshakeListener tlsHandshakeListener
traceFileback to summary
private OutputStream traceFile
traceTagInback to summary
private String traceTagIn
traceTagOutback to summary
private String traceTagOut
useableback to summary
pack-priv volatile boolean useable
v3back to summary
private boolean v3
workerback to summary
private final Thread worker

Constructor Detail

Connectionback to summary
pack-priv Connection(LdapClient parent, String host, int port, String socketFactory, int connectTimeout, int readTimeout, OutputStream trace) throws NamingException

Method Detail

abandonOutstandingReqsback to summary
pack-priv void abandonOutstandingReqs(Control[] reqCtls)
abandonRequestback to summary
pack-priv void abandonRequest(LdapRequest ldr, Control[] reqCtls)
addRequestback to summary
private void addRequest(LdapRequest ldapRequest)
cleanupback to summary
pack-priv void cleanup(Control[] reqCtls, boolean notifyParent)
Parameters
reqCtls:Control[]

Possibly null request controls that accompanies the abandon and unbind LDAP request.

notifyParent:boolean

true means to call parent LdapClient back, notifying it that the connection has been closed; false means not to notify parent. If LdapClient invokes cleanup(), notifyParent should be set to false because LdapClient already knows that it is closing the connection. If Connection invokes cleanup(), notifyParent should be set to true because LdapClient needs to know about the closure.

closeOpenedSocketback to summary
private void closeOpenedSocket(Socket socket)
createConnectionSocketback to summary
private Socket createConnectionSocket(String host, int port, SocketFactory factory, int connectTimeout) throws IOException
createInetSocketAddressback to summary
private InetSocketAddress createInetSocketAddress(String host, int port)
createSocketback to summary
private Socket createSocket(String host, int port, String socketFactory, int connectTimeout) throws Exception
findRequestback to summary
pack-priv LdapRequest findRequest(int msgId)
flushAndCloseOutputStreamback to summary
private void flushAndCloseOutputStream()
getInputStreamback to summary
private InputStream getInputStream()

Used by Connection thread to read inStream into a local variable. This ensures that there is no contention between the main thread and the Connection thread when the main thread updates inStream.

getMsgIdback to summary
pack-priv int getMsgId()
getSocketFactoryback to summary
private SocketFactory getSocketFactory(String socketFactoryName) throws Exception
getTlsServerCertificateback to summary
public X509Certificate getTlsServerCertificate() throws SaslException
hostnameVerificationDisabledValueback to summary
private static boolean hostnameVerificationDisabledValue()
initialSSLHandshakeback to summary
private void initialSSLHandshake(SSLSocket sslSocket, int connectTimeout) throws Exception
isTlsConnectionback to summary
public boolean isTlsConnection()
isUpgradedToStartTlsback to summary
public boolean isUpgradedToStartTls()
ldapUnbindback to summary
private void ldapUnbind(Control[] reqCtls)
pauseReaderback to summary
private void pauseReader() throws IOException
readFullyback to summary
private static byte[] readFully(InputStream is, int length) throws IOException
readReplyback to summary
pack-priv BerDecoder readReply(LdapRequest ldr) throws NamingException

Reads a reply; waits until one is ready.

removeRequestback to summary
pack-priv void removeRequest(LdapRequest req)
replaceStreamsback to summary
public void replaceStreams(InputStream newIn, OutputStream newOut)
replaceStreamsback to summary
public void replaceStreams(InputStream newIn, OutputStream newOut, boolean isStartTls)
runback to summary
public void run()

Implements java.lang.Runnable.run.

Doc from java.lang.Runnable.run.

Runs this operation.

Annotations
@Override
setBoundback to summary
pack-priv void setBound()
setHandshakeCompletedListenerback to summary
public void setHandshakeCompletedListener(SSLSocket sslSocket)
setV3back to summary
pack-priv void setV3(boolean v)
tryUnpauseReaderback to summary
private void tryUnpauseReader()
unpauseReaderback to summary
private void unpauseReader() throws IOException
writeRequestback to summary
pack-priv LdapRequest writeRequest(BerEncoder ber, int msgId) throws IOException
writeRequestback to summary
pack-priv LdapRequest writeRequest(BerEncoder ber, int msgId, boolean pauseAfterReceipt) throws IOException
writeRequestback to summary
pack-priv LdapRequest writeRequest(BerEncoder ber, int msgId, boolean pauseAfterReceipt, int replyQueueCapacity) throws IOException
com.sun.jndi.ldap back to summary

private Class Connection.HandshakeListener

extends Object
implements HandshakeCompletedListener
Class Inheritance
All Implemented Interfaces
javax.net.ssl.HandshakeCompletedListener, java.util.EventListener

Field Summary

Modifier and TypeField and Description
private final CompletableFuture<X509Certificate>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
handshakeCompleted(HandshakeCompletedEvent event)

Implements javax.net.ssl.HandshakeCompletedListener.handshakeCompleted.

This method is invoked on registered objects when a SSL handshake is completed.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

tlsHandshakeCompletedback to summary
private final CompletableFuture<X509Certificate> tlsHandshakeCompleted

Constructor Detail

HandshakeListenerback to summary
private HandshakeListener()

Method Detail

handshakeCompletedback to summary
public void handshakeCompleted(HandshakeCompletedEvent event)

Implements javax.net.ssl.HandshakeCompletedListener.handshakeCompleted.

Doc from javax.net.ssl.HandshakeCompletedListener.handshakeCompleted.

This method is invoked on registered objects when a SSL handshake is completed.

Annotations
@Override