title: Spring LDAP with dynamic base DN
body: <p>I have following LDAP scheme:</p>
  
  <p><a href="https://i.stack.imgur.com/Xs24v.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Xs24v.png" alt="enter image description here"></a></p>
  
  <p>Every subtree contains organization unit <strong>Team</strong>. I want to find all Teams from specific subtree. To do that I use <code>LdapTemplate</code> class and <code>findAll()</code> methods. </p>
  
  <pre><code>ldapTemplate.findAll(Team.class);
  </code></pre>
  
  <p>When I set base in <code>LdapContextSource</code> to <code>dc=global,dc=id,dc=pl</code> it returns me Teams from global subtree. When I change base to <code>dc=id,dc=pl</code> it returns me Teams from all subtrees.</p>
  
  <p>The problem is that I want to use dynamic base, to find Teams from specific subtree. I've tried multiple methods to achieve that, but none of them gives me results.</p>
  
  <p><strong>Method 1: find</strong></p>
  
  <pre><code>Name nameBase = LdapUtils.newLdapName("dc=global");
  return ldapTemplate.find(query().base(nameBase).where("ou").is("team"), Team.class);
  </code></pre>
  
  <p>returns <strong>empty list</strong></p>
  
  <p><strong>Method 2: findAll</strong></p>
  
  <pre><code>Name nameBase = LdapUtils.newLdapName("dc=global");
  SearchControls searchControls = new SearchControls();
  return ldapTemplate.findAll(nameBase, searchControls, Team.class);
  </code></pre>
  
  <p>returns <strong>empty list</strong> </p>
  
  <p>At first It looks like working correctly, because when I change subtree name to some which not exists I get <code>javax.naming.NameNotFoundException: [LDAP: error code 32 - No Such Object]</code></p>
  
  <p>Any ideas why I get proper results in this code:</p>
  
  <pre><code>LdapContextSource contextSource = new LdapContextSource();
  contextSource.setBase("dc=global,dc=id,dc=pl");
  
  LdapTemplate ldapTemplate = new LdapTemplate(contextSource);
  return ldapTemplate.findAll(Team.class);
  </code></pre>
  
  <p>And empty list from this one:</p>
  
  <pre><code>LdapContextSource contextSource = new LdapContextSource();
  contextSource.setBase("dc=id,dc=pl");
  
  LdapTemplate ldapTemplate = new LdapTemplate(contextSource);
  Name nameBase = LdapUtils.newLdapName("dc=global");
  SearchControls searchControls = new SearchControls();
  return ldapTemplate.findAll(nameBase, searchControls, Team.class);
  </code></pre>
  
  <p>I use Spring-ldap-core 2.0.3</p>