title: Java: request all locked AD accounts
body: <p>I have code today that I can grab a single users AD info. What I am looking for is code that acts like Powershells Search-ADAccount -LockedOut</p>
  
  <p>This is a snippet of what I have but it is not returning all Locked accounts.</p>
  
  <pre><code>env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
  env.put(Context.PROVIDER_URL, ldapUri);
  env.put(Context.SECURITY_AUTHENTICATION, "simple");
  env.put(Context.SECURITY_PRINCIPAL, "username@ourdomain.com");
  env.put(Context.SECURITY_CREDENTIALS, "password";
  
  try {
      DirContext ctx = new InitialLdapContext(env,null);
      SearchControls searchCtls = new SearchControls();
      searchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE);
      String searchFilter = "(&amp;(objectClass=User)(lockoutTime&gt;=1))";
      String searchBase = usersContainer;
      NamingEnumeration&lt;SearchResult&gt; answer = ctx.search(searchBase, searchFilter, searchCtls);
      while (answer.hasMore()) {
          SearchResult result = (SearchResult) answer.next();
          adInfo = result.getAttributes();
      }
  
      ctx.close();
  }
  catch (NamingException e) {
  
  }
  </code></pre>
  
  <p>I put this </p>
  
  <pre><code>(&amp;(objectClass=User)(lockoutTime&gt;=1)) 
  </code></pre>
  
  <p>line in there to see if it would just go and find all the locked accounts. I also tried</p>
  
  <pre><code>(&amp;(objectCategory=Person)(objectClass=User)(lockoutTime&gt;=1)) 
  </code></pre>
  
  <p>but no luck.</p>
  
  <p>So... I am at a stand still considering the lack of Java LDAP support so I turned to here to see if anyone has any ideas.</p>