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.
|