Package com.jsgalactic.axiom.security
Interface Authenticator
- All Known Implementing Classes:
JwtAuthenticator,SessionAuthenticator
public interface Authenticator
Turns the credentials a request carries into a verified
SecurityIdentity. Implemented
once per credential scheme, for example a bearer token or an API key, and used through Security.
Outcomes:
- The request carries no credentials for this scheme: return empty. The request continues
anonymously; a policy that needs an identity then answers 401 with
challenge(). - The credentials are valid: return the identity.
- The credentials are present but malformed, expired, forged or otherwise invalid: throw an
UnauthorizedExceptioncarrying a challenge, which is answered 401 asapplication/problem+jsonwithWWW-Authenticate. Never put the credential, or anything derived from it, into the exception's code or challenge; attach diagnostic detail as a cause withinitCause, which reaches logs only.
Thread safety and lifecycle. One instance serves every request concurrently, on the request's thread, under its deadline; implementations must be thread-safe and should not block for long. The application owns the instance through the middleware it is registered with.
-
Method Summary
Modifier and TypeMethodDescriptionauthenticate(Request request) Verifies the request's credentials.Returns theWWW-Authenticatechallenge sent when a policy requires an identity and the request carries no credentials, for exampleBearer realm="api".
-
Method Details
-
authenticate
Verifies the request's credentials.- Parameters:
request- the immutable request; headers are untrusted client input- Returns:
- the verified identity, or empty when the request carries no credentials for this scheme
- Throws:
UnauthorizedException- when credentials are present but invalid
-
challenge
String challenge()Returns theWWW-Authenticatechallenge sent when a policy requires an identity and the request carries no credentials, for exampleBearer realm="api". A constant chosen by the application, never a value taken from a request.- Returns:
- challenge: an auth scheme, optionally followed by a space and parameters, in visible ASCII
-