ラベル JNDI の投稿を表示しています。 すべての投稿を表示
ラベル JNDI の投稿を表示しています。 すべての投稿を表示

2010年9月3日金曜日

groovyとJNDIで特定のOU配下のinetOrgPersonを検索する

groovyとJNDIで特定のOU配下のinetOrgPersonを検索するには、以下のコードを実行します。

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配下のinetOrgPersonを検索
sc = new SearchControls()
sc.setSearchScope(SearchControls.SUBTREE_SCOPE)
results = ctx.search("ou=development,ou=users",
"(objectclass=inetOrgPerson)", sc)
while(results.hasMore()){
// 見つかったinetOrgPersonのcommon nameを表示
println "found:" + results.next().attributes.get("cn")
}


動作環境
groovy 1.7.4, JDK6 Update 21, Apache Directory Server 1.5.7

2010年9月2日木曜日

groovyとJNDIでinetOrgPersonを検索する

groovyとJNDIでinetOrgPersonを検索するには、以下のコードを実行します。

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)
// inetOrgPersonを検索
sc = new SearchControls()
sc.setSearchScope(SearchControls.SUBTREE_SCOPE)
results = ctx.search("", "(objectclass=inetOrgPerson)", sc)
while(results.hasMore()){
// 見つかったinetOrgPersonのcommon nameを表示
println "found:" + results.next().attributes.get("cn")
}


動作環境
groovy 1.7.4, JDK6 Update 21, Apache Directory Server 1.5.7

2010年9月1日水曜日

groovyとJNDIで特定の名前のOUを検索する

groovyとJNDIで特定の名前のOUを検索するには、以下のコードを実行します。

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("ou=groups", "(objectclass=organizationalUnit)", sc)
while(results.hasMore()){
println "found:" + results.next().toString()
}


動作環境
groovy 1.7.4, JDK6 Update 21, Apache Directory Server 1.5.7

2010年8月30日月曜日

groovyとJNDIでOUを検索する

groovyとJNDIでOUを検索するには、以下のコードを実行します。

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