Class PLAINBindRequest

All Implemented Interfaces:
ReadOnlyLDAPRequest, Serializable

This class provides a SASL PLAIN bind request implementation as described in RFC 4616. The SASL PLAIN mechanism allows the client to authenticate with an authentication ID and password, and optionally allows the client to provide an authorization ID for use in performing subsequent operations.

Elements included in a PLAIN bind request include:
  • Authentication ID -- A string which identifies the user that is attempting to authenticate. It should be an "authzId" value as described in section 5.2.1.8 of RFC 4513. That is, it should be either "dn:" followed by the distinguished name of the target user, or "u:" followed by the username. If the "u:" form is used, then the mechanism used to resolve the provided username to an entry may vary from server to server.
  • Authorization ID -- An optional string which specifies an alternate authorization identity that should be used for subsequent operations requested on the connection. Like the authentication ID, the authorization ID should use the "authzId" syntax.
  • Password -- The clear-text password for the target user.

Example

The following example demonstrates the process for performing a PLAIN bind against a directory server with a username of "test.user" and a password of "password":
 PLAINBindRequest bindRequest =
      new PLAINBindRequest("u:test.user", "password");
 BindResult bindResult;
 try
 {
   bindResult = connection.bind(bindRequest);
   // If we get here, then the bind was successful.
 }
 catch (LDAPException le)
 {
   // The bind failed for some reason.
   bindResult = new BindResult(le.toLDAPResult());
   ResultCode resultCode = le.getResultCode();
   String errorMessageFromServer = le.getDiagnosticMessage();
 }
 
See Also:
  • Field Details

  • Constructor Details

    • PLAINBindRequest

      public PLAINBindRequest(@NotNull String authenticationID, @NotNull String password)
      Creates a new SASL PLAIN bind request with the provided authentication ID and password. It will not include an authorization ID or set of controls.
      Parameters:
      authenticationID - The authentication ID for this bind request. It must not be null.
      password - The password for this bind request. It must not be null.
    • PLAINBindRequest

      public PLAINBindRequest(@NotNull String authenticationID, @NotNull byte[] password)
      Creates a new SASL PLAIN bind request with the provided authentication ID and password. It will not include an authorization ID or set of controls.
      Parameters:
      authenticationID - The authentication ID for this bind request. It must not be null.
      password - The password for this bind request. It must not be null.
    • PLAINBindRequest

      public PLAINBindRequest(@NotNull String authenticationID, @NotNull ASN1OctetString password)
      Creates a new SASL PLAIN bind request with the provided authentication ID and password. It will not include an authorization ID or set of controls.
      Parameters:
      authenticationID - The authentication ID for this bind request. It must not be null.
      password - The password for this bind request. It must not be null.
    • PLAINBindRequest

      public PLAINBindRequest(@NotNull String authenticationID, @Nullable String authorizationID, @NotNull String password)
      Creates a new SASL PLAIN bind request with the provided authentication ID, authorization ID, and password. It will not include a set of controls.
      Parameters:
      authenticationID - The authentication ID for this bind request. It must not be null.
      authorizationID - The authorization ID for this bind request, or null if there is to be no authorization ID.
      password - The password for this bind request. It must not be null.
    • PLAINBindRequest

      public PLAINBindRequest(@NotNull String authenticationID, @Nullable String authorizationID, @NotNull byte[] password)
      Creates a new SASL PLAIN bind request with the provided authentication ID, authorization ID, and password. It will not include a set of controls.
      Parameters:
      authenticationID - The authentication ID for this bind request. It must not be null.
      authorizationID - The authorization ID for this bind request, or null if there is to be no authorization ID.
      password - The password for this bind request. It must not be null.
    • PLAINBindRequest

      public PLAINBindRequest(@NotNull String authenticationID, @Nullable String authorizationID, @NotNull ASN1OctetString password)
      Creates a new SASL PLAIN bind request with the provided authentication ID, authorization ID, and password. It will not include a set of controls.
      Parameters:
      authenticationID - The authentication ID for this bind request. It must not be null.
      authorizationID - The authorization ID for this bind request, or null if there is to be no authorization ID.
      password - The password for this bind request. It must not be null.
    • PLAINBindRequest

      public PLAINBindRequest(@NotNull String authenticationID, @NotNull String password, @Nullable Control... controls)
      Creates a new SASL PLAIN bind request with the provided authentication ID, password, and set of controls. It will not include an authorization ID.
      Parameters:
      authenticationID - The authentication ID for this bind request. It must not be null.
      password - The password for this bind request. It must not be null.
      controls - The set of controls to include
    • PLAINBindRequest

      public PLAINBindRequest(@NotNull String authenticationID, @NotNull byte[] password, @Nullable Control... controls)
      Creates a new SASL PLAIN bind request with the provided authentication ID, password, and set of controls. It will not include an authorization ID.
      Parameters:
      authenticationID - The authentication ID for this bind request. It must not be null.
      password - The password for this bind request. It must not be null.
      controls - The set of controls to include
    • PLAINBindRequest

      public PLAINBindRequest(@NotNull String authenticationID, @NotNull ASN1OctetString password, @Nullable Control... controls)
      Creates a new SASL PLAIN bind request with the provided authentication ID, password, and set of controls. It will not include an authorization ID.
      Parameters:
      authenticationID - The authentication ID for this bind request. It must not be null.
      password - The password for this bind request. It must not be null.
      controls - The set of controls to include
    • PLAINBindRequest

      public PLAINBindRequest(@NotNull String authenticationID, @Nullable String authorizationID, @NotNull String password, @Nullable Control... controls)
      Creates a new SASL PLAIN bind request with the provided information.
      Parameters:
      authenticationID - The authentication ID for this bind request. It must not be null.
      authorizationID - The authorization ID for this bind request, or null if there is to be no authorization ID.
      password - The password for this bind request. It must not be null.
      controls - The set of controls to include
    • PLAINBindRequest

      public PLAINBindRequest(@NotNull String authenticationID, @Nullable String authorizationID, @NotNull byte[] password, @Nullable Control... controls)
      Creates a new SASL PLAIN bind request with the provided information.
      Parameters:
      authenticationID - The authentication ID for this bind request. It must not be null.
      authorizationID - The authorization ID for this bind request, or null if there is to be no authorization ID.
      password - The password for this bind request. It must not be null.
      controls - The set of controls to include
    • PLAINBindRequest

      public PLAINBindRequest(@NotNull String authenticationID, @Nullable String authorizationID, @NotNull ASN1OctetString password, @Nullable Control... controls)
      Creates a new SASL PLAIN bind request with the provided information.
      Parameters:
      authenticationID - The authentication ID for this bind request. It must not be null.
      authorizationID - The authorization ID for this bind request, or null if there is to be no authorization ID.
      password - The password for this bind request. It must not be null.
      controls - The set of controls to include
  • Method Details

    • getSASLMechanismName

      Retrieves the name of the SASL mechanism used in this SASL bind request.
      Specified by:
      getSASLMechanismName in class SASLBindRequest
      Returns:
      The name of the SASL mechanism used in this SASL bind request.
    • getAuthenticationID

      Retrieves the authentication ID for this bind request.
      Returns:
      The authentication ID for this bind request.
    • getAuthorizationID

      Retrieves the authorization ID for this bind request.
      Returns:
      The authorization ID for this bind request, or null if there is no authorization ID.
    • getPasswordString

      Retrieves the string representation of the password for this bind request.
      Returns:
      The string representation of the password for this bind request.
    • getPasswordBytes

      @NotNull public byte[] getPasswordBytes()
      Retrieves the bytes that comprise the the password for this bind request.
      Returns:
      The bytes that comprise the password for this bind request.
    • process

      @NotNull protected BindResult process(@NotNull LDAPConnection connection, int depth) throws LDAPException
      Sends this bind request to the target server over the provided connection and returns the corresponding response.
      Specified by:
      process in class BindRequest
      Parameters:
      connection - The connection to use to send this bind request to the server and read the associated response.
      depth - The current referral depth for this request. It should always be one for the initial request, and should only be incremented when following referrals.
      Returns:
      The bind response read from the server.
      Throws:
      LDAPException - If a problem occurs while sending the request or reading the response.
    • encodeCredentials

      @NotNull public static ASN1OctetString encodeCredentials(@NotNull String authenticationID, @Nullable String authorizationID, @NotNull ASN1OctetString password)
      Encodes the provided information into an ASN.1 octet string that may be used as the SASL credentials for an UnboundID delivered one-time password bind request.
      Parameters:
      authenticationID - The authentication identity for the bind request. It must not be null and must in the form "u:" followed by a username, or "dn:" followed by a DN.
      authorizationID - The authorization identity for the bind request. It may be null if the authorization identity should be the same as the authentication identity. If an authorization identity is specified, it must be in the form "u:" followed by a username, or "dn:" followed by a DN. The value "dn:" may be used to indicate the authorization identity of the anonymous user.
      password - The password for this PLAIN bind request. It must not be null.
      Returns:
      An ASN.1 octet string that may be used as the SASL credentials for an UnboundID delivered one-time password bind request.
    • getRebindRequest

      Retrieves a bind request that may be used to re-bind using the same credentials authentication type and credentials as previously used to perform the initial bind. This may be used in an attempt to automatically re-establish a connection that is lost, or potentially when following a referral to another directory instance.

      It is recommended that all bind request types which implement this capability be implemented so that the elements needed to create a new request are immutable. If this is not done, then changes made to a bind request object may alter the authentication/authorization identity and/or credentials associated with that request so that a rebind request created from it will not match the original request used to authenticate on a connection.
      Overrides:
      getRebindRequest in class BindRequest
      Parameters:
      host - The address of the directory server to which the connection is established.
      port - The port of the directory server to which the connection is established.
      Returns:
      A bind request that may be used to re-bind using the same authentication type and credentials as previously used to perform the initial bind, or null to indicate that automatic re-binding is not supported for this type of bind request.
    • duplicate

      Creates a new instance of this LDAP request that may be modified without impacting this request.
      Specified by:
      duplicate in interface ReadOnlyLDAPRequest
      Specified by:
      duplicate in class BindRequest
      Returns:
      A new instance of this LDAP request that may be modified without impacting this request.
    • duplicate

      Creates a new instance of this LDAP request that may be modified without impacting this request. The provided controls will be used for the new request instead of duplicating the controls from this request.
      Specified by:
      duplicate in interface ReadOnlyLDAPRequest
      Specified by:
      duplicate in class BindRequest
      Parameters:
      controls - The set of controls to include in the duplicate request.
      Returns:
      A new instance of this LDAP request that may be modified without impacting this request.
    • toString

      public void toString(@NotNull StringBuilder buffer)
      Appends a string representation of this request to the provided buffer.
      Specified by:
      toString in interface ReadOnlyLDAPRequest
      Specified by:
      toString in class LDAPRequest
      Parameters:
      buffer - The buffer to which to append a string representation of this request.
    • toCode

      public void toCode(@NotNull List<String> lineList, @NotNull String requestID, int indentSpaces, boolean includeProcessing)
      Appends a number of lines comprising the Java source code that can be used to recreate this request to the given list.
      Specified by:
      toCode in interface ReadOnlyLDAPRequest
      Overrides:
      toCode in class SASLBindRequest
      Parameters:
      lineList - The list to which the source code lines should be added.
      requestID - The name that should be used as an identifier for the request. If this is null or empty, then a generic ID will be used.
      indentSpaces - The number of spaces that should be used to indent the generated code. It must not be negative.
      includeProcessing - Indicates whether the generated code should include code required to actually process the request and handle the result (if true), or just to generate the request (if false).