How to use ldapjs - 10 common examples

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 thelounge / thelounge / test / plugins / auth / ldap.js View on Github external
function startLdapServer(callback) {
	const server = ldap.createServer();

	const searchConf = Helper.config.ldap.searchDN;
	const userDN = primaryKey + "=" + user + "," + baseDN;

	// Two users are authorized: john doe and the root user in case of
	// advanced auth (the user that does the search for john's actual
	// bindDN)
	const authorizedUsers = {};
	authorizedUsers[normalizeDN(searchConf.rootDN)] = searchConf.rootPassword;
	authorizedUsers[normalizeDN(userDN)] = correctPassword;

	function authorize(req, res, next) {
		const bindDN = req.connection.ldap.bindDN;

		if (bindDN in authorizedUsers) {
			return next();
github flamencist / ldap4net / .test_config / index.js View on Github external
function authorize(req, res, next) {
  /* Any user may search after bind, only cn=root has full power */
  var isSearch = (req instanceof ldap.SearchRequest);
  if (!req.connection.ldap.bindDN.equals('cn=admin,dc=example,dc=com'))
    return next(new ldap.InsufficientAccessRightsError());

  return next();
}
github PhilWaldmann / openrecord / test / ldap / __server.js View on Github external
function authorize(req, res, next) {
  /* Any user may search after bind, only cn=root has full power */
  var isSearch = req instanceof ldap.SearchRequest
  if (!req.connection.ldap.bindDN.equals('cn=root') && !isSearch) {
    return next(new ldap.InsufficientAccessRightsError())
  }

  return next()
}
github authelia / authelia / src / index.js View on Github external
var config = {
  port: process.env.PORT || 8080,
  ldap_url: yaml_config.ldap.url || 'ldap://127.0.0.1:389',
  ldap_user_search_base: yaml_config.ldap.user_search_base,
  ldap_user_search_filter: yaml_config.ldap.user_search_filter,
  ldap_user: yaml_config.ldap.user,
  ldap_password: yaml_config.ldap.password,
  session_domain: yaml_config.session.domain,
  session_secret: yaml_config.session.secret,
  session_max_age: yaml_config.session.expiration || 3600000, // in ms
  store_directory: yaml_config.store_directory,
  logs_level: yaml_config.logs_level,
  notifier: yaml_config.notifier,
}

var ldap_client = ldap.createClient({
  url: config.ldap_url,
  reconnect: true
});

ldap_client.on('error', function(err) {
  console.error('LDAP Error:', err.message)
})

var deps = {};
deps.u2f = u2f;
deps.nedb = nedb;
deps.nodemailer = nodemailer;
deps.ldap = ldap;
deps.session = session;

server.run(config, ldap_client, deps);
github easy-mock / easy-mock / util / ldap.js View on Github external
return new Promise((resolve, reject) => {
    const dn = opts.credentials.dn
    const passwd = opts.credentials.passwd
    const client = ldap.createClient(opts)

    function onConnect () {
      client.removeListener('error', onError)
      client.bind(dn, passwd, err => {
        /* istanbul ignore if */
        if (err) reject(new Error(err))
        else resolve(client)
      })
    }

    /* istanbul ignore next */
    function onError (err) {
      client.removeListener('connect', onConnect)
      reject(new Error(err))
    }
github PhilWaldmann / openrecord / lib / stores / ldap / includes.js View on Github external
this.afterInclude(function(Model, result, records, include, cache){
      var relation = include.relation
      if(!relation || !relation.ldap) return
      if(!result) return

      var type = include.relation.ldap

      if(!Array.isArray(result)) result = [result]

      for(var i = 0; i < result.length; i++){
        var dn = result[i].dn


        if(type === 'children'){
          dn = parseDN(dn).parent()

          if(relation.recursive){
            var found = false
            do{
              if(cache.dn_mapping[Utils.normalizeDn(dn)]){
                found = true
                break
              }
              if(!dn.parent()){
                found = true // actually not, but we stop the loop here...
              }else{
                dn = dn.parent()
              }
            }while(!found)
          }
github trueaccord / FallingRock / server.js View on Github external
function authorize(req, res, next) {
  /* Any user may search after bind, only cn=root has full power */
  if (!req.connection.ldap.bindDN.equals(config.admin.username)) {
    return next(new ldap.InsufficientAccessRightsError());
  }

  return next();
}
github conjurinc / teleport / lib / ldap / listUsers.js View on Github external
function listUsers(req, res, next) {
	assert([ 2, 3 ].indexOf(keys(req.rdns).length) !== null);
	assert('teleport' === req.rdns.o);
	assert('users' === req.rdns.ou);
	var layer = req.bindLayer;
	assert(layer);
	// If searching for a specific user
	var uid = req.rdns.uid;

  if ( uid ) {
    req.filter = new ldap.AndFilter({
      filters: [req.filter, new ldap.EqualityFilter({attribute: 'uid', value: uid})]
    });
  }
	
  var resultCount = 0;
  
	function end(err) {
		log.info({requestId: req.logId, command: 'listUsers', resultCount: resultCount}, "Sent %d users", resultCount);
    res.end();
		next(err);
	}

	dataStore.layerUsers(layer).on('user', function(user) {
    var attributes = clone(user);
    // Apply some defaults
    if ( !attributes.uid ) attributes.uid = user.uid;
github conjurinc / teleport / lib / ldap / listUsers.js View on Github external
function listUsers(req, res, next) {
	assert([ 2, 3 ].indexOf(keys(req.rdns).length) !== null);
	assert('teleport' === req.rdns.o);
	assert('users' === req.rdns.ou);
	var layer = req.bindLayer;
	assert(layer);
	// If searching for a specific user
	var uid = req.rdns.uid;

  if ( uid ) {
    req.filter = new ldap.AndFilter({
      filters: [req.filter, new ldap.EqualityFilter({attribute: 'uid', value: uid})]
    });
  }
	
  var resultCount = 0;
  
	function end(err) {
		log.info({requestId: req.logId, command: 'listUsers', resultCount: resultCount}, "Sent %d users", resultCount);
    res.end();
		next(err);
	}

	dataStore.layerUsers(layer).on('user', function(user) {
    var attributes = clone(user);
    // Apply some defaults
    if ( !attributes.uid ) attributes.uid = user.uid;
    if ( !attributes.cn ) attributes.cn = user.uid;
github auth0 / ad-ldap-connector / lib / users.js View on Github external
// AD will search and delay an error till later if no password is given
    if (password === '') {
      return callback(new WrongPassword(profile));
    }

    log('Change password for DN "' + profile.dn.green + '"');

    var modification = {};
    if(nconf.get('ENABLE_ACTIVE_DIRECTORY_UNICODE_PASSWORD') === true){
      modification.unicodePwd = Buffer.from('"'+password+'"',"utf16le").toString();
    }else{
      modification.userPassword = password;
    }

    var passwordResetChange = new ldap.Change({
      operation: 'replace',
      modification: modification
    });

    var changeSet = [passwordResetChange];

    if (nconf.get('AUTO_UNLOCK_ON_PASSWORD_CHANGE') === true) {
      var unlockAccountChange = {
        operation: 'replace',
        modification: { lockoutTime: 0 }
      };
      changeSet.push(unlockAccountChange);
    }

    self._client.modify(profile.dn, changeSet, function (err) {
      if (err) {