public class DefaultRealm extends Object implements Realm
Realm implementation| Modifier and Type | Class and Description |
|---|---|
static class |
DefaultRealm.RealmBuilder
Default
Builder implementation. |
Realm.BuilderAuthenticator.MessageAuthenticatorCONTEXT_KEY| Constructor and Description |
|---|
DefaultRealm()
Constructor
|
DefaultRealm(String name)
Constructor with Realm name.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addAuthenticationListener(Authentication.AuthenticationListener authenticationListener)
Register an
Authentication.AuthenticationListener. |
void |
addAuthenticationTokenResolver(AuthenticationToken.AuthenticationTokenResolver<?> authenticationTokenResolver)
Add an
AuthenticationToken.AuthenticationTokenResolver to translate messages into AuthenticationTokens. |
<T extends AuthenticationToken> |
addAuthenticator(Authenticator<T> authenticator)
Add a concrete
Authenticator for a specific AuthenticationToken type to this Realm |
<P extends Permission> |
addAuthorizer(Authorizer<P> authorizer)
Add and
Authorizer to support a specific Permission type |
Authentication |
authenticate(AuthenticationToken authenticationToken)
Attempts to perform authentication using given
AuthenticationToken. |
Authentication |
authenticate(Message<?,?> message,
String... schemes)
Try to authenticate given
message with the same contract as
Authenticator.authenticate(AuthenticationToken). |
Optional<String> |
getName()
Get optional realm name.
|
Class<? extends Permission> |
getPermissionType()
Get supported
Permission type |
<T extends Message> |
getResolversForMessageType(Class<T> messageType)
Get available
AuthenticationToken.AuthenticationTokenResolvers for given message type |
Class<? extends AuthenticationToken> |
getTokenType()
Get supported
AuthenticationToken type |
boolean |
isPermitted(Authentication authentication,
Collection<? extends Permission> permissions)
Check if given Authentication has all the specified permissions.
|
boolean |
isPermitted(Authentication authentication,
Permission... permissions)
Check if given Authentication has all the specified permission/s.
|
boolean |
isPermitted(Authentication authentication,
String... permissions)
Check if given Authentication has all specified permission/s, using the
String permission representation. |
boolean |
isPermittedAny(Authentication authentication,
Collection<? extends Permission> permissions)
Check if given Authentication has any of the specified permissions.
|
boolean |
isPermittedAny(Authentication authentication,
Permission... permissions)
Check if given Authentication has any of the specified permission/s.
|
boolean |
isPermittedAny(Authentication authentication,
String... permissions)
Check if given Authentication has any of the specified permission/s, using the
String permission
representation. |
void |
removeAuthenticationListener(Authentication.AuthenticationListener authenticationListener)
Removes a registered
Authentication.AuthenticationListener. |
void |
setName(String name)
Set Realm name
|
boolean |
supportsMessage(Class<? extends Message<?,?>> messageType)
Check whether this MessageAuthenticator supports given message type
|
boolean |
supportsPermission(Class<? extends Permission> permissionType)
Returns whether this Realm supports given
Permission type |
boolean |
supportsToken(Class<? extends AuthenticationToken> authenticationTokenType)
Returns whether this Realm supports given
AuthenticationToken type (i.e. |
String |
toString() |
equals, getClass, hashCode, notify, notifyAll, wait, wait, waitbuilder, getCurrent, requirecreatecreatepublic DefaultRealm()
public DefaultRealm(String name)
name - Realm namepublic Optional<String> getName()
Realmpublic void setName(String name)
name - the name to setpublic <T extends Message> List<AuthenticationToken.AuthenticationTokenResolver<T>> getResolversForMessageType(Class<T> messageType)
Authenticator.MessageAuthenticatorAuthenticationToken.AuthenticationTokenResolvers for given message typegetResolversForMessageType in interface Authenticator.MessageAuthenticatorT - Message typemessageType - Message typepublic Class<? extends AuthenticationToken> getTokenType()
AuthenticatorAuthenticationToken typegetTokenType in interface Authenticator<AuthenticationToken>AuthenticationToken typepublic <T extends AuthenticationToken> void addAuthenticator(Authenticator<T> authenticator)
RealmAuthenticator for a specific AuthenticationToken type to this RealmaddAuthenticator in interface RealmT - Authentication token typeauthenticator - The Authenticator to add (not null)public boolean supportsToken(Class<? extends AuthenticationToken> authenticationTokenType)
RealmAuthenticationToken type (i.e. and Authenticator bound
to given token type is registered in realm)supportsToken in interface RealmauthenticationTokenType - AuthenticationToken typetrue if Realm supports given AuthenticationToken typepublic Authentication authenticate(AuthenticationToken authenticationToken) throws AuthenticationException
AuthenticatorAuthenticationToken.
If the authentication is successful, an Authentication instance is returned that represents the user's
account data and provides authorization operations.
If authentication is not successful, a suitable exception should be thrown. See the specific exceptions listed below for builtin available authentication errors.
authenticate in interface Authenticator<AuthenticationToken>authenticationToken - the authentication request tokenAuthenticationException - Authentication failedDisabledAccountException,
LockedAccountException,
UnknownAccountException,
ExpiredCredentialsException,
InvalidCredentialsException,
UnsupportedTokenException,
UnexpectedAuthenticationExceptionpublic void addAuthenticationTokenResolver(AuthenticationToken.AuthenticationTokenResolver<?> authenticationTokenResolver)
Authenticator.MessageAuthenticatorAuthenticationToken.AuthenticationTokenResolver to translate messages into AuthenticationTokens.addAuthenticationTokenResolver in interface Authenticator.MessageAuthenticatorauthenticationTokenResolver - The AuthenticationToken.AuthenticationTokenResolver to add (not null)public boolean supportsMessage(Class<? extends Message<?,?>> messageType)
Authenticator.MessageAuthenticatorsupportsMessage in interface Authenticator.MessageAuthenticatormessageType - Message type to checktrue if message type is supportedpublic Authentication authenticate(Message<?,?> message, String... schemes) throws AuthenticationException
Authenticator.MessageAuthenticatormessage with the same contract as
Authenticator.authenticate(AuthenticationToken).
Message-based authentication is performed using a resolvers chain: all available resolvers for given message
type are called in the order they where registered, and the first not null AuthenticationToken
returned by a resolver is used for attempting authentication.
authenticate in interface Authenticator.MessageAuthenticatormessage - Request messageschemes - Optional authentication schemes to use. If not null or empty, only
AuthenticationToken.AuthenticationTokenResolvers bound to given scheme names will be usedAuthenticationException - Authentication failedpublic Class<? extends Permission> getPermissionType()
AuthorizerPermission typegetPermissionType in interface Authorizer<Permission>Permission typepublic boolean supportsPermission(Class<? extends Permission> permissionType)
RealmPermission typesupportsPermission in interface RealmpermissionType - Permission typetrue if this Realm supports given Permission typepublic <P extends Permission> void addAuthorizer(Authorizer<P> authorizer)
RealmAuthorizer to support a specific Permission typeaddAuthorizer in interface RealmP - Permission typeauthorizer - The Authorizer to add (not null)public boolean isPermitted(Authentication authentication, Permission... permissions)
AuthorizerisPermitted in interface Authorizer<Permission>authentication - The Authentication for which to check the permissionspermissions - The permissions to be checkedtrue if given Authentication has all the specified permissionspublic boolean isPermitted(Authentication authentication, String... permissions)
AuthorizerString permission representation.
String permission match against Authentication Permissions should be performed using the
Permission.getPermission() method.
isPermitted in interface Authorizer<Permission>authentication - The Authentication for which to check the permissionspermissions - The permissions to be checkedtrue if given Authentication has all the specified permissionspublic boolean isPermittedAny(Authentication authentication, Permission... permissions)
AuthorizerisPermittedAny in interface Authorizer<Permission>authentication - The Authentication for which to check the permissionspermissions - The permissions to be checkedtrue if given Authentication has any of the specified permissionpublic boolean isPermittedAny(Authentication authentication, String... permissions)
AuthorizerString permission
representation.
String permission match against Authentication Permissions will be performed using
Permission.getPermission() method.
isPermittedAny in interface Authorizer<Permission>authentication - The Authentication for which to check the permissionspermissions - The permissions to be checkedtrue if given Authentication has any of the specified permissionpublic boolean isPermitted(Authentication authentication, Collection<? extends Permission> permissions)
AuthorizerisPermitted in interface Authorizer<Permission>authentication - The Authentication for which to check the permissionspermissions - The permissions to be checkedtrue if given Authentication has all the specified permissionspublic boolean isPermittedAny(Authentication authentication, Collection<? extends Permission> permissions)
AuthorizerisPermittedAny in interface Authorizer<Permission>authentication - The Authentication for which to check the permissionspermissions - The permissions to be checkedtrue if given Authentication has any of the specified permissionpublic 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.