public class DefaultAuthenticator extends 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
| 限定符和类型 | 字段和说明 |
|---|---|
static String |
DEFAULT_REALMNAME |
| 构造器和说明 |
|---|
DefaultAuthenticator()
Create the Authenticator with default configurations
|
DefaultAuthenticator(boolean skipDefaultInitialization)
Create authenticator and optionally skip the default configuration.
|
| 限定符和类型 | 方法和说明 |
|---|---|
void |
addRealm(String name,
CredentialsValidator credentialsValidator)
Add an authentication realm.
|
User |
authenticate(AuthenticationInfo authenticationInfo,
Database database)
Perform user authentication.
|
void |
configureFromUrl(URL configUrl)
Configure the authenticator from a configuration file
|
protected static DefaultAuthenticator |
getInstance() |
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 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(String name, CredentialsValidator credentialsValidator)
name - realm namecredentialsValidator - credentials validator for realmpublic List<UserToRolesMapper> getUserToRolesMappers()
public void setUserToRolesMappers(UserToRolesMapper... userToRolesMappers)
public void init(Database database) throws AuthConfigException
init 在接口中 Authenticatordatabase - where authenticator is initializedAuthConfigExceptionpublic void configureFromUrl(URL configUrl) throws AuthenticationException, SAXException, IOException, ParserConfigurationException
configUrl - URL of configuration fileAuthenticationException - on failureSAXException - on failureIOException - on failureParserConfigurationException - on failurepublic final User authenticate(AuthenticationInfo authenticationInfo, Database database) throws AuthenticationException
Authenticatorauthenticate 在接口中 AuthenticatorauthenticationInfo - authentication info.database - target database instance.AuthenticationException - on failureCopyright © 2022. All rights reserved.