Java的LDAP身份验证问题 [英] Java ldap authentication issue

查看:311
本文介绍了Java的LDAP身份验证问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想有我的自定义的Java应用程序使用了Active Directory服务器进行身份验证,但我无法得到它的工作由于某种原因。任何人都可以看到这是为什么?下面是我下面的方法:

 私人布尔验证(字符串的serverName,字符串userid,字符串密码)抛出NamingException的{
    DirContext的CTX = NULL;
    Hashtable的ENV =新的Hashtable(11);
    布尔B = FALSE;
    尝试 {
        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,简单);
        env.put(Context.SECURITY_PRINCIPAL,UID =+用户id +,OU =所有用户,DC =网站,DC =组织);
        env.put(Context.SECURITY_CREDENTIALS,密码);
        的System.out.println(之前语境);
        //如果没有命名异常则用户被认证。返回true
        CTX =新InitialDirContext(ENV);
        //用户进行身份验证。
        B =真实;
    }赶上(NamingException的E){
        的System.out.println(用户未通过身份验证将返回false);
        B = FALSE;
    }最后{
        如果(CTX!= NULL)
            ctx.close();
    }
    返回b;
}
 

结果:

  [11年12月14日16:27:47:746 CST] 0000001f SystemErrř
javax.naming.AuthenticationException:[LDAP:错误code 49  -  80090308:LdapErr:DSID-0C090334,注释:AcceptSecurityContext错误,数据52E,vece
 

解决方案

您是否尝试过这种方法吗?

  // ...
env.put(Context.SECURITY_PRINCIPAL,CN =+用户id +,OU =所有用户,DC =网站,DC =组织);
// ...
 

另外替换

  Hashtable的ENV =新的Hashtable(11);
 

  Hashtable的ENV =新的Hashtable();
 

I'm trying to have my custom java application use our Active Directory Server for authentication but I cannot get it to work for some reason. Can anyone see why this is? Here is my method below:

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

Result:

[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

解决方案

Have you tried this way?

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

Also replace

Hashtable env = new Hashtable(11);

with

Hashtable env = new Hashtable();

这篇关于Java的LDAP身份验证问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆