0

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.

codingenious
  • 8,385
  • 12
  • 60
  • 90

1 Answers1

0

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.

Community
  • 1
  • 1
mvreijn
  • 2,807
  • 28
  • 40