2021-03-05 14:57:16 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <Interpreters/SystemLog.h>
|
|
|
|
#include <Interpreters/ClientInfo.h>
|
2021-11-01 14:03:20 +00:00
|
|
|
#include <Access/Common/AuthenticationData.h>
|
2021-03-05 14:57:16 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
enum SessionLogElementType : int8_t
|
|
|
|
{
|
|
|
|
SESSION_LOGIN_FAILURE = 0,
|
|
|
|
SESSION_LOGIN_SUCCESS = 1,
|
|
|
|
SESSION_LOGOUT = 2,
|
|
|
|
};
|
|
|
|
|
|
|
|
class ContextAccess;
|
|
|
|
|
|
|
|
/** A struct which will be inserted as row into session_log table.
|
|
|
|
*
|
|
|
|
* Allows to log information about user sessions:
|
|
|
|
* - auth attempts, auth result, auth method, etc.
|
|
|
|
* - log out events
|
|
|
|
*/
|
|
|
|
struct SessionLogElement
|
|
|
|
{
|
|
|
|
using Type = SessionLogElementType;
|
|
|
|
|
|
|
|
SessionLogElement() = default;
|
2021-10-30 14:51:58 +00:00
|
|
|
SessionLogElement(const UUID & auth_id_, Type type_);
|
2021-03-05 14:57:16 +00:00
|
|
|
SessionLogElement(const SessionLogElement &) = default;
|
|
|
|
SessionLogElement & operator=(const SessionLogElement &) = default;
|
|
|
|
SessionLogElement(SessionLogElement &&) = default;
|
|
|
|
SessionLogElement & operator=(SessionLogElement &&) = default;
|
|
|
|
|
2021-10-30 14:51:58 +00:00
|
|
|
UUID auth_id;
|
2021-03-05 14:57:16 +00:00
|
|
|
|
|
|
|
Type type = SESSION_LOGIN_FAILURE;
|
|
|
|
|
2021-10-30 14:51:58 +00:00
|
|
|
String session_id;
|
2021-03-05 14:57:16 +00:00
|
|
|
time_t event_time{};
|
|
|
|
Decimal64 event_time_microseconds{};
|
|
|
|
|
|
|
|
String user;
|
2021-11-01 14:03:20 +00:00
|
|
|
AuthenticationType user_identified_with = AuthenticationType::NO_PASSWORD;
|
2021-03-05 14:57:16 +00:00
|
|
|
String external_auth_server;
|
|
|
|
Strings roles;
|
|
|
|
Strings profiles;
|
2021-10-30 14:59:22 +00:00
|
|
|
std::vector<std::pair<String, String>> settings;
|
2021-03-05 14:57:16 +00:00
|
|
|
|
|
|
|
ClientInfo client_info;
|
|
|
|
String auth_failure_reason;
|
|
|
|
|
|
|
|
static std::string name() { return "SessionLog"; }
|
|
|
|
|
|
|
|
static NamesAndTypesList getNamesAndTypes();
|
|
|
|
static NamesAndAliases getNamesAndAliases() { return {}; }
|
|
|
|
|
|
|
|
void appendToBlock(MutableColumns & columns) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/// Instead of typedef - to allow forward declaration.
|
|
|
|
class SessionLog : public SystemLog<SessionLogElement>
|
|
|
|
{
|
|
|
|
using SystemLog<SessionLogElement>::SystemLog;
|
|
|
|
|
|
|
|
public:
|
2021-10-30 14:51:58 +00:00
|
|
|
void addLoginSuccess(const UUID & auth_id, std::optional<String> session_id, const Context & login_context);
|
|
|
|
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);
|
2021-03-05 14:57:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|