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)
    Given the specified ContainerRequest, the constructor retrieves a header named 'X-Api-Key', if it exists.
  • Method Summary

    Modifier and Type
    Method
    Description
    Authenticates the API key (if it was specified in the X-Api-Key header) 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)
      Given the specified ContainerRequest, the constructor retrieves a header named 'X-Api-Key', if it exists.
      Parameters:
      request - the ContainerRequest object
      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) 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