Class JdbcUserDirectory
java.lang.Object
org.ametys.runtime.plugin.component.AbstractLogEnabled
org.ametys.plugins.core.impl.user.directory.AbstractCachingUserDirectory
org.ametys.plugins.core.impl.user.directory.JdbcUserDirectory
- All Implemented Interfaces:
ModifiableUserDirectory
,UserDirectory
,Cacheable
,Model
,ModelItemAccessor
,ModelItemContainer
,LogEnabled
,Disposable
,Component
,Contextualizable
,Serviceable
public class JdbcUserDirectory
extends AbstractCachingUserDirectory
implements ModifiableUserDirectory, Component, Contextualizable
Use a jdbc driver for getting the list of users, modifying them and also
authenticate them.
Passwords need to be encrypted with MD5 and encoded in base64.
Passwords need to be encrypted with MD5 and encoded in base64.
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected class
An internal query executor.class
Class representing a SQL predicate (to use in a WHERE or HAVING clause), with optional string parameters.protected class
Query executor in order to select an userprotected class
Query executor in order to select usersNested classes/interfaces inherited from interface org.ametys.core.util.Cacheable
Cacheable.SingleCacheConfiguration
-
Field Summary
Modifier and TypeFieldDescriptionprotected Context
The avalon contextprotected String
The identifier of data sourceprotected ServiceManager
The avalon service managerprotected Map<String,
ElementDefinition> Modelprotected SourceResolver
The cocoon source resolverprotected String
The name of users' SQL tableprotected static final String
The base plugin (for i18n key) -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected User
Create the user implementation from the result set of the requestprotected void
_fillModifyStatement
(PreparedStatement stmt, Map<String, String> userInformation) Fill the statement with the user informationsprotected JdbcUserDirectory.JdbcPredicate
_getMandatoryPredicate
(String pattern) Get the mandatory predicate to use when querying users by pattern.protected String
_getPatternToMatch
(String pattern) Get the pattern to match user loginprotected User
Retrieve an user from a result set_getUsersProcessResultSet
(ResultSet rs, boolean isLogin) Populate the user list with the result setprotected boolean
_isMD5Encrypted
(String password) Determines if the password is encrypted with MD5 algorithmprotected void
_updateToSSHAPassword
(String login, String password) Generate a salt key and encrypt the password with the sha2 algorithmvoid
Add a new user to the list.boolean
checkCredentials
(String login, String password) Authenticate a user with its credentialsvoid
contextualize
(Context context) protected PreparedStatement
createAddStatement
(Connection con, Map<String, String> userInformation) Create Add statementprotected PreparedStatement
createModifyStatement
(Connection con, Map<String, String> userInformation) Create statement to update databaseprotected String
Returns a String identifying the type of this directory, used in the cache screen in _admin, such as 'SQL' or 'LDAP'.protected CurrentUserProvider
Lazy lookup theCurrentUserProvider
Retrieves the Family Id (for example the extension point) Each model Id have to be unique in it's family IdCollection<? extends ModelItem>
Retrieves all the model items of this accessorprotected ObservationManager
Lazy lookup theObservationManager
protected Connection
Get the connection to the databaseGet a particular user by his login.getUserByEmail
(String email) Get a particular user by his email (search should be case insensitive).getUsers()
Get the list of all users of one directory.Get a list of users from a directory given the parametersgetView()
Retrieve the view of the Modelvoid
Initialize the user's directory with given parameters' values.void
Remove an user from the list.void
service
(ServiceManager manager) void
Modify informations about an user of the list.Validate user information.Methods inherited from class org.ametys.plugins.core.impl.user.directory.AbstractCachingUserDirectory
dispose, getCacheByLogin, getCacheByMail, getCacheManager, getId, getLabel, getManagedCaches, getParameterValues, getPopulationId, getUserDirectoryModelId, setPopulationId
Methods inherited from class org.ametys.runtime.plugin.component.AbstractLogEnabled
getLogger, setLogger
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.ametys.core.util.Cacheable
createCaches, getCache, hasComputableSize, isCachingEnabled, removeCaches
Methods inherited from interface org.ametys.runtime.model.ModelItemAccessor
getChild, getModelItem, hasModelItem
Methods inherited from interface org.ametys.core.user.directory.UserDirectory
getId, getLabel, getParameterValues, getPopulationId, getUserDirectoryModelId, isCaseSensitive, setPopulationId
-
Field Details
-
BASE_PLUGIN_NAME
The base plugin (for i18n key)- See Also:
-
_dataSourceId
The identifier of data source -
_userTableName
The name of users' SQL table -
_model
Model -
_manager
The avalon service manager -
_context
The avalon context -
_sourceResolver
The cocoon source resolver
-
-
Constructor Details
-
JdbcUserDirectory
public JdbcUserDirectory()
-
-
Method Details
-
contextualize
- Specified by:
contextualize
in interfaceContextualizable
- Throws:
ContextException
-
service
- Specified by:
service
in interfaceServiceable
- Overrides:
service
in classAbstractCachingUserDirectory
- Throws:
ServiceException
-
getFamilyId
Description copied from interface:Model
Retrieves the Family Id (for example the extension point) Each model Id have to be unique in it's family Id- Specified by:
getFamilyId
in interfaceModel
- Returns:
- content point (for example "org.ametys.cms.contenttype.ContentTypeExtensionPoint" for a content)
-
getCacheTypeLabel
Description copied from class:AbstractCachingUserDirectory
Returns a String identifying the type of this directory, used in the cache screen in _admin, such as 'SQL' or 'LDAP'.- Specified by:
getCacheTypeLabel
in classAbstractCachingUserDirectory
- Returns:
- this directory's type
-
init
Description copied from interface:UserDirectory
Initialize the user's directory with given parameters' values.- Specified by:
init
in interfaceUserDirectory
- Overrides:
init
in classAbstractCachingUserDirectory
- Parameters:
id
- The non-null and non-empty unique identifierudModelId
- The id of user directory extension pointparamValues
- The parameters' valueslabel
- The optional label
-
getObservationManager
Lazy lookup theObservationManager
- Returns:
- the observation manager
-
getCurrentUserProvider
Lazy lookup theCurrentUserProvider
- Returns:
- the current user provider
-
getSQLConnection
Get the connection to the database- Returns:
- the SQL connection
-
getUsers
Description copied from interface:UserDirectory
Get the list of all users of one directory.- Specified by:
getUsers
in interfaceUserDirectory
- Returns:
- list of users as Collection of
User
s, empty if a problem occurs.
-
getUsers
Description copied from interface:UserDirectory
Get a list of users from a directory given the parameters- Specified by:
getUsers
in interfaceUserDirectory
- Parameters:
count
- The limit of users to retrieveoffset
- The number of result to ignore before starting to collect users.parameters
- A map of additional parameters, see implementation.- Returns:
- The list of retrieved
User
-
getUser
Description copied from interface:UserDirectory
Get a particular user by his login.- Specified by:
getUser
in interfaceUserDirectory
- Parameters:
login
- Login of the user to get. Cannot be null.- Returns:
- User's information as a
User
instance or null if the user login does not exist.
-
getUserByEmail
Description copied from interface:UserDirectory
Get a particular user by his email (search should be case insensitive).- Specified by:
getUserByEmail
in interfaceUserDirectory
- Parameters:
email
- Email of the user to get. Cannot be null.- Returns:
- User's information as a
User
instance or null if the user email does not exist. - Throws:
NotUniqueUserException
- If many users match this email
-
checkCredentials
Description copied from interface:UserDirectory
Authenticate a user with its credentials- Specified by:
checkCredentials
in interfaceUserDirectory
- Parameters:
login
- The login to check. Cannot be null.password
- The password to check.- Returns:
- true if the user is authenticated, false otherwise.
-
add
Description copied from interface:ModifiableUserDirectory
Add a new user to the list.- Specified by:
add
in interfaceModifiableUserDirectory
- Parameters:
userInformation
- Informations about the user, see implementation. Cannot be null.- Throws:
InvalidModificationException
- if the login exists yet or if at least one of the parameter is invalid.
-
validate
Description copied from interface:ModifiableUserDirectory
Validate user information.- Specified by:
validate
in interfaceModifiableUserDirectory
- Parameters:
userInformation
- Informations about the user, see implementation. Cannot be null.- Returns:
- validation errors.
-
update
Description copied from interface:ModifiableUserDirectory
Modify informations about an user of the list.- Specified by:
update
in interfaceModifiableUserDirectory
- Parameters:
userInformation
- New informations about the user, see implementation. Cannot be null.- Throws:
InvalidModificationException
- if the login does not match in the list or if at least one of the parameter is invalid.
-
remove
Description copied from interface:ModifiableUserDirectory
Remove an user from the list.- Specified by:
remove
in interfaceModifiableUserDirectory
- Parameters:
login
- The user's login. Cannot be null.- Throws:
InvalidModificationException
- if the user cannot be removed
-
getModelItems
Description copied from interface:ModelItemAccessor
Retrieves all the model items of this accessor- Specified by:
getModelItems
in interfaceModelItemAccessor
- Returns:
- the model items
-
_getMandatoryPredicate
Get the mandatory predicate to use when querying users by pattern.- Parameters:
pattern
- The pattern to match, can be null.- Returns:
- a
JdbcUserDirectory.JdbcPredicate
, can be null.
-
_getPatternToMatch
Get the pattern to match user login- Parameters:
pattern
- the pattern- Returns:
- the pattern to match user login
-
_isMD5Encrypted
Determines if the password is encrypted with MD5 algorithm- Parameters:
password
- The encrypted password- Returns:
- true if the password is encrypted with MD5 algorithm
-
_updateToSSHAPassword
Generate a salt key and encrypt the password with the sha2 algorithm- Parameters:
login
- The user loginpassword
- The user pasword
-
createAddStatement
protected PreparedStatement createAddStatement(Connection con, Map<String, String> userInformation) throws SQLExceptionCreate Add statement- Parameters:
con
- The sql connectionuserInformation
- the user informations- Returns:
- The statement
- Throws:
SQLException
- if an error occurred
-
createModifyStatement
protected PreparedStatement createModifyStatement(Connection con, Map<String, String> userInformation) throws SQLExceptionCreate statement to update database- Parameters:
con
- The sql connectionuserInformation
- The user information- Returns:
- The statement
- Throws:
SQLException
- if an error occurred
-
_fillModifyStatement
protected void _fillModifyStatement(PreparedStatement stmt, Map<String, String> userInformation) throws SQLExceptionFill the statement with the user informations- Parameters:
stmt
- The statement of the sql requestuserInformation
- the user informations- Throws:
SQLException
- if an error occurred
-
_getUsersProcessResultSet
Populate the user list with the result set- Parameters:
rs
- The result setisLogin
- true for login, false for email- Returns:
- The user list
- Throws:
SQLException
- If an SQL exception occurs
-
_createUserFromResultSet
Create the user implementation from the result set of the request- Parameters:
rs
- The result set where you can use get methods- Returns:
- The user reflecting the current cursor position in the result set
- Throws:
SQLException
- if an error occurred
-
_getUserProcessResultSet
protected User _getUserProcessResultSet(ResultSet rs, String login, Cache<String, User> cache) throws SQLExceptionRetrieve an user from a result set- Parameters:
rs
- The result setlogin
- The user logincache
- the cache to use. Is null if caching is not enabled- Returns:
- The retrieved user or null if not found
- Throws:
SQLException
- If an SQL Exception occurs
-
getView
Description copied from interface:ModifiableUserDirectory
Retrieve the view of the Model- Specified by:
getView
in interfaceModifiableUserDirectory
- Returns:
- The View
-