Skip to content

Commit

Permalink
Skip admin binding if searchDN is not defined
Browse files Browse the repository at this point in the history
For anonymous ldap access it's enough just to omit searchDN option in settings.json

Signed-off-by: Sergii Kipot <kipot.sergey@gmail.com>
  • Loading branch information
sergiik committed Jan 3, 2017
1 parent ecf6e54 commit 1312444
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions lib/MyLdapAuth.js
Expand Up @@ -39,7 +39,6 @@ var ldap = require('ldapjs');
function MyLdapAuth(opts) {
this.opts = opts;
assert.ok(opts.url);
assert.ok(opts.adminDn);
assert.ok(opts.searchBase);
assert.ok(opts.searchFilter);

Expand Down Expand Up @@ -78,15 +77,20 @@ MyLdapAuth.prototype._adminBind = function (cb) {
clientOpts.tlsOptions = {};
clientOpts.tlsOptions.ca = self.opts.tls_ca;
}

self._adminClient = ldap.createClient(clientOpts);
self._adminClient.bind(self.opts.adminDn, self.opts.adminPassword,
function (err) {
if (err) {
return cb(util.format('ldap bind with %s to %s failed: %s', self.opts.adminDn, self.opts.url, err));
}
if (typeof(self.opts.adminDn) !== 'undefined') {
self._adminClient.bind(self.opts.adminDn, self.opts.adminPassword,
function (err) {
if (err) {
return cb(util.format('ldap bind with %s to %s failed: %s', self.opts.adminDn, self.opts.url, err));
}
return cb();
});
}
else {
return cb();
});
}
}

/**
Expand Down

1 comment on commit 1312444

@menowaled
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#50

Please sign in to comment.