Class LdapConnectionFactory
- java.lang.Object
-
- org.forgerock.opendj.ldap.LdapConnectionFactory
-
- All Implemented Interfaces:
Closeable,AutoCloseable,ConnectionFactory
public final class LdapConnectionFactory extends Object implements ConnectionFactory
A factory class which can be used to obtain connections to an LDAP Directory Server. A connection attempt comprises of the following steps:- first of all a TCP connection to the remote LDAP server is obtained. The attempt will fail if a connection is
not obtained within the configured
connect timeout - if LDAPS (not StartTLS) is requested then an SSL handshake is performed. LDAPS is enabled by specifying the
SSL_OPTIONSoption along withSSL_USE_STARTTLSset tofalse - if StartTLS is requested then a StartTLS request is sent and then an SSL handshake performed once the response
has been received. StartTLS is enabled by specifying the
SSL_OPTIONSoption along withSSL_USE_STARTTLSset totrue - an initial authentication request is sent if the
AUTHN_BIND_REQUESToption is specified - the connect attempt will fail if it does not complete within the configured connection timeout. If the SSL handshake, StartTLS request, initial bind request fail for any reason then the connection attempt will be deemed to have failed and an appropriate error returned.
ConnectionExceptiongenerated and published to any registeredConnectionEventListeners. Note however, that keep-alives will only be sent when the connection is determined to be reasonably idle: there is no point in sending keep-alives if the connection has recently received a response. A connection is deemed to be idle if no response has been received during a period equivalent to half the keep-alive interval.The LDAP protocol specifically precludes clients from performing operations while bind or startTLS requests are being performed. Likewise, a bind or startTLS request will cause active operations to be aborted. This factory coordinates keep-alives with bind or startTLS requests, ensuring that they are not performed concurrently. Specifically, bind and startTLS requests are queued up while a keep-alive is pending, and keep-alives are not sent at all while there are pending bind or startTLS requests.
-
-
Field Summary
Fields Modifier and Type Field Description static StringASYNC_RX_TRANSPORTThe name of asynchronous transport implementation which has the value "AsyncRx".static Option<BindRequest>AUTHN_BIND_REQUESTConfigures the connection factory to return pre-authenticated connections using the specifiedBindRequest.static Option<Supplier<BindRequest>>AUTHN_BIND_REQUEST_FACTORYConfigures the connection factory to return pre-authenticated connections usingBindRequestprovided by the specifiedSupplier.static Option<Integer>BUFFER_SIZESize of the buffer used when reading/writing data from/to the network.static Option<DecodeOptions>DECODE_OPTIONSSets the decoding options which will be used to control how requests and responses are decoded.static StringDEFAULT_TRANSPORTThe name of the default transport implementation which has the value "Default".static Option<Integer>MAX_MSG_SIZE_IN_BYTESSpecifies the maximum request size in bytes for incoming LDAP messages.static StringMEMORY_RX_TRANSPORTThe name of the memory transport implementation which has the value "MemoryRx".static Option<IntConsumer>PROBE_BYTES_READCallback invoked each time this server read bytes from the network.static Option<IntConsumer>PROBE_BYTES_WRITTENCallback invoked each time this server write bytes to the network.static Option<Integer>SELECTOR_THREAD_COUNTSpecifies the number of threads which will be used to handle incoming network events.static Option<String>SELECTOR_THREAD_NAMESpecifies the thread name used for selector threads.static Option<Boolean>SO_KEEPALIVESpecifies the value of theSO_KEEPALIVEsocket option for new connections.static Option<Integer>SO_LINGER_IN_SECONDSSpecifies the value of theSO_LINGERsocket option for new connections.static Option<Boolean>SO_REUSE_ADDRESSSpecifies the value of theSO_REUSEADDRsocket option for new connections.static Option<SslOptions>SSL_OPTIONSSpecifies the options to use for the SSL support ornullif SSL is disabled.static Option<Boolean>SSL_USE_STARTTLSSpecifies whether SSL or StartTLS should be used for securing connections when an SSL context is specified.static StringSYNC_RX_TRANSPORTThe name of synchronous transport implementation which has the value "SyncRx".static Option<Boolean>TCP_NO_DELAYSpecifies the value of theTCP_NODELAYsocket option for new connections.static Option<String>TRANSPORTSpecifies the name of the transport implementation to be used.static Option<Duration>WRITE_TIMEOUTMaximum time allowed for write operations to complete.
-
Constructor Summary
Constructors Constructor Description LdapConnectionFactory(String host, int port)Creates a new LDAP connection factory which can be used to create LDAP connections to the Directory Server at the provided host and port number.LdapConnectionFactory(String host, int port, Options options)Creates a new LDAP connection factory which can be used to create LDAP connections to the Directory Server at the provided host and port number.LdapConnectionFactory(LdapClient ldapClient)Creates a new LDAP connection factory which can be used to create LDAP connections to the Directory Server at the provided host and port number.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Releases any resources associated with this connection factory.ConnectiongetConnection()Returns a connection to the Directory Server associated with this connection factory.Promise<Connection,LdapException>getConnectionAsync()Asynchronously obtains a connection to the Directory Server associated with this connection factory.StringtoString()
-
-
-
Field Detail
-
AUTHN_BIND_REQUEST
public static final Option<BindRequest> AUTHN_BIND_REQUEST
Configures the connection factory to return pre-authenticated connections using the specifiedBindRequest. The connections returned by the connection factory will support all operations with the exception of Bind requests. Attempts to perform a Bind will result in anUnsupportedOperationException.If the Bind request fails for some reason (e.g. invalid credentials), then the connection attempt will fail and an
LdapExceptionwill be thrown.
-
AUTHN_BIND_REQUEST_FACTORY
public static final Option<Supplier<BindRequest>> AUTHN_BIND_REQUEST_FACTORY
Configures the connection factory to return pre-authenticated connections usingBindRequestprovided by the specifiedSupplier. The connections returned by the connection factory will support all operations with the exception of Bind requests. Attempts to perform a Bind will result in anUnsupportedOperationException.If the Bind request fails for some reason (e.g. invalid credentials), then the connection attempt will fail and an
LdapExceptionwill be thrown.
-
SSL_USE_STARTTLS
public static final Option<Boolean> SSL_USE_STARTTLS
Specifies whether SSL or StartTLS should be used for securing connections when an SSL context is specified.By default SSL will be used in preference to StartTLS.
-
DEFAULT_TRANSPORT
public static final String DEFAULT_TRANSPORT
The name of the default transport implementation which has the value "Default".- See Also:
- Constant Field Values
-
MEMORY_RX_TRANSPORT
public static final String MEMORY_RX_TRANSPORT
The name of the memory transport implementation which has the value "MemoryRx".- See Also:
- Constant Field Values
-
ASYNC_RX_TRANSPORT
public static final String ASYNC_RX_TRANSPORT
The name of asynchronous transport implementation which has the value "AsyncRx".- See Also:
- Constant Field Values
-
SYNC_RX_TRANSPORT
public static final String SYNC_RX_TRANSPORT
The name of synchronous transport implementation which has the value "SyncRx".- See Also:
- Constant Field Values
-
TRANSPORT
public static final Option<String> TRANSPORT
Specifies the name of the transport implementation to be used. Possible values are:
-
TCP_NO_DELAY
public static final Option<Boolean> TCP_NO_DELAY
Specifies the value of theTCP_NODELAYsocket option for new connections.The default setting is
trueand may be configured using the "org.forgerock.opendj.io.tcpNoDelay" property.
-
SO_REUSE_ADDRESS
public static final Option<Boolean> SO_REUSE_ADDRESS
Specifies the value of theSO_REUSEADDRsocket option for new connections.The default setting is
trueand may be configured using the "org.forgerock.opendj.io.reuseAddress" property.
-
SO_LINGER_IN_SECONDS
public static final Option<Integer> SO_LINGER_IN_SECONDS
Specifies the value of theSO_LINGERsocket option for new connections.The default setting is
-1(disabled) and may be configured using the "org.forgerock.opendj.io.linger" property.
-
SO_KEEPALIVE
public static final Option<Boolean> SO_KEEPALIVE
Specifies the value of theSO_KEEPALIVEsocket option for new connections.The default setting is
trueand may be configured using the "org.forgerock.opendj.io.keepAlive" property.
-
WRITE_TIMEOUT
public static final Option<Duration> WRITE_TIMEOUT
Maximum time allowed for write operations to complete. Once the timeout is reached the socket will become unusable and an appropriate exception returned.
-
BUFFER_SIZE
public static final Option<Integer> BUFFER_SIZE
Size of the buffer used when reading/writing data from/to the network.
-
DECODE_OPTIONS
public static final Option<DecodeOptions> DECODE_OPTIONS
Sets the decoding options which will be used to control how requests and responses are decoded.
-
MAX_MSG_SIZE_IN_BYTES
public static final Option<Integer> MAX_MSG_SIZE_IN_BYTES
Specifies the maximum request size in bytes for incoming LDAP messages. If an incoming request exceeds the limit then the connection will be aborted. Default value is 0, indicating that no limit will be enforced by default.
-
SSL_OPTIONS
public static final Option<SslOptions> SSL_OPTIONS
Specifies the options to use for the SSL support ornullif SSL is disabled.
-
PROBE_BYTES_READ
public static final Option<IntConsumer> PROBE_BYTES_READ
Callback invoked each time this server read bytes from the network. Must be thread-safe.
-
PROBE_BYTES_WRITTEN
public static final Option<IntConsumer> PROBE_BYTES_WRITTEN
Callback invoked each time this server write bytes to the network. Must be thread-safe.
-
SELECTOR_THREAD_COUNT
public static final Option<Integer> SELECTOR_THREAD_COUNT
Specifies the number of threads which will be used to handle incoming network events. Default value is 0, indicating that the selected transport should select a suitable value.
-
-
Constructor Detail
-
LdapConnectionFactory
public LdapConnectionFactory(String host, int port)
Creates a new LDAP connection factory which can be used to create LDAP connections to the Directory Server at the provided host and port number.- Parameters:
host- The host name.port- The port number.- Throws:
NullPointerException- Ifhostwasnull.
-
LdapConnectionFactory
public LdapConnectionFactory(String host, int port, Options options)
Creates a new LDAP connection factory which can be used to create LDAP connections to the Directory Server at the provided host and port number.- Parameters:
host- The host name.port- The port number.options- The LDAP options to use when creating connections.- Throws:
NullPointerException- Ifhostoroptionswasnull.
-
LdapConnectionFactory
public LdapConnectionFactory(LdapClient ldapClient)
Creates a new LDAP connection factory which can be used to create LDAP connections to the Directory Server at the provided host and port number.- Parameters:
ldapClient- The LDAP client used to connect to the Directory Server.- Throws:
NullPointerException- IfldapClientoroptionswasnull.
-
-
Method Detail
-
getConnectionAsync
public Promise<Connection,LdapException> getConnectionAsync()
Description copied from interface:ConnectionFactoryAsynchronously obtains a connection to the Directory Server associated with this connection factory. The returnedPromisecan be used to retrieve the completed connection.- Specified by:
getConnectionAsyncin interfaceConnectionFactory- Returns:
- A promise which can be used to retrieve the connection.
-
getConnection
public Connection getConnection() throws LdapException
Description copied from interface:ConnectionFactoryReturns a connection to the Directory Server associated with this connection factory. The connection returned by this method can be used immediately.If the calling thread is interrupted while waiting for the connection attempt to complete then the calling thread unblock and throw a
CancelledResultExceptionwhose cause is the underlyingInterruptedException.- Specified by:
getConnectionin interfaceConnectionFactory- Returns:
- A connection to the Directory Server associated with this connection factory.
- Throws:
LdapException- If the connection request failed for some reason.
-
close
public void close()
Description copied from interface:ConnectionFactoryReleases any resources associated with this connection factory. Depending on the implementation a factory may:- do nothing
- close underlying connection factories (e.g. load-balancers)
- close pooled connections (e.g. connection pools)
- shutdown IO event service and related thread pools.
closeon a connection factory which is already closed has no effect.Applications should avoid closing connection factories while there are remaining active connections in use or connection attempts in progress.
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceConnectionFactory- See Also:
Connections.uncloseable(ConnectionFactory)
-
-