Package com.ongres.scram.common
Class ClientFirstMessage
- java.lang.Object
-
- com.ongres.scram.common.StringWritable
-
- com.ongres.scram.common.AbstractScramMessage
-
- com.ongres.scram.common.ClientFirstMessage
-
public final class ClientFirstMessage extends AbstractScramMessage
Constructs and parses client-first-messages. Message contains ags2-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.StringclientNoncenonce= "r=" c-nonce [s-nonce].private @NotNull Gs2Headergs2Headergs2-header = gs2-cbind-flag "," [ authzid ] ",".private @NotNull java.lang.Stringusernameusername = "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.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) @NotNull java.lang.StringBuilderclientFirstMessageBare(@NotNull java.lang.StringBuilder sb)Limited version of the StringWritableCsv method, that doesn't write the GS2 header.@NotNull java.lang.StringgetClientNonce()Return the client nonce.@NotNull Gs2HeadergetGs2Header()Return the Gs2Header.@NotNull java.lang.StringgetUsername()Return the username.booleanisChannelBindingRequired()Check to probe if gs2-cbind-flag is set to "p=".static @NotNull ClientFirstMessageparseFrom(@NotNull java.lang.String clientFirstMessage)Construct aClientFirstMessageinstance from a message (String).(package private) java.lang.StringBuilderwriteTo(java.lang.StringBuilder sb)Write the class information to the given StringBuffer.-
Methods inherited from class com.ongres.scram.common.AbstractScramMessage
toString
-
-
-
-
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 headerusername- The SCRAM usernameclientNonce- 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 flagauthzid- The optional authzidcbindName- The optional channel binding nameusername- The SCRAM userclientNonce- 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 userclientNonce- 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 aClientFirstMessageinstance 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-messagejava.lang.IllegalArgumentException- If the message is null or empty
-
writeTo
java.lang.StringBuilder writeTo(java.lang.StringBuilder sb)
Description copied from class:StringWritableWrite the class information to the given StringBuffer.- Specified by:
writeToin classStringWritable- Parameters:
sb- Where to write the data.- Returns:
- The same StringBuffer.
-
-