Class BasicAuthScheme

java.lang.Object
org.attribyte.api.http.AuthScheme
org.attribyte.api.http.impl.BasicAuthScheme

public class BasicAuthScheme extends AuthScheme
The Standard (insecure) "Basic" scheme.
  • Field Details

  • Constructor Details

    • BasicAuthScheme

      public BasicAuthScheme()
      Create a scheme with no realm.
    • BasicAuthScheme

      public BasicAuthScheme(String realm)
      Create a scheme with a realm.
      Parameters:
      realm - The realm.
  • Method Details

    • addAuth

      public Request addAuth(Request request, String id, String secret) throws GeneralSecurityException
      Description copied from class: AuthScheme
      Adds authentication credentials to a request.
      Specified by:
      addAuth in class AuthScheme
      Parameters:
      request - The request to which credentials are added.
      id - An id that uniquely identifies the user (e.g. 'username').
      secret - The authentication secret for the username.
      Returns:
      The request with authentication credentials added.
      Throws:
      GeneralSecurityException - on security-related error adding auth.
    • hasCredentials

      public boolean hasCredentials(Request request)
      Description copied from class: AuthScheme
      Determines if the request has any (invalid or valid) credentials for this scheme.
      Specified by:
      hasCredentials in class AuthScheme
      Parameters:
      request - The request.
      Returns:
      Does the request appear to have appropriate credentials?
    • getUserId

      public String getUserId(Request request) throws GeneralSecurityException
      Description copied from class: AuthScheme
      Gets the user id from the request, if possible.
      Specified by:
      getUserId in class AuthScheme
      Parameters:
      request - The request.
      Returns:
      The user id, or null if none.
      Throws:
      GeneralSecurityException - on security-related error getting user id.
    • authenticate

      public Response authenticate(Request request, String userId, String secret) throws GeneralSecurityException
      Description copied from class: AuthScheme
      Authenticates the request.
      Specified by:
      authenticate in class AuthScheme
      Parameters:
      request - The request.
      userId - The user id for the secret.
      secret - The secret data.
      Returns:
      The HTTP "Unauthorized" response if request is not authorized, otherwise null.
      Throws:
      GeneralSecurityException - on security-related error during authentication.
    • buildAuthHeaderValue

      public static final String buildAuthHeaderValue(String username, String password)
      Builds an auth header.
      Parameters:
      username - The username.
      password - The password.
      Returns:
      The auth header value.