Complete Contents
Preface
Chapter 1 Understanding LDAP
Chapter 2 Using the Netscape Directory SDK for Java
Chapter 3 Quick Start
Chapter 4 Writing an LDAP Client
Chapter 5 Using the LDAP Java Classes
Chapter 6 Searching the Directory
Chapter 7 Using Filter Configuration Files
Chapter 8 Adding, Updating, and Deleting Entries
Chapter 9 Comparing Values in Entries
Chapter 10 Working with LDAP URLs
Chapter 11 Getting Server Information
Chapter 12 Connecting Over SSL
Chapter 13 Working with LDAP Controls
Chapter 14 Using SASL Authentication
Chapter 15 Using Netscape's JNDI Service Provider
Chapter 16 Working with Extended Operations
Chapter 17 Using the Asynchronous Interface
Glossary
Directory SDK for Java 4.0 Programmer's Guide: Working with LDAP URLs
Previous Next Contents Index


Chapter 10 Working with LDAP URLs

This chapter describes what LDAP URLs are and explains how to use LDAP URLs to search and retrieve data from the directory.

The chapter contains the following sections:


Understanding LDAP URLs
An LDAP URL is a URL that begins with the ldap:// protocol prefix (or ldaps://, if the server is communicating over an SSL connection) and specifies a search request to be sent to an LDAP server.

In the LDAP Java classes, you can represent an LDAP URL as an LDAPUrl object. You can invoke methods of this object to parse an LDAP URL into its components and to process a search request specified by an LDAP URL.

LDAP URLs have the following syntax:

ldap[s]://<hostname>:<port>/<base_dn>?<attributes>?<scope>?<filter>
(RFC 2255, The LDAP URL Format, also specifies that a "bindname" extension can be present at the end of the URL. At this point in time, the LDAP Java classes do not handle this extension.)

The ldap:// protocol is used to connect to LDAP servers over unsecured connections, and the ldaps:// protocol is used to connect to LDAP servers over SSL connections.

Table 10.1 lists the components of an LDAP URL.

Table 10.1 Components of an LDAP URL
Component
Description
<hostname>
Name (or IP address in dotted format) of the LDAP server (for example, ldap.netscape.com or 192.202.185.90).
<port>
Port number of the LDAP server (for example, 696).
If no port is specified, the standard LDAP port (389) is used.
<base_dn>
Distinguished name (DN) of an entry in the directory. This DN identifies the entry that is starting point of the search.
If this component is empty, the search starts at the root DN.
<attributes>
The attributes to be returned. To specify more than one attribute, use commas to delimit the attributes (for example, "cn,mail,telephoneNumber").
If no attributes are specified in the URL, all attributes are returned.
<scope>
The scope of the search, which can be one of these values:
If no scope is specified, the server performs a base search.
<filter>
Search filter to apply to entries within the specified scope of the search.
If no filter is specified, the server uses the filter (objectClass=*).

Any "unsafe" characters in the URL need to be represented by a special sequence of characters (this is often called escaping unsafe characters). For example, a space must be represented as %20. Thus, the distinguished name "ou=Product Development" must be encoded as "ou=Product%20Development".

Note that <attributes>, <scope>, and <filter> are identified by their positions in the URL. If you do not want to specify any attributes, you still need to include the question marks delimiting that field.

For example, to specify a subtree search starting from "o=Airius.com" that returns all attributes for entries matching "(sn=Jensen)", use the following URL:

ldap://ldap.netscape.com/o=Airius.com??sub?(sn=Jensen)
Note that the two consecutive question marks — ?? — indicate that no attributes have been specified. Since no specific attributes are identified in the URL, all attributes are returned in the search.


Examples of LDAP URLs
The following LDAP URL specifies a base search for the entry with the distinguished name "o=Airius.com".

ldap://ldap.netscape.com/o=Airius.com
The following LDAP URL retrieves the postalAddress attribute of the o=Airius.com entry:

ldap://ldap.netscape.com/o=Airius.com?postalAddress
The following LDAP URL retrieves the cn, mail, and telephoneNumber attributes of the entry for Barbara Jensen:

ldap://ldap.netscape.com/
uid=bjensen,ou=People,o=Airius.com?cn,mail,telephoneNumber
The following LDAP URL specifies a search for entries that have the last name Jensen and are at any level under "o=Airius.com":

ldap://ldap.netscape.com/o=Airius.com??sub?(sn=Jensen)
The following LDAP URL specifies a search for the object class for all entries one level under "o=Airius.com":

ldap://ldap.netscape.com/o=Airius.com?objectClass?one
Important
The syntax for LDAP URLs does not include any means for specifying credentials or passwords. Search requests initiated through LDAP URLs are unauthenticated.


Getting the Components of an LDAP URL
To get the individual components of an LDAP URL, pass the URL to the LDAPUrl constructor to create a new LDAPUrl object, then use the following methods:


Processing an LDAP URL
To process the search request specified by an LDAP URL, you can invoke one of the following methods, passing in the LDAPUrl object:

Both methods create a new LDAPConnection object, connect to the LDAP server specified in the URL, perform the search, and disconnect.

 

© Copyright 1999 Netscape Communications Corporation. All rights reserved.