public class Ldap extends AbstractLdap<LdapConfig> implements Serializable
Ldap contains functions for basic interaction with an LDAP.
Methods are provided for connecting, binding, querying and updating.| Modifier and Type | Class and Description |
|---|---|
static class |
Ldap.AttributeModification
Enum to define the type of attribute modification.
|
BINDING_COPY_RESULT_HANDLER, config, connectionHandler, COPY_RESULT_HANDLER, logger, NCP_COPY_RESULT_HANDLER, SR_COPY_RESULT_HANDLER| Constructor and Description |
|---|
Ldap()
Default constructor.
|
Ldap(LdapConfig ldapConfig)
This will create a new
Ldap with the supplied
LdapConfig. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
compare(SearchFilter filter)
This will perform an LDAP compare operation with the supplied filter.
|
boolean |
compare(String dn,
SearchFilter filter)
This will perform an LDAP compare operation with the supplied filter and
dn.
|
void |
create(String dn,
Attributes attrs)
This will create the supplied dn in the LDAP namespace with the supplied
attributes.
|
void |
delete(String dn)
This will delete the supplied dn from the LDAP namespace.
|
Attributes |
getAttributes(String dn)
This will return all the attributes associated with the supplied dn.
|
Attributes |
getAttributes(String dn,
String[] retAttrs)
This will return the matching attributes associated with the supplied dn.
|
Attributes |
getAttributes(String dn,
String[] retAttrs,
AttributeHandler... handler)
This will return the matching attributes associated with the supplied dn.
|
LdapConfig |
getLdapConfig()
This returns the
LdapConfig of the Ldap. |
String[] |
getSaslMechanisms()
This will return a list of SASL mechanisms that this LDAP supports.
|
Iterator<SearchResult> |
getSchema(String dn)
This will return the LDAP schema associated with the supplied dn.
|
String[] |
getSupportedControls()
This will return a list of controls that this LDAP supports.
|
Iterator<NameClassPair> |
list(String dn)
This will enumerate the names bounds to the specified context, along with
the class names of objects bound to them.
|
Iterator<Binding> |
listBindings(String dn)
This will enumerate the names bounds to the specified context, along with
the objects bound to them.
|
void |
loadFromProperties()
This will set the config parameters of this
Ldap using the
default properties file, which must be located in your classpath. |
void |
loadFromProperties(InputStream is)
This will set the config parameters of this
Ldap using the
supplied input stream. |
void |
modifyAttributes(String dn,
Ldap.AttributeModification mod,
Attributes attrs)
This will modify the supplied attributes for the supplied value given by
the modification operation.
|
void |
modifyAttributes(String dn,
ModificationItem[] mods)
This will modify the supplied dn using the supplied modifications.
|
void |
rename(String oldDn,
String newDn)
This will rename the supplied dn in the LDAP namespace.
|
Iterator<SearchResult> |
search(SearchFilter filter)
This will query the LDAP with the supplied filter.
|
Iterator<SearchResult> |
search(SearchFilter filter,
SearchControls searchControls)
This will query the LDAP with the supplied filter and search controls.
|
Iterator<SearchResult> |
search(SearchFilter filter,
String[] retAttrs)
This will query the LDAP with the supplied filter and return attributes.
|
Iterator<SearchResult> |
search(String dn,
SearchFilter filter)
This will query the LDAP with the supplied dn and filter.
|
Iterator<SearchResult> |
search(String dn,
SearchFilter filter,
SearchControls searchControls)
This will query the LDAP with the supplied dn, filter, and search controls.
|
Iterator<SearchResult> |
search(String dn,
SearchFilter filter,
SearchControls searchControls,
SearchResultHandler... handler)
This will query the LDAP with the supplied dn, filter, search controls, and
search result handler.
|
Iterator<SearchResult> |
search(String dn,
SearchFilter filter,
String[] retAttrs)
This will query the LDAP with the supplied dn, filter, and return
attributes.
|
Iterator<SearchResult> |
search(String dn,
SearchFilter filter,
String[] retAttrs,
SearchResultHandler... handler)
This will query the LDAP with the supplied dn, filter, return attributes,
and search result handler.
|
Iterator<SearchResult> |
searchAttributes(Attributes matchAttrs)
This will query the LDAP for the supplied matching attributes.
|
Iterator<SearchResult> |
searchAttributes(Attributes matchAttrs,
String[] retAttrs)
This will query the LDAP for the supplied matching attributes and return
attributes.
|
Iterator<SearchResult> |
searchAttributes(String dn,
Attributes matchAttrs)
This will query the LDAP for the supplied dn and matching attributes.
|
Iterator<SearchResult> |
searchAttributes(String dn,
Attributes matchAttrs,
String[] retAttrs)
This will query the LDAP for the supplied dn, matching attributes and
return attributes.
|
Iterator<SearchResult> |
searchAttributes(String dn,
Attributes matchAttrs,
String[] retAttrs,
SearchResultHandler... handler)
This will query the LDAP for the supplied dn, matching attributes and
return attributes.
|
void |
setLdapConfig(LdapConfig ldapConfig)
This will set the config parameters of this
Ldap. |
close, compare, connect, finalize, getContext, modifyAttributes, operationRetry, pagedSearch, reconnect, search, toStringpublic Ldap()
public Ldap(LdapConfig ldapConfig)
Ldap with the supplied
LdapConfig.ldapConfig - LdapConfigpublic void setLdapConfig(LdapConfig ldapConfig)
Ldap.setLdapConfig in class AbstractLdap<LdapConfig>ldapConfig - LdapConfigpublic LdapConfig getLdapConfig()
LdapConfig of the Ldap.LdapConfigpublic void loadFromProperties()
Ldap using the
default properties file, which must be located in your classpath.public void loadFromProperties(InputStream is)
Ldap using the
supplied input stream.is - InputStreampublic boolean compare(SearchFilter filter) throws NamingException
LdapConfig.getBaseDn() is used as the dn to compare. See compare(String, SearchFilter).filter - SearchFilter expression to use for compareboolean - result of compare operationNamingException - if the LDAP returns an errorpublic boolean compare(String dn, SearchFilter filter) throws NamingException
dn - String name to comparefilter - SearchFilter expression to use for compareboolean - result of compare operationNamingException - if the LDAP returns an errorpublic Iterator<SearchResult> search(SearchFilter filter) throws NamingException
LdapConfig.getBaseDn() is used as the start point for
searching. Search controls will be created from LdapConfig.getSearchControls(String[]). See search(String,SearchFilter,String[]).filter - SearchFilter expression to use for the searchIterator - of LDAP search resultsNamingException - if the LDAP returns an errorpublic Iterator<SearchResult> search(SearchFilter filter, String[] retAttrs) throws NamingException
LdapConfig.getBaseDn() is used as the start point for searching.
Search controls will be created from LdapConfig.getSearchControls(String[]). See search(String,SearchFilter,String[]).filter - SearchFilter expression to use for the searchretAttrs - String[] attributes to returnIterator - of LDAP search resultsNamingException - if the LDAP returns an errorpublic Iterator<SearchResult> search(SearchFilter filter, SearchControls searchControls) throws NamingException
LdapConfig.getBaseDn() is used as the start point for searching.
See search(String,SearchFilter,SearchControls).filter - SearchFilter expression to use for the searchsearchControls - SearchControls to search withIterator - of LDAP search resultsNamingException - if the LDAP returns an errorpublic Iterator<SearchResult> search(String dn, SearchFilter filter) throws NamingException
LdapConfig.getSearchControls(String[]). See search(String,SearchFilter,String[]).dn - String name to begin search atfilter - SearchFilter expression to use for the searchIterator - of LDAP search resultsNamingException - if the LDAP returns an errorpublic Iterator<SearchResult> search(String dn, SearchFilter filter, String[] retAttrs) throws NamingException
LdapConfig.getSearchControls(String[]). See search(String,SearchFilter,SearchControls,SearchResultHandler[]).dn - String name to begin search atfilter - SearchFilter expression to use for the searchretAttrs - String[] attributes to returnIterator - of LDAP search resultsNamingException - if the LDAP returns an errorpublic Iterator<SearchResult> search(String dn, SearchFilter filter, SearchControls searchControls) throws NamingException
search(String,SearchFilter,SearchControls,SearchResultHandler[]).dn - String name to begin search atfilter - SearchFilter expression to use for the searchsearchControls - SearchControls to search withIterator - of LDAP search resultsNamingException - if the LDAP returns an errorpublic Iterator<SearchResult> search(String dn, SearchFilter filter, String[] retAttrs, SearchResultHandler... handler) throws NamingException
LdapConfig.getSearchControls(String[]). See search(
String,SearchFilter,SearchControls,SearchResultHandler...).dn - String name to begin search atfilter - SearchFilter expression to use for the searchretAttrs - String[] attributes to returnhandler - SearchResultHandler[] of handlers to executeIterator - of LDAP search resultsNamingException - if the LDAP returns an errorpublic Iterator<SearchResult> search(String dn, SearchFilter filter, SearchControls searchControls, SearchResultHandler... handler) throws NamingException
LdapConfig.getPagedResultsSize() is
greater than 0, the PagedResultsControl will be invoked. See #search(String,String,Object[],SearchControls,SearchResultHandler[]).dn - String name to begin search atfilter - SearchFilter expression to use for the searchsearchControls - SearchControls to search withhandler - SearchResultHandler[] of handlers to executeIterator - of LDAP search resultsNamingException - if the LDAP returns an errorpublic Iterator<SearchResult> searchAttributes(Attributes matchAttrs) throws NamingException
LdapConfig.getBaseDn() is used as the
name to search.
See searchAttributes(String, Attributes, String[]).matchAttrs - Attributes attributes to matchIterator - of LDAP search resultsNamingException - if the LDAP returns an errorpublic Iterator<SearchResult> searchAttributes(Attributes matchAttrs, String[] retAttrs) throws NamingException
LdapConfig.getBaseDn() is used as the name to search.
See searchAttributes(String, Attributes, String[]).matchAttrs - Attributes attributes to matchretAttrs - String[] attributes to returnIterator - of LDAP search resultsNamingException - if the LDAP returns an errorpublic Iterator<SearchResult> searchAttributes(String dn, Attributes matchAttrs) throws NamingException
searchAttributes(String,
Attributes, String[]).dn - String name to search inmatchAttrs - Attributes attributes to matchIterator - of LDAP search resultsNamingException - if the LDAP returns an errorpublic Iterator<SearchResult> searchAttributes(String dn, Attributes matchAttrs, String[] retAttrs) throws NamingException
searchAttributes( String, Attributes,
String[], SearchResultHandler[]). This method converts relative DNs to
fully qualified DNs, no post processing is requireddn - String name to search inmatchAttrs - Attributes attributes to matchretAttrs - String[] attributes to returnIterator - of LDAP search resultsNamingException - if the LDAP returns an errorpublic Iterator<SearchResult> searchAttributes(String dn, Attributes matchAttrs, String[] retAttrs, SearchResultHandler... handler) throws NamingException
Iterator is a deep copy of the original search
results. If matchAttrs is empty or null then all objects in the target
context are returned. If retAttrs is null then all attributes will be
returned. If retAttrs is an empty array then no attributes will be
returned. See DirContext.searchAttributes in class AbstractLdap<LdapConfig>dn - String name to search inmatchAttrs - Attributes attributes to matchretAttrs - String[] attributes to returnhandler - SearchResultHandler[] to post process resultsIterator - of LDAP search resultsNamingException - if the LDAP returns an errorpublic Iterator<NameClassPair> list(String dn) throws NamingException
Iterator is a deep copy of the original search results. See Context.list(String).list in class AbstractLdap<LdapConfig>dn - String LDAP context to listIterator - LDAP search resultNamingException - if the LDAP returns an errorpublic Iterator<Binding> listBindings(String dn) throws NamingException
Iterator is a deep
copy of the original search results. See Context.listBindings(String).listBindings in class AbstractLdap<LdapConfig>dn - String LDAP context to listIterator - LDAP search resultNamingException - if the LDAP returns an errorpublic Attributes getAttributes(String dn) throws NamingException
getAttributes(String, String[]).dn - String named object in the LDAPAttributesNamingException - if the LDAP returns an errorpublic Attributes getAttributes(String dn, String[] retAttrs) throws NamingException
getAttributes(String, String[], AttributeHandler[]).dn - String named object in the LDAPretAttrs - String[] attributes to returnAttributesNamingException - if the LDAP returns an errorpublic Attributes getAttributes(String dn, String[] retAttrs, AttributeHandler... handler) throws NamingException
DirContext.getAttributes in class AbstractLdap<LdapConfig>dn - String named object in the LDAPretAttrs - String[] attributes to returnhandler - AttributeHandler[] to post process resultsAttributesNamingException - if the LDAP returns an errorpublic Iterator<SearchResult> getSchema(String dn) throws NamingException
Iterator is a deep copy of the original search
results. See DirContext.getSchema in class AbstractLdap<LdapConfig>dn - String named object in the LDAPIterator - LDAP search resultNamingException - if the LDAP returns an errorpublic void modifyAttributes(String dn, Ldap.AttributeModification mod, Attributes attrs) throws NamingException
AbstractLdap.modifyAttributes(String, int, Attributes).dn - String named object in the LDAPmod - AttributeModification modification operationattrs - Attributes attributes to be used for the
operation, may be nullNamingException - if the LDAP returns an errorpublic void modifyAttributes(String dn, ModificationItem[] mods) throws NamingException
DirContext.modifyAttributes in class AbstractLdap<LdapConfig>dn - String named object in the LDAPmods - ModificationItem[] modificationsNamingException - if the LDAP returns an errorpublic void create(String dn, Attributes attrs) throws NamingException
DirContext. Note that the context created by this operation is
immediately closed.create in class AbstractLdap<LdapConfig>dn - String named object in the LDAPattrs - Attributes attributes to be added to this entryNamingException - if the LDAP returns an errorpublic void rename(String oldDn, String newDn) throws NamingException
Context.rename(String, String).rename in class AbstractLdap<LdapConfig>oldDn - String object to renamenewDn - String new nameNamingException - if the LDAP returns an errorpublic void delete(String dn) throws NamingException
Context.destroySubcontext(String).delete in class AbstractLdap<LdapConfig>dn - String named object in the LDAPNamingException - if the LDAP returns an errorpublic String[] getSaslMechanisms() throws NamingException
String[] - supported SASL mechanismsNamingException - if the LDAP returns an errorpublic String[] getSupportedControls() throws NamingException
String[] - supported controlsNamingException - if the LDAP returns an errorCopyright © 2014. All rights reserved.