Class Gs2Header

java.lang.Object
com.ongres.scram.common.StringWritable
com.ongres.scram.common.Gs2Header

public final class Gs2Header extends StringWritable
GS2 header for SCRAM.
Formal Syntax:
gs2-cbind-flag ("p=" cb-name) / "n" / "y"
;; "n" -> client doesn't support channel binding.
;; "y" -> client does support channel binding
;; but thinks the server does not.
;; "p" -> client requires channel binding.
;; The selected channel binding follows "p=".
gs2-header gs2-cbind-flag "," [ authzid ] ","
;; GS2 header for SCRAM
;; (the actual GS2 header includes an optional
;; flag to indicate that the GSS mechanism is not
;; "standard", but since SCRAM is "standard", we
;; don't include that flag).
authzid "a=" saslname
See Also:
  • Field Details

  • Constructor Details

    • Gs2Header

      public Gs2Header(@NotNull @NotNull Gs2CbindFlag cbindFlag, @Nullable @Nullable String cbName, @Nullable @Nullable String authzid)
      Construct and validates a Gs2Header. Only provide the channel binding name if the channel binding flag is set to required.
      Parameters:
      cbindFlag - The channel binding flag
      cbName - The channel-binding name. Should be not null if channel binding is required
      authzid - The optional SASL authorization identity
      Throws:
      IllegalArgumentException - If the channel binding flag and argument are invalid
    • Gs2Header

      public Gs2Header(@NotNull @NotNull Gs2CbindFlag cbindFlag, @Nullable @Nullable String cbName)
      Construct and validates a Gs2Header with no authzid. Only provide the channel binding name if the channel binding flag is set to required.
      Parameters:
      cbindFlag - The channel binding flag
      cbName - The channel-binding name. Should be not null iif channel binding is required
      Throws:
      IllegalArgumentException - If the channel binding flag and argument are invalid
    • Gs2Header

      public Gs2Header(@NotNull @NotNull Gs2CbindFlag cbindFlag)
      Construct and validates a Gs2Header with no authzid nor channel binding.
      Parameters:
      cbindFlag - The channel binding flag
      Throws:
      IllegalArgumentException - If the channel binding is supported (no cbname can be provided here)
  • Method Details

    • getChannelBindingFlag

      @NotNull public @NotNull Gs2CbindFlag getChannelBindingFlag()
      Return the channel binding flag.
      Returns:
      the gs2-cbind-flag
    • getChannelBindingName

      @Nullable public @Nullable String getChannelBindingName()
      Return the channel binding type.
      Returns:
      the cb-name
    • getAuthzid

      @Nullable public @Nullable String getAuthzid()
      Return the authzid.
      Returns:
      the "a=" saslname
    • writeTo

      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.
    • parseFrom

      @NotNull public static @NotNull Gs2Header parseFrom(@NotNull @NotNull String message)
      Read a Gs2Header from a String. String may contain trailing fields that will be ignored.
      Parameters:
      message - The String containing the Gs2Header
      Returns:
      The parsed Gs2Header object
      Throws:
      IllegalArgumentException - If the format/values of the String do not conform to a Gs2Header
    • checkChannelBinding

      private static void checkChannelBinding(@NotNull @NotNull Gs2CbindFlag cbindFlag, @Nullable @Nullable String cbName)
    • validateChannelBindingType

      private static void validateChannelBindingType(@NotNull @NotNull String cbname)
      Checks that the channel binding name is valid.
      
       cb-name = 1*(ALPHA / DIGIT / "." / "-")
                 ;; See RFC 5056, Section 7.
       
      Parameters:
      cbname - Channel Binding Name
      Throws:
      IllegalArgumentException - If the name is not a valid channel binding type.
      See Also: