2020-03-07 17:37:38 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <Access/EnabledRoles.h>
|
2022-05-19 07:24:28 +00:00
|
|
|
#include <Poco/AccessExpireCache.h>
|
2020-04-29 19:35:56 +00:00
|
|
|
#include <boost/container/flat_set.hpp>
|
2020-03-07 17:37:38 +00:00
|
|
|
#include <map>
|
|
|
|
#include <mutex>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
2021-11-02 11:06:20 +00:00
|
|
|
class AccessControl;
|
2020-03-07 17:37:38 +00:00
|
|
|
struct Role;
|
|
|
|
using RolePtr = std::shared_ptr<const Role>;
|
|
|
|
|
|
|
|
class RoleCache
|
|
|
|
{
|
|
|
|
public:
|
2022-03-11 15:52:15 +00:00
|
|
|
explicit RoleCache(const AccessControl & access_control_);
|
2020-03-07 17:37:38 +00:00
|
|
|
~RoleCache();
|
|
|
|
|
2020-04-29 19:35:56 +00:00
|
|
|
std::shared_ptr<const EnabledRoles> getEnabledRoles(
|
2021-02-26 22:37:00 +00:00
|
|
|
const std::vector<UUID> & current_roles,
|
|
|
|
const std::vector<UUID> & current_roles_with_admin_option);
|
2020-03-07 17:37:38 +00:00
|
|
|
|
|
|
|
private:
|
2022-05-16 18:43:55 +00:00
|
|
|
void collectEnabledRoles(scope_guard * notifications);
|
|
|
|
void collectEnabledRoles(EnabledRoles & enabled, scope_guard * notifications);
|
2020-03-07 17:37:38 +00:00
|
|
|
RolePtr getRole(const UUID & role_id);
|
|
|
|
void roleChanged(const UUID & role_id, const RolePtr & changed_role);
|
|
|
|
void roleRemoved(const UUID & role_id);
|
|
|
|
|
2021-11-02 11:06:20 +00:00
|
|
|
const AccessControl & access_control;
|
2022-05-19 07:24:28 +00:00
|
|
|
Poco::AccessExpireCache<UUID, std::pair<RolePtr, scope_guard>> cache;
|
2020-03-07 17:37:38 +00:00
|
|
|
std::map<EnabledRoles::Params, std::weak_ptr<EnabledRoles>> enabled_roles;
|
|
|
|
mutable std::mutex mutex;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|