LDAP: error code 49 - Simple Bind Failed: NT_STATUS_LOGON_FAILURE(LDAP:错误代码 49 - 简单绑定失败:NT_STATUS_LOGON_FAILURE)
问题描述
我正在尝试对用户进行身份验证,但它抛出 Exception
.可能是配置有问题.
I am trying to authenticate the user but it throws Exception
.May be there is problem in configuration.
public class LdapApplication {
private static final String INITIAL_CONTEXT_FACTORY = "com.sun.jndi.ldap.LdapCtxFactory";
private static final String SECURITY_AUTHENTICATION ="simple";
private static final String NAMED_CONTEXT = "CN=Users";
private static final String SAM_ACCOUNT_NAME = "sAMAccountName=";
public static void main(String[] args) {
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,INITIAL_CONTEXT_FACTORY);
env.put(Context.PROVIDER_URL, "ldap://ip:portNo/dc=organisation,dc=in");
env.put(Context.SECURITY_AUTHENTICATION, SECURITY_AUTHENTICATION);
env.put(Context.SECURITY_PRINCIPAL, "cn=userName,cn=Users");
env.put(Context.SECURITY_CREDENTIALS, "password" );
DirContext context = null;
NamingEnumeration namingEnumeration = null;
try {
context = new InitialDirContext(env);
namingEnumeration = context.search(NAMED_CONTEXT, SAM_ACCOUNT_NAME+ userName, null);
while (namingEnumeration.hasMore()) {
SearchResult searchResult = (SearchResult) namingEnumeration.next();
Attributes attributes = searchResult.getAttributes();
System.out.println(" Person Common Name = " + attributes.get("cn"));
System.out.println(" Person Display Name = " + attributes.get("displayName"));
}catch(Exception e){
System.out.println(e.getMessage());
e.printStackTrace();
}
}
} catch (Throwable e) {
e.printStackTrace();
} finally {
if (namingEnumeration != null) {
try {
namingEnumeration.close();
} catch (Exception e) {
}
}
if (context != null) {
try {
context.close();
} catch (Exception e) {
}
}
}
}
}
但如果我提到 Context.SECURITY_PRINCIPAL
作为 "organisation\userName"
而不是 "cn=userName,cn=Users"
它工作得很好.请提出一个可能的解决方案,因为我的要求是使用 cn 或 dc 给 SECURITY_PRINCIPAL 一些东西.
but if i mention Context.SECURITY_PRINCIPAL
as "organisation\userName"
instead of "cn=userName,cn=Users"
it works perfectly fine. Kindly suggest a possible solution because my requirement is to give SECURITY_PRINCIPAL something using cn or dc.
推荐答案
我们在代码中遇到了同样的问题,我们通过在用户名前添加域名来修复它.不要输入 user:password
,而是输入 domainuser:password
.
We were having the same issue in our code and we fixed it by adding the domain name before the user name. Instead of entering user:password
, enter domainuser:password
.
希望这会有所帮助.
这篇关于LDAP:错误代码 49 - 简单绑定失败:NT_STATUS_LOGON_FAILURE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:LDAP:错误代码 49 - 简单绑定失败:NT_STATUS_LOGON_FAILURE
基础教程推荐
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- 降序排序:Java Map 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01