使用匿名绑定连接到AD并搜索用户DN



我正在尝试使用Anonymous binding连接到AD,并执行一些操作,如使用CN搜索用户DN、查找邮件id等。。。。

这是代码:

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

}

它显示错误消息如下:

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

有人能告诉我代码中是否遗漏了什么吗
谢谢

您不能。匿名绑定只能用于查询根DN。就是这样。