Class SpringLdapTemplateWrapper

java.lang.Object
com.atlassian.crowd.directory.ldap.SpringLdapTemplateWrapper

public class SpringLdapTemplateWrapper extends Object

Wrap a CrowdLdapTemplate and perform all operations with the context ClassLoader set to this class's ClassLoader. com.sun.naming.internal.NamingManager uses the context ClassLoader so, without this wrapper, calls that originate from plugins and end up using LDAP will fail when they can't see the Spring LDAP implementation classes.

Also logs how long the ldap query took, at DEBUG level for all queries, or at INFO level if the query's duration exceeds a threshold (default 1 second), settable by com.atlassian.crowd.ldap.log.wait.threshold.

This class is the blessed way to interact with LDAP. CrowdLdapTemplate should not be used directly, as this could open us up to an LDAP object injection vulnerability (see CWD-4754). This class calls very specific methods of CrowdLdapTemplate in order to avoid manipulation of the SearchControls. CrowdLdapTemplate can set the returnObj flag in the SearchControls to true before executing the search, opening us up to that very vulnerability. Care should be taken when upgrading Spring LDAP to ensure that the search methods called still behave the same.

As a safety net around providing SearchControls with the returningObj flag set to false, the search methods of this class will throw an IllegalArgumentException if the search controls provided had the said flag set to true.