来自java程序的ldap身份验证错误

时间:2017-08-28 12:02:07

标签: java ldap

public static void main(String[] args)
{


    // Setup environment for authenticating

    Hashtable<String, String> environment = 
        new Hashtable<String, String>();

    environment.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");

    environment.put(Context.PROVIDER_URL,"ldap://192.168.0.100:389");

    environment.put(Context.SECURITY_AUTHENTICATION,"simple");

    environment.put(Context.SECURITY_PRINCIPAL,"uid=dilip.duraiswamy,dc=xxxx,dc=local");

    environment.put(Context.SECURITY_CREDENTIALS,"xxxx");

    try
    {
        DirContext authContext = 
            new InitialDirContext(environment);

        // user is authenticated
        System.out.println("USER IS AUTHETICATED");

    }
    catch (AuthenticationException ex)
    {

        // Authentication failed
        System.out.println("AUTH FAILED : "+ex );

    }
    catch (NamingException ex)
    {
        ex.printStackTrace();
    }
}

将错误视为 javax.naming.AuthenticationException:[LDAP:错误代码49 - 80090308:LdapErr:DSID-0C09042F,注释:AcceptSecurityContext错误,数据52e,v2580

1 个答案:

答案 0 :(得分:1)

对于身份验证,请添加正确的可分辨名称。

如果在空间或某些特殊字符的情况下未正确指定DN,则通常会出现此问题。

此处52e - 表示无效凭证

http://www-01.ibm.com/support/docview.wss?uid=swg21290631