LDAP
PROGRAMMING
WITH JAVATM
ROB WELTMAN and TONY DAHBURA
ADDISON–WESLEY
An Imprint of Addison Wesley Longman, Inc.
Reading, Massachusetts • Harlow, England • Menlo Park, California
Berkeley, California Don Mills, Ontario
Sydney
Bonn Amsterdam Tokyo Mexico City
As you may recall from Chapter 1, the major feature of an LDAP directory is its
ability to return search results on queries rapidly. The SDK provides many flexible
methods for obtaining and handling search results from the directory. We will focus in
this chapter on building queries using the SDK to retrieve the information we need.
The result set from a search can easily be parsed to return the entry’s name and
all or a subset of its attributes and values. In our discussion of searches, we will take
an example-based approach. Most of the examples here can be run directly from the
command-line interface with the java command. It is assumed that you have installed
or have access to a directory server and have loaded the sample database from the
LDIF file that is supplied on the CD-ROM that accompanies this book.
Our First Search
Before you can search an LDAP directory, you need certain information:
• Host name of the machine where the directory is installed
• Port number of the directory server
• Base DN of the directory tree managed by the server
• Scope of the search
• Search filter
• Attributes to request
• Optionally, search preferences
Searching
with the SDK
67
C H A P T E R 5
Host Name
The host name directs the search to the machine where the directory resides. This
parameter is mandatory and is usually of the form machinename.domain—for exam-
ple, dirhost.acme.com. If you are at the console on the machine that is running the
LDAP server, you can use the host name “localhost” for your test server. You can
specify the IP address of the host instead if you wish—for example, 127.0.0.1 for
“localhost.”
Port
The port is the TCP port of the machine (indicated by the host name) where the direc-
tory server is listening for LDAP connections. The stan