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.
The searchbase is always the domain root DC=extLDAP,DC=com
- you cannot search more objects in your AD.
However, if you do not know the domain root context beforehand, you can do either of three things:
Of course all Microsoft examples are in C# or worse, but you should be able to translate to proper Java.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.