Package com.jsgalactic.axiom.security
Class SessionAuthenticator
java.lang.Object
com.jsgalactic.axiom.security.SessionAuthenticator
- All Implemented Interfaces:
Authenticator
An
Authenticator that reads the identity from the request's session, so the policies of
Security work for cookie-authenticated browsers exactly as for bearer tokens.
var security = Security.of(sessions.authenticator());
app.use(sessions);
app.get("/account", handler, security.authenticated()); // 401 without a signed-in session
A request without a valid session is anonymous (empty), never a 401 by itself: an unknown,
expired, forged or malformed cookie is indistinguishable from none. Only the policy that requires
an identity answers 401, with this authenticator's challenge. Cookies carry no standard
authentication scheme, so the challenge is informational; set one with Sessions.authenticator(String). Inside Sessions the session already loaded for the
request is used; outside it the store is consulted read-only (the lookup counts as an access).
Thread-safe; created by Sessions.
-
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
Description copied from interface:AuthenticatorVerifies the request's credentials.- Specified by:
authenticatein interfaceAuthenticator- 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
-
challenge
Description copied from interface:AuthenticatorReturns 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.- Specified by:
challengein interfaceAuthenticator- Returns:
- challenge: an auth scheme, optionally followed by a space and parameters, in visible ASCII
-