Class BasicAuthScheme

java.lang.Object
uk.ac.starlink.auth.BasicAuthScheme
All Implemented Interfaces:
AuthScheme

public class BasicAuthScheme extends Object implements AuthScheme
Implements HTTP Basic Authentication as defined in RFC7617.
Since:
15 Jun 2020
Author:
Mark Taylor
See Also:
  • Field Details

  • Method Details

    • getName

      public String getName()
      Description copied from interface: AuthScheme
      Returns a human-readable name identifying the authentication scheme implemented by this object. The returned string is typically the auth-scheme token from an RFC7235 challenge (for instance "Basic" for Basic authentication), but a different value may be used if required to distinguish it from other instances.
      Specified by:
      getName in interface AuthScheme
      Returns:
      "Basic"
    • createContextFactory

      public ContextFactory createContextFactory(Challenge challenge, URL url) throws BadChallengeException
      Description copied from interface: AuthScheme
      Attempts to return an object that can take user input to generate an AuthContext based on a given challenge. There are three possible outcomes of this method.
      • If this scheme recognises the challenge type and expects to be able to use it to generate AuthContexts, it should return a suitable ContextFactory
      • If this scheme recognises the challenge type but something is wrong with the challenge syntax (for instance missing parameters), it should throw a BadChallengeException, preferably with an explanatory message
      • If this scheme doesn't recognise the challenge type (for instance the challenge scheme string is not that implemented by this object), it should return null

      Note that this method should just examine the syntax of the supplied challenge; it is not expected to make network connections etc to determine if context creation will be successful.

      Specified by:
      createContextFactory in interface AuthScheme
      Parameters:
      challenge - authentication challenge object
      url - URL with which the challenge is associated
      Returns:
      context factory if challenge is recognised, or null if it isn't
      Throws:
      BadChallengeException - if the challenge scheme etc indicates that it is destined for this AuthScheme, but the challenge is not of the correct form
    • encodeUserPass

      public static String encodeUserPass(String user, char[] pass)
      Encodes the user:password pair as a Base64-encoded string, as described by RFC 7617.
      Parameters:
      user - user name
      pass - password
      Returns:
      base64-encoded string