Package com.ongres.scram.common.message
Class ClientFirstMessage
- java.lang.Object
-
- com.ongres.scram.common.message.ClientFirstMessage
-
- All Implemented Interfaces:
StringWritable
public class ClientFirstMessage extends java.lang.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, java.lang.String authzid, java.lang.String cbindName, java.lang.String user, java.lang.String nonce)
Constructs a client-first-message for the given parameters.ClientFirstMessage(Gs2Header gs2Header, java.lang.String user, java.lang.String nonce)
Constructs a client-first-message for the given user, nonce and gs2Header.ClientFirstMessage(java.lang.String user, java.lang.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 java.lang.String
getAuthzid()
Gs2CbindFlag
getChannelBindingFlag()
java.lang.String
getChannelBindingName()
Gs2Header
getGs2Header()
java.lang.String
getNonce()
java.lang.String
getUser()
private static Gs2Header
gs2Header(Gs2CbindFlag gs2CbindFlag, java.lang.String authzid, java.lang.String cbindName)
boolean
isChannelBinding()
static ClientFirstMessage
parseFrom(java.lang.String clientFirstMessage)
Construct aClientFirstMessage
instance from a message (String)java.lang.String
toString()
java.lang.StringBuffer
writeTo(java.lang.StringBuffer sb)
Write the class information to the given StringBuffer.java.lang.StringBuffer
writeToWithoutGs2Header(java.lang.StringBuffer sb)
Limited version of theObject.toString()
method, that doesn't write the GS2 header.
-
-
-
Field Detail
-
gs2Header
private final Gs2Header gs2Header
-
user
private final java.lang.String user
-
nonce
private final java.lang.String nonce
-
-
Constructor Detail
-
ClientFirstMessage
public ClientFirstMessage(Gs2Header gs2Header, java.lang.String user, java.lang.String nonce) throws java.lang.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:
java.lang.IllegalArgumentException
- If any of the arguments is null or empty
-
ClientFirstMessage
public ClientFirstMessage(Gs2CbindFlag gs2CbindFlag, java.lang.String authzid, java.lang.String cbindName, java.lang.String user, java.lang.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:
java.lang.IllegalArgumentException
- If the flag, user or nonce are null or empty
-
ClientFirstMessage
public ClientFirstMessage(java.lang.String user, java.lang.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:
java.lang.IllegalArgumentException
- If the user or nonce are null or empty
-
-
Method Detail
-
gs2Header
private static Gs2Header gs2Header(Gs2CbindFlag gs2CbindFlag, java.lang.String authzid, java.lang.String cbindName)
-
getChannelBindingFlag
public Gs2CbindFlag getChannelBindingFlag()
-
isChannelBinding
public boolean isChannelBinding()
-
getChannelBindingName
public java.lang.String getChannelBindingName()
-
getAuthzid
public java.lang.String getAuthzid()
-
getGs2Header
public Gs2Header getGs2Header()
-
getUser
public java.lang.String getUser()
-
getNonce
public java.lang.String getNonce()
-
writeToWithoutGs2Header
public java.lang.StringBuffer writeToWithoutGs2Header(java.lang.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 java.lang.StringBuffer writeTo(java.lang.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(java.lang.String clientFirstMessage) throws ScramParseException, java.lang.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-messagejava.lang.IllegalArgumentException
- If the message is null or empty
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-