Class ClientFirstMessage
- java.lang.Object
-
- com.impossibl.postgres.protocol.sasl.scram.message.ClientFirstMessage
-
- All Implemented Interfaces:
StringWritable
public class ClientFirstMessage extends Object implements StringWritable
Constructs and parses client-first-messages. Message contains aGs2Header
, a username and a nonce. Formal syntax is:client-first-message-bare = [reserved-mext ","] username "," nonce ["," extensions] client-first-message = gs2-header client-first-message-bare
Note that extensions are not supported.- See Also:
- [RFC5802] Section 7
-
-
Constructor Summary
Constructors Constructor Description ClientFirstMessage(Gs2CbindFlag gs2CbindFlag, String authzid, String cbindName, String user, String nonce)
Constructs a client-first-message for the given parameters.ClientFirstMessage(Gs2Header gs2Header, String user, String nonce)
Constructs a client-first-message for the given user, nonce and gs2Header.ClientFirstMessage(String user, String nonce)
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 String
getAuthzid()
Gs2CbindFlag
getChannelBindingFlag()
String
getChannelBindingName()
Gs2Header
getGs2Header()
String
getNonce()
String
getUser()
boolean
isChannelBinding()
static ClientFirstMessage
parseFrom(String clientFirstMessage)
Construct aClientFirstMessage
instance from a message (String)String
toString()
StringBuffer
writeTo(StringBuffer sb)
Write the class information to the given StringBuffer.StringBuffer
writeToWithoutGs2Header(StringBuffer sb)
Limited version of theObject.toString()
method, that doesn't write the GS2 header.
-
-
-
Constructor Detail
-
ClientFirstMessage
public ClientFirstMessage(Gs2Header gs2Header, String user, String nonce) throws IllegalArgumentException
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 headeruser
- The SCRAM usernonce
- The nonce for this session- Throws:
IllegalArgumentException
- If any of the arguments is null or empty
-
ClientFirstMessage
public ClientFirstMessage(Gs2CbindFlag gs2CbindFlag, String authzid, String cbindName, String user, String nonce)
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 nameuser
- The SCRAM usernonce
- The nonce for this session- Throws:
IllegalArgumentException
- If the flag, user or nonce are null or empty
-
ClientFirstMessage
public ClientFirstMessage(String user, String nonce)
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:
user
- The SCRAM usernonce
- The nonce for this session- Throws:
IllegalArgumentException
- If the user or nonce are null or empty
-
-
Method Detail
-
getChannelBindingFlag
public Gs2CbindFlag getChannelBindingFlag()
-
isChannelBinding
public boolean isChannelBinding()
-
getChannelBindingName
public String getChannelBindingName()
-
getAuthzid
public String getAuthzid()
-
getGs2Header
public Gs2Header getGs2Header()
-
getUser
public String getUser()
-
getNonce
public String getNonce()
-
writeToWithoutGs2Header
public StringBuffer writeToWithoutGs2Header(StringBuffer sb)
Limited version of theObject.toString()
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
-
writeTo
public StringBuffer writeTo(StringBuffer sb)
Description copied from interface:StringWritable
Write the class information to the given StringBuffer.- Specified by:
writeTo
in interfaceStringWritable
- Parameters:
sb
- Where to write the data.- Returns:
- The same StringBuffer.
-
parseFrom
public static ClientFirstMessage parseFrom(String clientFirstMessage) throws ScramParseException, IllegalArgumentException
Construct aClientFirstMessage
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-messageIllegalArgumentException
- If the message is null or empty
-
-