Class ClientFirstMessage

  • All Implemented Interfaces:
    StringWritable

    public class ClientFirstMessage
    extends java.lang.Object
    implements StringWritable
    Constructs and parses client-first-messages. Message contains a Gs2Header, 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
    • 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 header
        user - The SCRAM user
        nonce - 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 flag
        authzid - The optional authzid
        cbindName - The optional channel binding name
        user - The SCRAM user
        nonce - 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 user
        nonce - 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.util.Optional<java.lang.String> getChannelBindingName()
      • getAuthzid

        public java.util.Optional<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 the Object.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 interface StringWritable
        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 a ClientFirstMessage 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-message
        java.lang.IllegalArgumentException - If the message is null or empty
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object