Class LDAPListenerClientConnection

java.lang.Object
java.lang.Thread
com.unboundid.ldap.listener.LDAPListenerClientConnection
All Implemented Interfaces:
Closeable, AutoCloseable, Runnable

This class provides an object which will be used to represent a connection to a client accepted by an LDAPListener, although connections may also be created independently if they were accepted in some other way. Each connection has its own thread that will be used to read requests from the client, and connections created outside of an LDAPListener instance, then the thread must be explicitly started.
  • Constructor Details

  • Method Details

    • close

      public void close() throws IOException
      Closes the connection to the client.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException - If a problem occurs while closing the socket.
    • run

      @InternalUseOnly public void run()
      Operates in a loop, waiting for a request to arrive from the client and handing it off to the request handler for processing. This method is for internal use only and must not be invoked by external callers.
      Specified by:
      run in interface Runnable
      Overrides:
      run in class Thread
    • sendSearchResultEntry

      public void sendSearchResultEntry(int messageID, @NotNull SearchResultEntryProtocolOp protocolOp, @Nullable Control... controls) throws LDAPException
      Sends a search result entry message to the client with the provided information.
      Parameters:
      messageID - The message ID for the LDAP message to send to the client. It must match the message ID of the associated search request.
      protocolOp - The search result entry protocol op to include in the LDAP message to send to the client. It must not be null.
      controls - The set of controls to include in the response message. It may be empty or null if no controls should be included.
      Throws:
      LDAPException - If a problem occurs while attempting to send the provided response message. If an exception is thrown, then the client connection will have been terminated.
    • sendSearchResultEntry

      public void sendSearchResultEntry(int messageID, @NotNull Entry entry, @Nullable Control... controls) throws LDAPException
      Sends a search result entry message to the client with the provided information.
      Parameters:
      messageID - The message ID for the LDAP message to send to the client. It must match the message ID of the associated search request.
      entry - The entry to return to the client. It must not be null.
      controls - The set of controls to include in the response message. It may be empty or null if no controls should be included.
      Throws:
      LDAPException - If a problem occurs while attempting to send the provided response message. If an exception is thrown, then the client connection will have been terminated.
    • sendSearchResultReference

      public void sendSearchResultReference(int messageID, @NotNull SearchResultReferenceProtocolOp protocolOp, @Nullable Control... controls) throws LDAPException
      Sends a search result reference message to the client with the provided information.
      Parameters:
      messageID - The message ID for the LDAP message to send to the client. It must match the message ID of the associated search request.
      protocolOp - The search result reference protocol op to include in the LDAP message to send to the client.
      controls - The set of controls to include in the response message. It may be empty or null if no controls should be included.
      Throws:
      LDAPException - If a problem occurs while attempting to send the provided response message. If an exception is thrown, then the client connection will have been terminated.
    • sendIntermediateResponse

      public void sendIntermediateResponse(int messageID, @NotNull IntermediateResponseProtocolOp protocolOp, @Nullable Control... controls) throws LDAPException
      Sends an intermediate response message to the client with the provided information.
      Parameters:
      messageID - The message ID for the LDAP message to send to the client. It must match the message ID of the associated search request.
      protocolOp - The intermediate response protocol op to include in the LDAP message to send to the client.
      controls - The set of controls to include in the response message. It may be empty or null if no controls should be included.
      Throws:
      LDAPException - If a problem occurs while attempting to send the provided response message. If an exception is thrown, then the client connection will have been terminated.
    • sendUnsolicitedNotification

      Sends an unsolicited notification message to the client with the provided extended result.
      Parameters:
      result - The extended result to use for the unsolicited notification.
      Throws:
      LDAPException - If a problem occurs while attempting to send the unsolicited notification. If an exception is thrown, then the client connection will have been terminated.
    • sendUnsolicitedNotification

      Sends an unsolicited notification message to the client with the provided information.
      Parameters:
      extendedResponse - The extended response to use for the unsolicited notification.
      controls - The set of controls to include with the unsolicited notification. It may be empty or null if no controls should be included.
      Throws:
      LDAPException - If a problem occurs while attempting to send the unsolicited notification. If an exception is thrown, then the client connection will have been terminated.
    • getSocket

      Retrieves the socket used to communicate with the client.
      Returns:
      The socket used to communicate with the client.
    • convertToTLS

      Attempts to convert this unencrypted connection to one that uses TLS encryption, as would be used during the course of invoking the StartTLS extended operation. If this is called, then the response that would have been returned from the associated request will be suppressed, so the returned output stream must be used to send the appropriate response to the client.
      Parameters:
      sslSocketFactory - The SSL socket factory that will be used to convert the existing Socket to an SSLSocket.
      Returns:
      An output stream that can be used to send a clear-text message to the client (e.g., the StartTLS response message).
      Throws:
      LDAPException - If a problem is encountered while trying to convert the existing socket to an SSL socket. If this is thrown, then the connection will have been closed.
    • convertToTLS

      @NotNull public OutputStream convertToTLS(@NotNull SSLSocketFactory sslSocketFactory, boolean requestClientCertificate, boolean requireClientCertificate) throws LDAPException
      Attempts to convert this unencrypted connection to one that uses TLS encryption, as would be used during the course of invoking the StartTLS extended operation. If this is called, then the response that would have been returned from the associated request will be suppressed, so the returned output stream must be used to send the appropriate response to the client.
      Parameters:
      sslSocketFactory - The SSL socket factory that will be used to convert the existing Socket to an SSLSocket.
      requestClientCertificate - Indicates whether the listener should request that the client present its own certificate chain during TLS negotiation. This will be ignored for non-TLS-based connections.
      requireClientCertificate - Indicates whether the listener should require that the client present its own certificate chain during TLS negotiation, and should fail negotiation if the client does not present one. This will be ignored for non-TLS-based connections or if requestClientCertificate is false.
      Returns:
      An output stream that can be used to send a clear-text message to the client (e.g., the StartTLS response message).
      Throws:
      LDAPException - If a problem is encountered while trying to convert the existing socket to an SSL socket. If this is thrown, then the connection will have been closed.
    • getConnectionID

      public long getConnectionID()
      Retrieves the connection ID that has been assigned to this connection by the associated listener.
      Returns:
      The connection ID that has been assigned to this connection by the associated listener, or -1 if it is not associated with a listener.
    • addSearchEntryTransformer

      Adds the provided search entry transformer to this client connection.
      Parameters:
      t - A search entry transformer to be used to intercept and/or alter search result entries before they are returned to the client.
    • removeSearchEntryTransformer

      Removes the provided search entry transformer from this client connection.
      Parameters:
      t - The search entry transformer to be removed.
    • addSearchReferenceTransformer

      Adds the provided search reference transformer to this client connection.
      Parameters:
      t - A search reference transformer to be used to intercept and/or alter search result references before they are returned to the client.
    • removeSearchReferenceTransformer

      Removes the provided search reference transformer from this client connection.
      Parameters:
      t - The search reference transformer to be removed.
    • addIntermediateResponseTransformer

      Adds the provided intermediate response transformer to this client connection.
      Parameters:
      t - An intermediate response transformer to be used to intercept and/or alter intermediate responses before they are returned to the client.
    • removeIntermediateResponseTransformer

      Removes the provided intermediate response transformer from this client connection.
      Parameters:
      t - The intermediate response transformer to be removed.