|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.ldaptemplate.LdapTemplate
Executes core LDAP functionality and helps to avoid common errors, relieving the user of the burden of looking up contexts, looping through NamingEnumerations and closing contexts.
Note for Active Directory (AD) users: AD servers are apparently
unable to handle referrals automatically, which causes a
PartialResultException
to be thrown whenever a referral is
encountered in a search. To avoid this, set the
ignorePartialResultException
property to true
.
There is currently no way of manually handling these referrals in the form of
ReferralException
, i.e. either you get the exception (and
your results are lost) or all referrals are ignored (if the server is unable
to handle them properly. Neither is there any simple way to get notified that
a PartialResultException
has been ignored (other than in the
log).
ContextSource
Nested Class Summary | |
class |
LdapTemplate.AttributesMapperCallbackHandler
A CollectingSearchResultCallbackHandler to wrap an AttributesMapper. |
class |
LdapTemplate.ContextMapperCallbackHandler
A CollectingSearchResultCallbackHandler to wrap a ContextMapper. |
Constructor Summary | |
LdapTemplate()
Constructor for bean usage. |
|
LdapTemplate(ContextSource contextSource)
Constructor to setup instance directly. |
Method Summary | |
void |
afterPropertiesSet()
|
void |
bind(javax.naming.Name dn,
java.lang.Object obj,
javax.naming.directory.Attributes attributes)
Bind the supplied object together with the attributes to the specified dn. |
void |
bind(java.lang.String dn,
java.lang.Object obj,
javax.naming.directory.Attributes attributes)
Bind the supplied object together with the attributes to the specified dn. |
protected void |
deleteRecursively(javax.naming.directory.DirContext ctx,
DistinguishedName name)
Delete all subcontexts including the current one recursively. |
java.lang.Object |
executeReadOnly(ContextExecutor ce)
Perform an operation (or series of operations) on a read-only context. |
java.lang.Object |
executeReadWrite(ContextExecutor ce)
Perform an operation (or series of operations) on a read-write context. |
NamingExceptionTranslator |
getExceptionTranslator()
Get the NamingExceptionTranslator that will be used by this instance. |
java.lang.Object |
lookup(javax.naming.Name dn)
Lookup the supplied DN and return the found object. |
java.lang.Object |
lookup(javax.naming.Name dn,
AttributesMapper mapper)
Convenience method to get the attributes of a specified DN and automatically pass them to an AttributesMapper. |
java.lang.Object |
lookup(javax.naming.Name dn,
ContextMapper mapper)
Convenience method to lookup a specified DN and automatically pass the found objectt to a ContextMapper. |
java.lang.Object |
lookup(java.lang.String dn)
Lookup the supplied DN and return the found object. |
java.lang.Object |
lookup(java.lang.String dn,
AttributesMapper mapper)
Convenience method to get the attributes of a specified DN and automatically pass them to an AttributesMapper. |
java.lang.Object |
lookup(java.lang.String dn,
ContextMapper mapper)
Convenience method to lookup a specified DN and automatically pass the found objectt to a ContextMapper. |
void |
modifyAttributes(javax.naming.Name dn,
javax.naming.directory.ModificationItem[] mods)
Modify the distinguished name dn with the supplied ModificationItems. |
void |
modifyAttributes(java.lang.String dn,
javax.naming.directory.ModificationItem[] mods)
Modify the distinguished name dn with the supplied ModificationItems. |
void |
rebind(javax.naming.Name dn,
java.lang.Object obj,
javax.naming.directory.Attributes attributes)
Rebind the name to the object along with the specified attributes, overwriting any previous values. |
void |
rebind(java.lang.String dn,
java.lang.Object obj,
javax.naming.directory.Attributes attributes)
Rebind the name to the object along with the specified attributes, overwriting any previous values. |
void |
rename(javax.naming.Name oldDn,
javax.naming.Name newDn)
Binds a new name to the object bound to an old name, and unbinds the old name. |
void |
rename(java.lang.String oldDn,
java.lang.String newDn)
Binds a new name to the object bound to an old name, and unbinds the old name. |
java.util.List |
search(javax.naming.Name base,
java.lang.String filter,
AttributesMapper mapper)
Search for all objects matching the supplied filter. |
java.util.List |
search(javax.naming.Name base,
java.lang.String filter,
ContextMapper mapper)
Search for all objects matching the supplied filter. |
java.util.List |
search(javax.naming.Name base,
java.lang.String filter,
int searchScope,
AttributesMapper mapper)
Search for all objects matching the supplied filter. |
void |
search(javax.naming.Name base,
java.lang.String filter,
int searchScope,
boolean returningObjFlag,
SearchResultCallbackHandler handler)
Search for all objects matching the supplied filter. |
java.util.List |
search(javax.naming.Name base,
java.lang.String filter,
int searchScope,
ContextMapper mapper)
Search for all objects matching the supplied filter. |
java.util.List |
search(javax.naming.Name base,
java.lang.String filter,
javax.naming.directory.SearchControls controls,
AttributesMapper mapper)
Search for all objects matching the supplied filter. |
java.util.List |
search(javax.naming.Name base,
java.lang.String filter,
javax.naming.directory.SearchControls controls,
ContextMapper mapper)
Search for all objects matching the supplied filter. |
void |
search(javax.naming.Name base,
java.lang.String filter,
javax.naming.directory.SearchControls controls,
SearchResultCallbackHandler handler)
Search for all objects matching the supplied filter. |
void |
search(javax.naming.Name base,
java.lang.String filter,
SearchResultCallbackHandler handler)
Search for all objects matching the supplied filter. |
void |
search(SearchExecutor se,
SearchResultCallbackHandler handler)
Perform a search. |
java.util.List |
search(java.lang.String base,
java.lang.String filter,
AttributesMapper mapper)
Search for all objects matching the supplied filter. |
java.util.List |
search(java.lang.String base,
java.lang.String filter,
ContextMapper mapper)
Search for all objects matching the supplied filter. |
java.util.List |
search(java.lang.String base,
java.lang.String filter,
int searchScope,
AttributesMapper mapper)
Search for all objects matching the supplied filter. |
void |
search(java.lang.String base,
java.lang.String filter,
int searchScope,
boolean returningObjFlag,
SearchResultCallbackHandler handler)
Search for all objects matching the supplied filter. |
java.util.List |
search(java.lang.String base,
java.lang.String filter,
int searchScope,
ContextMapper mapper)
Search for all objects matching the supplied filter. |
java.util.List |
search(java.lang.String base,
java.lang.String filter,
javax.naming.directory.SearchControls controls,
AttributesMapper mapper)
Search for all objects matching the supplied filter. |
java.util.List |
search(java.lang.String base,
java.lang.String filter,
javax.naming.directory.SearchControls controls,
ContextMapper mapper)
Search for all objects matching the supplied filter. |
void |
search(java.lang.String base,
java.lang.String filter,
javax.naming.directory.SearchControls controls,
SearchResultCallbackHandler handler)
Search for all objects matching the supplied filter. |
void |
search(java.lang.String base,
java.lang.String filter,
SearchResultCallbackHandler handler)
Search for all objects matching the supplied filter. |
void |
setContextSource(ContextSource contextSource)
Set the ContextSource. |
void |
setExceptionTranslator(NamingExceptionTranslator exceptionTranslator)
Set the NamingExceptionTranslator to be used by this instance. |
void |
setIgnorePartialResultException(boolean ignore)
Specify whether PartialResultException should be ignored
in searches. |
void |
unbind(javax.naming.Name dn)
Unbind the specified distinguished name. |
void |
unbind(javax.naming.Name dn,
boolean recursive)
Unbind the specified distinguished name. |
void |
unbind(java.lang.String dn)
Unbind the specified distinguished name. |
void |
unbind(java.lang.String dn,
boolean recursive)
Unbind the specified distinguished name. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public LdapTemplate()
public LdapTemplate(ContextSource contextSource)
contextSource
- the ContextSource to use.Method Detail |
public void setContextSource(ContextSource contextSource)
contextSource
- the ContextSource.public void setIgnorePartialResultException(boolean ignore)
PartialResultException
should be ignored
in searches. AD servers typically have a problem with referrals. Normally
a referral should be followed automatically, but this does not seem to
work with AD servers. The problem manifests itself with a a
PartialResultException
being thrown when a referral is
encountered by the server. Setting this property to true
presents a workaround to this problem by causing
PartialResultException
to be ignored, so that the search
method returns normally. Default value of this parameter is
false
.
ignore
- true
if PartialResultException
should be ignored in searches, false
otherwise.
Default is false
.public void search(javax.naming.Name base, java.lang.String filter, int searchScope, boolean returningObjFlag, SearchResultCallbackHandler handler)
LdapOperations
search
in interface LdapOperations
base
- The base DN where the search should begin.filter
- the filter to use in the search.searchScope
- the search scope to set in SearchControls.returningObjFlag
- whether the bound object should be returned in search results.handler
- the SearchResultCallbackHandler to supply the SearchResults
to.public void search(java.lang.String base, java.lang.String filter, int searchScope, boolean returningObjFlag, SearchResultCallbackHandler handler) throws org.springframework.dao.DataAccessException
LdapOperations
search
in interface LdapOperations
base
- The base DN where the search should begin.filter
- the filter to use in the search.searchScope
- the search scope to set in SearchControls.returningObjFlag
- whether the bound object should be returned in search results.handler
- the SearchResultCallbackHandler to supply the SearchResults
to.
org.springframework.dao.DataAccessException
- if any error occurs. Note that a NameNotFoundException will
be ignored. Instead this is interpreted that no entries were
found.public void search(javax.naming.Name base, java.lang.String filter, javax.naming.directory.SearchControls controls, SearchResultCallbackHandler handler)
LdapOperations
search
in interface LdapOperations
base
- The base DN where the search should begin.filter
- the filter to use in the search.controls
- the SearchControls to use in the search.handler
- the SearchResultCallbackHandler to supply the SearchResults
to.public void search(java.lang.String base, java.lang.String filter, javax.naming.directory.SearchControls controls, SearchResultCallbackHandler handler)
LdapOperations
search
in interface LdapOperations
base
- The base DN where the search should begin.filter
- the filter to use in the search.controls
- the SearchControls to use in the search.handler
- the SearchResultCallbackHandler to supply the SearchResults
to.public void search(SearchExecutor se, SearchResultCallbackHandler handler)
LdapOperations
search
in interface LdapOperations
se
- the SearchExecutor to use for performing the actual search.handler
- the SearchResultCallbackHandler to which each found entry will
be passed.public void search(javax.naming.Name base, java.lang.String filter, SearchResultCallbackHandler handler) throws org.springframework.dao.DataAccessException
LdapOperations
search
in interface LdapOperations
base
- The base DN where the search should begin.filter
- the filter to use in the search.handler
- the SearchResultCallbackHandler to supply the SearchResults
to.
org.springframework.dao.DataAccessException
- if any error occurs. Note that a NameNotFoundException will
be ignored. Instead this is interpreted that no entries were
found.public void search(java.lang.String base, java.lang.String filter, SearchResultCallbackHandler handler) throws org.springframework.dao.DataAccessException
LdapOperations
search
in interface LdapOperations
base
- The base DN where the search should begin.filter
- the filter to use in the search.handler
- the SearchResultCallbackHandler to supply the SearchResults
to.
org.springframework.dao.DataAccessException
- if any error occurs. Note that a NameNotFoundException will
be ignored. Instead this is interpreted that no entries were
found.public java.util.List search(javax.naming.Name base, java.lang.String filter, int searchScope, AttributesMapper mapper)
LdapOperations
search
in interface LdapOperations
base
- The base DN where the search should begin.filter
- the filter to use in the search.searchScope
- the search scope to set in SearchControls.mapper
- the AttributesMapper to use for translating each entry.
public java.util.List search(java.lang.String base, java.lang.String filter, int searchScope, AttributesMapper mapper) throws org.springframework.dao.DataAccessException
LdapOperations
search
in interface LdapOperations
base
- The base DN where the search should begin.filter
- the filter to use in the search.searchScope
- the search scope to set in SearchControls.mapper
- the AttributesMapper to use for translating each entry.
org.springframework.dao.DataAccessException
- if any error occurs. Note that a NameNotFoundException will
be ignored. Instead this is interpreted that no entries were
found.public java.util.List search(javax.naming.Name base, java.lang.String filter, AttributesMapper mapper) throws org.springframework.dao.DataAccessException
LdapOperations
search
in interface LdapOperations
base
- The base DN where the search should begin.filter
- the filter to use in the search.mapper
- the AttributesMapper to use for translating each entry.
org.springframework.dao.DataAccessException
- if any error occurs. Note that a NameNotFoundException will
be ignored. Instead this is interpreted that no entries were
found.public java.util.List search(java.lang.String base, java.lang.String filter, AttributesMapper mapper) throws org.springframework.dao.DataAccessException
LdapOperations
search
in interface LdapOperations
base
- The base DN where the search should begin.filter
- the filter to use in the search.mapper
- the AttributesMapper to use for translating each entry.
org.springframework.dao.DataAccessException
- if any error occurs. Note that a NameNotFoundException will
be ignored. Instead this is interpreted that no entries were
found.public java.util.List search(javax.naming.Name base, java.lang.String filter, int searchScope, ContextMapper mapper)
LdapOperations
search
in interface LdapOperations
base
- The base DN where the search should begin.filter
- the filter to use in the search.searchScope
- the search scope to set in SearchControls.mapper
- the ContextMapper to use for translating each entry.
public java.util.List search(java.lang.String base, java.lang.String filter, int searchScope, ContextMapper mapper) throws org.springframework.dao.DataAccessException
LdapOperations
search
in interface LdapOperations
base
- The base DN where the search should begin.filter
- the filter to use in the search.searchScope
- the search scope to set in SearchControls.mapper
- the ContextMapper to use for translating each entry.
org.springframework.dao.DataAccessException
- if any error occurs. Note that a NameNotFoundException will
be ignored. Instead this is interpreted that no entries were
found.public java.util.List search(javax.naming.Name base, java.lang.String filter, ContextMapper mapper) throws org.springframework.dao.DataAccessException
LdapOperations
search
in interface LdapOperations
base
- The base DN where the search should begin.filter
- the filter to use in the search.mapper
- the ContextMapper to use for translating each entry.
org.springframework.dao.DataAccessException
- if any error occurs. Note that a NameNotFoundException will
be ignored. Instead this is interpreted that no entries were
found.public java.util.List search(java.lang.String base, java.lang.String filter, ContextMapper mapper) throws org.springframework.dao.DataAccessException
LdapOperations
search
in interface LdapOperations
base
- The base DN where the search should begin.filter
- the filter to use in the search.mapper
- the ContextMapper to use for translating each entry.
org.springframework.dao.DataAccessException
- if any error occurs. Note that a NameNotFoundException will
be ignored. Instead this is interpreted that no entries were
found.public java.util.List search(java.lang.String base, java.lang.String filter, javax.naming.directory.SearchControls controls, ContextMapper mapper)
LdapOperations
search
in interface LdapOperations
base
- The base DN where the search should begin.filter
- the filter to use in the search.controls
- the SearchControls to use in the search. If the returnObjFlag
is not set in the SearchControls, this method will set it
automatically, as this is required for the ContextMapper to
work.mapper
- the ContextMapper to use for translating each entry.
public java.util.List search(javax.naming.Name base, java.lang.String filter, javax.naming.directory.SearchControls controls, ContextMapper mapper)
LdapOperations
search
in interface LdapOperations
base
- The base DN where the search should begin.filter
- the filter to use in the search.controls
- the SearchControls to use in the search. If the returnObjFlag
is not set in the SearchControls, this method will set it
automatically, as this is required for the ContextMapper to
work.mapper
- the ContextMapper to use for translating each entry.
public java.util.List search(javax.naming.Name base, java.lang.String filter, javax.naming.directory.SearchControls controls, AttributesMapper mapper)
LdapOperations
search
in interface LdapOperations
base
- The base DN where the search should begin.filter
- the filter to use in the search.controls
- the SearchControls to use in the search. If the returnObjFlag
is not set in the SearchControls, this method will set it
automatically, as this is required for the ContextMapper to
work.mapper
- the AttributesMapper to use for translating each entry.
public java.util.List search(java.lang.String base, java.lang.String filter, javax.naming.directory.SearchControls controls, AttributesMapper mapper)
LdapOperations
search
in interface LdapOperations
base
- The base DN where the search should begin.filter
- the filter to use in the search.controls
- the SearchControls to use in the search.mapper
- the AttributesMapper to use for translating each entry.
public java.lang.Object executeReadOnly(ContextExecutor ce)
LdapOperations
LdapOperations.search(SearchExecutor, SearchResultCallbackHandler)
or any of
the overloaded search methods for this.
executeReadOnly
in interface LdapOperations
ce
- the ContextExecutor to which the actual operation on the
DirContext will be delegated.
public java.lang.Object executeReadWrite(ContextExecutor ce)
LdapOperations
executeReadWrite
in interface LdapOperations
ce
- the ContextExecutor to which the actual operation on the
DirContext will be delegated.
public java.lang.Object lookup(javax.naming.Name dn)
LdapOperations
lookup
in interface LdapOperations
dn
- the distinguished name of the object to find.
public java.lang.Object lookup(java.lang.String dn) throws org.springframework.dao.DataAccessException
LdapOperations
lookup
in interface LdapOperations
dn
- the distinguished name of the object to find.
org.springframework.dao.DataAccessException
- if any error occurs.public java.lang.Object lookup(javax.naming.Name dn, AttributesMapper mapper)
LdapOperations
lookup
in interface LdapOperations
dn
- the distinguished name to find.mapper
- the AttributesMapper to use for mapping the found object.
public java.lang.Object lookup(java.lang.String dn, AttributesMapper mapper) throws org.springframework.dao.DataAccessException
LdapOperations
lookup
in interface LdapOperations
dn
- the distinguished name to find.mapper
- the AttributesMapper to use for mapping the found object.
org.springframework.dao.DataAccessException
- if any error occurs.public java.lang.Object lookup(javax.naming.Name dn, ContextMapper mapper)
LdapOperations
lookup
in interface LdapOperations
dn
- the distinguished name to find.mapper
- the ContextMapper to use for mapping the found object.
public java.lang.Object lookup(java.lang.String dn, ContextMapper mapper) throws org.springframework.dao.DataAccessException
LdapOperations
lookup
in interface LdapOperations
dn
- the distinguished name to find.mapper
- the ContextMapper to use for mapping the found object.
org.springframework.dao.DataAccessException
- if any error occurs.public void modifyAttributes(javax.naming.Name dn, javax.naming.directory.ModificationItem[] mods)
LdapOperations
modifyAttributes
in interface LdapOperations
dn
- The distinguished name of the node to modify.mods
- the modifications to perform.public void modifyAttributes(java.lang.String dn, javax.naming.directory.ModificationItem[] mods) throws org.springframework.dao.DataAccessException
LdapOperations
modifyAttributes
in interface LdapOperations
dn
- The distinguished name of the node to modify.mods
- the modifications to perform.
org.springframework.dao.DataAccessException
- if any error occurs.public void bind(javax.naming.Name dn, java.lang.Object obj, javax.naming.directory.Attributes attributes)
LdapOperations
bind
in interface LdapOperations
dn
- the distinguished name to bind the object and attributes to.obj
- the object to bind, may be null.attributes
- the attributes to bind.public void bind(java.lang.String dn, java.lang.Object obj, javax.naming.directory.Attributes attributes) throws org.springframework.dao.DataAccessException
LdapOperations
bind
in interface LdapOperations
dn
- the distinguished name to bind the object and attributes to.obj
- the object to bind, may be null.attributes
- the attributes to bind.
org.springframework.dao.DataAccessException
- if any error occurs.public void unbind(javax.naming.Name dn)
LdapOperations
unbind
in interface LdapOperations
dn
- the distinguished name to unbind.public void unbind(java.lang.String dn) throws org.springframework.dao.DataAccessException
LdapOperations
unbind
in interface LdapOperations
dn
- the distinguished name to unbind.
org.springframework.dao.DataAccessException
- if any error occurs.public void unbind(javax.naming.Name dn, boolean recursive) throws org.springframework.dao.DataAccessException
LdapOperations
unbind
in interface LdapOperations
dn
- the distinguished name to unbind.recursive
- whether to unbind all subcontexts as well.
org.springframework.dao.DataAccessException
- if any error occurs.public void unbind(java.lang.String dn, boolean recursive) throws org.springframework.dao.DataAccessException
LdapOperations
unbind
in interface LdapOperations
dn
- the distinguished name to unbind.recursive
- whether to unbind all subcontexts as well.
org.springframework.dao.DataAccessException
- if any error occurs.protected void deleteRecursively(javax.naming.directory.DirContext ctx, DistinguishedName name) throws org.springframework.dao.DataAccessException
ctx
- The context to use for deleting.name
- The starting point to delete recursively.
org.springframework.dao.DataAccessException
- if any error occurspublic void rebind(javax.naming.Name dn, java.lang.Object obj, javax.naming.directory.Attributes attributes) throws org.springframework.dao.DataAccessException
LdapOperations
rebind
in interface LdapOperations
dn
- the distinguished name to rebind.obj
- the object to bind to the DN.attributes
- the attributes to bind.
org.springframework.dao.DataAccessException
public void rebind(java.lang.String dn, java.lang.Object obj, javax.naming.directory.Attributes attributes) throws org.springframework.dao.DataAccessException
LdapOperations
rebind
in interface LdapOperations
dn
- the distinguished name to rebind.obj
- the object to bind to the DN.attributes
- the attributes to bind.
org.springframework.dao.DataAccessException
public void rename(javax.naming.Name oldDn, javax.naming.Name newDn) throws org.springframework.dao.DataAccessException
LdapOperations
rename
in interface LdapOperations
oldDn
- the name of the existing binding; may not be emptynewDn
- the name of the new binding; may not be empty
org.springframework.dao.DataAccessException
public void rename(java.lang.String oldDn, java.lang.String newDn) throws org.springframework.dao.DataAccessException
LdapOperations
LdapOperations.rename(Name, Name)
for details.
rename
in interface LdapOperations
oldDn
- the name of the existing binding; may not be emptynewDn
- the name of the new binding; may not be empty
org.springframework.dao.DataAccessException
public void afterPropertiesSet() throws java.lang.Exception
afterPropertiesSet
in interface org.springframework.beans.factory.InitializingBean
java.lang.Exception
public NamingExceptionTranslator getExceptionTranslator()
public void setExceptionTranslator(NamingExceptionTranslator exceptionTranslator)
exceptionTranslator
- the NamingExceptionTranslator to use.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |