Software /
code /
prosody
Comparison
core/usermanager.lua @ 3180:99be525bcfb4
Rename mod_defaultauth -> mod_auth_internal, mod_hashpassauth -> mod_auth_internal_hashed, and the providers to internal and internal_hashed respectively. Also no longer auto-load defaultauth, but instead auto-load the plugin selected for each host at startup based on the provider name.
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Fri, 04 Jun 2010 14:33:36 +0100 |
parent | 3177:b932dde3bca5 |
child | 3185:09174a6e8366 |
comparison
equal
deleted
inserted
replaced
3179:99c5288a26e4 | 3180:99be525bcfb4 |
---|---|
5 -- This project is MIT/X11 licensed. Please see the | 5 -- This project is MIT/X11 licensed. Please see the |
6 -- COPYING file in the source package for more information. | 6 -- COPYING file in the source package for more information. |
7 -- | 7 -- |
8 | 8 |
9 local datamanager = require "util.datamanager"; | 9 local datamanager = require "util.datamanager"; |
10 local modulemanager = require "core.modulemanager"; | |
10 local log = require "util.logger".init("usermanager"); | 11 local log = require "util.logger".init("usermanager"); |
11 local type = type; | 12 local type = type; |
12 local error = error; | 13 local error = error; |
13 local ipairs = ipairs; | 14 local ipairs = ipairs; |
14 local hashes = require "util.hashes"; | 15 local hashes = require "util.hashes"; |
20 | 21 |
21 local prosody = _G.prosody; | 22 local prosody = _G.prosody; |
22 | 23 |
23 local setmetatable = setmetatable; | 24 local setmetatable = setmetatable; |
24 | 25 |
26 local default_provider = "internal"; | |
27 | |
25 module "usermanager" | 28 module "usermanager" |
26 | 29 |
27 function new_null_provider() | 30 function new_null_provider() |
28 local function dummy() end; | 31 local function dummy() end; |
29 return setmetatable({name = "null"}, { __index = function() return dummy; end }); | 32 return setmetatable({name = "null"}, { __index = function() return dummy; end }); |
31 | 34 |
32 local function host_handler(host) | 35 local function host_handler(host) |
33 local host_session = hosts[host]; | 36 local host_session = hosts[host]; |
34 host_session.events.add_handler("item-added/auth-provider", function (event) | 37 host_session.events.add_handler("item-added/auth-provider", function (event) |
35 local provider = event.item; | 38 local provider = event.item; |
36 if config.get(host, "core", "authentication") == nil and provider.name == "default" then | 39 local auth_provider = config.get(host, "core", "authentication") or default_provider; |
37 host_session.users = provider; | 40 if provider.name == auth_provider then |
38 elseif config.get(host, "core", "authentication") == provider.name then | |
39 host_session.users = provider; | 41 host_session.users = provider; |
40 end | 42 end |
41 if host_session.users ~= nil and host_session.users.name ~= nil then | 43 if host_session.users ~= nil and host_session.users.name ~= nil then |
42 log("debug", "host '%s' now set to use user provider '%s'", host, host_session.users.name); | 44 log("debug", "host '%s' now set to use user provider '%s'", host, host_session.users.name); |
43 end | 45 end |
47 if host_session.users == provider then | 49 if host_session.users == provider then |
48 host_session.users = new_null_provider(); | 50 host_session.users = new_null_provider(); |
49 end | 51 end |
50 end); | 52 end); |
51 host_session.users = new_null_provider(); -- Start with the default usermanager provider | 53 host_session.users = new_null_provider(); -- Start with the default usermanager provider |
54 local auth_provider = config.get(host, "core", "authentication") or default_provider; | |
55 if auth_provider ~= "null" then | |
56 modulemanager.load(host, "auth_"..auth_provider); | |
57 end | |
52 end; | 58 end; |
53 prosody.events.add_handler("host-activated", host_handler, 100); | 59 prosody.events.add_handler("host-activated", host_handler, 100); |
54 prosody.events.add_handler("component-activated", host_handler, 100); | 60 prosody.events.add_handler("component-activated", host_handler, 100); |
55 | 61 |
56 function is_cyrus(host) return config.get(host, "core", "sasl_backend") == "cyrus"; end | 62 function is_cyrus(host) return config.get(host, "core", "sasl_backend") == "cyrus"; end |