Package alpine.server.auth
Class ApiKeyAuthenticationService
java.lang.Object
alpine.server.auth.ApiKeyAuthenticationService
- All Implemented Interfaces:
AuthenticationService
Authentication service that validates API keys.
- Since:
- 1.0.0
- Author:
- Steve Springett
-
Constructor Summary
ConstructorsConstructorDescriptionApiKeyAuthenticationService(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 TypeMethodDescriptionAuthenticates the API key (if it was specified in the X-Api-Key header) and returns a Principal if authentication is successful.booleanReturns whether an API key was specified or not.
-
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:
isSpecifiedin interfaceAuthenticationService- Returns:
- true if API key was specified, false if not
- Since:
- 1.0.0
-
authenticate
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:
authenticatein interfaceAuthenticationService- Returns:
- a Principal of which ApiKey is an instance of
- Throws:
AuthenticationException- upon an authentication failure- Since:
- 1.0.0
-