How to use the ldapjs.filters function in ldapjs

To help you get started, we’ve selected a few ldapjs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github codingchili / kibana-mithril / src / authentication / ldap.js View on Github external
authenticate: function (username, password, callback) {
        const search = {
            dn: Config.search["user-dn"],
            options: {
                scope: Config.search.scope,
                filter: new LDAP.filters.EqualityFilter({attribute: 'uid', value: username})
            }
        };

        client.search(search.dn, search.options, (err, result) => {
            let found = false;

            result.on('searchEntry', entry => {
                found = true;

                // Verify api by binding to the LDAP server.
                LDAP.createClient({url: Config.url})
                    .bind(entry.dn, password, err => {

                        member(entry.object.uid, groups => {
                            callback(err, {uid: entry.object.uid, groups: groups});
                        });
github gheeres / node-activedirectory / lib / activedirectory.js View on Github external
if (typeof(this.opts.maxConnections) === 'undefined') {
      this.opts.maxConnections = 20;
    }
    events.EventEmitter.call(this);
  }
  else {
    return(new ActiveDirectory(url, baseDN, username, password, defaults));
  }
};
util.inherits(ActiveDirectory, events.EventEmitter);

/**
 * Expose ldapjs filters to avoid TypeErrors for filters
 * @static
 */
ActiveDirectory.filters = ldap.filters;

/**
 * Truncates the specified output to the specified length if exceeded.
 * @param {String} output The output to truncate if too long
 * @param {Number} [maxLength] The maximum length. If not specified, then the global value maxOutputLength is used.
 */
function truncateLogOutput(output, maxLength) {
  if (typeof(maxLength) === 'undefined') maxLength = maxOutputLength;
  if (! output) return(output);

  if (typeof(output) !== 'string') output = output.toString();
  var length = output.length;
  if ((! length) || (length < (maxLength + 3))) return(output);

  var prefix = Math.ceil((maxLength - 3)/2);
  var suffix = Math.floor((maxLength - 3)/2);
github codingchili / kibana-mithril / src / authentication / ldap.js View on Github external
function member(id, callback) {
    const search = {
        dn: Config.search["group-dn"],
        options: {
            scope: Config.search.scope,
            filter: new LDAP.filters.AndFilter({
                filters: [
                    new LDAP.filters.EqualityFilter({attribute: 'objectClass', value: 'groupOfNames'}),
                    new LDAP.filters.EqualityFilter({attribute: 'member', value: 'uid=' + id})
                ]
            })
        }
    };

    client.search(search.dn, search.options, (err, result) => {
        let member = [];

        result.on('searchEntry', entry => {
            member.push(entry.object.cn);
        });

        result.on('end', () => {
            callback(member);
        });