|
Spring LDAP | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.ldap.core.simple.SimpleLdapTemplate
public class SimpleLdapTemplate
Java-5-based convenience wrapper for the classic LdapTemplate, adding some
convenient shortcuts and taking advantage of Java 5 Generics.
Use the getLdapOperations()
method if you need to invoke less
commonly used template methods.
Constructor Summary | |
---|---|
SimpleLdapTemplate(ContextSource contextSource)
Constructs a new SimpleLdapTemplate instance, automatically creating a wrapped LdapTemplate instance to work with. |
|
SimpleLdapTemplate(LdapOperations ldapOperations)
Constructs a new SimpleLdapTemplate instance wrapping the supplied LdapOperations instance. |
Method Summary | ||
---|---|---|
boolean |
authenticate(Name base,
String filter,
String password)
Utility method to perform a simple LDAP 'bind' authentication. |
|
boolean |
authenticate(String base,
String filter,
String password)
Utility method to perform a simple LDAP 'bind' authentication. |
|
void |
bind(DirContextOperations ctx)
Bind the data in the supplied context in the tree. |
|
void |
bind(Name dn,
Object obj,
Attributes attributes)
Create an entry in the LDAP tree. |
|
void |
bind(String dn,
Object obj,
Attributes attributes)
Create an entry in the LDAP tree. |
|
LdapOperations |
getLdapOperations()
Get the wrapped LdapOperations instance. |
|
|
lookup(Name dn,
ParameterizedContextMapper<T> mapper)
Perform a lookup of the specified DN and map the result using the mapper. |
|
|
lookup(String dn,
ParameterizedContextMapper<T> mapper)
Perform a lookup of the specified DN and map the result using the mapper. |
|
DirContextOperations |
lookupContext(Name dn)
Look up the specified DN, and automatically cast it to a DirContextOperations instance. |
|
DirContextOperations |
lookupContext(String dn)
Look up the specified DN, and automatically cast it to a DirContextOperations instance. |
|
void |
modifyAttributes(DirContextOperations ctx)
Modify the Attributes of the entry corresponding to the supplied DirContextOperations instance. |
|
|
search(Name base,
String filter,
ParameterizedContextMapper<T> mapper)
Search for a List of type T using the supplied filter and link ParameterizedContextMapper. |
|
|
search(Name base,
String filter,
SearchControls controls,
ParameterizedContextMapper<T> mapper,
DirContextProcessor processor)
Search for a List of type T using the supplied filter, SearchControls, DirContextProcessor and ParameterizedContextMapper. |
|
|
search(String base,
String filter,
ParameterizedContextMapper<T> mapper)
Search for a List of type T using the supplied filter and link ParameterizedContextMapper. |
|
|
search(String base,
String filter,
SearchControls controls,
ParameterizedContextMapper<T> mapper,
DirContextProcessor processor)
Search for a List of type T using the supplied filter, SearchControls, DirContextProcessor and ParameterizedContextMapper. |
|
|
searchForObject(Name base,
String filter,
ParameterizedContextMapper<T> mapper)
Perform a search for a unique entry matching the specified search criteria and return the found object. |
|
|
searchForObject(String base,
String filter,
ParameterizedContextMapper<T> mapper)
Perform a search for a unique entry matching the specified search criteria and return the found object. |
|
void |
unbind(Name dn)
Remove an entry from the LDAP tree. |
|
void |
unbind(String dn)
Remove an entry from the LDAP tree. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public SimpleLdapTemplate(LdapOperations ldapOperations)
ldapOperations
- the LdapOperations instance to wrap.public SimpleLdapTemplate(ContextSource contextSource)
contextSource
- Method Detail |
---|
public LdapOperations getLdapOperations()
SimpleLdapOperations
getLdapOperations
in interface SimpleLdapOperations
public <T> T lookup(String dn, ParameterizedContextMapper<T> mapper)
SimpleLdapOperations
lookup
in interface SimpleLdapOperations
dn
- the Distinguished Name to look up.mapper
- the mapper to use.
public <T> List<T> search(String base, String filter, ParameterizedContextMapper<T> mapper)
SimpleLdapOperations
search
in interface SimpleLdapOperations
base
- Base DN relative to the base of the ContextSource - where to
start the search.filter
- Search filter.mapper
- the Mapper to supply all results to.
public <T> List<T> search(String base, String filter, SearchControls controls, ParameterizedContextMapper<T> mapper, DirContextProcessor processor)
SimpleLdapOperations
search
in interface SimpleLdapOperations
base
- Base DN relative to the base of the ContextSource - where to
start the search.filter
- Search filter.controls
- the SearchControls. Make sure that the returningObjFlag
is set to true
.mapper
- the Mapper to supply all results to.processor
- the DirContextProcessor to be used for applying pre/post
processing on the DirContext instance.
public DirContextOperations lookupContext(String dn)
SimpleLdapOperations
DirContextOperations
instance.
lookupContext
in interface SimpleLdapOperations
dn
- The Distinguished Name of the entry to look up.
DirContextOperations
instance constructed from the
found entry.public void modifyAttributes(DirContextOperations ctx)
SimpleLdapOperations
DirContextOperations
instance. The instance should have been
received from the SimpleLdapOperations.lookupContext(String)
operation, and then
modified to match the current state of the matching domain object, e.g.:
public void update(Person person) { DirContextOperations ctx = simpleLdapOperations.lookup(person.getDn()); ctx.setAttributeValue("description", person.getDescription()); ctx.setAttributeValue("telephoneNumber", person.getPhone()); // More modifications here simpleLdapOperations.modifyAttributes(ctx); }
modifyAttributes
in interface SimpleLdapOperations
ctx
- the entry to update in the LDAP tree.public void bind(String dn, Object obj, Attributes attributes)
SimpleLdapOperations
obj
parameter or the
attributes
parameter (or both). One of these parameters may
be null but not both.
bind
in interface SimpleLdapOperations
dn
- The distinguished name to bind the object and attributes to.obj
- The object to bind, may be null. Typically a DirContext
implementation.attributes
- The attributes to bind, may be null.public void unbind(String dn)
SimpleLdapOperations
unbind
in interface SimpleLdapOperations
dn
- The distinguished name to unbind.public void bind(Name dn, Object obj, Attributes attributes)
SimpleLdapOperations
obj
parameter or the
attributes
parameter (or both). One of these parameters may
be null but not both.
bind
in interface SimpleLdapOperations
dn
- The distinguished name to bind the object and attributes to.obj
- The object to bind, may be null. Typically a DirContext
implementation.attributes
- The attributes to bind, may be null.public <T> T lookup(Name dn, ParameterizedContextMapper<T> mapper)
SimpleLdapOperations
lookup
in interface SimpleLdapOperations
dn
- the Distinguished Name to look up.mapper
- the mapper to use.
public DirContextOperations lookupContext(Name dn)
SimpleLdapOperations
DirContextOperations
instance.
lookupContext
in interface SimpleLdapOperations
dn
- The Distinguished Name of the entry to look up.
DirContextOperations
instance constructed from the
found entry.public <T> List<T> search(Name base, String filter, ParameterizedContextMapper<T> mapper)
SimpleLdapOperations
search
in interface SimpleLdapOperations
base
- Base DN relative to the base of the ContextSource - where to
start the search.filter
- Search filter.mapper
- the Mapper to supply all results to.
public <T> List<T> search(Name base, String filter, SearchControls controls, ParameterizedContextMapper<T> mapper, DirContextProcessor processor)
SimpleLdapOperations
search
in interface SimpleLdapOperations
base
- Base DN relative to the base of the ContextSource - where to
start the search.filter
- Search filter.controls
- the SearchControls. Make sure that the returningObjFlag
is set to true
.mapper
- the Mapper to supply all results to.processor
- the DirContextProcessor to be used for applying pre/post
processing on the DirContext instance.
public void unbind(Name dn)
SimpleLdapOperations
unbind
in interface SimpleLdapOperations
dn
- The distinguished name to unbind.public void bind(DirContextOperations ctx)
SimpleLdapOperations
bind
in interface SimpleLdapOperations
ctx
- the context to bindpublic <T> T searchForObject(String base, String filter, ParameterizedContextMapper<T> mapper)
SimpleLdapOperations
IncorrectResultSizeDataAccessException
is thrown.
searchForObject
in interface SimpleLdapOperations
base
- the DN to use as the base of the search.filter
- the search filter.mapper
- the mapper to use for the search.
public <T> T searchForObject(Name base, String filter, ParameterizedContextMapper<T> mapper)
SimpleLdapOperations
IncorrectResultSizeDataAccessException
is thrown.
searchForObject
in interface SimpleLdapOperations
base
- the DN to use as the base of the search.filter
- the search filter.mapper
- the mapper to use for the search.
public boolean authenticate(String base, String filter, String password)
SimpleLdapOperations
ContextSource.getContext(String, String)
, thus authenticating the
entry.
Example:
AndFilter filter = new AndFilter(); filter.and("objectclass", "person").and("uid", userId); boolean authenticated = ldapTemplate.authenticate(DistinguishedName.EMPTY_PATH, filter.toString(), password);
authenticate
in interface SimpleLdapOperations
base
- the DN to use as the base of the search.filter
- the search filter - must result in a unique result.password
- the password to use for authentication.
true
if the authentication was successful,
false
otherwise.public boolean authenticate(Name base, String filter, String password)
SimpleLdapOperations
ContextSource.getContext(String, String)
, thus authenticating the
entry.
Example:
AndFilter filter = new AndFilter(); filter.and("objectclass", "person").and("uid", userId); boolean authenticated = ldapTemplate.authenticate(DistinguishedName.EMPTY_PATH, filter.toString(), password);
authenticate
in interface SimpleLdapOperations
base
- the DN to use as the base of the search.filter
- the search filter - must result in a unique result.password
- the password to use for authentication.
true
if the authentication was successful,
false
otherwise.
|
Spring LDAP | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |