1

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

Piyush Mattoo
  • 15,454
  • 6
  • 47
  • 56
cablop
  • 177
  • 2
  • 6

1 Answers1

1

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

Terry Gardner
  • 10,957
  • 2
  • 28
  • 38
  • 1
    well, i know some of those facts, but my question is how can i make that filter or how to perform that "query" using jdni... i have to search for a group and i have the cn of the group or the dn of the group, i think i can query for a unique field on the group... what we are doing now is just to make the filter this way filter = "(" + groupCn + ")"; but i think this is not the best filter we can do... but i am pretty new in ldap and ldif and when i search on google about it the pages are more cryptic than a simple plane ldif text... – cablop Dec 09 '11 at 02:28
  • i get it... so now i need to make a filter than includes both the cn or dn and the attribute 1.1... if there's more than 1 result... but i don't know how to make that filter. – cablop Dec 09 '11 at 02:30
  • The filter should be `(cn=whatever)`, or if you know the objectClass to which the entry belongs, `(&(cn=whatever)(objectClass=theKnownObjectClass))`. The requested attributes is a different parameter. – Terry Gardner Dec 09 '11 at 09:25