ldap: add provider field

This commit is contained in:
Girish Ramakrishnan
2019-10-25 15:40:22 -07:00
parent a478134759
commit 1a21423401
3 changed files with 16 additions and 13 deletions
+11 -11
View File
@@ -50,7 +50,7 @@ function testConfig(config, callback) {
assert.strictEqual(typeof config, 'object');
assert.strictEqual(typeof callback, 'function');
if (!config.enabled) return callback();
if (config.provider === 'noop') return callback();
if (!config.url) return callback(new BoxError(BoxError.BAD_FIELD, 'url must not be empty'));
if (!config.baseDn) return callback(new BoxError(BoxError.BAD_FIELD, 'basedn must not be empty'));
@@ -81,7 +81,7 @@ function verifyPassword(user, password, callback) {
settings.getExternalLdapConfig(function (error, externalLdapConfig) {
if (error) return callback(error);
if (!externalLdapConfig.enabled) return callback(new BoxError(BoxError.BAD_STATE, 'not enabled'));
if (externalLdapConfig.provider === 'noop') return callback(new BoxError(BoxError.BAD_STATE, 'not enabled'));
getClient(externalLdapConfig, function (error, client) {
if (error) return callback(error);
@@ -103,7 +103,7 @@ function startSyncer(callback) {
settings.getExternalLdapConfig(function (error, externalLdapConfig) {
if (error) return callback(error);
if (!externalLdapConfig.enabled) return callback(new BoxError(BoxError.BAD_STATE, 'not enabled'));
if (externalLdapConfig.provider === 'noop') return callback(new BoxError(BoxError.BAD_STATE, 'not enabled'));
tasks.add(tasks.TASK_SYNC_EXTERNAL_LDAP, [], function (error, taskId) {
if (error) return callback(error);
@@ -125,7 +125,7 @@ function sync(progressCallback, callback) {
settings.getExternalLdapConfig(function (error, externalLdapConfig) {
if (error) return callback(error);
if (!externalLdapConfig.enabled) return callback(new BoxError(BoxError.BAD_STATE, 'not enabled'));
if (externalLdapConfig.provider === 'noop') return callback(new BoxError(BoxError.BAD_STATE, 'not enabled'));
getClient(externalLdapConfig, function (error, client) {
if (error) return callback(error);
@@ -157,15 +157,15 @@ function sync(progressCallback, callback) {
debug(`Found ${ldapUsers.length} users`);
// we ignore all errors here and just log them for now
async.eachSeries(ldapUsers, function (user, callback) {
async.eachSeries(ldapUsers, function (user, iteratorCallback) {
// ignore the bindDn user if any
if (user.dn === externalLdapConfig.bindDn) return callback();
if (user.dn === externalLdapConfig.bindDn) return iteratorCallback();
users.getByUsername(user.uid, function (error, result) {
if (error && error.reason !== BoxError.NOT_FOUND) {
console.error(error);
return callback();
return iteratorCallback();
}
if (error) {
@@ -173,22 +173,22 @@ function sync(progressCallback, callback) {
users.create(user.uid, null, user.mail, user.cn, { source: 'ldap' }, auditsource.EXTERNAL_LDAP_TASK, function (error) {
if (error) console.error('Failed to create user', user, error);
callback();
iteratorCallback();
});
} else if (result.source !== 'ldap') {
debug('[conflicting user]', user.uid, user.mail, user.cn);
callback();
iteratorCallback();
} else if (result.email !== user.mail || result.displayName !== user.cn) {
debug('[updating user] ', user.uid, user.mail, user.cn);
users.update(result.id, { email: user.mail, fallbackEmail: user.mail, displayName: user.cn }, auditsource.EXTERNAL_LDAP_TASK, function (error) {
if (error) console.error('Failed to update user', user, error);
callback();
iteratorCallback();
});
} else {
// user known and up-to-date
callback();
iteratorCallback();
}
});
}, function () {