views:

7

answers:

0

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");
    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);