Package org.ametys.core.user.population
Class UserPopulationDAO
- java.lang.Object
-
- org.ametys.runtime.plugin.component.AbstractLogEnabled
-
- org.ametys.core.user.population.UserPopulationDAO
-
- All Implemented Interfaces:
LogEnabled,Disposable,Initializable,Component,Serviceable
public class UserPopulationDAO extends AbstractLogEnabled implements Component, Serviceable, Initializable, Disposable
DAO for accessingUserPopulation
-
-
Field Summary
Fields Modifier and Type Field Description private static String__ADMIN_TABLENAMEThe sql table for admin usersprivate static String__ID_REGEXThe regular expression for an id of a user populationprivate static File__USER_POPULATIONS_FILEThe path of the XML file containing the user populationsprivate UserPopulation_adminUserPopulationThe population adminprivate CredentialProviderFactory_credentialProviderFactoryThe credential providers factoryprivate CurrentUserProvider_currentUserProviderprivate I18nUtils_i18nutilsprivate Set<String>_ignoredPopulationsThe list of population ids which are declared in the user population file but were not instanciated since their configuration led to an errorprivate long_lastFileReadingThe date (as a long) of the last time thePopulations filewas read (last update)private ServiceManager_managerprivate Set<String>_misconfiguredUserPopulationsThe misconfigured user populationsprivate ObservationManager_observationManagerprivate PopulationConsumerExtensionPoint_populationConsumerEPThe extension point for population consumersprivate UserDirectoryFactory_userDirectoryFactoryThe user directories factoryprivate Map<String,UserPopulation>_userPopulationsThe whole user populations of the applicationstatic StringADMIN_POPULATION_IDThe id of the "admin" populationstatic StringROLEAvalon Rolestatic UserIdentitySYSTEM_USER_IDENTITYThe id of the "user system" populationstatic StringSYSTEM_USER_LOGINThe id of the "user system" login
-
Constructor Summary
Constructors Constructor Description UserPopulationDAO()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private List<CredentialProvider>_configureCredentialProviders(Configuration configuration, String upId)private UserPopulation_configurePopulation(Configuration configuration, Set<String> misconfiguredUserPopulations)private List<UserDirectory>_configureUserDirectories(Configuration configuration, String upId, Set<String> misconfiguredUserPopulations)private void_createPopulationsFile(File file)private void_fillUserPopulation(UserPopulation up, I18nizableText label, List<Map<String,String>> userDirectories, List<Map<String,String>> credentialProviders, Map<String,Map<String,Object>> existingUdParameters, Map<String,Map<String,Object>> existingCpParameters, Map<String,String> udModels, Map<String,String> cpModels)private Map<String,Object>_getCPParametersFromConfiguration(Configuration conf, String modelId, String populationId)Get the typed parameters of a credential provider used by a populationprivate CredentialProviderFactory_getCredentialProviderFactory()private CurrentUserProvider_getCurrentUserProvider()private I18nUtils_getI18nUtils()private ObservationManager_getObservationManager()private PopulationConsumerExtensionPoint_getPopulationConsumerExtensionPoint()private Map<String,Object>_getTypedCPParameters(Map<String,String> parameters, String modelId)private Map<String,Object>_getTypedUDParameters(Map<String,String> parameters, String modelId)private Map<String,Object>_getUDParametersFromConfiguration(Configuration conf, String modelId, String populationId)Get the typed parameters of a user directory used by a populationprivate UserDirectoryFactory_getUserDirectoryFactory()private boolean_isCorrectId(String id)private void_keepExistingCredentialProviderPassword(String modelId, Map<String,Object> typedParamValues, Map<String,Object> existingCpParameters, String existingModelId)private void_keepExistingUserDirectoryPassword(String modelId, Map<String,Object> typedParamValues, Map<String,Object> existingUdParameters, String existingModelId)private void_readPopulations(boolean forceRead)If needed, reads the config file representing the populations and then reinitializes and updates the internal representation of the populations.private void_saxUserPopulation(UserPopulation userPopulation, TransformerHandler handler)private void_toSAX(TransformerHandler handler)private boolean_writePopulations()Erases the config file representing the populations and rebuild it from the internal representation of the populations.Map<String,Object>add(String id, String label, List<Map<String,String>> userDirectories, List<Map<String,String>> credentialProviders)Adds a new populationMap<String,Object>canRemove(String populationId)Determines if a population can be removedvoiddispose()Map<String,Object>edit(String id, String label, List<Map<String,String>> userDirectories, List<Map<String,String>> credentialProviders)Edits the given population.Map<String,Object>enable(String populationId, boolean enabled)Enables/Disables the given populationUserPopulationgetAdminPopulation()Gets the "admin" populationFilegetConfigurationFile()Return the configuration file.Map<String,Object>getEditionConfiguration()Gets the configuration for creating/editing a user population.List<UserPopulation>getEnabledUserPopulations(boolean withAdmin)Gets all the enabled populations of this applicationSet<String>getIgnoredPopulations()Returns the id of population which have a fatal invalid configuration.Set<String>getMisconfiguredPopulations()Returns the id of population which have at least one user directory or one credential provider misconfigured These populations can be used by application.Map<String,Object>getPopulationParameterValues(String id)Gets the values of the parameters of the given populationUserPopulationgetUserPopulation(String id)Gets a population with its id.Map<String,Object>getUserPopulationAsJson(UserPopulation userPopulation)Gets a population to JSON formatList<UserPopulation>getUserPopulations(boolean includeAdminPopulation)Gets all the populations of this applicationList<Object>getUserPopulationsAsJson(boolean withAdmin)Gets all the populations to JSON formatList<String>getUserPopulationsIds()Gets the list of the ids of all the population of the applicationvoidinitialize()Map<String,Object>isEnabled(String populationId)Returns the enabled state of the given populationbooleanisValid(String populationId)Determines if a population has a valid configurationMap<String,Object>remove(String id)Removes the given population.Map<String,Object>remove(String id, boolean forceDeletion)Removes the given population.voidservice(ServiceManager manager)-
Methods inherited from class org.ametys.runtime.plugin.component.AbstractLogEnabled
getLogger, setLogger
-
-
-
-
Field Detail
-
ADMIN_POPULATION_ID
public static final String ADMIN_POPULATION_ID
The id of the "admin" population- See Also:
- Constant Field Values
-
SYSTEM_USER_LOGIN
public static final String SYSTEM_USER_LOGIN
The id of the "user system" login- See Also:
- Constant Field Values
-
SYSTEM_USER_IDENTITY
public static final UserIdentity SYSTEM_USER_IDENTITY
The id of the "user system" population
-
__ADMIN_TABLENAME
private static final String __ADMIN_TABLENAME
The sql table for admin users- See Also:
- Constant Field Values
-
__USER_POPULATIONS_FILE
private static File __USER_POPULATIONS_FILE
The path of the XML file containing the user populations
-
__ID_REGEX
private static final String __ID_REGEX
The regular expression for an id of a user population- See Also:
- Constant Field Values
-
_lastFileReading
private long _lastFileReading
The date (as a long) of the last time thePopulations filewas read (last update)
-
_userPopulations
private Map<String,UserPopulation> _userPopulations
The whole user populations of the application
-
_misconfiguredUserPopulations
private Set<String> _misconfiguredUserPopulations
The misconfigured user populations
-
_ignoredPopulations
private Set<String> _ignoredPopulations
The list of population ids which are declared in the user population file but were not instanciated since their configuration led to an error
-
_adminUserPopulation
private UserPopulation _adminUserPopulation
The population admin
-
_userDirectoryFactory
private UserDirectoryFactory _userDirectoryFactory
The user directories factory
-
_credentialProviderFactory
private CredentialProviderFactory _credentialProviderFactory
The credential providers factory
-
_populationConsumerEP
private PopulationConsumerExtensionPoint _populationConsumerEP
The extension point for population consumers
-
_observationManager
private ObservationManager _observationManager
-
_currentUserProvider
private CurrentUserProvider _currentUserProvider
-
_i18nutils
private I18nUtils _i18nutils
-
_manager
private ServiceManager _manager
-
-
Constructor Detail
-
UserPopulationDAO
public UserPopulationDAO()
-
-
Method Detail
-
initialize
public void initialize()
- Specified by:
initializein interfaceInitializable
-
_getPopulationConsumerExtensionPoint
private PopulationConsumerExtensionPoint _getPopulationConsumerExtensionPoint()
-
_getObservationManager
private ObservationManager _getObservationManager()
-
_getUserDirectoryFactory
private UserDirectoryFactory _getUserDirectoryFactory()
-
_getCredentialProviderFactory
private CredentialProviderFactory _getCredentialProviderFactory()
-
_getCurrentUserProvider
private CurrentUserProvider _getCurrentUserProvider()
-
_getI18nUtils
private I18nUtils _getI18nUtils()
-
service
public void service(ServiceManager manager) throws ServiceException
- Specified by:
servicein interfaceServiceable- Throws:
ServiceException
-
getUserPopulationsAsJson
public List<Object> getUserPopulationsAsJson(boolean withAdmin)
Gets all the populations to JSON format- Parameters:
withAdmin- True to include the "admin" population- Returns:
- A list of object representing the
UserPopulations
-
getUserPopulationAsJson
public Map<String,Object> getUserPopulationAsJson(UserPopulation userPopulation)
Gets a population to JSON format- Parameters:
userPopulation- The user population to get- Returns:
- An object representing a
UserPopulation
-
getUserPopulations
public List<UserPopulation> getUserPopulations(boolean includeAdminPopulation)
Gets all the populations of this application- Parameters:
includeAdminPopulation- True to include the "admin" population- Returns:
- A list of
UserPopulation
-
getEnabledUserPopulations
public List<UserPopulation> getEnabledUserPopulations(boolean withAdmin)
Gets all the enabled populations of this application- Parameters:
withAdmin- True to include the "admin" population- Returns:
- A list of enabled
UserPopulation
-
getUserPopulation
public UserPopulation getUserPopulation(String id)
Gets a population with its id.- Parameters:
id- The id of the population- Returns:
- The
UserPopulation, or null if not found
-
getUserPopulationsIds
public List<String> getUserPopulationsIds()
Gets the list of the ids of all the population of the application- Returns:
- The list of the ids of all the populations
-
getIgnoredPopulations
public Set<String> getIgnoredPopulations()
Returns the id of population which have a fatal invalid configuration. These populations can NOT be used by application.- Returns:
- The ignored populations
-
getMisconfiguredPopulations
public Set<String> getMisconfiguredPopulations()
Returns the id of population which have at least one user directory or one credential provider misconfigured These populations can be used by application.- Returns:
- The misconfigured populations.
-
getConfigurationFile
public File getConfigurationFile()
Return the configuration file.- Returns:
- the configuration file.
-
getEditionConfiguration
public Map<String,Object> getEditionConfiguration() throws Exception
Gets the configuration for creating/editing a user population.- Returns:
- A map containing information about what is needed to create/edit a user population
- Throws:
Exception- If an error occurs.
-
getPopulationParameterValues
public Map<String,Object> getPopulationParameterValues(String id)
Gets the values of the parameters of the given population- Parameters:
id- The id of the population- Returns:
- The values of the parameters
-
getAdminPopulation
public UserPopulation getAdminPopulation()
Gets the "admin" population- Returns:
- The "admin" population
-
add
public Map<String,Object> add(String id, String label, List<Map<String,String>> userDirectories, List<Map<String,String>> credentialProviders)
Adds a new population- Parameters:
id- The unique id of the populationlabel- The label of the populationuserDirectories- A list of user directory parameterscredentialProviders- A list of credential provider parameters- Returns:
- A map containing the id of the created population, or the kind of error that occured
-
_isCorrectId
private boolean _isCorrectId(String id)
-
edit
public Map<String,Object> edit(String id, String label, List<Map<String,String>> userDirectories, List<Map<String,String>> credentialProviders)
Edits the given population.- Parameters:
id- The id of the population to editlabel- The label of the populationuserDirectories- A list of user directory parameterscredentialProviders- A list of credential provider parameters- Returns:
- A map containing the id of the edited population, or the kind of error that occured
-
_fillUserPopulation
private void _fillUserPopulation(UserPopulation up, I18nizableText label, List<Map<String,String>> userDirectories, List<Map<String,String>> credentialProviders, Map<String,Map<String,Object>> existingUdParameters, Map<String,Map<String,Object>> existingCpParameters, Map<String,String> udModels, Map<String,String> cpModels)
-
_keepExistingUserDirectoryPassword
private void _keepExistingUserDirectoryPassword(String modelId, Map<String,Object> typedParamValues, Map<String,Object> existingUdParameters, String existingModelId)
-
_keepExistingCredentialProviderPassword
private void _keepExistingCredentialProviderPassword(String modelId, Map<String,Object> typedParamValues, Map<String,Object> existingCpParameters, String existingModelId)
-
_getTypedUDParameters
private Map<String,Object> _getTypedUDParameters(Map<String,String> parameters, String modelId)
-
_getTypedCPParameters
private Map<String,Object> _getTypedCPParameters(Map<String,String> parameters, String modelId)
-
remove
public Map<String,Object> remove(String id)
Removes the given population.- Parameters:
id- The id of the population to remove- Returns:
- A map containing the id of the removed population
-
remove
public Map<String,Object> remove(String id, boolean forceDeletion)
Removes the given population.- Parameters:
id- The id of the population to removeforceDeletion- Delete the population even if it is still in use- Returns:
- A map containing the id of the removed population
-
enable
public Map<String,Object> enable(String populationId, boolean enabled)
Enables/Disables the given population- Parameters:
populationId- The id of the population to enable/disableenabled- True to enable the population, false to disable it.- Returns:
- A map containing the id of the enabled/disabled population, or with an error.
-
isValid
public boolean isValid(String populationId)
Determines if a population has a valid configuration- Parameters:
populationId- The id of the population to retrieve state- Returns:
- A map, with the response as a boolean, or an error.
-
isEnabled
public Map<String,Object> isEnabled(String populationId)
Returns the enabled state of the given population- Parameters:
populationId- The id of the population to retrieve state- Returns:
- A map, with the response as a booolean, or an error.
-
canRemove
public Map<String,Object> canRemove(String populationId)
Determines if a population can be removed- Parameters:
populationId- The id of the population- Returns:
- A map, with the response as a boolean, or an error.
-
_readPopulations
private void _readPopulations(boolean forceRead)
If needed, reads the config file representing the populations and then reinitializes and updates the internal representation of the populations.- Parameters:
forceRead- True to avoid the use of the cache and force the reading of the file
-
_createPopulationsFile
private void _createPopulationsFile(File file) throws IOException, TransformerConfigurationException, SAXException
-
_configurePopulation
private UserPopulation _configurePopulation(Configuration configuration, Set<String> misconfiguredUserPopulations) throws ConfigurationException
- Throws:
ConfigurationException
-
_configureUserDirectories
private List<UserDirectory> _configureUserDirectories(Configuration configuration, String upId, Set<String> misconfiguredUserPopulations) throws ConfigurationException
- Throws:
ConfigurationException
-
_configureCredentialProviders
private List<CredentialProvider> _configureCredentialProviders(Configuration configuration, String upId) throws ConfigurationException
- Throws:
ConfigurationException
-
_getUDParametersFromConfiguration
private Map<String,Object> _getUDParametersFromConfiguration(Configuration conf, String modelId, String populationId) throws ConfigurationException, IllegalArgumentException
Get the typed parameters of a user directory used by a population- Parameters:
conf- The user directory's configuration.modelId- The id of user directory modelpopulationId- The id of population- Returns:
- The typed parameters
- Throws:
IllegalArgumentException- if the configured user directory references a non-existing user directory modelConfigurationException- if a parameter is missing
-
_getCPParametersFromConfiguration
private Map<String,Object> _getCPParametersFromConfiguration(Configuration conf, String modelId, String populationId) throws ConfigurationException, IllegalArgumentException
Get the typed parameters of a credential provider used by a population- Parameters:
conf- The credential provider's configuration.modelId- The id of credential provider modelpopulationId- The id of population- Returns:
- The typed parameters
- Throws:
IllegalArgumentException- if the configured credential provider references a non-existing credential provider modelConfigurationException- if a parameter is missing
-
_writePopulations
private boolean _writePopulations()
Erases the config file representing the populations and rebuild it from the internal representation of the populations.- Returns:
- True if an error occured
-
_toSAX
private void _toSAX(TransformerHandler handler)
-
_saxUserPopulation
private void _saxUserPopulation(UserPopulation userPopulation, TransformerHandler handler)
-
dispose
public void dispose()
- Specified by:
disposein interfaceDisposable
-
-