Record Class BasicCredentials

java.lang.Object
java.lang.Record
com.iizix.server.push.engine.http.BasicCredentials
Record Components:
userName - The user name, never null.
password - The password, never null, possibly empty.

public record BasicCredentials(String userName, String password) extends Record
The user name and password of an Authorization: Basic header, decoded as PUSH-WIRE-CONTRACT.md section 3.2 says: the scheme compared case-insensitively, the credentials decoded from base64 as UTF-8 (RFC 7617 charset) and split at the first colon, so a password may contain one.

A header that is not Basic, not base64 or carries no colon parses to null; the caller answers one code for every one of those, so nothing here says which it was.

Author:
Christopher Mindus
  • Constructor Details

    • BasicCredentials

      public BasicCredentials(String userName, String password)
      Creates an instance of a BasicCredentials record class.
      Parameters:
      userName - the value for the userName record component
      password - the value for the password record component
  • Method Details

    • parse

      public static BasicCredentials parse(String header)
      Parses an Authorization header.
      Parameters:
      header - The header value, null for none.
      Returns:
      The credentials, or null when the header is absent, not Basic, not base64, or carries no colon.
    • toString

      public String toString()
      Gets a string representation that never carries the password.
      Specified by:
      toString in class Record
      Returns:
      The user name only.
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • userName

      public String userName()
      Returns the value of the userName record component.
      Returns:
      the value of the userName record component
    • password

      public String password()
      Returns the value of the password record component.
      Returns:
      the value of the password record component