Class ClientFirstMessage


  • public final class ClientFirstMessage
    extends AbstractScramMessage
    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:
    [RFC5802] Section 7
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private @NotNull java.lang.String clientNonce
      nonce= "r=" c-nonce [s-nonce].
      private @NotNull Gs2Header gs2Header
      gs2-header = gs2-cbind-flag "," [ authzid ] ",".
      private @NotNull java.lang.String username
      username = "n=" saslname.
    • Constructor Summary

      Constructors 
      Constructor Description
      ClientFirstMessage​(@NotNull Gs2CbindFlag gs2CbindFlag, @Nullable java.lang.String cbindName, @Nullable java.lang.String authzid, @NotNull java.lang.String username, @NotNull java.lang.String clientNonce)
      Constructs a client-first-message for the given parameters.
      ClientFirstMessage​(@NotNull Gs2Header gs2Header, @NotNull java.lang.String username, @NotNull java.lang.String clientNonce)
      Constructs a client-first-message for the given user, nonce and gs2Header.
      ClientFirstMessage​(@NotNull java.lang.String username, @NotNull java.lang.String clientNonce)
      Constructs a client-first-message for the given parameters, with no channel binding nor authzid.
    • Field Detail

      • gs2Header

        @NotNull
        private final @NotNull Gs2Header gs2Header
        gs2-header = gs2-cbind-flag "," [ authzid ] ",".
      • username

        @NotNull
        private final @NotNull java.lang.String username
        username = "n=" saslname.
      • clientNonce

        @NotNull
        private final @NotNull java.lang.String clientNonce
        nonce= "r=" c-nonce [s-nonce].
    • Constructor Detail

      • ClientFirstMessage

        public ClientFirstMessage​(@NotNull
                                  @NotNull Gs2Header gs2Header,
                                  @NotNull
                                  @NotNull java.lang.String username,
                                  @NotNull
                                  @NotNull java.lang.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:
        java.lang.IllegalArgumentException - If any of the arguments is null or empty
      • ClientFirstMessage

        public ClientFirstMessage​(@NotNull
                                  @NotNull Gs2CbindFlag gs2CbindFlag,
                                  @Nullable
                                  @Nullable java.lang.String cbindName,
                                  @Nullable
                                  @Nullable java.lang.String authzid,
                                  @NotNull
                                  @NotNull java.lang.String username,
                                  @NotNull
                                  @NotNull java.lang.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
        authzid - The optional authzid
        cbindName - The optional channel binding name
        username - The SCRAM user
        clientNonce - The nonce for this session
        Throws:
        java.lang.IllegalArgumentException - If the flag, user or nonce are null or empty
      • ClientFirstMessage

        public ClientFirstMessage​(@NotNull
                                  @NotNull java.lang.String username,
                                  @NotNull
                                  @NotNull java.lang.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:
        java.lang.IllegalArgumentException - If the user or nonce are null or empty
    • Method Detail

      • 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 java.lang.String getUsername()
        Return the username.
        Returns:
        the "n=" saslname
      • getClientNonce

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

        @NotNull
        @NotNull java.lang.StringBuilder clientFirstMessageBare​(@NotNull
                                                                @NotNull java.lang.StringBuilder sb)
        Limited version of the StringWritableCsv method, that doesn't write the GS2 header. This method is useful to construct the auth message used as part of the SCRAM algorithm.
        Parameters:
        sb - A StringBuffer where to write the data to.
        Returns:
        The same StringBuffer
      • parseFrom

        @NotNull
        public static @NotNull ClientFirstMessage parseFrom​(@NotNull
                                                            @NotNull java.lang.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
        java.lang.IllegalArgumentException - If the message is null or empty
      • writeTo

        java.lang.StringBuilder writeTo​(java.lang.StringBuilder sb)
        Description copied from class: StringWritable
        Write the class information to the given StringBuffer.
        Specified by:
        writeTo in class StringWritable
        Parameters:
        sb - Where to write the data.
        Returns:
        The same StringBuffer.