2019-11-17 11:57:02 +00:00
|
|
|
#pragma once
|
|
|
|
|
2020-03-07 17:37:38 +00:00
|
|
|
#include <Access/EnabledRowPolicies.h>
|
2020-01-29 15:51:12 +00:00
|
|
|
#include <ext/scope_guard.h>
|
2019-11-17 11:57:02 +00:00
|
|
|
#include <mutex>
|
2020-03-07 17:37:38 +00:00
|
|
|
#include <map>
|
2019-11-17 11:57:02 +00:00
|
|
|
#include <unordered_map>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
class AccessControlManager;
|
|
|
|
|
|
|
|
/// Stores read and parsed row policies.
|
2020-03-07 17:37:38 +00:00
|
|
|
class RowPolicyCache
|
2019-11-17 11:57:02 +00:00
|
|
|
{
|
|
|
|
public:
|
2020-03-07 17:37:38 +00:00
|
|
|
RowPolicyCache(const AccessControlManager & access_control_manager_);
|
|
|
|
~RowPolicyCache();
|
2019-11-17 11:57:02 +00:00
|
|
|
|
2020-03-07 17:37:38 +00:00
|
|
|
std::shared_ptr<const EnabledRowPolicies> getEnabledRowPolicies(const UUID & user_id, const std::vector<UUID> & enabled_roles);
|
2019-11-17 11:57:02 +00:00
|
|
|
|
|
|
|
private:
|
2020-03-07 17:37:38 +00:00
|
|
|
using ParsedConditions = EnabledRowPolicies::ParsedConditions;
|
2019-11-17 11:57:02 +00:00
|
|
|
|
|
|
|
struct PolicyInfo
|
|
|
|
{
|
|
|
|
PolicyInfo(const RowPolicyPtr & policy_) { setPolicy(policy_); }
|
|
|
|
void setPolicy(const RowPolicyPtr & policy_);
|
|
|
|
|
|
|
|
RowPolicyPtr policy;
|
2020-03-07 17:37:38 +00:00
|
|
|
const ExtendedRoleSet * roles = nullptr;
|
2019-11-17 11:57:02 +00:00
|
|
|
ParsedConditions parsed_conditions;
|
|
|
|
};
|
|
|
|
|
|
|
|
void ensureAllRowPoliciesRead();
|
|
|
|
void rowPolicyAddedOrChanged(const UUID & policy_id, const RowPolicyPtr & new_policy);
|
|
|
|
void rowPolicyRemoved(const UUID & policy_id);
|
2020-03-07 17:37:38 +00:00
|
|
|
void mixConditions();
|
|
|
|
void mixConditionsFor(EnabledRowPolicies & enabled);
|
2019-11-17 11:57:02 +00:00
|
|
|
|
|
|
|
const AccessControlManager & access_control_manager;
|
|
|
|
std::unordered_map<UUID, PolicyInfo> all_policies;
|
|
|
|
bool all_policies_read = false;
|
2020-01-29 15:51:12 +00:00
|
|
|
ext::scope_guard subscription;
|
2020-03-07 17:37:38 +00:00
|
|
|
std::map<EnabledRowPolicies::Params, std::weak_ptr<EnabledRowPolicies>> enabled_row_policies;
|
2019-11-17 11:57:02 +00:00
|
|
|
std::mutex mutex;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|