Class LdapServer

  • All Implemented Interfaces:
    Closeable, AutoCloseable

    public final class LdapServer
    extends Object
    implements Closeable
    An LDAP server connection listener which waits for LDAP connection requests to come in over the network and binds them to a server connection created using the provided server connection factory.

    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 Detail

      • CONNECT_MAX_BACKLOG

        public static final Option<Integer> 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

        public static final Option<Integer> 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

        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.
      • ACCEPTED_CLIENT_VALIDATOR

        public static final Option<io.reactivex.rxjava3.functions.Consumer<RxSocket<?>>> 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

        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
      • TCP_NO_DELAY

        public static final Option<Boolean> TCP_NO_DELAY
        Specifies the value of the TCP_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 the SO_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 the SO_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 the SO_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

        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 or null 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.
    • Constructor Detail

      • LdapServer

        public LdapServer​(int port,
                          io.reactivex.rxjava3.functions.Function<LdapSession,​io.reactivex.rxjava3.functions.BiFunction<Integer,​Request,​io.reactivex.rxjava3.core.Flowable<Response>>> factory)
                   throws IOException
        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} was null.
      • LdapServer

        public LdapServer​(int port,
                          io.reactivex.rxjava3.functions.Function<LdapSession,​io.reactivex.rxjava3.functions.BiFunction<Integer,​Request,​io.reactivex.rxjava3.core.Flowable<Response>>> factory,
                          Options options)
                   throws IOException
        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} or options was null.
      • LdapServer

        public LdapServer​(Set<InetSocketAddress> addresses,
                          io.reactivex.rxjava3.functions.Function<LdapSession,​io.reactivex.rxjava3.functions.BiFunction<Integer,​Request,​io.reactivex.rxjava3.core.Flowable<Response>>> factory)
                   throws IOException
        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 - If address or {code factory} was null.
      • LdapServer

        public LdapServer​(Set<InetSocketAddress> addresses,
                          io.reactivex.rxjava3.functions.Function<LdapSession,​io.reactivex.rxjava3.functions.BiFunction<Integer,​Request,​io.reactivex.rxjava3.core.Flowable<Response>>> factory,
                          Options options)
                   throws IOException
        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 - If address, {code factory}, or options was null.
      • LdapServer

        public LdapServer​(String host,
                          int port,
                          io.reactivex.rxjava3.functions.Function<LdapSession,​io.reactivex.rxjava3.functions.BiFunction<Integer,​Request,​io.reactivex.rxjava3.core.Flowable<Response>>> factory)
                   throws IOException
        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 - If host or {code factory} was null.
      • LdapServer

        public LdapServer​(String host,
                          int port,
                          io.reactivex.rxjava3.functions.Function<LdapSession,​io.reactivex.rxjava3.functions.BiFunction<Integer,​Request,​io.reactivex.rxjava3.core.Flowable<Response>>> factory,
                          Options options)
                   throws IOException
        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 - If host, {code factory}, or options was null.
    • Method Detail

      • setOptions

        public void setOptions​(Options options)
        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

        public Options getOptions()
        Returns a copy of the options currently used by this LDAP listener. Modifying the returned Options will have not impact until applied with setOptions(Options).
        Returns:
        The LDAP listener options.
      • close

        public void close()
        Closes this LDAP connection listener.
        Specified by:
        close in interface AutoCloseable
        Specified by:
        close in interface Closeable
      • getSocketAddresses

        public Set<InetSocketAddress> getSocketAddresses()
        Returns the addresses that this LDAP listener is listening on.
        Returns:
        The addresses that this LDAP listener is listening on.
      • firstSocketAddress

        public InetSocketAddress firstSocketAddress()
        Returns the first address that his LDAP listener is listening on.
        Returns:
        The addresses that this LDAP listener is listening on.