Class LdapServer
- All Implemented Interfaces:
Closeable
,AutoCloseable
When processing requests, server connection implementations are passed an integer as the first parameter. This
integer represents the requestID
associated with the client request and corresponds to the requestID
passed as a parameter to abandon and cancel extended requests. The request ID may also be useful for logging
purposes.
An LdapServer
does not require server connection implementations to return a result when processing
requests. More specifically, an LdapServer
does not maintain any internal state information associated with
each request which must be released. This is useful when implementing LDAP abandon operations which may prevent
results being sent for abandoned operations.
The following code illustrates how to create a simple LDAP server:
/** Server connection. */ class MyClientConnection implements BiFunction<Integer, Request, Flowable<Response>> { private final LDAPClientContext clientContext; private MyClientConnection(LDAPClientContext clientContext) { this.clientContext = clientContext; } public Flowable<Response> apply(Integer requestID, Request request) throws Exception { // ... } } /** Server connection factory. */ class MyServer implements Function<LdapSession, BiFunction<Integer, Request, Flowable<Response>>> { public BiFunction<Integer, Request, Flowable<Response>> accept(LDAPClientContext context) { System.out.println("Connection from: " + context.getPeerAddress()); return new MyClientConnection(context); } } public static void main(String[] args) throws Exception { try (LdapServer server = new LdapServer(1389, new MyServer())) { // ... } }
-
Field Summary
Modifier and TypeFieldDescriptionA consumer which is invoked immediately after a new connection has been accepted in order to determine whether the connection should be accepted or not, in which case it will be closed immediately.static final String
The name of asynchronous transport implementation which has the value "AsyncRx".Size of the buffer used when reading/writing data from/to the network.Specifies the maximum queue length for incoming connections requests.static final Option<DecodeOptions>
Sets the decoding options which will be used to control how requests and responses are decoded.static final String
The name of the default transport implementation which has the value "Default".Specifies the maximum number of concurrent requests per connection.Specifies the maximum request size in bytes for incoming LDAP messages.static final String
The name of the memory transport implementation which has the value "MemoryRx".static final Option<IntConsumer>
Callback invoked each time this server read bytes from the network.static final Option<IntConsumer>
Callback invoked each time this server write bytes to the network.static final Option<Set<AddressMask>>
Specifies the clients that are allowed to access the server and that should use proxy protocol.Indicates if the proxy protocol is enabled on the server .Specifies the number of threads which will be used to handle incoming network events.Specifies the thread name used for selector threads.Specifies the value of theSO_KEEPALIVE
socket option for new connections.Specifies the value of theSO_LINGER
socket option for new connections.Specifies the value of theSO_REUSEADDR
socket option for new connections.static final Option<SslOptions>
Specifies the options to use for the SSL support ornull
if SSL is disabled.static final String
The name of synchronous transport implementation which has the value "SyncRx".Specifies the value of theTCP_NODELAY
socket option for new connections.Specifies the name of the transport implementation to be used.Maximum time allowed for write operations to complete. -
Constructor Summary
ConstructorDescriptionLdapServer
(int port, Function<LdapSession, BiFunction<Integer, Request, Flowable<Response>>> factory) Creates a new LDAP listener implementation which will listen for LDAP client connections at the provided address.LdapServer
(int port, Function<LdapSession, BiFunction<Integer, Request, Flowable<Response>>> factory, Options options) Creates a new LDAP listener implementation which will listen for LDAP client connections at the provided address.LdapServer
(String host, int port, Function<LdapSession, BiFunction<Integer, Request, Flowable<Response>>> factory) Creates a new LDAP listener implementation which will listen for LDAP client connections at the provided address.LdapServer
(String host, int port, Function<LdapSession, BiFunction<Integer, Request, Flowable<Response>>> factory, Options options) Creates a new LDAP listener implementation which will listen for LDAP client connections at the provided address.LdapServer
(Set<InetSocketAddress> addresses, Function<LdapSession, BiFunction<Integer, Request, Flowable<Response>>> factory) Creates a new LDAP listener implementation which will listen for LDAP client connections at the provided address.LdapServer
(Set<InetSocketAddress> addresses, Function<LdapSession, BiFunction<Integer, Request, Flowable<Response>>> factory, Options options) Creates a new LDAP listener implementation which will listen for LDAP client connections at the provided address. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Closes this LDAP connection listener.Returns the first address that his LDAP listener is listening on.Returns a copy of the options currently used by this LDAP listener.Returns the addresses that this LDAP listener is listening on.void
setOptions
(Options options) Updates the options of this LDAP listener.toString()
-
Field Details
-
CONNECT_MAX_BACKLOG
Specifies the maximum queue length for incoming connections requests. If a connection request arrives when the queue is full, the connection is refused. -
MAX_CONCURRENT_REQUESTS
Specifies the maximum number of concurrent requests per connection. Once this number is reached, back-pressure mechanism will stop reading requests from the connection. -
PROXY_PROTOCOL_SERVER_ENABLED
Indicates if the proxy protocol is enabled on the server . -
PROXY_PROTOCOL_SERVER_ALLOWED_CLIENTS
Specifies the clients that are allowed to access the server and that should use proxy protocol. -
ACCEPTED_CLIENT_VALIDATOR
A consumer which is invoked immediately after a new connection has been accepted in order to determine whether the connection should be accepted or not, in which case it will be closed immediately. Implementations should throw an appropriate exception if the connection should be rejected. -
DEFAULT_TRANSPORT
The name of the default transport implementation which has the value "Default".- See Also:
-
MEMORY_RX_TRANSPORT
The name of the memory transport implementation which has the value "MemoryRx".- See Also:
-
ASYNC_RX_TRANSPORT
The name of asynchronous transport implementation which has the value "AsyncRx".- See Also:
-
SYNC_RX_TRANSPORT
The name of synchronous transport implementation which has the value "SyncRx".- See Also:
-
TRANSPORT
Specifies the name of the transport implementation to be used. Possible values are: -
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
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
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
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. -
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
Size of the buffer used when reading/writing data from/to the network. -
DECODE_OPTIONS
Sets the decoding options which will be used to control how requests and responses are decoded. -
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
Specifies the options to use for the SSL support ornull
if SSL is disabled. -
PROBE_BYTES_READ
Callback invoked each time this server read bytes from the network. Must be thread-safe. -
PROBE_BYTES_WRITTEN
Callback invoked each time this server write bytes to the network. Must be thread-safe. -
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
Specifies the thread name used for selector threads.
-
-
Constructor Details
-
LdapServer
public LdapServer(int port, Function<LdapSession, BiFunction<Integer, throws IOExceptionRequest, Flowable<Response>>> factory) Creates a new LDAP listener implementation which will listen for LDAP client connections at the provided address.- Parameters:
port
- The port to listen on.factory
- The handler factory which will be used to create handlers.- Throws:
IOException
- If an error occurred while trying to listen on the provided address.NullPointerException
- If {code factory} wasnull
.
-
LdapServer
public LdapServer(int port, Function<LdapSession, BiFunction<Integer, throws IOExceptionRequest, Flowable<Response>>> factory, Options options) Creates a new LDAP listener implementation which will listen for LDAP client connections at the provided address.- Parameters:
port
- The port to listen on.factory
- The handler factory which will be used to create handlers.options
- The LDAP listener options.- Throws:
IOException
- If an error occurred while trying to listen on the provided address.NullPointerException
- If {code factory} oroptions
wasnull
.
-
LdapServer
public LdapServer(Set<InetSocketAddress> addresses, Function<LdapSession, BiFunction<Integer, throws IOExceptionRequest, Flowable<Response>>> factory) Creates a new LDAP listener implementation which will listen for LDAP client connections at the provided address.- Parameters:
addresses
- The addresses to listen on.factory
- The handler factory which will be used to create handlers.- Throws:
IOException
- If an error occurred while trying to listen on the provided address.NullPointerException
- Ifaddress
or {code factory} wasnull
.
-
LdapServer
public LdapServer(Set<InetSocketAddress> addresses, Function<LdapSession, BiFunction<Integer, throws IOExceptionRequest, Flowable<Response>>> factory, Options options) Creates a new LDAP listener implementation which will listen for LDAP client connections at the provided address.- Parameters:
addresses
- The addresses to listen on.factory
- The handler factory which will be used to create handlers.options
- The LDAP listener options.- Throws:
IOException
- If an error occurred while trying to listen on the provided address.NullPointerException
- Ifaddress
, {code factory}, oroptions
wasnull
.
-
LdapServer
public LdapServer(String host, int port, Function<LdapSession, BiFunction<Integer, throws IOExceptionRequest, Flowable<Response>>> factory) Creates a new LDAP listener implementation which will listen for LDAP client connections at the provided address.- Parameters:
host
- The address to listen on.port
- The port to listen on.factory
- The handler factory which will be used to create handlers.- Throws:
IOException
- If an error occurred while trying to listen on the provided address.NullPointerException
- Ifhost
or {code factory} wasnull
.
-
LdapServer
public LdapServer(String host, int port, Function<LdapSession, BiFunction<Integer, throws IOExceptionRequest, Flowable<Response>>> factory, Options options) Creates a new LDAP listener implementation which will listen for LDAP client connections at the provided address.- Parameters:
host
- The address to listen on.port
- The port to listen on.factory
- The handler factory which will be used to create handlers.options
- The LDAP listener options.- Throws:
IOException
- If an error occurred while trying to listen on the provided address.NullPointerException
- Ifhost
, {code factory}, oroptions
wasnull
.
-
-
Method Details
-
setOptions
Updates the options of this LDAP listener. Most of the options will be applied only for next client connection, current connections will not impacted by this operation. Some options are not modifiable and will be ignored by this operation.- Parameters:
options
- The LDAP listener options.
-
getOptions
Returns a copy of the options currently used by this LDAP listener. Modifying the returned Options will have not impact until applied withsetOptions(Options)
.- Returns:
- The LDAP listener options.
-
close
public void close()Closes this LDAP connection listener.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
getSocketAddresses
Returns the addresses that this LDAP listener is listening on.- Returns:
- The addresses that this LDAP listener is listening on.
-
firstSocketAddress
Returns the first address that his LDAP listener is listening on.- Returns:
- The addresses that this LDAP listener is listening on.
-
toString
-