Class AbstractLDAPConnector

java.lang.Object
org.ametys.runtime.plugin.component.AbstractLogEnabled
org.ametys.core.util.ldap.AbstractLDAPConnector
All Implemented Interfaces:
LogEnabled, Serviceable
Direct Known Subclasses:
LDAPCollectionHelper, LDAPConnector, LdapDataSourceFactory, LdapGroupDirectory, LdapUserDirectory

public abstract class AbstractLDAPConnector extends AbstractLogEnabled implements Serviceable
This abstract class contains all basic for a ldap connection using config parameters
  • Field Details

  • Constructor Details

  • Method Details

    • _delayedInitialize

      protected void _delayedInitialize(String dataSourceId) throws Exception
      Call this method with the datasource id to initialize this component
      Parameters:
      dataSourceId - The id of the datasource
      Throws:
      Exception - If an error occurs.
    • service

      public void service(ServiceManager serviceManager) throws ServiceException
      Specified by:
      service in interface Serviceable
      Throws:
      ServiceException
    • _getFilter

      protected String _getFilter(Configuration configuration, String filterKey) throws ConfigurationException
      Get the filter from configuration key and check it
      Parameters:
      configuration - The configuration
      filterKey - The name of the child in configuration containing the filter config parameter name
      Returns:
      The value of the configured filter
      Throws:
      ConfigurationException - if the filter does not match
    • _getSearchScope

      protected int _getSearchScope(Configuration configuration, String searchScopeKey) throws ConfigurationException
      Get the search scope from configuration key
      Parameters:
      configuration - The configuration
      searchScopeKey - The name of the child in configuration containing the search scope parameter name
      Returns:
      The scope between SearchControls.ONELEVEL_SCOPE, SearchControls.SUBTREE_SCOPE and SearchControls.OBJECT_SCOPE.
      Throws:
      ConfigurationException - if a configuration problem occurs
    • isPagingSupported

      public boolean isPagingSupported()
      Test if paging is supported by the underlying directory server.
      Returns:
      true if the server supports paging.
    • _getConfigParameter

      protected String _getConfigParameter(Configuration configuration, String key) throws ConfigurationException
      Get a config parameter value
      Parameters:
      configuration - The configuration
      key - The child node of configuration containing the config parameter name
      Returns:
      The value (can be null)
      Throws:
      ConfigurationException - if parameter is missing
    • _getContextEnv

      Get the parameters for connecting to the ldap server.
      Returns:
      Parameters for connecting.
    • _getRootContextEnv

      Get the parameters for connecting to the ldap server, root DN.
      Returns:
      Parameters for connecting.
    • _testPagingSupported

      protected boolean _testPagingSupported()
      Test if paging is supported by the underlying directory server.
      Returns:
      true if the server supports paging.
    • _testConnectionsPooled

      protected boolean _testConnectionsPooled()
      Test if connections are pooled
      Returns:
      true if connections are pooled
    • _cleanup

      protected void _cleanup(Context context, NamingEnumeration result)
      Clean a connection to an ldap server.
      Parameters:
      context - The connection to the database to close.
      result - The result to close.
    • _search

      protected List<SearchResult> _search(int pageSize, String name, String filter, SearchControls searchControls) throws NamingException
      Executes a LDAP search
      Parameters:
      pageSize - The number of entries in a page
      name - the name of the context or object to search
      filter - the filter expression to use for the search
      searchControls - the search controls that control the search.
      Returns:
      The results of the LDAP search
      Throws:
      NamingException - if a naming exception is encountered
    • _search

      protected List<SearchResult> _search(int pageSize, String name, String filter, SearchControls searchControls, boolean sorted) throws NamingException
      Executes a LDAP search
      Parameters:
      pageSize - The number of entries in a page
      name - the name of the context or object to search
      filter - the filter expression to use for the search
      searchControls - the search controls that control the search.
      sorted - True to sort the results
      Returns:
      The results of the LDAP search
      Throws:
      NamingException - if a naming exception is encountered
    • _search

      protected List<SearchResult> _search(int pageSize, String name, String filter, Object[] filterArgs, SearchControls searchControls, int offset, int limit) throws NamingException
      Executes a LDAP search
      Parameters:
      pageSize - The number of entries in a page
      name - the name of the context or object to search
      filter - the filter expression to use for the search
      filterArgs - the array of arguments to substitute for the variables in filter. Can be null.
      searchControls - the search controls that control the search.
      offset - the start index
      limit - The max number of results
      Returns:
      The results of the LDAP search
      Throws:
      NamingException - if a naming exception is encountered
    • _search

      protected List<SearchResult> _search(int pageSize, String name, String filter, Object[] filterArgs, SearchControls searchControls, int offset, int limit, boolean sorted) throws NamingException
      Executes a LDAP search
      Parameters:
      pageSize - The number of entries in a page
      name - the name of the context or object to search
      filter - the filter expression to use for the search
      filterArgs - the array of arguments to substitute for the variables in filter. Can be null.
      searchControls - the search controls that control the search.
      offset - the start index
      limit - The max number of results
      sorted - True to sort the results
      Returns:
      The results of the LDAP search
      Throws:
      NamingException - if a naming exception is encountered
    • _hasMoreEntries

      protected boolean _hasMoreEntries(int pageSize, LdapContext context) throws NamingException
      Determines if there are more entries for the LDAP server to return based on server-generated cookie.
      Parameters:
      pageSize - The number of entries to be returned per page
      context - The ldap context
      Returns:
      false if there are no more entries.
      Throws:
      NamingException - If an error occurred while getting/setting the request controls
    • _setResultsControls

      protected void _setResultsControls(int pageSize, LdapContext context, boolean sorted) throws NamingException
      Set paging on ldap if supported, and set the sort
      Parameters:
      pageSize - The page size to communicate with ldap
      context - The ldap context
      sorted - True add the sort controls
      Throws:
      NamingException - if an error occurred
    • getSortByFields

      protected String[] getSortByFields()
      Get the fields to sort by if the search is sorted
      Returns:
      The list of fields to sort by