gpt4 book ai didi

java - 使用纯 Java 的 AuthenticationException LDAP

转载 作者:行者123 更新时间:2023-11-29 05:05:13 26 4
gpt4 key购买 nike

我在使用纯 Java 通过 ldap 连接到 Active Directory 时遇到问题。

如果 displayName 以 ,(逗号,例如“, name”)开头,我会得到一个 javax.naming.AuthenticationException。 displayName 从不在应用程序中使用。 Context.SECURITY_PRINCIPALContext.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 StudioWebsphere Application Server(针对 LDAP 配置的安全性)重现此问题。所以这个问题似乎与 JVM 无关。 Oracle 和 IBM 的行为相似。

提前致谢!

最佳答案

所以 .. 我做了一些进一步的调查并获得了一些新的细节。

这一切都与“LDAP 身份验证模式”有关。我的客户端(也可能是 Apache Directory StudioWebsphere Application Server)使用简单 Auth-Mode。

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 与 DisplayName 有关系,但我的测试表明,Java 不是问题所在 - 正如 olexd 之前所伤心的那样。

在我的测试中,我使用了一个名为 AdFind 的控制台应用程序。这个应用程序使我能够使用非 Java 应用程序重现与我的客户相同的行为

关于java - 使用纯 Java 的 AuthenticationException LDAP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30597880/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com