2019-11-17 11:57:02 +00:00
|
|
|
#pragma once
|
|
|
|
|
2020-03-07 17:37:38 +00:00
|
|
|
#include <Access/EnabledRowPolicies.h>
|
2021-10-02 07:13:14 +00:00
|
|
|
#include <base/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
|
|
|
|
{
|
2021-11-02 11:06:20 +00:00
|
|
|
class AccessControl;
|
2021-11-18 13:04:42 +00:00
|
|
|
struct RolesOrUsersSet;
|
|
|
|
struct RowPolicy;
|
|
|
|
using RowPolicyPtr = std::shared_ptr<const RowPolicy>;
|
2019-11-17 11:57:02 +00:00
|
|
|
|
|
|
|
/// 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:
|
2021-11-02 11:06:20 +00:00
|
|
|
RowPolicyCache(const AccessControl & access_control_);
|
2020-03-07 17:37:38 +00:00
|
|
|
~RowPolicyCache();
|
2019-11-17 11:57:02 +00:00
|
|
|
|
2020-04-29 19:35:56 +00:00
|
|
|
std::shared_ptr<const EnabledRowPolicies> getEnabledRowPolicies(const UUID & user_id, const boost::container::flat_set<UUID> & enabled_roles);
|
2019-11-17 11:57:02 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
struct PolicyInfo
|
|
|
|
{
|
|
|
|
PolicyInfo(const RowPolicyPtr & policy_) { setPolicy(policy_); }
|
|
|
|
void setPolicy(const RowPolicyPtr & policy_);
|
|
|
|
|
|
|
|
RowPolicyPtr policy;
|
2020-05-30 20:10:45 +00:00
|
|
|
const RolesOrUsersSet * roles = nullptr;
|
2020-05-07 02:45:27 +00:00
|
|
|
std::shared_ptr<const std::pair<String, String>> database_and_table_name;
|
2021-11-18 13:04:42 +00:00
|
|
|
ASTPtr parsed_filters[static_cast<size_t>(RowPolicyFilterType::MAX)];
|
2019-11-17 11:57:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void ensureAllRowPoliciesRead();
|
|
|
|
void rowPolicyAddedOrChanged(const UUID & policy_id, const RowPolicyPtr & new_policy);
|
|
|
|
void rowPolicyRemoved(const UUID & policy_id);
|
2021-11-18 13:04:42 +00:00
|
|
|
void mixFilters();
|
|
|
|
void mixFiltersFor(EnabledRowPolicies & enabled);
|
2019-11-17 11:57:02 +00:00
|
|
|
|
2021-11-02 11:06:20 +00:00
|
|
|
const AccessControl & access_control;
|
2019-11-17 11:57:02 +00:00
|
|
|
std::unordered_map<UUID, PolicyInfo> all_policies;
|
|
|
|
bool all_policies_read = false;
|
2021-06-15 19:55:21 +00:00
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|