Skip to content
Snippets Groups Projects
Commit 2450b7ca authored by Rodrigo Nascimento's avatar Rodrigo Nascimento
Browse files

Allow bind a master user before search in LDAP

parent 9a0f1e68
No related branches found
No related tags found
No related merge requests found
......@@ -67,6 +67,8 @@ LDAP.prototype.ldapCheck = function(options) {
url: fullUrl
});
var bindSync = Meteor.wrapAsync(client.bind.bind(client));
// Slide @xyz.whatever from username if it was passed in
// and replace it with the domain specified in defaults
var emailSliceIndex = options.username.indexOf('@');
......@@ -132,24 +134,48 @@ LDAP.prototype.ldapCheck = function(options) {
var bindSearch = LDAP_DEFAULTS.bindSearch.replace(/#{username}/g, options.username);
var opts = JSON.parse(bindSearch);
if (opts.userDN && opts.password) {
try {
console.log('Bind before search', opts.userDN, opts.password);
bindSync(opts.userDN, opts.password);
delete opts.userDN;
delete opts.password;
} catch(e) {
console.log('LDAP: Error', e);
ldapAsyncFut.return({
error: e
});
}
}
console.log('LDAP search dn', options.ldapOptions.dn);
console.log('LDAP search options', opts);
client.search(options.ldapOptions.dn, opts, function(err, res) {
if (err) {
console.log('LDAP: Error', err);
return bind(self.options.dn);
console.log('LDAP: Search Error', err);
ldapAsyncFut.return({
error: err
});
}
var dn = self.options.dn;
res.on('searchEntry', function(entry) {
dn = entry.object.dn;
});
res.on('error', function(err) {
console.log('LDAP: Error', err);
console.log('LDAP: Search on Error', err);
ldapAsyncFut.return({
error: err
});
});
res.on('end', function(result) {
bind(dn);
});
});
} catch (e) {
console.log('LDAP: Error', e);
console.log('LDAP: BindSearch Error', e);
ldapAsyncFut.return({
error: e
});
}
} else {
bind(self.options.dn);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment