Comparison

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
comparison
equal deleted inserted replaced
12639:6d9ee0a3eb4b 12674:72f431b4dc2c
121 end 121 end
122 122
123 retire_session(session); 123 retire_session(session);
124 end 124 end
125 125
126 local function make_authenticated(session, username, scope) 126 local function make_authenticated(session, username, role_name)
127 username = nodeprep(username); 127 username = nodeprep(username);
128 if not username or #username == 0 then return nil, "Invalid username"; end 128 if not username or #username == 0 then return nil, "Invalid username"; end
129 session.username = username; 129 session.username = username;
130 if session.type == "c2s_unauthed" then 130 if session.type == "c2s_unauthed" then
131 session.type = "c2s_unbound"; 131 session.type = "c2s_unbound";
132 end 132 end
133 session.auth_scope = scope; 133
134 session.log("info", "Authenticated as %s@%s", username, session.host or "(unknown)"); 134 local role;
135 if role_name then
136 role = hosts[session.host].authz.get_role_by_name(role_name);
137 else
138 role = hosts[session.host].authz.get_user_role(username);
139 end
140 if role then
141 sessionlib.set_role(session, role);
142 end
143 session.log("info", "Authenticated as %s@%s [%s]", username, session.host or "(unknown)", role and role.name or "no role");
135 return true; 144 return true;
136 end 145 end
137 146
138 -- returns true, nil on success 147 -- returns true, nil on success
139 -- returns nil, err_type, err, err_message on failure 148 -- returns nil, err_type, err, err_message on failure