I Want Only One Record and I Have the DN

The DN uniquely identifies a single entry in the directory. In some situations you have the DN (for example, because you saved it or because information is provided to allow you to build it), and you want to retrieve the single record corresponding to the DN. The read method of the LDAPConnection class provides this functionality. Although not as flexible as issuing a full search, this method provides the benefit of retrieving the single uniquely identified record with few parameters required. Within the SDK the method is just a search with the scope set to SCOPE_BASE and the filter to objectclass=*.

The following code is a modification of FilterSearch that takes a DN as argument instead of a search base ...

Get LDAP Programming with Java™ now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.