public interface AuthContext extends AuthenticationInspector, Authentication.AuthenticationNotifier
As an AuthenticationInspector, provides methods to check if an authentication is currently available and
obtain the Authentication reference.
Additionally, provides methods to perform authentication operations using an AuthenticationToken. As an
Authentication.AuthenticationNotifier, supports Authentication.AuthenticationListener registration to be notified when an
authentication request is successful, providing the Authentication reference.
An AuthContext is tipically bound to a Realm, to which authentication operations and permission control
strategies are delegated. In such situation, the authentication and authorization semantics are the same as those
implemented by the Realm through the registered Authenticators and Authorizers. The
create(Realm) static methods can be used to create a default AuthContext instance using a
Realm. The AuthContext.AuthenticationHolder interface can be used to customize how the Authentication
reference is managed by the AuthContext.
| Modifier and Type | Interface and Description |
|---|---|
static interface |
AuthContext.AuthenticationHolder
Auth context
Authentication holder, which handles the current Authentication reference on behalf
of the Auth context. |
| Modifier and Type | Field and Description |
|---|---|
static String |
CONTEXT_KEY
Default
Context resource reference |
| Modifier and Type | Method and Description |
|---|---|
Authentication |
authenticate(AuthenticationToken authenticationToken)
Attempts to authenticate a user using given
AuthenticationToken. |
Authentication |
authenticate(Message<?,?> message,
String... schemes)
Attempts to authenticate using given
message with the same contract as
authenticate(AuthenticationToken), using Realm registered AuthenticationToken.AuthenticationTokenResolvers
for given message type, if any. |
static AuthContext |
create(Realm realm)
Create a default
AuthContext using given realm. |
static AuthContext |
create(Realm realm,
AuthContext.AuthenticationHolder authenticationHolder)
Create a default
AuthContext using given realm and a custom AuthContext.AuthenticationHolder to
handle the current Authentication reference. |
static Optional<AuthContext> |
getCurrent()
Convenience method to obtain the current
AuthContext made available as Context resource, using
default ClassLoader. |
static AuthContext |
require()
Requires the current
AuthContext. |
Optional<Authentication> |
unauthenticate()
Unbound current
Authentication from this AuthContext, if any |
getAuthentication, isAuthenticated, isPermitted, isPermitted, isPermitted, isPermittedAny, isPermittedAny, isPermittedAny, requireAuthenticationaddAuthenticationListener, removeAuthenticationListenerAuthentication authenticate(AuthenticationToken authenticationToken) throws AuthenticationException
AuthenticationToken.
If the authentication is successful, an Authentication instance is stored in this AuthContext and can be
retrieved using AuthenticationInspector.getAuthentication(). That Authentication instance is also returned by this method.
If authentication is not successful, a suitable exception is thrown.
authenticationToken - the authentication request tokenAuthentication instance result of authentication processAuthenticationException - Authentication failedAuthentication authenticate(Message<?,?> message, String... schemes) throws AuthenticationException
message with the same contract as
authenticate(AuthenticationToken), using Realm registered AuthenticationToken.AuthenticationTokenResolvers
for given message type, if any.
If the authentication is successful, an Authentication instance is stored in this AuthContext and can be
retrieved using AuthenticationInspector.getAuthentication(). That Authentication instance is also returned by this method.
If authentication is not successful, a suitable exception is thrown.
message - Authentication request messageschemes - Optional authentication schemes to use. If not null or empty, only
AuthenticationToken.AuthenticationTokenResolvers bound to given scheme names will be usedAuthentication instance result of authentication processAuthenticationException - Authentication failedOptional<Authentication> unauthenticate()
Authentication from this AuthContext, if anystatic Optional<AuthContext> getCurrent()
AuthContext made available as Context resource, using
default ClassLoader.
See Context.resource(String, Class) for details about context resources availability conditions.
static AuthContext require()
AuthContext. If not available using getCurrent(), an
IllegalStateException is thrown.IllegalStateException - AuthContext is not available as a Context resourcestatic AuthContext create(Realm realm)
AuthContext using given realm.realm - The Realm which acts as Authenticator and Authorizer (not null)AuthContext instancestatic AuthContext create(Realm realm, AuthContext.AuthenticationHolder authenticationHolder)
AuthContext using given realm and a custom AuthContext.AuthenticationHolder to
handle the current Authentication reference.realm - The Realm Realm which acts as Authenticator and Authorizer (not null)authenticationHolder - The AuthContext.AuthenticationHolder to which the current Authentication handling
is delegated (not null)AuthContext instanceCopyright © 2019 The Holon Platform. All rights reserved.