jsumners / node-activedirectory

ActiveDirectory is an Node.js ldapjs client for authN (authentication) and authZ (authorization) for Microsoft Active Directory with range retrieval support for large Active Directory installations. Originally forked from gheeres/node-activedirectory.
MIT License
52 stars 43 forks source link

Not getting all users #77

Closed dennisbrouwer91 closed 4 years ago

dennisbrouwer91 commented 4 years ago

Hi,

I'm using this module to fetch around 27000 users from our AD. The module itself works, and i'm getting back around ~2000 users, but the other users are nowhere to be found in the resultset. Is this a bug in the pagination system in the module?

Code used :

var query = 'objectClass=user';
ad.find(query, function(err, results) {
                if ((err) || (! results)) {
                  console.log('ERROR: ' + JSON.stringify(err));
                  return;
                }

                _.each(results.users , function(user) {
jsumners commented 4 years ago

Possible duplicate of https://github.com/jsumners/node-activedirectory/issues/16

jurjendijkstra commented 4 years ago

Following, because I don't currently have 2000 users but I need to know if there is a new bug before we use release 2.0.0 in production.

@dennisbrouwer91 Is this problem new in release 2.0.0 of this module? I notice in your code snippet that you have not used {paged:true} in the options parameter. That should help. I am actually surprised that you got more than 1000 results without the paged option, because 1000 is the default page size, but perhaps your AD administrator has specified a non-default page size. By the way I have never tried ad.find, I use ad.findUsers, I can only guess that the {paged:true} option works just the same in ad.find.

dennisbrouwer91 commented 4 years ago

@jurjendijkstra : Thanks for your reply. Just to make sure. The "paged" option should be set in the config parameter right? Or do i need to set it on the ad.find ?

jurjendijkstra commented 4 years ago

last time I checked it does nothing in the connection config parameter, it has to be used in the options parameter of ad.findUsers

(and probably ad.find too)

jurjendijkstra commented 4 years ago

last time I tried was in issue #20 so that was a while ago

dennisbrouwer91 commented 4 years ago

Thanks @jurjendijkstra. Do you have an example of that code that is working? Because i seem to be unable to drop in the config and the query?

jurjendijkstra commented 4 years ago

hope this one line helps

ad.findUsers({baseDN: 'OU=testdepartment,DC=testcompany,DC=nl', paged: true}).then((adusers) => {

dennisbrouwer91 commented 4 years ago

ad.findUsers({baseDN: 'dc=', paged: true}).then((adusers) => { ^

TypeError: Cannot read property 'then' of undefined

That seems to not be working with 2.0.0? @jurjendijkstra

jurjendijkstra commented 4 years ago

Yes I am testing with 2.0.0! The line I copied into the comment was actually: return this.proxy.findUsers({baseDN: userDN.ou, paged: true}).then((adusers) => { but you don't have my this.proxy so I replaced that by ad. Never mind. The intention is to show the options parameter

dennisbrouwer91 commented 4 years ago

After making a promise around the retrieval of the users : It's working.

aSearchFilter = "objectClass=user";
var opts = {
    filter: aSearchFilter,
    attributes: ["cn", "sAMAccountName", "userPrincipalName", "dn"],
    paged:true
}

function getAllUsers() {
        return new Promise((resolve, reject) => {
            ad.findUsers(opts, function(err, users) {
                if (err) {
                    console.log('ERROR: ' +JSON.stringify(err));
                    return;
                }
                if ((! users) || (users.length == 0)) {
                    console.log('No users found.');
                    reject('No users found.')
                    return;
                }
                else {
                    resolve(users);
                }
            });
        });
    }
jsumners commented 4 years ago

Just use https://github.com/jsumners/node-activedirectory/blob/7b0cf44c0eb2fddf8749fe128a78919a411e5686/lib/adpromise.js

const AD = require('activedirectory2/lib/adpromise')