lib/activedirectory.js
function(url, baseDN, username, password, defaults) {
  if (this instanceof ActiveDirectory) {
    this.opts = {};
    if (typeof(url) === 'string') {
      this.opts.url = url;
      this.baseDN = baseDN;
      this.opts.bindDN = username;
      this.opts.bindCredentials = password;

      if (typeof((defaults || {}).entryParser) === 'function') {
        this.opts.entryParser = defaults.entryParser;
      }
    }
    else {
      this.opts = _.defaults({}, url);
      this.baseDN = this.opts.baseDN;

      if (! this.opts.bindDN) this.opts.bindDN = this.opts.username;
      if (! this.opts.bindCredentials) this.opts.bindCredentials = this.opts.password;

      if (this.opts.logging) {
        log = bunyan.createLogger(_.defaults({}, this.opts.logging));
        delete(this.opts.logging);
      }
    }

    defaultAttributes = _.extend({}, originalDefaultAttributes, (this.opts || {}).attributes || {}, (defaults || {}).attributes || {});
    defaultReferrals = _.extend({}, originalDefaultReferrals, (this.opts || {}).referrals || {}, (defaults || {}).referrals  || {});

    log.info('Using username/password (%s/%s) to bind to ActiveDirectory (%s).', this.opts.bindDN,
             isPasswordLoggingEnabled ? this.opts.bindCredentials : '********', this.opts.url);
    log.info('Referrals are %s', defaultReferrals.enabled ? 'enabled. Exclusions: '+JSON.stringify(defaultReferrals.exclude): 'disabled');
    log.info('Default user attributes: %j', defaultAttributes.user || []);
    log.info('Default group attributes: %j', defaultAttributes.group || []);

    // Enable connection pooling
    // TODO: To be disabled / removed in future release of ldapjs > 0.7.1
    if (typeof(this.opts.maxConnections) === 'undefined') {
      this.opts.maxConnections = 20;
    }
    events.EventEmitter.call(this);
  }
  else {
    return(new ActiveDirectory(url, baseDN, username, password, defaults));
  }
}
function(url, baseDN, username, password, defaults) {
  if (this instanceof ActiveDirectory) {
    this.opts = {};
    if (typeof(url) === 'string') {
      this.opts.url = url;
      this.baseDN = baseDN;
      this.opts.bindDN = username;
      this.opts.bindCredentials = password;

      if (typeof((defaults || {}).entryParser) === 'function') {
        this.opts.entryParser = defaults.entryParser;
      }
    }
    else {
      this.opts = _.defaults({}, url);
      this.baseDN = this.opts.baseDN;

      if (! this.opts.bindDN) this.opts.bindDN = this.opts.username;
      if (! this.opts.bindCredentials) this.opts.bindCredentials = this.opts.password;

      if (this.opts.logging) {
        log = bunyan.createLogger(_.defaults({}, this.opts.logging));
        delete(this.opts.logging);
      }
    }

    defaultAttributes = _.extend({}, originalDefaultAttributes, (this.opts || {}).attributes || {}, (defaults || {}).attributes || {});
    defaultReferrals = _.extend({}, originalDefaultReferrals, (this.opts || {}).referrals || {}, (defaults || {}).referrals  || {});

    log.info('Using username/password (%s/%s) to bind to ActiveDirectory (%s).', this.opts.bindDN,
             isPasswordLoggingEnabled ? this.opts.bindCredentials : '********', this.opts.url);
    log.info('Referrals are %s', defaultReferrals.enabled ? 'enabled. Exclusions: '+JSON.stringify(defaultReferrals.exclude): 'disabled');
    log.info('Default user attributes: %j', defaultAttributes.user || []);
    log.info('Default group attributes: %j', defaultAttributes.group || []);

    // Enable connection pooling
    // TODO: To be disabled / removed in future release of ldapjs > 0.7.1
    if (typeof(this.opts.maxConnections) === 'undefined') {
      this.opts.maxConnections = 20;
    }
    events.EventEmitter.call(this);
  }
  else {
    return(new ActiveDirectory(url, baseDN, username, password, defaults));
  }
}
function ( url , baseDN , username , password , defaults ) { if ( this instanceof ActiveDirectory ) { this . opts = { } ; if ( typeof ( url ) === 'string' ) { this . opts . url = url ; this . baseDN = baseDN ; this . opts . bindDN = username ; this . opts . bindCredentials = password ; if ( typeof ( ( defaults || { } ) . entryParser ) === 'function' ) { this . opts . entryParser = defaults . entryParser ; } } else { this . opts = _ . defaults ( { } , url ) ; this . baseDN = this . opts . baseDN ; if ( ! this . opts . bindDN ) this . opts . bindDN = this . opts . username ; if ( ! this . opts . bindCredentials ) this . opts . bindCredentials = this . opts . password ; if ( this . opts . logging ) { log = bunyan . createLogger ( _ . defaults ( { } , this . opts . logging ) ) ; delete ( this . opts . logging ) ; } } defaultAttributes = _ . extend ( { } , originalDefaultAttributes , ( this . opts || { } ) . attributes || { } , ( defaults || { } ) . attributes || { } ) ; defaultReferrals = _ . extend ( { } , originalDefaultReferrals , ( this . opts || { } ) . referrals || { } , ( defaults || { } ) . referrals || { } ) ; log . info ( 'Using username/password (%s/%s) to bind to ActiveDirectory (%s).' , this . opts . bindDN , isPasswordLoggingEnabled ? this . opts . bindCredentials : '********' , this . opts . url ) ; log . info ( 'Referrals are %s' , defaultReferrals . enabled ? 'enabled. Exclusions: ' + JSON . stringify ( defaultReferrals . exclude ) : 'disabled' ) ; log . info ( 'Default user attributes: %j' , defaultAttributes . user || [ ] ) ; log . info ( 'Default group attributes: %j' , defaultAttributes . group || [ ] ) ; // Enable connection pooling // TODO: To be disabled / removed in future release of ldapjs > 0.7.1 if ( typeof ( this . opts . maxConnections ) === 'undefined' ) { this . opts . maxConnections = 20 ; } events . EventEmitter . call ( this ) ; } else { return ( new ActiveDirectory ( url , baseDN , username , password , defaults ) ) ; } }
Agent for retrieving ActiveDirectory user & group information.

@public
@constructor
@param {Object|String} url The url of the ldap server (i.e. ldap://domain.com). Optionally, all of the parameters can be specified as an object. { url: 'ldap://domain.com', baseDN: 'dc=domain,dc=com', username: 'admin@domain.com', password: 'supersecret', { referrals: { enabled: true }, attributes: { user: [ 'attributes to include in response' ], group: [ 'attributes to include in response' ] } } }. 'attributes' & 'referrals' parameter is optional and only necesary if overriding functionality.
@param {String} baseDN The default base container where all LDAP queries originate from. (i.e. dc=domain,dc=com)
@param {String} username The administrative username or dn of the user for retrieving user & group information. (i.e. Must be a DN or a userPrincipalName (email))
@param {String} password The administrative password of the specified user.
@param {Object} defaults Allow for default options to be overridden. { attributes: { user: [ 'attributes to include in response' ], group: [ 'attributes to include in response' ] } }
@returns {ActiveDirectory}
Agent for retrieving ActiveDirectory user & group information .