org.acegisecurity.ldap
Class LdapTemplate

java.lang.Object
  extended by org.acegisecurity.ldap.LdapTemplate

public class LdapTemplate
extends java.lang.Object

LDAP equivalent of the Spring JdbcTemplate class.

This is mainly intended to simplify Ldap access within Acegi Security's LDAP-related services.

Author:
Ben Alex, Luke Taylor

Field Summary
static java.lang.String[] NO_ATTRS
           
 
Constructor Summary
LdapTemplate(InitialDirContextFactory dirContextFactory)
           
LdapTemplate(InitialDirContextFactory dirContextFactory, java.lang.String userDn, java.lang.String password)
           
 
Method Summary
 boolean compare(java.lang.String dn, java.lang.String attributeName, java.lang.Object value)
          Performs an LDAP compare operation of the value of an attribute for a particular directory entry.
 java.lang.Object execute(LdapCallback callback)
           
 boolean nameExists(java.lang.String dn)
           
 java.lang.Object retrieveEntry(java.lang.String dn, LdapEntryMapper mapper, java.lang.String[] attributesToRetrieve)
          Composes an object from the attributes of the given DN.
 java.util.Set searchForSingleAttributeValues(java.lang.String base, java.lang.String filter, java.lang.Object[] params, java.lang.String attributeName)
          Performs a search using the supplied filter and returns the union of the values of the named attribute found in all entries matched by the search.
 java.lang.Object searchForSingleEntry(java.lang.String base, java.lang.String filter, java.lang.Object[] params, LdapEntryMapper mapper)
          Performs a search, with the requirement that the search shall return a single directory entry, and uses the supplied mapper to create the object from that entry.
 void setSearchControls(javax.naming.directory.SearchControls searchControls)
          Sets the search controls which will be used for search operations by the template.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NO_ATTRS

public static final java.lang.String[] NO_ATTRS
Constructor Detail

LdapTemplate

public LdapTemplate(InitialDirContextFactory dirContextFactory)

LdapTemplate

public LdapTemplate(InitialDirContextFactory dirContextFactory,
                    java.lang.String userDn,
                    java.lang.String password)
Parameters:
dirContextFactory - the source of DirContexts
userDn - the user name to authenticate as when obtaining new contexts
password - the user's password
Method Detail

compare

public boolean compare(java.lang.String dn,
                       java.lang.String attributeName,
                       java.lang.Object value)
Performs an LDAP compare operation of the value of an attribute for a particular directory entry.

Parameters:
dn - the entry who's attribute is to be used
attributeName - the attribute who's value we want to compare
value - the value to be checked against the directory value
Returns:
true if the supplied value matches that in the directory

execute

public java.lang.Object execute(LdapCallback callback)
                         throws org.springframework.dao.DataAccessException
Throws:
org.springframework.dao.DataAccessException

nameExists

public boolean nameExists(java.lang.String dn)

retrieveEntry

public java.lang.Object retrieveEntry(java.lang.String dn,
                                      LdapEntryMapper mapper,
                                      java.lang.String[] attributesToRetrieve)
Composes an object from the attributes of the given DN.

Parameters:
dn - the directory entry which will be read
mapper - maps the attributes to the required object
attributesToRetrieve - the named attributes which will be retrieved from the directory entry.
Returns:
the object created by the mapper

searchForSingleAttributeValues

public java.util.Set searchForSingleAttributeValues(java.lang.String base,
                                                    java.lang.String filter,
                                                    java.lang.Object[] params,
                                                    java.lang.String attributeName)
Performs a search using the supplied filter and returns the union of the values of the named attribute found in all entries matched by the search. Note that one directory entry may have several values for the attribute. Intended for role searches and similar scenarios.

Parameters:
base - the DN to search in
filter - search filter to use
params - the parameters to substitute in the search filter
attributeName - the attribute who's values are to be retrieved.
Returns:
the set of String values for the attribute as a union of the values found in all the matching entries.

searchForSingleEntry

public java.lang.Object searchForSingleEntry(java.lang.String base,
                                             java.lang.String filter,
                                             java.lang.Object[] params,
                                             LdapEntryMapper mapper)
Performs a search, with the requirement that the search shall return a single directory entry, and uses the supplied mapper to create the object from that entry.

Parameters:
base -
filter -
params -
mapper -
Returns:
the object created by the mapper from the matching entry
Throws:
org.springframework.dao.IncorrectResultSizeDataAccessException - if no results are found or the search returns more than one result.

setSearchControls

public void setSearchControls(javax.naming.directory.SearchControls searchControls)
Sets the search controls which will be used for search operations by the template.

Parameters:
searchControls - the SearchControls instance which will be cached in the template.


Copyright © 2004-2012 Interface21, Inc. All Rights Reserved.