2 -- Copyright (C) 2008-2010 Matthew Wild
3 -- Copyright (C) 2008-2010 Waqas Hussain
5 -- This project is MIT/X11 licensed. Please see the
6 -- COPYING file in the source package for more information.
9 local new_sasl = require "util.sasl".new;
10 local datamanager = require "util.datamanager";
11 local hosts = prosody.hosts;
13 -- define auth provider
16 function provider.test_password(username, password)
17 return nil, "Password based auth not supported.";
20 function provider.get_password(username)
21 return nil, "Password not available.";
24 function provider.set_password(username, password)
25 return nil, "Password based auth not supported.";
28 function provider.user_exists(username)
29 return nil, "Only anonymous users are supported."; -- FIXME check if anonymous user is connected?
32 function provider.create_user(username, password)
33 return nil, "Account creation/modification not supported.";
36 function provider.get_sasl_handler()
37 local anonymous_authentication_profile = {
38 anonymous = function(sasl, username, realm)
39 return true; -- for normal usage you should always return true here
42 return new_sasl(module.host, anonymous_authentication_profile);
45 function provider.users()
46 return next, hosts[host].sessions, nil;
49 -- datamanager callback to disable writes
50 local function dm_callback(username, host, datastore, data)
51 if host == module.host then
54 return username, host, datastore, data;
57 if not module:get_option_boolean("allow_anonymous_s2s", false) then
58 module:hook("route/remote", function (event)
59 return false; -- Block outgoing s2s from anonymous users
63 function module.load()
64 datamanager.add_callback(dm_callback);
66 function module.unload()
67 datamanager.remove_callback(dm_callback);
70 module:provides("auth", provider);