Class GSSAPIBindRequest

All Implemented Interfaces:
ReadOnlyLDAPRequest, Serializable, PrivilegedExceptionAction<Object>, CallbackHandler

This class provides a SASL GSSAPI bind request implementation as described in RFC 4752. It provides the ability to authenticate to a directory server using Kerberos V, which can serve as a kind of single sign-on mechanism that may be shared across client applications that support Kerberos.

This class uses the Java Authentication and Authorization Service (JAAS) behind the scenes to perform all Kerberos processing. This framework requires a configuration file to indicate the underlying mechanism to be used. It is possible for clients to explicitly specify the path to the configuration file that should be used, but if none is given then a default file will be created and used. This default file should be sufficient for Sun-provided JVMs, but a custom file may be required for JVMs provided by other vendors.

Elements included in a GSSAPI bind request include:
  • Authentication ID -- A string which identifies the user that is attempting to authenticate. It should be the user's Kerberos principal.
  • 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 be a Kerberos principal.
  • KDC Address -- An optional string which specifies the IP address or resolvable name for the Kerberos key distribution center. If this is not provided, an attempt will be made to determine the appropriate value from the system configuration.
  • Realm -- An optional string which specifies the realm into which the user should authenticate. If this is not provided, an attempt will be made to determine the appropriate value from the system configuration
  • Password -- The clear-text password for the target user in the Kerberos realm.

Example

The following example demonstrates the process for performing a GSSAPI bind against a directory server with a username of "john.doe" and a password of "password":
 GSSAPIBindRequestProperties gssapiProperties =
      new GSSAPIBindRequestProperties("john.doe@EXAMPLE.COM", "password");
 gssapiProperties.setKDCAddress("kdc.example.com");
 gssapiProperties.setRealm("EXAMPLE.COM");

 GSSAPIBindRequest bindRequest =
      new GSSAPIBindRequest(gssapiProperties);
 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

    • GSSAPIBindRequest

      public GSSAPIBindRequest(@NotNull String authenticationID, @NotNull String password) throws LDAPException
      Creates a new SASL GSSAPI bind request with the provided authentication ID and password.
      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.
      Throws:
      LDAPException - If a problem occurs while creating the JAAS configuration file to use during authentication processing.
    • GSSAPIBindRequest

      public GSSAPIBindRequest(@NotNull String authenticationID, @NotNull byte[] password) throws LDAPException
      Creates a new SASL GSSAPI bind request with the provided authentication ID and password.
      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.
      Throws:
      LDAPException - If a problem occurs while creating the JAAS configuration file to use during authentication processing.
    • GSSAPIBindRequest

      public GSSAPIBindRequest(@NotNull String authenticationID, @NotNull String password, @Nullable Control[] controls) throws LDAPException
      Creates a new SASL GSSAPI bind request with the provided authentication ID and password.
      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 in the request.
      Throws:
      LDAPException - If a problem occurs while creating the JAAS configuration file to use during authentication processing.
    • GSSAPIBindRequest

      public GSSAPIBindRequest(@NotNull String authenticationID, @NotNull byte[] password, @Nullable Control[] controls) throws LDAPException
      Creates a new SASL GSSAPI bind request with the provided authentication ID and password.
      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 in the request.
      Throws:
      LDAPException - If a problem occurs while creating the JAAS configuration file to use during authentication processing.
    • GSSAPIBindRequest

      public GSSAPIBindRequest(@NotNull String authenticationID, @Nullable String authorizationID, @NotNull String password, @Nullable String realm, @Nullable String kdcAddress, @Nullable String configFilePath) throws LDAPException
      Creates a new SASL GSSAPI 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. It may be null if no alternate authorization ID should be used.
      password - The password for this bind request. It must not be null.
      realm - The realm to use for the authentication. It may be null to attempt to use the default realm from the system configuration.
      kdcAddress - The address of the Kerberos key distribution center. It may be null to attempt to use the default KDC from the system configuration.
      configFilePath - The path to the JAAS configuration file to use for the authentication processing. It may be null to use the default JAAS configuration.
      Throws:
      LDAPException - If a problem occurs while creating the JAAS configuration file to use during authentication processing.
    • GSSAPIBindRequest

      public GSSAPIBindRequest(@NotNull String authenticationID, @Nullable String authorizationID, @NotNull byte[] password, @Nullable String realm, @Nullable String kdcAddress, @Nullable String configFilePath) throws LDAPException
      Creates a new SASL GSSAPI 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. It may be null if no alternate authorization ID should be used.
      password - The password for this bind request. It must not be null.
      realm - The realm to use for the authentication. It may be null to attempt to use the default realm from the system configuration.
      kdcAddress - The address of the Kerberos key distribution center. It may be null to attempt to use the default KDC from the system configuration.
      configFilePath - The path to the JAAS configuration file to use for the authentication processing. It may be null to use the default JAAS configuration.
      Throws:
      LDAPException - If a problem occurs while creating the JAAS configuration file to use during authentication processing.
    • GSSAPIBindRequest

      public GSSAPIBindRequest(@NotNull String authenticationID, @Nullable String authorizationID, @NotNull String password, @Nullable String realm, @Nullable String kdcAddress, @Nullable String configFilePath, @Nullable Control[] controls) throws LDAPException
      Creates a new SASL GSSAPI 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. It may be null if no alternate authorization ID should be used.
      password - The password for this bind request. It must not be null.
      realm - The realm to use for the authentication. It may be null to attempt to use the default realm from the system configuration.
      kdcAddress - The address of the Kerberos key distribution center. It may be null to attempt to use the default KDC from the system configuration.
      configFilePath - The path to the JAAS configuration file to use for the authentication processing. It may be null to use the default JAAS configuration.
      controls - The set of controls to include in the request.
      Throws:
      LDAPException - If a problem occurs while creating the JAAS configuration file to use during authentication processing.
    • GSSAPIBindRequest

      public GSSAPIBindRequest(@NotNull String authenticationID, @Nullable String authorizationID, @NotNull byte[] password, @Nullable String realm, @Nullable String kdcAddress, @Nullable String configFilePath, @Nullable Control[] controls) throws LDAPException
      Creates a new SASL GSSAPI 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. It may be null if no alternate authorization ID should be used.
      password - The password for this bind request. It must not be null.
      realm - The realm to use for the authentication. It may be null to attempt to use the default realm from the system configuration.
      kdcAddress - The address of the Kerberos key distribution center. It may be null to attempt to use the default KDC from the system configuration.
      configFilePath - The path to the JAAS configuration file to use for the authentication processing. It may be null to use the default JAAS configuration.
      controls - The set of controls to include in the request.
      Throws:
      LDAPException - If a problem occurs while creating the JAAS configuration file to use during authentication processing.
    • GSSAPIBindRequest

      Creates a new SASL GSSAPI bind request with the provided set of properties.
      Parameters:
      gssapiProperties - The set of properties that should be used for the GSSAPI bind request. It must not be null.
      controls - The set of controls to include in the request.
      Throws:
      LDAPException - If a problem occurs while creating the JAAS configuration file to use during authentication processing.
  • 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 the GSSAPI bind request, if defined.
      Returns:
      The authentication ID for the GSSAPI bind request, or null if an existing Kerberos session should be used.
    • getAuthorizationID

      Retrieves the authorization ID for this bind request, if any.
      Returns:
      The authorization ID for this bind request, or null if there should not be a separate authorization identity.
    • getPasswordString

      Retrieves the string representation of the password for this bind request, if defined.
      Returns:
      The string representation of the password for this bind request, or null if an existing Kerberos session should be used.
    • getPasswordBytes

      @Nullable public byte[] getPasswordBytes()
      Retrieves the bytes that comprise the the password for this bind request, if defined.
      Returns:
      The bytes that comprise the password for this bind request, or null if an existing Kerberos session should be used.
    • getRealm

      Retrieves the realm for this bind request, if any.
      Returns:
      The realm for this bind request, or null if none was defined and the client should attempt to determine the realm from the system configuration.
    • getAllowedQoP

      Retrieves the list of allowed qualities of protection that may be used for communication that occurs on the connection after the authentication has completed, in order from most preferred to least preferred.
      Returns:
      The list of allowed qualities of protection that may be used for communication that occurs on the connection after the authentication has completed, in order from most preferred to least preferred.
    • getKDCAddress

      Retrieves the address of the Kerberos key distribution center.
      Returns:
      The address of the Kerberos key distribution center, or null if none was defined and the client should attempt to determine the KDC address from the system configuration.
    • getConfigFilePath

      Retrieves the path to the JAAS configuration file that will be used during authentication processing.
      Returns:
      The path to the JAAS configuration file that will be used during authentication processing.
    • getServicePrincipalProtocol

      Retrieves the protocol specified in the service principal that the directory server uses for its communication with the KDC.
      Returns:
      The protocol specified in the service principal that the directory server uses for its communication with the KDC.
    • refreshKrb5Config

      public boolean refreshKrb5Config()
      Indicates whether to refresh the configuration before the JAAS login method is called.
      Returns:
      true if the GSSAPI implementation should refresh the configuration before the JAAS login method is called, or false if not.
    • useKeyTab

      public boolean useKeyTab()
      Indicates whether to use a keytab to obtain the user credentials.
      Returns:
      true if the GSSAPI login attempt should use a keytab to obtain the user credentials, or false if not.
    • getKeyTabPath

      Retrieves the path to the keytab file from which to obtain the user credentials. This will only be used if useKeyTab returns true.
      Returns:
      The path to the keytab file from which to obtain the user credentials, or null if the default keytab location should be used.
    • useTicketCache

      public boolean useTicketCache()
      Indicates whether to enable the use of a ticket cache to to avoid the need to supply credentials if the client already has an existing Kerberos session.
      Returns:
      true if a ticket cache may be used to take advantage of an existing Kerberos session, or false if Kerberos credentials should always be provided.
    • requireCachedCredentials

      public boolean requireCachedCredentials()
      Indicates whether GSSAPI authentication should only occur using an existing Kerberos session.
      Returns:
      true if GSSAPI authentication should only use an existing Kerberos session and should fail if the client does not have an existing session, or false if the client will be allowed to create a new session if one does not already exist.
    • getTicketCachePath

      Retrieves the path to the Kerberos ticket cache file that should be used during authentication, if defined.
      Returns:
      The path to the Kerberos ticket cache file that should be used during authentication, or null if the default ticket cache file should be used.
    • renewTGT

      public boolean renewTGT()
      Indicates whether to attempt to renew the client's ticket-granting ticket (TGT) if an existing Kerberos session is used to authenticate.
      Returns:
      true if the client should attempt to renew its ticket-granting ticket if the authentication is processed using an existing Kerberos session, or false if not.
    • useSubjectCredentialsOnly

      public boolean useSubjectCredentialsOnly()
      Indicates whether to allow the client to use credentials that are outside of the current subject, obtained via some system-specific mechanism.
      Returns:
      true if the client will only be allowed to use credentials that are within the current subject, or false if the client will be allowed to use credentials outside the current subject.
    • getIsInitiator

      Indicates whether the client should be configured so that it explicitly indicates whether it is the initiator or the acceptor.
      Returns:
      Boolean.TRUE if the client should explicitly indicate that it is the GSSAPI initiator, Boolean.FALSE if the client should explicitly indicate that it is the GSSAPI acceptor, or null if the client should not explicitly indicate either state (which is the default behavior unless the GSSAPIBindRequestProperties.setIsInitiator(java.lang.Boolean) method has been used to explicitly specify a value).
    • getSuppressedSystemProperties

      Retrieves a set of system properties that will not be altered by GSSAPI processing.
      Returns:
      A set of system properties that will not be altered by GSSAPI processing.
    • getChannelBindingType

      Retrieves the type of channel binding that should be used for this GSSAPI bind request.
      Returns:
      The type of channel binding that should be used for this GSSAPI bind request, or GSSAPIChannelBindingType.NONE if no channel binding should be used.
    • enableGSSAPIDebugging

      public boolean enableGSSAPIDebugging()
      Indicates whether JVM-level debugging should be enabled for GSSAPI bind processing.
      Returns:
      true if JVM-level debugging should be enabled for GSSAPI bind processing, or false if not.
    • 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.
    • run

      Perform the privileged portion of the authentication processing.
      Specified by:
      run in interface PrivilegedExceptionAction<Object>
      Returns:
      null, since no return value is actually needed.
      Throws:
      LDAPException - If a problem occurs during processing.
    • 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.
    • handle

      Handles any necessary callbacks required for SASL authentication.
      Specified by:
      handle in interface CallbackHandler
      Parameters:
      callbacks - The set of callbacks to be handled.
      Throws:
      UnsupportedCallbackException - If an unsupported type of callback was received.
    • getLastMessageID

      public int getLastMessageID()
      Retrieves the message ID for the last LDAP message sent using this request.
      Overrides:
      getLastMessageID in class SASLBindRequest
      Returns:
      The message ID for the last LDAP message sent using this request, or -1 if it no LDAP messages have yet been sent using this 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).