Explicitly passing a user object to create a LogIn event

This commit is contained in:
Vasily Nemkov 2022-03-30 23:37:24 +03:00
parent 31e07fe078
commit dc88d8d571
3 changed files with 8 additions and 9 deletions

View File

@ -486,7 +486,8 @@ ContextMutablePtr Session::makeQueryContextImpl(const ClientInfo * client_info_t
session_log->addLoginSuccess(
auth_id,
named_session ? std::optional<std::string>(named_session->key.second) : std::nullopt,
*query_context);
*query_context,
*user);
notified_session_log_about_login = true;
}

View File

@ -203,7 +203,7 @@ void SessionLogElement::appendToBlock(MutableColumns & columns) const
columns[i++]->insertData(auth_failure_reason.data(), auth_failure_reason.length());
}
void SessionLog::addLoginSuccess(const UUID & auth_id, std::optional<String> session_id, const Context & login_context)
void SessionLog::addLoginSuccess(const UUID & auth_id, std::optional<String> session_id, const Context & login_context, const User & login_user)
{
const auto access = login_context.getAccess();
const auto & settings = login_context.getSettingsRef();
@ -212,12 +212,9 @@ void SessionLog::addLoginSuccess(const UUID & auth_id, std::optional<String> ses
DB::SessionLogElement log_entry(auth_id, SESSION_LOGIN_SUCCESS);
log_entry.client_info = client_info;
if (const auto user = login_context.getUser())
{
log_entry.user = user->getName();
log_entry.user_identified_with = user->auth_data.getType();
log_entry.external_auth_server = user->auth_data.getLDAPServerName();
}
log_entry.user = login_user.getName();
log_entry.user_identified_with = login_user.auth_data.getType();
log_entry.external_auth_server = login_user.auth_data.getLDAPServerName();
if (session_id)
log_entry.session_id = *session_id;

View File

@ -18,6 +18,7 @@ enum SessionLogElementType : int8_t
};
class ContextAccess;
struct User;
/** A struct which will be inserted as row into session_log table.
*
@ -69,7 +70,7 @@ class SessionLog : public SystemLog<SessionLogElement>
using SystemLog<SessionLogElement>::SystemLog;
public:
void addLoginSuccess(const UUID & auth_id, std::optional<String> session_id, const Context & login_context);
void addLoginSuccess(const UUID & auth_id, std::optional<String> session_id, const Context & login_context, const User & login_user);
void addLoginFailure(const UUID & auth_id, const ClientInfo & info, const String & user, const Exception & reason);
void addLogOut(const UUID & auth_id, const String & user, const ClientInfo & client_info);
};