Class ApiKeyAuthenticationService

java.lang.Object
alpine.server.auth.ApiKeyAuthenticationService
All Implemented Interfaces:
AuthenticationService

public class ApiKeyAuthenticationService extends Object implements AuthenticationService
Authentication service that validates API keys.
Since:
1.0.0
Author:
Steve Springett
  • Constructor Summary

    Constructors
    Constructor
    Description
    ApiKeyAuthenticationService(org.glassfish.jersey.server.ContainerRequest request, boolean allowByQuery)
    Given the specified ContainerRequest, the constructor retrieves a header named 'X-Api-Key' or, if allowed, a URI query parameter named 'apiKey', if they exist.
  • Method Summary

    Modifier and Type
    Method
    Description
    Authenticates the API key (if it was specified in the X-Api-Key header or apiKey query param and returns a Principal if authentication is successful.
    boolean
    Returns whether an API key was specified or not.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ApiKeyAuthenticationService

      public ApiKeyAuthenticationService(org.glassfish.jersey.server.ContainerRequest request, boolean allowByQuery)
      Given the specified ContainerRequest, the constructor retrieves a header named 'X-Api-Key' or, if allowed, a URI query parameter named 'apiKey', if they exist.
      Parameters:
      request - the ContainerRequest object
      allowByQuery - allow looking for the API key in the query when it is not passed via header
      Since:
      1.0.0
  • Method Details

    • isSpecified

      public boolean isSpecified()
      Returns whether an API key was specified or not.
      Specified by:
      isSpecified in interface AuthenticationService
      Returns:
      true if API key was specified, false if not
      Since:
      1.0.0
    • authenticate

      public Principal authenticate() throws AuthenticationException
      Authenticates the API key (if it was specified in the X-Api-Key header or apiKey query param and returns a Principal if authentication is successful. Otherwise, returns an AuthenticationException.
      Specified by:
      authenticate in interface AuthenticationService
      Returns:
      a Principal of which ApiKey is an instance of
      Throws:
      AuthenticationException - upon an authentication failure
      Since:
      1.0.0