Querying Active Directory via Java

Question:

What is the best way to query Active Directory from Java?

Now I know that .NET has special methods built in for doing this sort of thing. But in Java, would calling a Powershell script by launching a process/command line be a good way of doing this?

Furthermore, why is the decision taken to call C# from Java anytime Java needs to access Windows WMI data? Is there a reason why running something like pstools (which can launch processes/commands on remote computers) from a command line called by Java, won’t work?

Thanks

Answer:

What is the best way to query Active
Directory from Java?

I don’t know if it is the BEST way, but the typical approach is to use LDAP. You can do this using JNDI. Examples of this can be found here.

Now I know that .NET has special
methods built in for doing this sort
of thing. But in Java, would calling a
Powershell script by launching a
process/command line be a good way of
doing this?

That depends. I think some java folks would cringe at this as it is a pretty clear violation of the “write once, run anywhere” type mentality. However, if you can guarantee that your app will only be used on windows and you have no other alternatives then I don’t see the harm.

Furthermore, why is the decision taken
to call C# from Java anytime Java
needs to access Windows WMI data? Is
there a reason why running something
like pstools (which can launch
processes/commands on remote
computers) from a command line called
by Java, won’t work?

I’m not particularly sure I know the answer to this one. I think I’d need to see some clear examples to take a crack it it.

I hope this helps.

Source:

Querying Active Directory via Java by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply