Class ClientFirstMessage

java.lang.Object
com.ongres.scram.common.ClientFirstMessage

public final class ClientFirstMessage extends Object
Constructs and parses client-first-messages. Message contains a gs2-header, a username and a nonce.
Formal Syntax:
client-first-message-bare [reserved-mext ","] username "," nonce ["," extensions]
client-first-message gs2-header client-first-message-bare
See Also:
Implementation Note:
extensions are not supported.
  • Constructor Details

    • ClientFirstMessage

      public ClientFirstMessage(@NotNull @NotNull Gs2Header gs2Header, @NotNull @NotNull String username, @NotNull @NotNull String clientNonce)
      Constructs a client-first-message for the given user, nonce and gs2Header. This constructor is intended to be instantiated by a scram client, and not directly. The client should be providing the header, and nonce (and probably the user too).
      Parameters:
      gs2Header - The GSS-API header
      username - The SCRAM username
      clientNonce - The nonce for this session
      Throws:
      IllegalArgumentException - If any of the arguments is null or empty
    • ClientFirstMessage

      public ClientFirstMessage(@NotNull @NotNull Gs2CbindFlag gs2CbindFlag, @Nullable @Nullable String cbindName, @Nullable @Nullable String authzid, @NotNull @NotNull String username, @NotNull @NotNull String clientNonce)
      Constructs a client-first-message for the given parameters. Under normal operation, this constructor is intended to be instantiated by a scram client, and not directly. However, this constructor is more user- or test-friendly, as the arguments are easier to provide without building other indirect object parameters.
      Parameters:
      gs2CbindFlag - The channel-binding flag
      cbindName - The optional channel binding name
      authzid - The optional authzid
      username - The SCRAM user
      clientNonce - The nonce for this session
      Throws:
      IllegalArgumentException - If the flag, user or nonce are null or empty
    • ClientFirstMessage

      public ClientFirstMessage(@NotNull @NotNull String username, @NotNull @NotNull String clientNonce)
      Constructs a client-first-message for the given parameters, with no channel binding nor authzid. Under normal operation, this constructor is intended to be instantiated by a scram client, and not directly. However, this constructor is more user- or test-friendly, as the arguments are easier to provide without building other indirect object parameters.
      Parameters:
      username - The SCRAM user
      clientNonce - The nonce for this session
      Throws:
      IllegalArgumentException - If the user or nonce are null or empty
  • Method Details

    • isChannelBindingRequired

      public boolean isChannelBindingRequired()
      Check to probe if gs2-cbind-flag is set to "p=".
      Returns:
      true if the message requires channel binding
    • getGs2Header

      @NotNull public @NotNull Gs2Header getGs2Header()
      Return the Gs2Header.
      Returns:
      the gs2-header
    • getUsername

      @NotNull public @NotNull String getUsername()
      Return the username.
      Returns:
      the "n=" saslname
    • getClientNonce

      @NotNull public @NotNull String getClientNonce()
      Return the client nonce.
      Returns:
      the c-nonce
    • parseFrom

      @NotNull public static @NotNull ClientFirstMessage parseFrom(@NotNull @NotNull String clientFirstMessage) throws ScramParseException
      Construct a ClientFirstMessage instance from a message (String).
      Parameters:
      clientFirstMessage - The String representing the client-first-message
      Returns:
      The instance
      Throws:
      ScramParseException - If the message is not a valid client-first-message
      IllegalArgumentException - If the message is null or empty
    • toString

      @NotNull public final @NotNull String toString()
      String representation of the SCRAM message.
      Overrides:
      toString in class Object