我正在尝试引导一些非常简单的LDAP代码,连接到公共可用的LDAP提供程序。但是,即使目录在Apache DS中正常工作,我的代码也找不到任何对象。
import javax.naming._
import javax.naming.directory._
import javax.naming.ldap._
import java.util._
val env = new Hashtable[String, Object]()
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.SECURITY_AUTHENTICATION, "none")
env.put(Context.PROVIDER_URL, "ldap://ldap.virginia.edu:389/o=University of Virginia,c=US")
var ctx = new InitialDirContext(env)
val searchControls = new SearchControls()
searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE)
现在无论我如何尝试搜索或查找,例如
var results = ctx.search("o=University of Virginia,c=US", "(cn=*)", searchControls)
或更具体地说
var results = ctx.search("ou=adagn, ou=Business Non-Degree-adagn, o=University of Virginia, c=US", "(cn=*)", searchControls)
我刚收到javax.naming.NameNotFoundException: [LDAP: error code 32 - No Such Object]; remaining name 'ou=adagn, ou=Business Non-Degree-adagn, o=University of Virginia, c=US'
。
我甚至不知道基数是错还是搜索表达式错了......?
编辑:这有效:
ldapsearch -h ldap.virginia.edu -p 389 -s sub -b 'o=University of Virginia,c=US' -x -z 1 '(cn=*)'
答案 0 :(得分:1)
它适用于以下修改:
env.put(Context.PROVIDER_URL, "ldap://ldap.virginia.edu:389")