Package org.ametys.core.util.ldap
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
This abstract class contains all basic for a ldap connection using config parameters
-
Field Summary
Modifier and TypeFieldDescriptionprotected static final int
The default LDAP search page sizeprotected String
Password associated with the admin.protected String
Distinguished name of the admin used for searching.protected String
Alias dereferencing mode.protected String
Authentication method used.protected String
Base DN to the ldap server.protected boolean
Enable following referrals.protected String
URL connection to the ldap server.protected boolean
Use ssl for connecting to ldap server.protected boolean
Indicates if the LDAP server supports paging feature.protected boolean
True to sort the results on the server side, false to get the results unsorted. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
_cleanup
(Context context, NamingEnumeration result) Clean a connection to an ldap server.protected void
_delayedInitialize
(String dataSourceId) Call this method with the datasource id to initialize this componentprotected String
_getConfigParameter
(Configuration configuration, String key) Get a config parameter valueGet the parameters for connecting to the ldap server.protected String
_getFilter
(Configuration configuration, String filterKey) Get the filter from configuration key and check itGet the parameters for connecting to the ldap server, root DN.protected int
_getSearchScope
(Configuration configuration, String searchScopeKey) Get the search scope from configuration keyprotected boolean
_hasMoreEntries
(int pageSize, LdapContext context) Determines if there are more entries for the LDAP server to return based on server-generated cookie.protected List<SearchResult>
_search
(int pageSize, String name, String filter, Object[] filterArgs, SearchControls searchControls, int offset, int limit) Executes a LDAP searchprotected List<SearchResult>
_search
(int pageSize, String name, String filter, Object[] filterArgs, SearchControls searchControls, int offset, int limit, boolean sorted) Executes a LDAP searchprotected List<SearchResult>
_search
(int pageSize, String name, String filter, SearchControls searchControls) Executes a LDAP searchprotected List<SearchResult>
_search
(int pageSize, String name, String filter, SearchControls searchControls, boolean sorted) Executes a LDAP searchprotected void
_setResultsControls
(int pageSize, LdapContext context, boolean sorted) Set paging on ldap if supported, and set the sortprotected boolean
Test if connections are pooledprotected boolean
Test if paging is supported by the underlying directory server.protected String[]
Get the fields to sort by if the search is sortedboolean
Test if paging is supported by the underlying directory server.void
service
(ServiceManager serviceManager) Methods inherited from class org.ametys.runtime.plugin.component.AbstractLogEnabled
getLogger, setLogger
-
Field Details
-
__DEFAULT_PAGE_SIZE
The default LDAP search page size- See Also:
-
_ldapUrl
URL connection to the ldap server. -
_ldapBaseDN
Base DN to the ldap server. -
_ldapAdminRelativeDN
Distinguished name of the admin used for searching. -
_ldapAdminPassword
Password associated with the admin. -
_ldapAuthenticationMethod
Authentication method used. -
_ldapUseSSL
Use ssl for connecting to ldap server. -
_ldapFollowReferrals
Enable following referrals. -
_ldapAliasDerefMode
Alias dereferencing mode. -
_serverSideSorting
True to sort the results on the server side, false to get the results unsorted. -
_pagingSupported
Indicates if the LDAP server supports paging feature.
-
-
Constructor Details
-
AbstractLDAPConnector
public AbstractLDAPConnector()
-
-
Method Details
-
_delayedInitialize
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
- Specified by:
service
in interfaceServiceable
- Throws:
ServiceException
-
_getFilter
protected String _getFilter(Configuration configuration, String filterKey) throws ConfigurationException Get the filter from configuration key and check it- Parameters:
configuration
- The configurationfilterKey
- 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 configurationsearchScopeKey
- The name of the child in configuration containing the search scope parameter name- Returns:
- The scope between
SearchControls.ONELEVEL_SCOPE
,SearchControls.SUBTREE_SCOPE
andSearchControls.OBJECT_SCOPE
. - Throws:
ConfigurationException
- if a configuration problem occurs
-
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 configurationkey
- 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
Test if paging is supported by the underlying directory server.- Returns:
- true if the server supports paging.
-
_testConnectionsPooled
Test if connections are pooled- Returns:
- true if connections are pooled
-
_cleanup
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 pagename
- the name of the context or object to searchfilter
- the filter expression to use for the searchsearchControls
- 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 pagename
- the name of the context or object to searchfilter
- the filter expression to use for the searchsearchControls
- 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 pagename
- the name of the context or object to searchfilter
- the filter expression to use for the searchfilterArgs
- 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 indexlimit
- 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 pagename
- the name of the context or object to searchfilter
- the filter expression to use for the searchfilterArgs
- 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 indexlimit
- The max number of resultssorted
- True to sort the results- Returns:
- The results of the LDAP search
- Throws:
NamingException
- if a naming exception is encountered
-
_hasMoreEntries
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 pagecontext
- 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 ldapcontext
- The ldap contextsorted
- True add the sort controls- Throws:
NamingException
- if an error occurred
-
getSortByFields
Get the fields to sort by if the search is sorted- Returns:
- The list of fields to sort by
-