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.
8 -- luacheck: ignore 212
10 local new_sasl
= require
"util.sasl".new
;
11 local datamanager
= require
"util.datamanager";
12 local hosts
= prosody
.hosts
;
14 -- define auth provider
17 function provider
.test_password(username
, password
)
18 return nil, "Password based auth not supported.";
21 function provider
.get_password(username
)
22 return nil, "Password not available.";
25 function provider
.set_password(username
, password
)
26 return nil, "Password based auth not supported.";
29 function provider
.user_exists(username
)
30 return nil, "Only anonymous users are supported."; -- FIXME check if anonymous user is connected?
33 function provider
.create_user(username
, password
)
34 return nil, "Account creation/modification not supported.";
37 function provider
.get_sasl_handler()
38 local anonymous_authentication_profile
= {
39 anonymous
= function(sasl
, username
, realm
)
40 return true; -- for normal usage you should always return true here
43 return new_sasl(module
.host
, anonymous_authentication_profile
);
46 function provider
.users()
47 return next, hosts
[module
.host
].sessions
, nil;
50 -- datamanager callback to disable writes
51 local function dm_callback(username
, host
, datastore
, data
)
52 if host
== module
.host
then
55 return username
, host
, datastore
, data
;
58 if not module
:get_option_boolean("allow_anonymous_s2s", false) then
59 module
:hook("route/remote", function (event
)
60 return false; -- Block outgoing s2s from anonymous users
64 function module
.load()
65 datamanager
.add_callback(dm_callback
);
67 function module
.unload()
68 datamanager
.remove_callback(dm_callback
);
71 module
:provides("auth", provider
);