5.1 search has been edited by Stefan Zoerner (Feb 16, 2009).

(View changes)

Content:

search

Three options to call a search method

Short cut methods

For the most common types of search requests, the LDAP class contains two direct methods.

public List<Object> search( String filter ) throws NamingException
public List<Object> search( String filter, String base, SearchScope scope ) throws NamingException

This example uses the second variant:

...
ldap = LDAP.newInstance('ldap://zanzibar:10389/')

results = ldap.search('(objectClass=person)', 'dc=example,dc=com', SearchScope.ONE)
println " ${results.size} entries found ".center(40,'-')
for (entry in results) {
  println entry.dn
}
...

Using a Search object

The class org.apache.directory.groovyldap.Search is a JavaBean which contains parameters for a search.

Property name Type Default value Description
base java.lang.String "" Search base
scope org.apache.directory.groovyldap.SearchScope SearchScope.SUB (whole sub tree) Search scope, one of BASE, ONE, SUB
filter java.lang.String "(objectClass=*)" (matches all entries) filter expression
filterArgs java.lang.Object[] null filter arguments
attrs java.lang.String[] null (all attributes) returning attributes

You can simply create an object of this class, adjust the attributes to your needs and call an appropriate search method from the LDAP with it. Here is an example:

...
params = new Search()
params.filter='(objectClass=person)'
params.base='dc=example,dc=com'
params.scope=SearchScope.ONE

results = ldap.search(params)
...

Using map style syntax

Powered by Atlassian Confluence (Version: 2.2.9 Build:#527 Sep 07, 2006) - Bug/feature request

Unsubscribe or edit your notifications preferences