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 io = require("socket.io");
var dns = require("dns"); var dns = require("dns");
var Helper = require("./helper"); var Helper = require("./helper");
var ldapAuth = require("./plugins/auth/ldap");
var localAuth = require("./plugins/auth/local");
var colors = require("colors/safe"); var colors = require("colors/safe");
const net = require("net"); const net = require("net");
const Identification = require("./identification"); 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; var manager = null;
module.exports = function() { module.exports = function() {
@ -436,11 +441,14 @@ function performAuthentication(data) {
} }
// Perform password checking // Perform password checking
let auth; let auth = () => {
if (ldapAuth.isEnabled()) { log.error("None of the auth plugins is enabled");
auth = ldapAuth.auth; };
} else if (localAuth.isEnabled()) { for (let i = 0; i < authPlugins.length; ++i) {
auth = localAuth.auth; if (authPlugins[i].isEnabled()) {
auth = authPlugins[i].auth;
break;
}
} }
auth(manager, client, data.user, data.password, authCallback); auth(manager, client, data.user, data.password, authCallback);
} }