I use a service account to connect to Active Directory and then search for a user using the context like :
String searchBase = "DC=extLDAP,DC=com";
String query = "(&(objectCategory=person)(objectClass=user)(SAMAccountName=batty))";
final SearchControls constraints = new SearchControls();
final NamingEnumeration<?> searchResults = dirContext.search(searchBase,searchQuery,constraints);
But I have a scenario when searchBase is not given to me. In this case, I need to search through complete active directory.
I tried to use searchBase=null;
and searchBase="";
but in both cases I get NullPointerException
and NameNotFoundException
respectively.
Is there any way I can search through complete active directory without knowing searchBase
or domain name.
Note: I am making connection using full dn of service account. So, not knowing domain name specifically.