title: Fetching list of users using spring LdapQueryBuilder
body: <p>we are using spring ldap to do user operations(get,update,delete) in active directory.</p>
  
  <p>We have requirement like if we have usergroup(testusergroup) in active directory then we need to fetch all users from that group. Otherwise we need to fetch all users from domain.
  Having usergroup in active directory is not mandatory.</p>
  
  <p>I am using below code to fetch users.</p>
  
  <p>If group exists : </p>
  
  <pre><code>LdapQuery userQuery = LdapQueryBuilder.query().where("objectClass").is("user").and(LdapQueryBuilder.query().where("objectCategory").is("person"))
        .and(LdapQueryBuilder.query().where("memberOf").is(userGroupDN));
  </code></pre>
  
  <p>If no group : </p>
  
  <pre><code> LdapQuery userQuery = LdapQueryBuilder.query().where("objectClass").is("user").and(LdapQueryBuilder.query().where("objectCategory").is("person"));
  </code></pre>
  
  <p>This code is working exactly for my requirement.
  But i would like to reduce the code duplication because i have this kind of queries in multiple places.</p>
  
  <p>I tried like below. </p>
  
  <pre><code>LdapQuery query = LdapQueryBuilder.query().where("objectClass").is("user").and(LdapQueryBuilder.query().where("objectCategory").is("person"))
  </code></pre>
  
  <p>If group exists :</p>
  
  <pre><code>query = query.and(LdapQueryBuilder.query().where("memberOf").is(userGroupDN));
  </code></pre>
  
  <p>It is showing me error like this(The method and(ContainerCriteria) is undefined for the type LdapQuery)</p>
  
  <p>Can anyone help me on this.</p>