Java ldap身份验证问题

Java ldap身份验证问题,java,authentication,active-directory,ldap,jndi,Java,Authentication,Active Directory,Ldap,Jndi,我试图让我的自定义java应用程序使用我们的Active Directory服务器进行身份验证,但由于某些原因,我无法让它工作。有人知道这是为什么吗?以下是我的方法: private boolean authenticate(String serverName, String userId, String password) throws NamingException { DirContext ctx = null; Hashtable env = new Hashtable(

我试图让我的自定义java应用程序使用我们的Active Directory服务器进行身份验证,但由于某些原因,我无法让它工作。有人知道这是为什么吗?以下是我的方法:

private boolean authenticate(String serverName, String userId, String password) throws NamingException {
    DirContext ctx = null;
    Hashtable env = new Hashtable(11);
    boolean b = false;
    try {
        env.put(Context.INITIAL_CONTEXT_FACTORY,
        "com.sun.jndi.ldap.LdapCtxFactory");
        env.put(Context.PROVIDER_URL, "ldap://servername.org:389");
        env.put(Context.SECURITY_AUTHENTICATION, "simple");
        env.put(Context.SECURITY_PRINCIPAL, "uid="+ userId +",ou=All Users,dc=site,dc=org");
        env.put(Context.SECURITY_CREDENTIALS, password);
        System.out.println("before context");
        // If there isn't a naming exception then the user is authenticated. Return true
        ctx = new InitialDirContext(env);
        //The user is authenticated.
        b = true;
    } catch (NamingException e) {
        System.out.println("the user is not authenticated return false");
        b = false;
    }finally{
        if(ctx != null)
            ctx.close();
    }
    return b;
}
结果:

[12/14/11 16:27:47:746 CST] 0000001f SystemErr     R
javax.naming.AuthenticationException: [LDAP: error code 49 - 80090308: LdapErr: DSID-0C090334, comment: AcceptSecurityContext error, data 52e, vece

你试过这种方法吗

//...
env.put(Context.SECURITY_PRINCIPAL, "cn="+ userId +",ou=All Users,dc=site,dc=org");
//...
也代替

Hashtable env = new Hashtable(11);


会发生什么?你能发布堆栈跟踪吗?我得到一个ldap错误代码49,这是一个身份验证错误。但是,我提供的凭据是正确的。我可以用它登录到我的windows计算机和其他服务器。您的ldap需要加密吗?您是否使用了任何特定的连接参数,您可能会发现这些参数很重要,需要共享?否则这只是猜测。谢谢!!我知道这一定很简单。
Hashtable env = new Hashtable();