1#include <Access/AccessControlManager.h>
2#include <Access/MultipleAccessStorage.h>
3#include <Access/MemoryAccessStorage.h>
4#include <Access/UsersConfigAccessStorage.h>
5#include <Access/QuotaContextFactory.h>
6#include <Access/RowPolicyContextFactory.h>
7
8
9namespace DB
10{
11namespace
12{
13 std::vector<std::unique_ptr<IAccessStorage>> createStorages()
14 {
15 std::vector<std::unique_ptr<IAccessStorage>> list;
16 list.emplace_back(std::make_unique<MemoryAccessStorage>());
17 list.emplace_back(std::make_unique<UsersConfigAccessStorage>());
18 return list;
19 }
20}
21
22
23AccessControlManager::AccessControlManager()
24 : MultipleAccessStorage(createStorages()),
25 quota_context_factory(std::make_unique<QuotaContextFactory>(*this)),
26 row_policy_context_factory(std::make_unique<RowPolicyContextFactory>(*this))
27{
28}
29
30
31AccessControlManager::~AccessControlManager()
32{
33}
34
35
36void AccessControlManager::loadFromConfig(const Poco::Util::AbstractConfiguration & users_config)
37{
38 auto & users_config_access_storage = dynamic_cast<UsersConfigAccessStorage &>(getStorageByIndex(1));
39 users_config_access_storage.loadFromConfig(users_config);
40}
41
42
43std::shared_ptr<QuotaContext> AccessControlManager::createQuotaContext(
44 const String & user_name, const Poco::Net::IPAddress & address, const String & custom_quota_key)
45{
46 return quota_context_factory->createContext(user_name, address, custom_quota_key);
47}
48
49
50std::vector<QuotaUsageInfo> AccessControlManager::getQuotaUsageInfo() const
51{
52 return quota_context_factory->getUsageInfo();
53}
54
55
56std::shared_ptr<RowPolicyContext> AccessControlManager::getRowPolicyContext(const String & user_name) const
57{
58 return row_policy_context_factory->createContext(user_name);
59}
60
61}
62