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_OPTIONS
option along withSSL_USE_STARTTLS
set 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_OPTIONS
option along withSSL_USE_STARTTLS
set totrue
- an initial authentication request is sent if the
AUTHN_BIND_REQUEST
option 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.
ConnectionException
generated and published to any registeredConnectionEventListener
s. 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 String
ASYNC_RX_TRANSPORT
The name of asynchronous transport implementation which has the value "AsyncRx".static Option<BindRequest>
AUTHN_BIND_REQUEST
Configures the connection factory to return pre-authenticated connections using the specifiedBindRequest
.static Option<Supplier<BindRequest>>
AUTHN_BIND_REQUEST_FACTORY
Configures the connection factory to return pre-authenticated connections usingBindRequest
provided by the specifiedSupplier
.static Option<Integer>
BUFFER_SIZE
Size of the buffer used when reading/writing data from/to the network.static Option<Duration>
CONNECT_TIMEOUT
Specifies the connect timeout.static Option<DecodeOptions>
DECODE_OPTIONS
Sets the decoding options which will be used to control how requests and responses are decoded.static String
DEFAULT_TRANSPORT
The name of the default transport implementation which has the value "Default".static Option<Integer>
MAX_MSG_SIZE_IN_BYTES
Specifies the maximum request size in bytes for incoming LDAP messages.static String
MEMORY_RX_TRANSPORT
The name of the memory transport implementation which has the value "MemoryRx".static Option<IntConsumer>
PROBE_BYTES_READ
Callback invoked each time this server read bytes from the network.static Option<IntConsumer>
PROBE_BYTES_WRITTEN
Callback invoked each time this server write bytes to the network.static Option<ProxyProtocolHeader>
PROXY_PROTOCOL_HEADER_CLIENT
Enables the proxy protocol for client connections using the provided proxy header.static Option<Set<AddressMask>>
PROXY_PROTOCOL_SERVER_ALLOWED_CLIENTS
Specifies the clients that are allowed to access the server and that should use proxy protocol.static Option<Boolean>
PROXY_PROTOCOL_SERVER_ENABLED
Indicates if the proxy protocol is enabled on the server .static Option<Integer>
SELECTOR_THREAD_COUNT
Specifies the number of threads which will be used to handle incoming network events.static Option<String>
SELECTOR_THREAD_NAME
Specifies the thread name used for selector threads.static Option<Boolean>
SO_KEEPALIVE
Specifies the value of theSO_KEEPALIVE
socket option for new connections.static Option<Integer>
SO_LINGER_IN_SECONDS
Specifies the value of theSO_LINGER
socket option for new connections.static Option<Boolean>
SO_REUSE_ADDRESS
Specifies the value of theSO_REUSEADDR
socket option for new connections.static Option<SslOptions>
SSL_OPTIONS
Specifies the options to use for the SSL support ornull
if SSL is disabled.static Option<Boolean>
SSL_USE_STARTTLS
Specifies whether SSL or StartTLS should be used for securing connections when an SSL context is specified.static String
SYNC_RX_TRANSPORT
The name of synchronous transport implementation which has the value "SyncRx".static Option<Boolean>
TCP_NO_DELAY
Specifies the value of theTCP_NODELAY
socket option for new connections.static Option<String>
TRANSPORT
Specifies the name of the transport implementation to be used.static Option<Duration>
WRITE_TIMEOUT
Maximum 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 void
close()
Releases any resources associated with this connection factory.Connection
getConnection()
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.String
toString()
-
-
-
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
LdapException
will 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 usingBindRequest
provided 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
LdapException
will 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_NODELAY
socket option for new connections.The default setting is
true
and 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_REUSEADDR
socket option for new connections.The default setting is
true
and 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_LINGER
socket 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_KEEPALIVE
socket option for new connections.The default setting is
true
and may be configured using the "org.forgerock.opendj.io.keepAlive" property.
-
CONNECT_TIMEOUT
public static final Option<Duration> CONNECT_TIMEOUT
Specifies the connect timeout. If a connection is not established within the timeout period (incl. SSL negotiation, initial bind request, keep-alive, availability check), then aTimeoutResultException
error result will be returned.The default operation timeout is 10 seconds and may be configured using the "org.forgerock.opendj.io.connectTimeout" property. A timeout setting of 0 causes the OS connect timeout to be used.
-
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 ornull
if 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.
-
SELECTOR_THREAD_NAME
public static final Option<String> SELECTOR_THREAD_NAME
Specifies the thread name used for selector threads.
-
PROXY_PROTOCOL_HEADER_CLIENT
public static final Option<ProxyProtocolHeader> PROXY_PROTOCOL_HEADER_CLIENT
Enables the proxy protocol for client connections using the provided proxy header.
-
PROXY_PROTOCOL_SERVER_ENABLED
public static final Option<Boolean> PROXY_PROTOCOL_SERVER_ENABLED
Indicates if the proxy protocol is enabled on the server .
-
PROXY_PROTOCOL_SERVER_ALLOWED_CLIENTS
public static final Option<Set<AddressMask>> PROXY_PROTOCOL_SERVER_ALLOWED_CLIENTS
Specifies the clients that are allowed to access the server and that should use proxy protocol.
-
-
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
- Ifhost
wasnull
.
-
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
- Ifhost
oroptions
wasnull
.
-
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
- IfldapClient
oroptions
wasnull
.
-
-
Method Detail
-
getConnectionAsync
public Promise<Connection,LdapException> getConnectionAsync()
Description copied from interface:ConnectionFactory
Asynchronously obtains a connection to the Directory Server associated with this connection factory. The returnedPromise
can be used to retrieve the completed connection.- Specified by:
getConnectionAsync
in interfaceConnectionFactory
- Returns:
- A promise which can be used to retrieve the connection.
-
getConnection
public Connection getConnection() throws LdapException
Description copied from interface:ConnectionFactory
Returns 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
CancelledResultException
whose cause is the underlyingInterruptedException
.- Specified by:
getConnection
in 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:ConnectionFactory
Releases 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.
close
on 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:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfaceConnectionFactory
- See Also:
Connections.uncloseable(ConnectionFactory)
-
-