Class SpringSecurityLdapTemplate

  • All Implemented Interfaces:
    org.springframework.beans.factory.InitializingBean, org.springframework.ldap.core.LdapOperations

    public class SpringSecurityLdapTemplate
    extends org.springframework.ldap.core.LdapTemplate
    Extension of Spring LDAP's LdapTemplate class which adds extra functionality required by Spring Security.
    Since:
    2.0
    • Nested Class Summary

      • Nested classes/interfaces inherited from class org.springframework.ldap.core.LdapTemplate

        org.springframework.ldap.core.LdapTemplate.MappingCollectingNameClassPairCallbackHandler<T extends java.lang.Object>, org.springframework.ldap.core.LdapTemplate.NullDirContextProcessor
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String DN_KEY
      Every search results where a record is defined by a Map<String,String[]> contains at least this key - the DN of the record itself.
      static java.lang.String[] NO_ATTRS  
    • Constructor Summary

      Constructors 
      Constructor Description
      SpringSecurityLdapTemplate​(org.springframework.ldap.core.ContextSource contextSource)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      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.
      org.springframework.ldap.core.DirContextOperations retrieveEntry​(java.lang.String dn, java.lang.String[] attributesToRetrieve)
      Composes an object from the attributes of the given DN.
      java.util.Set<java.util.Map<java.lang.String,​java.util.List<java.lang.String>>> searchForMultipleAttributeValues​(java.lang.String base, java.lang.String filter, java.lang.Object[] params, java.lang.String[] attributeNames)
      Performs a search using the supplied filter and returns the values of each named attribute found in all entries matched by the search.
      java.util.Set<java.lang.String> 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.
      org.springframework.ldap.core.DirContextOperations searchForSingleEntry​(java.lang.String base, java.lang.String filter, java.lang.Object[] params)
      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.
      static org.springframework.ldap.core.DirContextOperations searchForSingleEntryInternal​(javax.naming.directory.DirContext ctx, javax.naming.directory.SearchControls searchControls, java.lang.String base, java.lang.String filter, java.lang.Object[] params)
      Internal method extracted to avoid code duplication in AD search.
      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 org.springframework.ldap.core.LdapTemplate

        afterPropertiesSet, authenticate, authenticate, authenticate, authenticate, authenticate, authenticate, authenticate, authenticate, authenticate, authenticate, bind, bind, bind, create, delete, deleteRecursively, executeReadOnly, executeReadWrite, find, find, findAll, findAll, findByDn, findOne, getContextSource, getObjectDirectoryMapper, list, list, list, list, list, list, listBindings, listBindings, listBindings, listBindings, listBindings, listBindings, listBindings, listBindings, lookup, lookup, lookup, lookup, lookup, lookup, lookup, lookup, lookup, lookup, lookupContext, lookupContext, modifyAttributes, modifyAttributes, modifyAttributes, rebind, rebind, rebind, rename, rename, search, search, search, search, search, search, search, search, search, search, search, search, search, search, search, search, search, search, search, search, search, search, search, search, search, search, search, search, search, search, search, search, search, searchForContext, searchForObject, searchForObject, searchForObject, searchForObject, searchForObject, setContextSource, setDefaultCountLimit, setDefaultSearchScope, setDefaultTimeLimit, setIgnoreNameNotFoundException, setIgnorePartialResultException, setIgnoreSizeLimitExceededException, setObjectDirectoryMapper, unbind, unbind, unbind, unbind, update
      • 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
      • DN_KEY

        public static final java.lang.String DN_KEY
        Every search results where a record is defined by a Map<String,String[]> contains at least this key - the DN of the record itself.
        See Also:
        Constant Field Values
    • Constructor Detail

      • SpringSecurityLdapTemplate

        public SpringSecurityLdapTemplate​(org.springframework.ldap.core.ContextSource contextSource)
    • 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
      • retrieveEntry

        public org.springframework.ldap.core.DirContextOperations retrieveEntry​(java.lang.String dn,
                                                                                java.lang.String[] attributesToRetrieve)
        Composes an object from the attributes of the given DN.
        Parameters:
        dn - the directory entry which will be read
        attributesToRetrieve - the named attributes which will be retrieved from the directory entry.
        Returns:
        the object created by the mapper
      • searchForSingleAttributeValues

        public java.util.Set<java.lang.String> 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.
      • searchForMultipleAttributeValues

        public java.util.Set<java.util.Map<java.lang.String,​java.util.List<java.lang.String>>> searchForMultipleAttributeValues​(java.lang.String base,
                                                                                                                                      java.lang.String filter,
                                                                                                                                      java.lang.Object[] params,
                                                                                                                                      java.lang.String[] attributeNames)
        Performs a search using the supplied filter and returns the values of each 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
        attributeNames - the attributes' values that are to be retrieved.
        Returns:
        the set of String values for each attribute found in all the matching entries. The attribute name is the key for each set of values. In addition each map contains the DN as a String with the key predefined key DN_KEY.
      • searchForSingleEntry

        public org.springframework.ldap.core.DirContextOperations searchForSingleEntry​(java.lang.String base,
                                                                                       java.lang.String filter,
                                                                                       java.lang.Object[] params)
        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.

        Ignores PartialResultException if thrown, for compatibility with Active Directory (see LdapTemplate.setIgnorePartialResultException(boolean)).

        Parameters:
        base - the search base, relative to the base context supplied by the context source.
        filter - the LDAP search filter
        params - parameters to be substituted in the search.
        Returns:
        a DirContextOperations instance created from the matching entry.
        Throws:
        org.springframework.dao.IncorrectResultSizeDataAccessException - if no results are found or the search returns more than one result.
      • searchForSingleEntryInternal

        public static org.springframework.ldap.core.DirContextOperations searchForSingleEntryInternal​(javax.naming.directory.DirContext ctx,
                                                                                                      javax.naming.directory.SearchControls searchControls,
                                                                                                      java.lang.String base,
                                                                                                      java.lang.String filter,
                                                                                                      java.lang.Object[] params)
                                                                                               throws javax.naming.NamingException
        Internal method extracted to avoid code duplication in AD search.
        Throws:
        javax.naming.NamingException
      • 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.