public interface AuthContext extends Authentication.AuthenticationNotifier
The AuthContext stores an Authentication obtained through an Authenticator using an
AuthenticationToken. The authenticate(AuthenticationToken) method is provided to perform an authentication
operation. As opposite, the unauthenticate() method removes any authentication informations from the
AuthContext.
The getAuthentication() method can be used to check whether an Authentication is currently bound to
AuthContext and obtain it.
A list of authorization control methods are provided to perform access control decisions using current context Authentication.
Extends Authentication.AuthenticationNotifier to allow Authentication.AuthenticationListener registration.
| 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. |
Optional<Authentication> |
getAuthentication()
Get current Authentication in this context.
|
static Optional<AuthContext> |
getCurrent()
Convenience method to obtain the current
AuthContext made available as Context resource, using
default ClassLoader. |
default boolean |
isAuthenticated()
Gets whether this
AuthContext is authenticated, i.e. an Authentication is available. |
boolean |
isPermitted(Collection<Permission> permissions)
Check if current Authentication has all specified permission/s using a Collection
If no Authentication in bound to this context, always returns
false. |
boolean |
isPermitted(Permission... permissions)
Check if current Authentication has all specified permission/s.
|
boolean |
isPermitted(String... permissions)
Check if current Authentication has all specified permission/s using String permission form.
|
boolean |
isPermittedAny(Collection<Permission> permissions)
Check if current Authentication has any of specified permission/s using a Collection
If no Authentication in bound to this context, always returns
false. |
boolean |
isPermittedAny(Permission... permissions)
Check if current Authentication has any of specified permission/s
If no Authentication in bound to this context, always returns
false. |
boolean |
isPermittedAny(String... permissions)
Check if current Authentication has any of specified permission/s using String permission form.
|
Optional<Authentication> |
unauthenticate()
Unbound current
Authentication from this AuthContext, if any |
addAuthenticationListener, removeAuthenticationListenerOptional<Authentication> getAuthentication()
Principals are authenticated using authenticate(AuthenticationToken). When authentication process is
successful, an Authentication is bound to this AuthContext and can be obtained using this method.
Authentication is bound to this
AuthContextdefault boolean isAuthenticated()
AuthContext is authenticated, i.e. an Authentication is available.true if this AuthContext is authenticated, false otherwiseAuthentication authenticate(AuthenticationToken authenticationToken) throws AuthenticationException
AuthenticationToken.
If the authentication is successful, an Authentication instance is stored in this AuthContext and can be
retrieved using 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 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 anyboolean isPermitted(Permission... permissions)
If no Authentication in bound to this context, always returns false.
permissions - Permissions to checktrue if current Authentication has all specified permissionboolean isPermitted(String... permissions)
String permission match against Authentication Permissions will be performed using
Permission.getPermission() method.
If no Authentication in bound to this context, always returns false.
permissions - Permissions to checktrue if current Authentication has all specified permissionboolean isPermittedAny(Permission... permissions)
If no Authentication in bound to this context, always returns false.
permissions - Permissions to checktrue if current Authentication has any of specified permissionboolean isPermittedAny(String... permissions)
String permission match against Authentication Permissions will be performed using
Permission.getPermission() method.
If no Authentication in bound to this context, always returns false.
permissions - Permissions to checktrue if current Authentication has any of specified permissionboolean isPermitted(Collection<Permission> permissions)
If no Authentication in bound to this context, always returns false.
permissions - Permissions to checktrue if current Authentication has all specified permissionboolean isPermittedAny(Collection<Permission> permissions)
If no Authentication in bound to this context, always returns false.
permissions - Permissions to checktrue if current Authentication has any of specified permissionstatic 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 create(Realm realm)
AuthContext using given realm.realm - Realm which acts as Authenticator and AuthorizerAuthContext instanceCopyright © 2017 The Holon Platform. All rights reserved.