Package com.ongres.scram.common
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:
- [RFC5802] Formal Syntax
-
-
Field Summary
Fields Modifier and Type Field Description private @Nullable Gs2AttributeValue
authzid
private @NotNull Gs2AttributeValue
gs2CbindFlag
-
Constructor Summary
Constructors Constructor Description Gs2Header(@NotNull Gs2CbindFlag cbindFlag)
Construct and validates a Gs2Header with no authzid nor channel binding.Gs2Header(@NotNull Gs2CbindFlag cbindFlag, @Nullable java.lang.String cbName)
Construct and validates a Gs2Header with no authzid.Gs2Header(@NotNull Gs2CbindFlag cbindFlag, @Nullable java.lang.String cbName, @Nullable java.lang.String authzid)
Construct and validates a Gs2Header.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static void
checkChannelBinding(@NotNull Gs2CbindFlag cbindFlag, @Nullable java.lang.String cbName)
@Nullable java.lang.String
getAuthzid()
Return the authzid.@NotNull Gs2CbindFlag
getChannelBindingFlag()
Return the channel binding flag.@Nullable java.lang.String
getChannelBindingName()
Return the channel binding type.static @NotNull Gs2Header
parseFrom(@NotNull java.lang.String message)
Read a Gs2Header from a String.private static void
validateChannelBindingType(@NotNull java.lang.String cbname)
Checks that the channel binding name is valid.(package private) java.lang.StringBuilder
writeTo(java.lang.StringBuilder sb)
Write the class information to the given StringBuffer.
-
-
-
Field Detail
-
gs2CbindFlag
@NotNull private final @NotNull Gs2AttributeValue gs2CbindFlag
-
authzid
@Nullable private final @Nullable Gs2AttributeValue authzid
-
-
Constructor Detail
-
Gs2Header
public Gs2Header(@NotNull @NotNull Gs2CbindFlag cbindFlag, @Nullable @Nullable java.lang.String cbName, @Nullable @Nullable java.lang.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 flagcbName
- The channel-binding name. Should be not null if channel binding is requiredauthzid
- The optional SASL authorization identity- Throws:
java.lang.IllegalArgumentException
- If the channel binding flag and argument are invalid
-
Gs2Header
public Gs2Header(@NotNull @NotNull Gs2CbindFlag cbindFlag, @Nullable @Nullable java.lang.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 flagcbName
- The channel-binding name. Should be not null iif channel binding is required- Throws:
java.lang.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:
java.lang.IllegalArgumentException
- If the channel binding is supported (no cbname can be provided here)
-
-
Method Detail
-
getChannelBindingFlag
@NotNull public @NotNull Gs2CbindFlag getChannelBindingFlag()
Return the channel binding flag.- Returns:
- the
gs2-cbind-flag
-
getChannelBindingName
@Nullable public @Nullable java.lang.String getChannelBindingName()
Return the channel binding type.- Returns:
- the
cb-name
-
getAuthzid
@Nullable public @Nullable java.lang.String getAuthzid()
Return the authzid.- Returns:
- the
"a=" saslname
-
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 classStringWritable
- Parameters:
sb
- Where to write the data.- Returns:
- The same StringBuffer.
-
parseFrom
@NotNull public static @NotNull Gs2Header parseFrom(@NotNull @NotNull java.lang.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:
java.lang.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 java.lang.String cbName)
-
validateChannelBindingType
private static void validateChannelBindingType(@NotNull @NotNull java.lang.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:
java.lang.IllegalArgumentException
- If the name is not a valid channel binding type.- See Also:
- IANA Channel-Binding Types
-
-