Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
let dn = req.dn.toString(),
normalizedDn = dn.replace(/ /g, ''),
password = req.credentials;
console.log(dn, normalizedDn, password);
let matchingUsers = _.filter(users, user => normalizedDn == user.dn);
console.log(matchingUsers);
if (matchingUsers.length > 1) {
return next(new ldap.UnwillingToPerformError());
}
if (matchingUsers.length == 0) {
return next(new ldap.NoSuchObjectError(dn));
}
let user = matchingUsers[0];
if (user.password != password) {
return next(new ldap.InvalidCredentialsError());
}
res.end();
return next();
});
server.compare(SUFFIX, authorize, function(req, res, next) {
var dn = req.dn
.toString()
.replace(/, /g, ',')
.toLowerCase()
if (!db[dn]) {
return next(new ldap.NoSuchObjectError(dn))
}
if (!db[dn][req.attribute]) {
return next(new ldap.NoSuchAttributeError(req.attribute))
}
var matches = false
var vals = db[dn][req.attribute]
for (var i = 0; i < vals.length; i++) {
if (vals[i] === req.value) {
matches = true
break
}
}
res.end(matches)
server.del(SUFFIX, authorize, function(req, res, next) {
var dn = req.dn.toString().replaceSpaces();
if (!db[dn])
return next(new ldap.NoSuchObjectError(dn));
delete db[dn];
res.end();
return next();
});
server.modifyDN(SUFFIX, function(req, res, next) {
var dn = req.dn
.toString()
.replace(/, /g, ',')
.toLowerCase()
var newDn = req.newRdn.toString() + ', ' + req.dn.parent().toString()
if (!db[dn]) {
return next(new ldap.NoSuchObjectError(req.newSuperior.toString()))
}
if (req.newSuperior) {
if (!db[req.newSuperior.toString().replace(/, /g, ',')]) {
return next(new ldap.NoSuchObjectError(req.newSuperior.toString()))
}
newDn = req.newRdn.toString() + ', ' + req.newSuperior.toString()
}
newDn = newDn.replace(/, /g, ',').toLowerCase()
db[newDn] = db[dn]
if (req.deleteOldRdn) {
delete db[dn]
}
res.end()
})
server.compare(SUFFIX, authorize, function (req, res, next) {
var dn = req.dn.toString();
if (!db[dn]) {
return next(new ldap.NoSuchObjectError(dn));
}
if (!db[dn][req.attribute]) {
return next(new ldap.NoSuchAttributeError(req.attribute));
}
var matches = false;
var vals = db[dn][req.attribute];
for (var i = 0; i < vals.length; i++) {
if (vals[i] === req.value) {
matches = true;
break;
}
}
res.end(matches);
server.bind('', authorize, function(req, res, next) {
var db = getCurrentDB();
var dn = req.dn.toString();
if (!db[dn] || db[dn].type !== 'user') {
return next(new ldap.NoSuchObjectError(dn));
}
var u = db[dn].original;
okta.checkUserAndPassword(u.profile.login, req.credentials).then(
function(r) {
res.end();
next();
},
function(r) {
next(new ldap.InvalidCredentialsError(dn));
});
});
server.bind(config.admin.username, function(req, res, next) {
if (!req.dn.equals(config.admin.username)) {
winston.info('Got a bind for a child of the admin user: %s', req.dn.toString());
return next(new ldap.NoSuchObjectError(req.dn.toString()));
}
if (req.credentials !== config.admin.password) {
winston.info('Got invalid credentials for admin user.');
return next(new ldap.InvalidCredentialsError());
}
res.end();
return next();
});
result.on('end', () => {
if (!found) {
callback(new LDAP.NoSuchObjectError());
}
});
});