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
This is a snippet of what I have but it is not returning all Locked accounts.
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 = "(&(objectClass=User)(lockoutTime>=1))";
String searchBase = usersContainer;
NamingEnumeration<SearchResult> answer = ctx.search(searchBase, searchFilter, searchCtls);
while (answer.hasMore()) {
SearchResult result = (SearchResult) answer.next();
adInfo = result.getAttributes();
}
ctx.close();
}
catch (NamingException e) {
}
I put this
(&(objectClass=User)(lockoutTime>=1))
line in there to see if it would just go and find all the locked accounts. I also tried
(&(objectCategory=Person)(objectClass=User)(lockoutTime>=1))
but no luck.
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.