ldap java 密码,LDAP通过JAVA而不提供密码

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"));

}

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.

but in 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");

}

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?

Regards,

解决方案

I used JNI to invoke a C# dll... the problem is JNI is very slow. it is taking almost 15-20 sec per call

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值