0

I am trying to connect to AD using Anonymous binding and do some operations like search a user DN using CN, find mail id etc ....

Here is the code:

public class TestADAnanymousConnection {

  public static void main(String[] args) throws NamingException {

    Hashtable<String, Object> env = new Hashtable<String, Object>();
    env.put(Context.INITIAL_CONTEXT_FACTORY,
            "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL,
            "ldap://localhost:389/dc=myad,dc=com");
    env.put(Context.SECURITY_AUTHENTICATION, "none");
    DirContext ctx;
    ctx = new InitialDirContext(env);
    System.out.println(ctx.lookup("cn=Administrator"));
}

}

It shows error message as below:

Exception in thread "main" javax.naming.NamingException: [LDAP: error code 1 - 000004DC: LdapErr: DSID-0C0906E8, comment: **In order to perform this operation a successful bind must be completed on the connection**., data 0, v1db1 remaining name 'cn=Administrator'
    at line System.out.println(ctx.lookup("cn=Administrator"));

Can somebody please let me know whether I missed anything in the code?
Thanks.

SonalPM
  • 1,317
  • 8
  • 17
bbcr
  • 1
  • 2
  • Have a look at [What is LDAP anonymous binding?](http://stackoverflow.com/questions/4644490/what-is-ldap-anonymous-binding) & [Binding and unbinding - Apache LDAP API](https://directory.apache.org/api/user-guide/2.2-binding-unbinding.html) – OO7 Nov 10 '14 at 11:42

1 Answers1

-2

You cannot. Anonymous binding is only possible for quering root DN. That's it.

Michael-O
  • 18,123
  • 6
  • 55
  • 121