正在将 java 连接到 Active-Directory - 错误 49 数据 5
Connecting java to Active-Directory - Error 49 data 5
我正在尝试从 java (8u241) 连接到 AD (2012 R2),但出现此错误
javax.naming.AuthenticationException: [LDAP: error code 49 - 80090308: LdapErr: DSID-0C0903C8, comment: AcceptSecurityContext error, data 5, v2580 ]
错误是49,意思是错误user/pass。但这也可能意味着登录被阻止。我发现使用名为 ADExplorer 的应用程序(来自 sysinternals.com,Microsft):My Issue On ServerFault - Login blocked for using the ip instead of the name。当主机是 ip 而不是域名时,Active-Directory 将回复错误 user/pass。
子错误代码是 5。我没有在任何地方找到关于此代码 5 的任何文档。
(不是 52e。当我输入错误的用户名时得到 52e)
这是什么错误(LDAP 错误 49 数据 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 ]
"data"后面的数字是Windows系统错误代码,可以在微软文档中找到。那个特定的在 the first page 上,意思是 "access is denied"。
这更像是授权错误,而不是身份验证。意思是"I know who you are and you aren't allowed to do this."
我不知道究竟是什么情况会导致该错误。也许您的域上禁用了简单绑定。也许您使用的帐户有某种限制。我不能肯定。
我通过删除 OS 并安装另一个版本解决了这个问题。
我正在尝试从 java (8u241) 连接到 AD (2012 R2),但出现此错误
javax.naming.AuthenticationException: [LDAP: error code 49 - 80090308: LdapErr: DSID-0C0903C8, comment: AcceptSecurityContext error, data 5, v2580 ]
错误是49,意思是错误user/pass。但这也可能意味着登录被阻止。我发现使用名为 ADExplorer 的应用程序(来自 sysinternals.com,Microsft):My Issue On ServerFault - Login blocked for using the ip instead of the name。当主机是 ip 而不是域名时,Active-Directory 将回复错误 user/pass。
子错误代码是 5。我没有在任何地方找到关于此代码 5 的任何文档。 (不是 52e。当我输入错误的用户名时得到 52e)
这是什么错误(LDAP 错误 49 数据 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 ]
"data"后面的数字是Windows系统错误代码,可以在微软文档中找到。那个特定的在 the first page 上,意思是 "access is denied"。
这更像是授权错误,而不是身份验证。意思是"I know who you are and you aren't allowed to do this."
我不知道究竟是什么情况会导致该错误。也许您的域上禁用了简单绑定。也许您使用的帐户有某种限制。我不能肯定。
我通过删除 OS 并安装另一个版本解决了这个问题。