简体   繁体   中英

How to verify if an object does exist in a directory (LDAP or AD) using jndi?

Currently we are doing something like:

Attributes attributes = directoryConnection.find(filter, false);
if (attributes == null) {
    // then the object does not exist
}

i think this is not efficient, we don't need to retrieve the whole attributes (they could be a few thousends in the case of a group object... i just want to know if the object does exist or not)

is there a better way to check if the object does exist? i can use the cn of the object or the whole dn of it

To determine if an "object" exists, you must search for the object. A search request consists of at least:

  • base object
  • scope
  • filter
  • requested attributes

Plus some other, optional, parameters such as size limit and time limit, and so forth. Search for the object, request attribute 1.1 , and the search response will have an indication of how many entries are returned. If the number of entries returned is zero, then the object does not exist. For further information, see "LDAP: ldapsearch" and "LDAP: Programming Practices" .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM