public class DefaultAuthContext extends Object implements AuthContext
AuthContext implementation using a Realm to perform authentication and authorization
operations.AuthContext.AuthenticationHolderCONTEXT_KEY| Constructor and Description |
|---|
DefaultAuthContext(Realm realm)
Constructor using the default
AuthenticationHolder. |
DefaultAuthContext(Realm realm,
AuthContext.AuthenticationHolder authenticationHolder)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addAuthenticationListener(Authentication.AuthenticationListener authenticationListener)
Register an
Authentication.AuthenticationListener. |
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
AuthContext.authenticate(AuthenticationToken), using Realm registered AuthenticationToken.AuthenticationTokenResolvers
for given message type, if any. |
Optional<Authentication> |
getAuthentication()
Get the current
Authentication, if available. |
boolean |
isPermitted(Collection<? extends Permission> permissions)
Checks if the current
Authentication has all the specified Permissions. |
boolean |
isPermitted(Permission... permissions)
Checks if the current
Authentication has all the specified Permissions. |
boolean |
isPermitted(String... permissions)
Checks if the current
Authentication has all the specified permissions, using the String
permission representation. |
boolean |
isPermittedAny(Collection<? extends Permission> permissions)
Checks if the current
Authentication has any of the specified Permission. |
boolean |
isPermittedAny(Permission... permissions)
Checks if the current
Authentication has any of the specified Permission. |
boolean |
isPermittedAny(String... permissions)
Checks if the current
Authentication has any of the specified permission, using the String
permission representation. |
void |
removeAuthenticationListener(Authentication.AuthenticationListener authenticationListener)
Removes a registered
Authentication.AuthenticationListener. |
Optional<Authentication> |
unauthenticate()
Unbound current
Authentication from this AuthContext, if any |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitcreate, create, getCurrent, requireisAuthenticated, requireAuthenticationpublic DefaultAuthContext(Realm realm)
AuthenticationHolder.realm - the Realm which will be used as Authenticator and Authorizer (not null)public DefaultAuthContext(Realm realm, AuthContext.AuthenticationHolder authenticationHolder)
realm - the Realm which will be used as Authenticator and Authorizer (not null)authenticationHolder - Authentication holder (not null)public Optional<Authentication> getAuthentication()
AuthenticationInspectorAuthentication, if available.getAuthentication in interface AuthenticationInspectorAuthentication, or an empty Optional if not available.public Authentication authenticate(AuthenticationToken authenticationToken) throws AuthenticationException
AuthContextAuthenticationToken.
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.
authenticate in interface AuthContextauthenticationToken - the authentication request tokenAuthentication instance result of authentication processAuthenticationException - Authentication failedpublic Authentication authenticate(Message<?,?> message, String... schemes) throws AuthenticationException
AuthContextmessage with the same contract as
AuthContext.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.
authenticate in interface AuthContextmessage - 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 failedpublic Optional<Authentication> unauthenticate()
AuthContextAuthentication from this AuthContext, if anyunauthenticate in interface AuthContextpublic boolean isPermitted(Permission... permissions)
AuthenticationInspectorAuthentication has all the specified Permissions.
The permission control strategy depends on the concrete authorization strategy of the current authentication context.
isPermitted in interface AuthenticationInspectorpermissions - The permissions to be checkedtrue if the current Authentication has all the specified permission,
false otherwisepublic boolean isPermitted(String... permissions)
AuthenticationInspectorAuthentication has all the specified permissions, using the String
permission representation.
The permission control strategy depends on the concrete authorization strategy of the current authentication context.
isPermitted in interface AuthenticationInspectorpermissions - The permissions to be checkedtrue if the current Authentication has all the specified permission,
false otherwisepublic boolean isPermittedAny(Permission... permissions)
AuthenticationInspectorAuthentication has any of the specified Permission.
The permission control strategy depends on the concrete authorization strategy of the current authentication context.
isPermittedAny in interface AuthenticationInspectorpermissions - The permissions to be checkedtrue if the current Authentication has any of the specified permission,
false otherwisepublic boolean isPermittedAny(String... permissions)
AuthenticationInspectorAuthentication has any of the specified permission, using the String
permission representation.
The permission control strategy depends on the concrete authorization strategy of the current authentication context.
isPermittedAny in interface AuthenticationInspectorpermissions - The permissions to be checkedtrue if the current Authentication has any of the specified permission,
false otherwisepublic boolean isPermitted(Collection<? extends Permission> permissions)
AuthenticationInspectorAuthentication has all the specified Permissions.
The permission control strategy depends on the concrete authorization strategy of the current authentication context.
isPermitted in interface AuthenticationInspectorpermissions - The permissions to be checkedtrue if the current Authentication has all the specified permission,
false otherwisepublic boolean isPermittedAny(Collection<? extends Permission> permissions)
AuthenticationInspectorAuthentication has any of the specified Permission.
The permission control strategy depends on the concrete authorization strategy of the current authentication context.
isPermittedAny in interface AuthenticationInspectorpermissions - The permissions to be checkedtrue if the current Authentication has any of the specified permission,
false otherwisepublic void addAuthenticationListener(Authentication.AuthenticationListener authenticationListener)
Authentication.AuthenticationNotifierAuthentication.AuthenticationListener.addAuthenticationListener in interface Authentication.AuthenticationNotifierauthenticationListener - The listener to add (not null)public void removeAuthenticationListener(Authentication.AuthenticationListener authenticationListener)
Authentication.AuthenticationNotifierAuthentication.AuthenticationListener.removeAuthenticationListener in interface Authentication.AuthenticationNotifierauthenticationListener - Listener to removeCopyright © 2019 The Holon Platform. All rights reserved.