开发者

Authenticating in one Domain and querying users from another in Java

Is it possible to authenticate users in Active Directory Server A, and then search for users in Active Directory Server B using java? These servers are configured to be 2-way trusted.

The above code fails. I can authenticate in server A perfectly fine, but when I start searching for users in B, it returns nothing

    Hashtable<String, String> env = new Hashtable<String, String>();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, "ldap://A.AD.COM:389");
    env.put(Context.SECURITY_AUTHENTICATION, "simple");

    StringBuffer principal = new StringBuffer("user@A开发者_如何学JAVA");
    env.put(Context.SECURITY_PRINCIPAL, principal.toString());
    env.put(Context.SECURITY_CREDENTIALS, "password");

    env.put(Context.REFERRAL, "follow");
    InitialLdapContext ctx = new InitialLdapContext(env, null);

    String base = "DC=b,DC=ad,DC=com";

    String filter = "(&(objectClass=user))";

    SearchControls controls = new SearchControls();
    String []strReturningAttr = null;
    controls.setSearchScope(SearchControls.SUBTREE_SCOPE);

    NamingEnumeration answer = ctx.search(base, filter, controls);


Only if your are in a global catalog with linked domains.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜