gstackoverflow
gstackoverflow

Reputation: 37106

Is there a way to get multiple entries by dn using a single ldap call?

I have a code like this:

List<String> dns = ...
List<Entry> entries = new ArrayList<>()
for(dn: dns)
  entries.add(connection.getEntry())

I don't like this code because it makes n ldap calls.

Is there a way to rewrite it to make a single Ldap call ?

Upvotes: 1

Views: 88

Answers (1)

grawity_u1686
grawity_u1686

Reputation: 16572

  • Option A:

    If the LDAP server supports a special "distinguished name" attribute (non-standard), you can construct an OR filter that matches multiple DNs. For example, Active Directory has the distinguishedName attribute while OpenLDAP and 389ds have entryDN, so if your server is AD then you should be able to write (|(distinguishedName=FOO)(distinguishedName=BAR)(distinguishedName=BAZ)).

    (Don't forget to escape the DNs before using them in a filter – it seems you can use Filter.or(Filter.equals(...), Filter.equals(...), ...) to let UnboundId generate a valid filter.)

  • Option B:

    Issue multiple calls asynchronously. LDAP supports having multiple operations in flight, so you can submit a batch of ~50 search operations by calling asyncSearch(), then gather up their results.

    The exact number of pending operations you can submit will vary depending on TCP window size, I think, but 50 should be a safe limit and still a significant performance improvement (especially over high-latency connections).

Upvotes: 0

Related Questions