Software / code / prosody
Diff
core/sessionmanager.lua @ 12674:72f431b4dc2c
Merge role-auth->trunk
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Mon, 22 Aug 2022 13:53:35 +0100 |
| parent | 12662:07424992d7fc |
| child | 12677:3b9771d496ed |
line wrap: on
line diff
--- a/core/sessionmanager.lua Fri Aug 19 14:24:31 2022 +0200 +++ b/core/sessionmanager.lua Mon Aug 22 13:53:35 2022 +0100 @@ -123,15 +123,24 @@ retire_session(session); end -local function make_authenticated(session, username, scope) +local function make_authenticated(session, username, role_name) username = nodeprep(username); if not username or #username == 0 then return nil, "Invalid username"; end session.username = username; if session.type == "c2s_unauthed" then session.type = "c2s_unbound"; end - session.auth_scope = scope; - session.log("info", "Authenticated as %s@%s", username, session.host or "(unknown)"); + + local role; + if role_name then + role = hosts[session.host].authz.get_role_by_name(role_name); + else + role = hosts[session.host].authz.get_user_role(username); + end + if role then + sessionlib.set_role(session, role); + end + session.log("info", "Authenticated as %s@%s [%s]", username, session.host or "(unknown)", role and role.name or "no role"); return true; end