Generalize auth plugin fallback mechanism

@astorije this is for you ;)
https://github.com/thelounge/lounge/pull/1478#discussion_r136492534
This commit is contained in:
Elie Michel 2017-09-01 11:44:53 +02:00
parent 435e14669b
commit 32e1a36980
2 changed files with 16 additions and 8 deletions

View file

@ -11,12 +11,17 @@ var path = require("path");
var io = require("socket.io");
var dns = require("dns");
var Helper = require("./helper");
var ldapAuth = require("./plugins/auth/ldap");
var localAuth = require("./plugins/auth/local");
var colors = require("colors/safe");
const net = require("net");
const Identification = require("./identification");
// The order defined the priority: the first available plugin is used
// ALways keep local auth in the end, which should always be enabled.
const authPlugins = [
require("./plugins/auth/ldap"),
require("./plugins/auth/local"),
];
var manager = null;
module.exports = function() {
@ -436,11 +441,14 @@ function performAuthentication(data) {
}
// Perform password checking
let auth;
if (ldapAuth.isEnabled()) {
auth = ldapAuth.auth;
} else if (localAuth.isEnabled()) {
auth = localAuth.auth;
let auth = () => {
log.error("None of the auth plugins is enabled");
};
for (let i = 0; i < authPlugins.length; ++i) {
if (authPlugins[i].isEnabled()) {
auth = authPlugins[i].auth;
break;
}
}
auth(manager, client, data.user, data.password, authCallback);
}

View file

@ -76,7 +76,7 @@ function startLdapServer(callback) {
});
server.listen(serverPort, callback);
return server;
}