Class AuthorizationHeader

java.lang.Object
org.forgerock.http.protocol.Header
org.forgerock.http.header.AuthorizationHeader

public class AuthorizationHeader extends Header
A header class representing the Authorization HTTP header.

The Authorization header is made up of <type><space><credentials>, where credentials can be any text that fulfils the requirements of the type. e.g. for a type of Basic, the credentials will be base64encode(username + ":" + password).

  • Field Details

  • Constructor Details

    • AuthorizationHeader

      public AuthorizationHeader()
  • Method Details

    • getName

      public String getName()
      Description copied from class: Header
      Returns the name of the header, as it would canonically appear within an HTTP message.
      Specified by:
      getName in class Header
      Returns:
      The name of the header, as it would canonically appear within an HTTP message.
    • getValues

      public List<String> getValues()
      Description copied from class: Header
      Returns the header as a list of strings. If the header has no values then it must return an empty list, never null. Each String should represent the value component of the key-value pair that makes up the HTTP header - as such, for some Header implementations each String in this List may contain multiple token-separated values.

      The List returned from this method should not be expected to be mutable. However, some subclasses of Header may choose to implement it as such.

      Specified by:
      getValues in class Header
      Returns:
      The header as a non-null list of string values. Can be an empty list.
    • setRawValue

      public AuthorizationHeader setRawValue(String rawValue) throws MalformedHeaderException
      Set the raw value of the header.
      Parameters:
      rawValue - The raw value.
      Returns:
      The header.
      Throws:
      MalformedHeaderException - If the value is malformed.
    • getRawValue

      public String getRawValue()
      Get the raw value of the header.
      Returns:
      The raw value.
    • getType

      public String getType()
      Get the type of the authorization being presented, e.g. Basic
      Returns:
      The type.
    • getCredentials

      public String getCredentials()
      Get the credentials component of the header value.
      Returns:
      The credentials string.
    • parseCredentials

      public <C> Optional<C> parseCredentials(CredentialsParser<C> parser) throws MalformedHeaderException
      Parse the credentials to a rich type.
      Type Parameters:
      C - The rich type for the credentials.
      Parameters:
      parser - The parser that can parse to the rich type.
      Returns:
      An optional of the parsed credentials, or an empty optional if the type is not supported by the provided parser.
      Throws:
      MalformedHeaderException - If the credentials are not valid for the type.
    • valueOf

      public static AuthorizationHeader valueOf(String value) throws MalformedHeaderException
      Parse a string as an Authorization header value.
      Parameters:
      value - The value.
      Returns:
      The header.
      Throws:
      MalformedHeaderException - If the header cannot be parsed as an Authorization header.
    • valueOf

      public static AuthorizationHeader valueOf(Message<?> message) throws MalformedHeaderException
      Constructs a new header, initialized from the specified message.
      Parameters:
      message - The message to initialize the header from.
      Returns:
      The parsed header.
      Throws:
      MalformedHeaderException - If the Authorization header is present but malformed.