Class Challenge

java.lang.Object
uk.ac.starlink.auth.Challenge

public class Challenge extends Object
Represents and parses challenge specifications as defined by RFC7235.
Since:
9 Jun 2020
Author:
Mark Taylor
See Also:
  • Constructor Details

    • Challenge

      public Challenge(String schemeName, String realm, Map<String,String> params)
      Constructs a challenge with an optional realm and auth parameters.
      Parameters:
      schemeName - scheme name, case insensitive
      realm - specified realm value, or null
      params - additional parameters (excluding realm); keys are case insensitive and will be mapped to lower
    • Challenge

      public Challenge(String schemeName, String token68)
      Constructs a challenge with token68 string
      Parameters:
      schemeName - scheme name, case insensitive
      token68 - token68 string
  • Method Details

    • getSchemeName

      public String getSchemeName()
      Returns the authentication scheme name.
      Returns:
      scheme name, case insensitive
    • getRealm

      public String getRealm()
      Returns the authentication realm if defined.
      Returns:
      realm or null
    • getToken68

      public String getToken68()
      Returns the token68 value if defined. If this is non-null, then there will be no parameters or realm.
      Returns:
      token68 or null
    • getParams

      public Map<String,String> getParams()
      Returns any auth parameters that form part of this challenge excluding the realm.
      Returns:
      name->value map giving parameters; parameter names have been normalised to lower case
    • getRequiredRealm

      public String getRequiredRealm() throws BadChallengeException
      Utility method giving a non-empty realm for this challenge. If no realm has been defined, a BadChallengeException is thrown.
      Returns:
      non-empty realm string
      Throws:
      BadChallengeException - if there is no realm
    • getRequiredParameter

      public String getRequiredParameter(String key) throws BadChallengeException
      Utility method giving a non-empty value for a named parameter of this challenge. If the named parameter has not been specified, a BadChallengeException is thrown.
      Parameters:
      key - parameter name, case-insensitive
      Returns:
      non-empty value for parameter key
      Throws:
      BadChallengeException - if no value is specified for key
    • getRequiredParameterUrl

      public URL getRequiredParameterUrl(String key) throws BadChallengeException
      Utility method giving a non-null URL value for a named parameter of this challenge. If the named parameter is not specified or cannot be turned into a URL, a BadChallengeException is thrown.
      Parameters:
      key - parameter name, case-insensitive
      Returns:
      non-null URL for parameter key
      Throws:
      BadChallengeException - if no URL value is specified for key
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • parseChallenges

      public static List<Challenge> parseChallenges(String challengeTxt)
      Parses the content of a WWW-Authenticate header as a sequence of RFC7235 challenges. According to RFC7235 there should be at least one value in the result, but syntactically invalid challenge text is just ignored, so the result is not guaranteed to be non-empty.
      Parameters:
      challengeTxt - text as value of WWW-Authenticate header
      Returns:
      list of parsed challenges
    • main

      public static void main(String[] args)
      Will parse a WWW-Authenticate string on the command line and print out the parsed challenges.