使用普通Java的AuthenticationException LDAP

使用普通Java的AuthenticationException LDAP,java,authentication,exception,active-directory,ldap,Java,Authentication,Exception,Active Directory,Ldap,使用普通Java通过ldap连接到Active Directory时出现问题 如果displayName以逗号开头(例如“,”name“),我会得到一个javax.naming.AuthenticationException。displayName从未在应用程序中使用上下文.SECURITY\u主体和上下文.SECURITY\u凭证我使用的凭证不包含任何逗号 有人能给我解释一下这种行为吗 一些堆栈: javax.naming.AuthenticationException: [LDAP: err

使用普通Java通过ldap连接到Active Directory时出现问题

如果displayName以逗号开头(例如“,”name“),我会得到一个
javax.naming.AuthenticationException
。displayName从未在应用程序中使用<代码>上下文.SECURITY\u主体和
上下文.SECURITY\u凭证
我使用的凭证不包含任何逗号

有人能给我解释一下这种行为吗

一些堆栈:

javax.naming.AuthenticationException: [LDAP: error code 49 - 80090308: LdapErr: DSID-0C090334, comment: AcceptSecurityContext error, data 525, vece]
    at com.sun.jndi.ldap.LdapCtx.mapErrorCode(LdapCtx.java:3100)
    at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:3046)
    at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2848)
    at com.sun.jndi.ldap.LdapCtx.connect(LdapCtx.java:2762)
    at com.sun.jndi.ldap.LdapCtx.<init>(LdapCtx.java:329)
    at com.sun.jndi.ldap.LdapCtxFactory.getUsingURL(LdapCtxFactory.java:206)
    at com.sun.jndi.ldap.LdapCtxFactory.getUsingURLs(LdapCtxFactory.java:224)
    at com.sun.jndi.ldap.LdapCtxFactory.getLdapCtxInstance(LdapCtxFactory.java:167)
    at com.sun.jndi.ldap.LdapCtxFactory.getInitialContext(LdapCtxFactory.java:97)
javax.naming.AuthenticationException:[LDAP:错误代码49-80090308:LDAPPER:DSID-0C0900334,注释:AcceptSecurityContext错误,数据525,vece]
位于com.sun.jndi.ldap.LdapCtx.maperrocode(LdapCtx.java:3100)
位于com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:3046)
位于com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2848)
位于com.sun.jndi.ldap.LdapCtx.connect(LdapCtx.java:2762)
位于com.sun.jndi.ldap.LdapCtx.(LdapCtx.java:329)
位于com.sun.jndi.ldap.LdapCtxFactory.getUsingURL(LdapCtxFactory.java:206)
位于com.sun.jndi.ldap.LdapCtxFactory.getUsingURLs(LdapCtxFactory.java:224)
位于com.sun.jndi.ldap.LdapCtxFactory.getLdapCtxInstance(LdapCtxFactory.java:167)
位于com.sun.jndi.ldap.LdapCtxFactory.getInitialContext(LdapCtxFactory.java:97)
测试客户端(只需替换占位符):

import java.util.Hashtable;
导入javax.naming.Context;
导入javax.naming.NamingException;
导入javax.naming.directory.DirContext;
导入javax.naming.directory.InitialDirContext;
公共类LdapClient{
公共静态void main(字符串[]args){
//Active Directory的URL
字符串ldapContextUrl=####URL###;
//登录
字符串ldapContextUserDn=####用户###;
//密码
字符串ldapContextPassword=########;
Hashtable环境=新的Hashtable();
put(Context.INITIAL\u Context\u工厂,“com.sun.jndi.ldap.LdapCtxFactory”);
put(Context.SECURITY_身份验证,“simple”);
environment.put(Context.STATE_FACTORIES,“PersonStateFactory”);
put(Context.OBJECT_工厂,“PersonObjectFactory”);
put(Context.PROVIDER\uURL、ldapContextUrl);
put(Context.SECURITY\u主体,ldapContextUserDn);
put(Context.SECURITY\u凭证、ldapContextPassword);
试一试{
DirContext ctx=new InitialDirContext(环境);//此处发生错误
}捕获(NamingE例外){
e、 printStackTrace();
}
}
}
请不要说:不要使用这样的显示名。我只是感兴趣的是,为什么应用程序会像上面描述的那样运行。它是一个bug、一个特性还是介于两者之间的东西

您还可以使用Apache Directory Studio或Websphere Application Server(针对LDAP配置的安全性)重现此问题。因此,问题似乎与JVM无关。Oracle和IBM的行为类似


提前谢谢

中的错误代码
525

LDAP: error code 49 - 80090308: LdapErr: DSID-0C090334, comment: AcceptSecurityContext error, data 525, vece

表示“未找到用户”,是服务器端错误消息。因此,本机Java JNDI或任何其他LDAP客户端对其没有影响。有关更多详细信息,请参阅。

So。。我做了进一步的调查,得到了一些新的细节

这一切都与“LDAP身份验证模式”有关。我的客户机(可能还有Apache Directory Studio或Websphere Application Server)使用简单身份验证模式

environment.put( Context.SECURITY_AUTHENTICATION, "simple" );
如果我将此更改为更高级的模式,则客户端工作正常

environment.put( Context.SECURITY_AUTHENTICATION, "DIGEST-MD5" );
请参阅一些Oracle文档:

我不知道为什么Auth模式与DisplayName有关,但我的测试表明,Java并不是问题所在——就像olexd之前所说的那样


在测试中,我使用了一个名为AdFind的控制台应用程序。此应用程序使我能够与使用非java应用程序的客户端恢复相同的行为

在“开箱即用”中,AD将创建DN为:“,name,…,dc=example,dc=domain”的条目。我想问题是您的DN带有逗号。逗号必须在DN内转义。嗨!我以前读过一些doc für LDAP错误代码,但是“未找到用户”对我来说没有任何意义,因为用户肯定存储在AD中。我做了更多的调查。。请看一下我的下一个答案。
environment.put( Context.SECURITY_AUTHENTICATION, "DIGEST-MD5" );