使用普通 Java 的 AuthenticationException LDAP
AuthenticationException LDAP using plain Java
我在使用纯 Java.
通过 ldap 连接到 Active Directory 时遇到问题
如果 displayName 以 ,(逗号,例如“, name”)开头,我会得到 javax.naming.AuthenticationException
。 displayName 从不在应用程序中使用。我使用的 Context.SECURITY_PRINCIPAL
和 Context.SECURITY_CREDENTIALS
不包含任何逗号。
有人可以向我解释一下这种行为吗?
一些堆栈:
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)
测试客户端(只需替换占位符):
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.NamingException;
import javax.naming.directory.DirContext;
import javax.naming.directory.InitialDirContext;
public class LdapClient {
public static void main( String[] args ) {
// URL to Active Directory
String ldapContextUrl = ###URL###;
//Login
String ldapContextUserDn = ###USER###;
//Password
String ldapContextPassword = ###PASSWORD###;
Hashtable<String, String> environment = new Hashtable<String, String>();
environment.put( Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory" );
environment.put( Context.SECURITY_AUTHENTICATION, "simple" );
environment.put( Context.STATE_FACTORIES, "PersonStateFactory" );
environment.put( Context.OBJECT_FACTORIES, "PersonObjectFactory" );
environment.put( Context.PROVIDER_URL, ldapContextUrl );
environment.put( Context.SECURITY_PRINCIPAL, ldapContextUserDn );
environment.put( Context.SECURITY_CREDENTIALS, ldapContextPassword );
try {
DirContext ctx = new InitialDirContext( environment ); // Error occures here
} catch( NamingException e ) {
e.printStackTrace();
}
}
}
请不要说:不要使用这样的显示名称。我只是感兴趣,为什么应用程序会像上面描述的那样运行。是错误、功能还是介于两者之间?
您也可以使用 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
表示"user not found"
,是服务器端的错误信息。因此,本机 Java JNDI 或任何其他 LDAP 客户端对其没有影响。有关详细信息,请参阅 Data codes related to 'LDAP: error code 49' with Microsoft Active Directory。
所以 .. 我做了一些进一步的调查并获得了一些新的细节。
这一切都与"Modes of Authenticating to LDAP"有关。我的客户端(也可能是 Apache Directory Studio 或 Websphere Application Server)使用 simple 身份验证模式。
environment.put( Context.SECURITY_AUTHENTICATION, "simple" );
如果我将其更改为更高级的模式,客户端工作正常。
environment.put( Context.SECURITY_AUTHENTICATION, "DIGEST-MD5" );
查看一些 Oracle 文档:
https://docs.oracle.com/javase/tutorial/jndi/ldap/authentication.html
https://docs.oracle.com/javase/tutorial/jndi/ldap/auth_mechs.html
我不知道为什么 Auth-Mode 与显示名称有关,但我的测试表明,Java 不是问题 - olexd[=31 令人难过=]之前。
对于我的测试,我使用了一个名为 AdFind 的控制台应用程序。这个应用程序使我能够使用非 java-应用程序
重现与我的客户相同的行为
我在使用纯 Java.
通过 ldap 连接到 Active Directory 时遇到问题如果 displayName 以 ,(逗号,例如“, name”)开头,我会得到 javax.naming.AuthenticationException
。 displayName 从不在应用程序中使用。我使用的 Context.SECURITY_PRINCIPAL
和 Context.SECURITY_CREDENTIALS
不包含任何逗号。
有人可以向我解释一下这种行为吗?
一些堆栈:
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)
测试客户端(只需替换占位符):
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.NamingException;
import javax.naming.directory.DirContext;
import javax.naming.directory.InitialDirContext;
public class LdapClient {
public static void main( String[] args ) {
// URL to Active Directory
String ldapContextUrl = ###URL###;
//Login
String ldapContextUserDn = ###USER###;
//Password
String ldapContextPassword = ###PASSWORD###;
Hashtable<String, String> environment = new Hashtable<String, String>();
environment.put( Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory" );
environment.put( Context.SECURITY_AUTHENTICATION, "simple" );
environment.put( Context.STATE_FACTORIES, "PersonStateFactory" );
environment.put( Context.OBJECT_FACTORIES, "PersonObjectFactory" );
environment.put( Context.PROVIDER_URL, ldapContextUrl );
environment.put( Context.SECURITY_PRINCIPAL, ldapContextUserDn );
environment.put( Context.SECURITY_CREDENTIALS, ldapContextPassword );
try {
DirContext ctx = new InitialDirContext( environment ); // Error occures here
} catch( NamingException e ) {
e.printStackTrace();
}
}
}
请不要说:不要使用这样的显示名称。我只是感兴趣,为什么应用程序会像上面描述的那样运行。是错误、功能还是介于两者之间?
您也可以使用 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
表示"user not found"
,是服务器端的错误信息。因此,本机 Java JNDI 或任何其他 LDAP 客户端对其没有影响。有关详细信息,请参阅 Data codes related to 'LDAP: error code 49' with Microsoft Active Directory。
所以 .. 我做了一些进一步的调查并获得了一些新的细节。
这一切都与"Modes of Authenticating to LDAP"有关。我的客户端(也可能是 Apache Directory Studio 或 Websphere Application Server)使用 simple 身份验证模式。
environment.put( Context.SECURITY_AUTHENTICATION, "simple" );
如果我将其更改为更高级的模式,客户端工作正常。
environment.put( Context.SECURITY_AUTHENTICATION, "DIGEST-MD5" );
查看一些 Oracle 文档: https://docs.oracle.com/javase/tutorial/jndi/ldap/authentication.html https://docs.oracle.com/javase/tutorial/jndi/ldap/auth_mechs.html
我不知道为什么 Auth-Mode 与显示名称有关,但我的测试表明,Java 不是问题 - olexd[=31 令人难过=]之前。
对于我的测试,我使用了一个名为 AdFind 的控制台应用程序。这个应用程序使我能够使用非 java-应用程序
重现与我的客户相同的行为