public class DefaultAuthenticator extends java.lang.Object implements Authenticator
When client connectionInfo contains property AUTHREALM={realName} credentials
(typically user id and password) are validated by
CredentialsValidator configured for that realm.
When client connectionInfo doesn't contains AUTHREALM property credentials are validated internally on the database
Rights assignment can be managed through UserToRolesMapper
Default configuration has a realm H2 that validate credentials through JAAS api (appName=h2). To customize configuration set h2.authConfigFile system property to refer a valid h2auth.xml config file
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
DEFAULT_REALMNAME |
| Constructor and Description |
|---|
DefaultAuthenticator()
Create the Authenticator with default configurations
|
DefaultAuthenticator(boolean skipDefaultInitialization)
Create authenticator and optionally skip the default configuration.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addRealm(java.lang.String name,
CredentialsValidator credentialsValidator)
Add an authentication realm.
|
User |
authenticate(AuthenticationInfo authenticationInfo,
Database database)
Perform user authentication.
|
void |
configureFromUrl(java.net.URL configUrl)
Configure the authenticator from a configuration file
|
protected static DefaultAuthenticator |
getInstance() |
java.util.List<UserToRolesMapper> |
getUserToRolesMappers()
UserToRoleMappers assign roles to authenticated users
|
void |
init(Database database)
Initializes the authenticator.
|
boolean |
isAllowUserRegistration()
If set create external users in the database if not present.
|
boolean |
isCreateMissingRoles()
When set create roles not found in the database.
|
boolean |
isPersistUsers()
If set save users externals defined during the authentication.
|
void |
setAllowUserRegistration(boolean allowUserRegistration)
If set to
true creates external users in the database if not present. |
void |
setCreateMissingRoles(boolean createMissingRoles)
Sets the flag that define behavior in case external roles not found in the database.
|
void |
setPersistUsers(boolean persistUsers)
If set to
true saves users externals defined during the authentication. |
void |
setUserToRolesMappers(UserToRolesMapper... userToRolesMappers) |
public static final java.lang.String DEFAULT_REALMNAME
public DefaultAuthenticator()
public DefaultAuthenticator(boolean skipDefaultInitialization)
skipDefaultInitialization - if true default initialization is skippedprotected static final DefaultAuthenticator getInstance()
public boolean isPersistUsers()
true if user will be persisted,
otherwise returns falsepublic void setPersistUsers(boolean persistUsers)
true saves users externals defined during the authentication.persistUsers - true if user will be persisted,
otherwise false.public boolean isAllowUserRegistration()
true if creation external user is allowed,
otherwise returns falsepublic void setAllowUserRegistration(boolean allowUserRegistration)
true creates external users in the database if not present.allowUserRegistration - true if creation external user is allowed,
otherwise returns falsepublic boolean isCreateMissingRoles()
true if not found roles will be created,
false roles are silently skipped.public void setCreateMissingRoles(boolean createMissingRoles)
createMissingRoles - when is true not found roles are created,
when is false roles are silently skipped.public void addRealm(java.lang.String name,
CredentialsValidator credentialsValidator)
name - realm namecredentialsValidator - credentials validator for realmpublic java.util.List<UserToRolesMapper> getUserToRolesMappers()
public void setUserToRolesMappers(UserToRolesMapper... userToRolesMappers)
public void init(Database database) throws AuthConfigException
init in interface Authenticatordatabase - where authenticator is initializedAuthConfigExceptionpublic void configureFromUrl(java.net.URL configUrl)
throws AuthenticationException,
org.xml.sax.SAXException,
java.io.IOException,
javax.xml.parsers.ParserConfigurationException
configUrl - URL of configuration fileAuthenticationExceptionorg.xml.sax.SAXExceptionjava.io.IOExceptionjavax.xml.parsers.ParserConfigurationExceptionpublic final User authenticate(AuthenticationInfo authenticationInfo, Database database) throws AuthenticationException
Authenticatorauthenticate in interface AuthenticatorauthenticationInfo - authentication info.database - target database instance.AuthenticationException