public class DefaultAuthContext extends Object implements AuthContext
AuthContext
implementation using a Realm
to perform authentication and authorization
operations.AuthContext.AuthenticationHolder
CONTEXT_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.AuthenticationTokenResolver s
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 Permission s. |
boolean |
isPermitted(Permission... permissions)
Checks if the current
Authentication has all the specified Permission s. |
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, wait
create, create, getCurrent, require
isAuthenticated, requireAuthentication
public 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()
AuthenticationInspector
Authentication
, if available.getAuthentication
in interface AuthenticationInspector
Authentication
, or an empty Optional if not available.public Authentication authenticate(AuthenticationToken authenticationToken) throws AuthenticationException
AuthContext
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.
authenticate
in interface AuthContext
authenticationToken
- the authentication request tokenAuthentication
instance result of authentication processAuthenticationException
- Authentication failedpublic Authentication authenticate(Message<?,?> message, String... schemes) throws AuthenticationException
AuthContext
message
with the same contract as
AuthContext.authenticate(AuthenticationToken)
, using Realm
registered AuthenticationToken.AuthenticationTokenResolver
s
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 AuthContext
message
- Authentication request messageschemes
- Optional authentication schemes to use. If not null or empty, only
AuthenticationToken.AuthenticationTokenResolver
s bound to given scheme names will be usedAuthentication
instance result of authentication processAuthenticationException
- Authentication failedpublic Optional<Authentication> unauthenticate()
AuthContext
Authentication
from this AuthContext, if anyunauthenticate
in interface AuthContext
public boolean isPermitted(Permission... permissions)
AuthenticationInspector
Authentication
has all the specified Permission
s.
The permission control strategy depends on the concrete authorization strategy of the current authentication context.
isPermitted
in interface AuthenticationInspector
permissions
- The permissions to be checkedtrue
if the current Authentication
has all the specified permission,
false
otherwisepublic boolean isPermitted(String... permissions)
AuthenticationInspector
Authentication
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 AuthenticationInspector
permissions
- The permissions to be checkedtrue
if the current Authentication
has all the specified permission,
false
otherwisepublic boolean isPermittedAny(Permission... permissions)
AuthenticationInspector
Authentication
has any of the specified Permission
.
The permission control strategy depends on the concrete authorization strategy of the current authentication context.
isPermittedAny
in interface AuthenticationInspector
permissions
- The permissions to be checkedtrue
if the current Authentication
has any of the specified permission,
false
otherwisepublic boolean isPermittedAny(String... permissions)
AuthenticationInspector
Authentication
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 AuthenticationInspector
permissions
- The permissions to be checkedtrue
if the current Authentication
has any of the specified permission,
false
otherwisepublic boolean isPermitted(Collection<? extends Permission> permissions)
AuthenticationInspector
Authentication
has all the specified Permission
s.
The permission control strategy depends on the concrete authorization strategy of the current authentication context.
isPermitted
in interface AuthenticationInspector
permissions
- The permissions to be checkedtrue
if the current Authentication
has all the specified permission,
false
otherwisepublic boolean isPermittedAny(Collection<? extends Permission> permissions)
AuthenticationInspector
Authentication
has any of the specified Permission
.
The permission control strategy depends on the concrete authorization strategy of the current authentication context.
isPermittedAny
in interface AuthenticationInspector
permissions
- The permissions to be checkedtrue
if the current Authentication
has any of the specified permission,
false
otherwisepublic void addAuthenticationListener(Authentication.AuthenticationListener authenticationListener)
Authentication.AuthenticationNotifier
Authentication.AuthenticationListener
.addAuthenticationListener
in interface Authentication.AuthenticationNotifier
authenticationListener
- The listener to add (not null)public void removeAuthenticationListener(Authentication.AuthenticationListener authenticationListener)
Authentication.AuthenticationNotifier
Authentication.AuthenticationListener
.removeAuthenticationListener
in interface Authentication.AuthenticationNotifier
authenticationListener
- Listener to removeCopyright © 2019 The Holon Platform. All rights reserved.