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
public abstract class AbstractLDAPConnector extends AbstractLogEnabled implements Serviceable
This abstract class contains all basic for a ldap connection using config parameters
-
-
Field Summary
Fields Modifier and Type Field Description protected static int__DEFAULT_PAGE_SIZEThe default LDAP search page sizeprotected String_ldapAdminPasswordPassword associated with the admin.protected String_ldapAdminRelativeDNDistinguished name of the admin used for searching.protected String_ldapAliasDerefModeAlias dereferencing mode.protected String_ldapAuthenticationMethodAuthentication method used.protected String_ldapBaseDNBase DN to the ldap server.protected boolean_ldapFollowReferralsEnable following referrals.protected String_ldapUrlURL connection to the ldap server.protected boolean_ldapUseSSLUse ssl for connecting to ldap server.protected boolean_pagingSupportedIndicates if the LDAP server supports paging feature.protected boolean_serverSideSortingTrue to sort the results on the server side, false to get the results unsorted.
-
Constructor Summary
Constructors Constructor Description AbstractLDAPConnector()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected 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 valueprotected Hashtable<String,String>_getContextEnv()Get the parameters for connecting to the ldap server.protected String_getFilter(Configuration configuration, String filterKey)Get the filter from configuration key and check itprotected Hashtable<String,String>_getRootContextEnv()Get 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_testConnectionsPooled()Test if connections are pooledprotected boolean_testPagingSupported()Test if paging is supported by the underlying directory server.protected String[]getSortByFields()Get the fields to sort by if the search is sortedbooleanisPagingSupported()Test if paging is supported by the underlying directory server.voidservice(ServiceManager serviceManager)-
Methods inherited from class org.ametys.runtime.plugin.component.AbstractLogEnabled
getLogger, setLogger
-
-
-
-
Field Detail
-
__DEFAULT_PAGE_SIZE
protected static final int __DEFAULT_PAGE_SIZE
The default LDAP search page size- See Also:
- Constant Field Values
-
_ldapBaseDN
protected String _ldapBaseDN
Base DN to the ldap server.
-
_ldapAdminRelativeDN
protected String _ldapAdminRelativeDN
Distinguished name of the admin used for searching.
-
_ldapAdminPassword
protected String _ldapAdminPassword
Password associated with the admin.
-
_ldapAuthenticationMethod
protected String _ldapAuthenticationMethod
Authentication method used.
-
_ldapUseSSL
protected boolean _ldapUseSSL
Use ssl for connecting to ldap server.
-
_ldapFollowReferrals
protected boolean _ldapFollowReferrals
Enable following referrals.
-
_ldapAliasDerefMode
protected String _ldapAliasDerefMode
Alias dereferencing mode.
-
_serverSideSorting
protected boolean _serverSideSorting
True to sort the results on the server side, false to get the results unsorted.
-
_pagingSupported
protected boolean _pagingSupported
Indicates if the LDAP server supports paging feature.
-
-
Constructor Detail
-
AbstractLDAPConnector
public AbstractLDAPConnector()
-
-
Method Detail
-
_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:
servicein 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_SCOPEandSearchControls.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 configurationkey- The child node of configuration containing the config parameter name- Returns:
- The value (can be null)
- Throws:
ConfigurationException- if parameter is missing
-
_getContextEnv
protected Hashtable<String,String> _getContextEnv()
Get the parameters for connecting to the ldap server.- Returns:
- Parameters for connecting.
-
_getRootContextEnv
protected Hashtable<String,String> _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 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
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 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
protected String[] getSortByFields()
Get the fields to sort by if the search is sorted- Returns:
- The list of fields to sort by
-
-