import javax.naming.*
import javax.naming.directory.*
// LDAPサーバに接続
env = new Hashtable()
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.ldap.LdapCtxFactory")
env.put(Context.PROVIDER_URL, "ldap://localhost:10389/ou=system")
env.put(Context.SECURITY_AUTHENTICATION, "simple")
env.put(Context.SECURITY_PRINCIPAL, "uid=admin,ou=system")
env.put(Context.SECURITY_CREDENTIALS, "secret")
ctx = new InitialDirContext(env)
// OUを検索
sc = new SearchControls()
sc.setSearchScope(SearchControls.SUBTREE_SCOPE)
results = ctx.search("", "(objectclass=organizationalUnit)", sc)
while(results.hasMore()){
println "found:" + results.next().toString()
}
動作環境
groovy 1.7.4, JDK6 Update 21, Apache Directory Server 1.5.7
0 件のコメント:
コメントを投稿