Software / code / prosody
Annotate
plugins/mod_auth_internal_plain.lua @ 4709:98bfebb38705
net.server.http: Parse absolute URIs in requests (thanks Maranda)
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Thu, 26 Apr 2012 15:05:05 +0100 |
| parent | 4603:6900c9484834 |
| child | 4762:943f9f860ab4 |
| rev | line source |
|---|---|
| 3162 | 1 -- Prosody IM |
| 2 -- Copyright (C) 2008-2010 Matthew Wild | |
| 3 -- Copyright (C) 2008-2010 Waqas Hussain | |
| 4 -- | |
| 5 -- This project is MIT/X11 licensed. Please see the | |
| 6 -- COPYING file in the source package for more information. | |
| 7 -- | |
| 8 | |
| 9 local datamanager = require "util.datamanager"; | |
|
3336
3a8ce659edfc
mod_auth_internal, usermanager: Rename to mod_auth_internal_plain, and update usermanager to still use it as the default
Matthew Wild <mwild1@gmail.com>
parents:
3335
diff
changeset
|
10 local log = require "util.logger".init("auth_internal_plain"); |
| 3162 | 11 local type = type; |
| 12 local error = error; | |
| 13 local ipairs = ipairs; | |
| 14 local hashes = require "util.hashes"; | |
| 15 local jid_bare = require "util.jid".bare; | |
| 16 local config = require "core.configmanager"; | |
| 3163 | 17 local usermanager = require "core.usermanager"; |
|
3186
b5f261123013
mod_auth_internal, mod_auth_internal_hashed: Updated to provide get_sasl_handler.
Waqas Hussain <waqas20@gmail.com>
parents:
3180
diff
changeset
|
18 local new_sasl = require "util.sasl".new; |
|
b5f261123013
mod_auth_internal, mod_auth_internal_hashed: Updated to provide get_sasl_handler.
Waqas Hussain <waqas20@gmail.com>
parents:
3180
diff
changeset
|
19 local nodeprep = require "util.encodings".stringprep.nodeprep; |
| 3162 | 20 local hosts = hosts; |
| 21 | |
| 22 local prosody = _G.prosody; | |
| 23 | |
| 24 function new_default_provider(host) | |
|
3336
3a8ce659edfc
mod_auth_internal, usermanager: Rename to mod_auth_internal_plain, and update usermanager to still use it as the default
Matthew Wild <mwild1@gmail.com>
parents:
3335
diff
changeset
|
25 local provider = { name = "internal_plain" }; |
|
4603
6900c9484834
mod_auth_internal_{plain,hashed}: Clarify log messages on initialization
Matthew Wild <mwild1@gmail.com>
parents:
4160
diff
changeset
|
26 log("debug", "initializing internal_plain authentication provider for host '%s'", host); |
| 3163 | 27 |
| 3162 | 28 function provider.test_password(username, password) |
| 3163 | 29 log("debug", "test password '%s' for user %s at host %s", password, username, module.host); |
| 3162 | 30 local credentials = datamanager.load(username, host, "accounts") or {}; |
| 31 | |
| 32 if password == credentials.password then | |
| 33 return true; | |
| 34 else | |
| 35 return nil, "Auth failed. Invalid username or password."; | |
| 36 end | |
| 37 end | |
| 38 | |
| 39 function provider.get_password(username) | |
| 3163 | 40 log("debug", "get_password for username '%s' at host '%s'", username, module.host); |
| 3162 | 41 return (datamanager.load(username, host, "accounts") or {}).password; |
| 42 end | |
| 43 | |
| 44 function provider.set_password(username, password) | |
| 45 local account = datamanager.load(username, host, "accounts"); | |
| 46 if account then | |
| 47 account.password = password; | |
| 48 return datamanager.store(username, host, "accounts", account); | |
| 49 end | |
| 50 return nil, "Account not available."; | |
| 51 end | |
| 52 | |
| 53 function provider.user_exists(username) | |
| 54 local account = datamanager.load(username, host, "accounts"); | |
| 55 if not account then | |
| 3163 | 56 log("debug", "account not found for username '%s' at host '%s'", username, module.host); |
| 3162 | 57 return nil, "Auth failed. Invalid username"; |
| 58 end | |
| 59 return true; | |
| 60 end | |
| 61 | |
| 62 function provider.create_user(username, password) | |
| 63 return datamanager.store(username, host, "accounts", {password = password}); | |
| 64 end | |
|
3994
42899d5efe3b
mod_auth_internal_*: Support for delete_user method
Matthew Wild <mwild1@gmail.com>
parents:
3981
diff
changeset
|
65 |
|
42899d5efe3b
mod_auth_internal_*: Support for delete_user method
Matthew Wild <mwild1@gmail.com>
parents:
3981
diff
changeset
|
66 function provider.delete_user(username) |
|
42899d5efe3b
mod_auth_internal_*: Support for delete_user method
Matthew Wild <mwild1@gmail.com>
parents:
3981
diff
changeset
|
67 return datamanager.store(username, host, "accounts", nil); |
|
42899d5efe3b
mod_auth_internal_*: Support for delete_user method
Matthew Wild <mwild1@gmail.com>
parents:
3981
diff
changeset
|
68 end |
| 3162 | 69 |
|
3186
b5f261123013
mod_auth_internal, mod_auth_internal_hashed: Updated to provide get_sasl_handler.
Waqas Hussain <waqas20@gmail.com>
parents:
3180
diff
changeset
|
70 function provider.get_sasl_handler() |
|
b5f261123013
mod_auth_internal, mod_auth_internal_hashed: Updated to provide get_sasl_handler.
Waqas Hussain <waqas20@gmail.com>
parents:
3180
diff
changeset
|
71 local getpass_authentication_profile = { |
|
3981
2b0b8fe68df2
util.sasl.*, mod_auth_*, mod_saslauth: Pass SASL handler as first parameter to SASL profile callbacks.
Waqas Hussain <waqas20@gmail.com>
parents:
3465
diff
changeset
|
72 plain = function(sasl, username, realm) |
|
3186
b5f261123013
mod_auth_internal, mod_auth_internal_hashed: Updated to provide get_sasl_handler.
Waqas Hussain <waqas20@gmail.com>
parents:
3180
diff
changeset
|
73 local prepped_username = nodeprep(username); |
|
b5f261123013
mod_auth_internal, mod_auth_internal_hashed: Updated to provide get_sasl_handler.
Waqas Hussain <waqas20@gmail.com>
parents:
3180
diff
changeset
|
74 if not prepped_username then |
|
b5f261123013
mod_auth_internal, mod_auth_internal_hashed: Updated to provide get_sasl_handler.
Waqas Hussain <waqas20@gmail.com>
parents:
3180
diff
changeset
|
75 log("debug", "NODEprep failed on username: %s", username); |
|
b5f261123013
mod_auth_internal, mod_auth_internal_hashed: Updated to provide get_sasl_handler.
Waqas Hussain <waqas20@gmail.com>
parents:
3180
diff
changeset
|
76 return "", nil; |
|
b5f261123013
mod_auth_internal, mod_auth_internal_hashed: Updated to provide get_sasl_handler.
Waqas Hussain <waqas20@gmail.com>
parents:
3180
diff
changeset
|
77 end |
|
b5f261123013
mod_auth_internal, mod_auth_internal_hashed: Updated to provide get_sasl_handler.
Waqas Hussain <waqas20@gmail.com>
parents:
3180
diff
changeset
|
78 local password = usermanager.get_password(prepped_username, realm); |
|
b5f261123013
mod_auth_internal, mod_auth_internal_hashed: Updated to provide get_sasl_handler.
Waqas Hussain <waqas20@gmail.com>
parents:
3180
diff
changeset
|
79 if not password then |
|
b5f261123013
mod_auth_internal, mod_auth_internal_hashed: Updated to provide get_sasl_handler.
Waqas Hussain <waqas20@gmail.com>
parents:
3180
diff
changeset
|
80 return "", nil; |
|
b5f261123013
mod_auth_internal, mod_auth_internal_hashed: Updated to provide get_sasl_handler.
Waqas Hussain <waqas20@gmail.com>
parents:
3180
diff
changeset
|
81 end |
|
b5f261123013
mod_auth_internal, mod_auth_internal_hashed: Updated to provide get_sasl_handler.
Waqas Hussain <waqas20@gmail.com>
parents:
3180
diff
changeset
|
82 return password, true; |
|
b5f261123013
mod_auth_internal, mod_auth_internal_hashed: Updated to provide get_sasl_handler.
Waqas Hussain <waqas20@gmail.com>
parents:
3180
diff
changeset
|
83 end |
|
b5f261123013
mod_auth_internal, mod_auth_internal_hashed: Updated to provide get_sasl_handler.
Waqas Hussain <waqas20@gmail.com>
parents:
3180
diff
changeset
|
84 }; |
|
4160
f08f649b898b
mod_auth_*: Get rid of undocumented and broken 'sasl_realm' config option.
Waqas Hussain <waqas20@gmail.com>
parents:
3994
diff
changeset
|
85 return new_sasl(module.host, getpass_authentication_profile); |
| 3162 | 86 end |
|
3287
e425e27c12be
mod_auth_internal, mod_auth_internal_hashed: Remove is_admin method from providers
Matthew Wild <mwild1@gmail.com>
parents:
3272
diff
changeset
|
87 |
| 3162 | 88 return provider; |
| 89 end | |
| 90 | |
| 91 module:add_item("auth-provider", new_default_provider(module.host)); | |
| 92 |