【发布时间】:2020-04-11 10:55:58
【问题描述】:
我正在尝试从 java (8u241) 连接到 AD (2012 R2),但出现此错误
javax.naming.AuthenticationException: [LDAP: error code 49 - 80090308: LdapErr: DSID-0C0903C8, comment: AcceptSecurityContext error, data 5, v2580 ]
错误是 49,这意味着错误的用户/密码。但这也可能意味着登录被阻止。我使用名为 ADExplorer 的应用程序(来自 sysinternals.com,Microsft)发现了这一点:My Issue On ServerFault - Login blocked for using the ip instead of the name。当主机是 ip 而不是域名时,Active-Directory 将回复错误的用户/密码。
子错误代码是 5。我在任何地方都没有找到有关此代码 5 的任何文档。 (不是 52e。当我输入错误的用户名时,我得到 52e)
这是什么错误(LDAP Err 49 data 5),我该如何解决?
我的代码:
public void authenticate(String username, String password) throws Exception {
@SuppressWarnings("UseOfObsoleteCollectionType")
java.util.Hashtable<Object, Object> env = new java.util.Hashtable<>();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
String url = "LDAP://" + serverName.toUpperCase()+ '.' + domainName.toUpperCase();
System.out.println("url = '" + url + "'");
env.put(Context.PROVIDER_URL, url);
String sp = takeUntil(domainName.toUpperCase(), '.') + "\\" + username;
System.out.println("sp = '" + sp + "'");
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, sp);
env.put(Context.SECURITY_CREDENTIALS, password.getBytes(StandardCharsets.UTF_8));
DirContext ctx = new InitialDirContext(env); // javax.naming.AuthenticationException here
ctx.close();
}
结果(在服务器中执行 - Win Server 2012 R2):
C:\Users\Administrator\Desktop>java -jar ActiveDirectory.jar array.is blackhole ARRAY\muaaz P0987654321q
url = 'LDAP://BLACKHOLE.ARRAY.IS'
sp = 'ARRAY\muaaz'
javax.naming.AuthenticationException: [LDAP: error code 49 - 80090308: LdapErr: DSID-0C0903C8, comment: AcceptSecurityContext error, data 5, v2580 ]
【问题讨论】:
-
尝试其他用户登录。
-
所有用户的结果相同。
标签: java active-directory ldap windows-server-2012-r2