开发者

How to list the available Windows domains from a java application?

I have to authorise users using its Windows account in a web application. I use LDAP to validate with the Active Directory if the user/pwd in a specific domain is correct, but I need a list of the available domains because the users c开发者_JAVA百科an be from differents domains. I try a DNS SRV query to list the ldap servers ( _ldap._tcp ) but I don't get the ssl ldap Active Directory servers. The host app is in a Unix machine, not Windows.


I can't be sure that this will work since I don't have access to the necessary libraries, but it seems that you'll need to do something like this:

Get hold of the ADSI JARs. This is the really tricky bit. Perhaps this article can help with the initial configuration or you can go with J++ here, or maybe this one from Isocra consulting. If you're hosting your application on Linux and calling into a Windows based AD server, then see section 3 of the first article. In essence you'll be creating some Java proxies onto the ADSI COM object and then calling through them into a remote AD server.

Once that's configured, then this might just do it

public class Main {

  public static void main(String args[]) throws Exception {
      // The key is not to include any domain in your call apparently
      Set domains = (Set) ADsGetObject("WinNT:", IADs.iid);
      for (PropertyCache domain: domains) {
        System.out.println(domain.getName());
      }
  }

  /**
   * @dll.import("activeds", ole)
   */
  private static native IUnknown ADsGetObject(String path, _Guid riid);

}

Rather than being a complete answer, this may just get you started in the right direction. However, it does look like it could be very difficult to get working.

This SO answer may also help (it's in C#)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜