public class DefaultRealm extends Object implements Realm
Realm
implementationModifier and Type | Class and Description |
---|---|
static class |
DefaultRealm.RealmBuilder
Default
Builder implementation. |
Realm.Builder
Authenticator.MessageAuthenticator
CONTEXT_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 AuthenticationToken s. |
<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.AuthenticationTokenResolver s 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. and Authenticator bound
to given token type is registered in realm) |
String |
toString() |
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
builder, getCurrent, require
create
create
public DefaultRealm()
public DefaultRealm(String name)
name
- Realm namepublic Optional<String> getName()
Realm
public void setName(String name)
name
- the name to setpublic <T extends Message> List<AuthenticationToken.AuthenticationTokenResolver<T>> getResolversForMessageType(Class<T> messageType)
Authenticator.MessageAuthenticator
AuthenticationToken.AuthenticationTokenResolver
s for given message typegetResolversForMessageType
in interface Authenticator.MessageAuthenticator
T
- Message typemessageType
- Message typepublic Class<? extends AuthenticationToken> getTokenType()
Authenticator
AuthenticationToken
typegetTokenType
in interface Authenticator<AuthenticationToken>
AuthenticationToken
typepublic <T extends AuthenticationToken> void addAuthenticator(Authenticator<T> authenticator)
Realm
Authenticator
for a specific AuthenticationToken
type to this RealmaddAuthenticator
in interface Realm
T
- Authentication token typeauthenticator
- The Authenticator
to add (not null)public boolean supportsToken(Class<? extends AuthenticationToken> authenticationTokenType)
Realm
AuthenticationToken
type (i.e. and Authenticator
bound
to given token type is registered in realm)supportsToken
in interface Realm
authenticationTokenType
- AuthenticationToken typetrue
if Realm supports given AuthenticationToken typepublic Authentication authenticate(AuthenticationToken authenticationToken) throws AuthenticationException
Authenticator
AuthenticationToken
.
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
,
UnexpectedAuthenticationException
public void addAuthenticationTokenResolver(AuthenticationToken.AuthenticationTokenResolver<?> authenticationTokenResolver)
Authenticator.MessageAuthenticator
AuthenticationToken.AuthenticationTokenResolver
to translate messages into AuthenticationToken
s.addAuthenticationTokenResolver
in interface Authenticator.MessageAuthenticator
authenticationTokenResolver
- The AuthenticationToken.AuthenticationTokenResolver
to add (not null)public boolean supportsMessage(Class<? extends Message<?,?>> messageType)
Authenticator.MessageAuthenticator
supportsMessage
in interface Authenticator.MessageAuthenticator
messageType
- Message type to checktrue
if message type is supportedpublic Authentication authenticate(Message<?,?> message, String... schemes) throws AuthenticationException
Authenticator.MessageAuthenticator
message
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.MessageAuthenticator
message
- Request messageschemes
- Optional authentication schemes to use. If not null or empty, only
AuthenticationToken.AuthenticationTokenResolver
s bound to given scheme names will be usedAuthenticationException
- Authentication failedpublic Class<? extends Permission> getPermissionType()
Authorizer
Permission
typegetPermissionType
in interface Authorizer<Permission>
Permission
typepublic boolean supportsPermission(Class<? extends Permission> permissionType)
Realm
Permission
typesupportsPermission
in interface Realm
permissionType
- Permission typetrue
if this Realm supports given Permission typepublic <P extends Permission> void addAuthorizer(Authorizer<P> authorizer)
Realm
Authorizer
to support a specific Permission
typeaddAuthorizer
in interface Realm
P
- Permission typeauthorizer
- The Authorizer
to add (not null)public boolean isPermitted(Authentication authentication, Permission... permissions)
Authorizer
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 isPermitted(Authentication authentication, String... permissions)
Authorizer
String
permission representation.
String permission match against Authentication Permission
s 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)
Authorizer
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 isPermittedAny(Authentication authentication, String... permissions)
Authorizer
String
permission
representation.
String permission match against Authentication Permission
s 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)
Authorizer
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, Collection<? extends Permission> permissions)
Authorizer
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 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.