jaeseung you
jaeseung you

Reputation: 33

Query results are not sorted using ldap.js framework in node.js server

I tried to query 'LDAP server users' with my node.js server. here is my codes what i tried with 'Ldapjs framework'

function ldapQuery_Users(){
var opts = {
    filter: '(uid=*)',
    scope: 'sub'
// attributes: ['dn', 'sn', 'cn', 'phone', 'fax', 'mail']
};

client.search('dc=mirageworks, dc=kr', opts, function(err, res) {
    assert.ifError(err);
    res.on('searchEntry', function(entry) {
      console.log(entry.attributes.toString());
    });
    res.on('searchReference', function(referral) {
      console.log('referral: ' + referral.uris.join());
    });
    res.on('error', function(err) {
      console.error('error: ' + err.message);
    });
    res.on('end', function(result) {
      //console.log('ldapLogin status: ' + ((result.status == 0) ? "success" :  result.status));
    });
 });
}

And the result is like this.

enter image description here

When I set attributes items in opts array, the results are sorted as what I set. But with no attributes, no sorted items.

The first user's result is starting "type" : "uid". these items seem ascending sorted. But second and thrid are decending sorted. these are starting with "type":"telephoneNumber"

Upvotes: 0

Views: 527

Answers (1)

jwilleke
jwilleke

Reputation: 11026

The LDAP protocol specifically states the result order is unspecified.

LDAP server Implementations MAY return entries or attributes within a specific order, however there is no standard.

Using the LDAP Control Extension for Server Side Sorting of Search Results is a possibility for returning the entries within a specified order.

There is no "Standard" for sorting Attribute Results and they will need to be sorted "client-side"

Upvotes: 1

Related Questions