LDAP通过JAVA而不提供密码 [英] LDAP via JAVA without providing password
问题描述
在C#中,我写了下面的代码来连接到LDAP服务器并查询相同的内容。
in C#, I have written below code to connect to LDAP server and query the same.
String ldapUrl = "LDAP://...";
DirectoryEntry entry = new DirectoryEntry(ldapUrl);
DirectorySearcher dSearch = new DirectorySearcher(entry);
String Name = "ravi";
dSearch.Filter = "(&(objectClass=user)(sAMAccountName=" + Name + "))";
foreach (SearchResult sResultSet in dSearch.FindAll())
{
String data = "Login Name :" + (GetProperty(sResultSet, "cn")) + "\r\n" +
"First Name :" + (GetProperty(sResultSet, "givenName")) + "\r\n" +
"Middle Initials :" + (GetProperty(sResultSet, "initials")) + "\r\n" +
"Last Name : " + (GetProperty(sResultSet, "sn"));
}
如果您注意到,我没有提供用户名和/或密码。我认为它使用登录用户凭据的操作系统登录LDAP服务器。
If you notice, no where I have provided the username and or password. I think it logs-in to the LDAP server using the OS logged in users credentials.
但是在JAVA中
String url = "ldap://localhost:10389";
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, url);
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(***Context.SECURITY_PRINCIPAL, "uid=admin,ou=system"***);
env.put(***Context.SECURITY_CREDENTIALS, "secret"***);
try {
DirContext ctx = new InitialDirContext(env);
System.out.println("connected");
System.out.println(ctx.getEnvironment());
ctx.close();
} catch (Exception ex) {
System.out.println("error when trying to create the context");
}
java中是否有办法在不提供用户名的情况下绑定到LDAP服务器和密码?我尝试通过将Context.SECURITY_AUTHENTICATION设置为NONE来绑定,但是它们会抛出匿名登录的例外,不允许。我不知道如何使用匿名用户凭据,但操作系统已登录用户凭据。
Is there a way in java to bind to the LDAP server without providing the username and password? I tried bind to by setting the Context.SECURITY_AUTHENTICATION as NONE, but it them throws the exception for anonymous login not allowed. I don't what to use Anonymous user credentials but the OS logged in users credentials.
这是可能的以及如何实现?
is this possible and how?
问候,
推荐答案
我用JNI来调用C#dll ...问题是JNI非常慢。每次通话大约需要15-20秒
I used JNI to invoke a C# dll... the problem is JNI is very slow. it is taking almost 15-20 sec per call
这篇关于LDAP通过JAVA而不提供密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!