protected LdapTemplate retrieveLdapTemplate(final LdapLookupRequest inLdapLookupRequest)
{
String templateKey = inLdapLookupRequest.getTemplateKey();
String searchString = inLdapLookupRequest.getQueryString();
LdapTemplate result = null;
if (searchString != null && searchString.contains("\\"))
{
String[] domainQueryArr = searchString.split("\\\\");
// Example: "domain\attribute=foo" will give domain of "domain" and searchString of "attribute=foo".
String domain = domainQueryArr[0].toLowerCase();
searchString = domainQueryArr[1];
// no matter what domain we get, modify search string to remove domain.
inLdapLookupRequest.setQueryString(searchString);
// if domain is not null/empty, try to use it for ldap template.
if (domain != null && !domain.isEmpty())
{
result = getLdapTemplates().get(domain);
}
// no dice on domain from search string, try template key.
if (result == null && templateKey != null)
{
result = getLdapTemplates().get(templateKey);
}
// if not found, give back default, but log as error.
if (result == null)
{
result = getDefaultLdapTemplate();
log.error("Domain specified (" + domain + "), but not found in list of templates. "
+ "Attempting search on default template");
}
if (log.isDebugEnabled())
{
log.debug("Domain specified, searching only on "
+ ((LdapContextSource) result.getContextSource()).getUrls()[0]
+ " with base: " + ((LdapContextSource) result.getContextSource()).getBaseLdapPathAsString()
+ " for : " + searchString);
}
}
else
{
// no domain specified in search string, try template key.
if (templateKey != null)
{
result = getLdapTemplates().get(templateKey);
}
// no dice with template key, use default.
if (result == null)
{
result = getDefaultLdapTemplate();
}
if (log.isDebugEnabled())
{
log.debug("No domain specified, searching only on "
+ ((LdapContextSource) result.getContextSource()).getUrls()[0] + " for : " + searchString);
}
}
return result;
}