2019-11-09 15:33:07 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <Access/MemoryAccessStorage.h>
|
2020-08-05 19:54:06 +00:00
|
|
|
#include <Common/ZooKeeper/Common.h>
|
2019-11-09 15:33:07 +00:00
|
|
|
|
|
|
|
|
2020-08-05 19:54:06 +00:00
|
|
|
namespace Poco::Util
|
2019-11-09 15:33:07 +00:00
|
|
|
{
|
2020-08-05 19:54:06 +00:00
|
|
|
class AbstractConfiguration;
|
2019-11-09 15:33:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
2022-05-06 23:37:23 +00:00
|
|
|
class AccessControl;
|
2020-08-05 19:54:06 +00:00
|
|
|
class ConfigReloader;
|
|
|
|
|
2019-11-09 15:33:07 +00:00
|
|
|
/// Implementation of IAccessStorage which loads all from users.xml periodically.
|
|
|
|
class UsersConfigAccessStorage : public IAccessStorage
|
|
|
|
{
|
|
|
|
public:
|
2022-03-11 06:22:51 +00:00
|
|
|
|
2020-08-05 19:54:06 +00:00
|
|
|
static constexpr char STORAGE_TYPE[] = "users.xml";
|
2022-03-11 15:52:15 +00:00
|
|
|
|
2022-05-16 18:43:55 +00:00
|
|
|
UsersConfigAccessStorage(const String & storage_name_, AccessControl & access_control_);
|
2020-08-05 19:54:06 +00:00
|
|
|
~UsersConfigAccessStorage() override;
|
|
|
|
|
|
|
|
const char * getStorageType() const override { return STORAGE_TYPE; }
|
2020-09-14 22:51:53 +00:00
|
|
|
String getStorageParamsJSON() const override;
|
2021-11-22 22:14:11 +00:00
|
|
|
bool isReadOnly() const override { return true; }
|
2020-09-14 22:51:53 +00:00
|
|
|
|
|
|
|
String getPath() const;
|
|
|
|
bool isPathEqual(const String & path_) const;
|
2019-11-09 15:33:07 +00:00
|
|
|
|
2022-02-28 18:51:49 +00:00
|
|
|
void setConfig(const Poco::Util::AbstractConfiguration & config);
|
2020-08-05 19:54:06 +00:00
|
|
|
void load(const String & users_config_path,
|
|
|
|
const String & include_from_path = {},
|
|
|
|
const String & preprocessed_dir = {},
|
2022-02-28 18:51:49 +00:00
|
|
|
const zkutil::GetZooKeeper & get_zookeeper_function = {});
|
2022-05-16 18:43:55 +00:00
|
|
|
|
|
|
|
void reload() override;
|
|
|
|
void startPeriodicReloading() override;
|
|
|
|
void stopPeriodicReloading() override;
|
2019-11-09 15:33:07 +00:00
|
|
|
|
2021-11-22 21:50:15 +00:00
|
|
|
bool exists(const UUID & id) const override;
|
|
|
|
|
2019-11-09 15:33:07 +00:00
|
|
|
private:
|
2022-02-28 18:51:49 +00:00
|
|
|
void parseFromConfig(const Poco::Util::AbstractConfiguration & config);
|
2021-11-18 20:54:18 +00:00
|
|
|
std::optional<UUID> findImpl(AccessEntityType type, const String & name) const override;
|
|
|
|
std::vector<UUID> findAllImpl(AccessEntityType type) const override;
|
2021-12-11 16:29:38 +00:00
|
|
|
AccessEntityPtr readImpl(const UUID & id, bool throw_if_not_exists) const override;
|
|
|
|
std::optional<String> readNameImpl(const UUID & id, bool throw_if_not_exists) const override;
|
2019-11-09 15:33:07 +00:00
|
|
|
|
2022-05-16 18:43:55 +00:00
|
|
|
AccessControl & access_control;
|
2019-11-09 15:33:07 +00:00
|
|
|
MemoryAccessStorage memory_storage;
|
2020-08-05 19:54:06 +00:00
|
|
|
String path;
|
|
|
|
std::unique_ptr<ConfigReloader> config_reloader;
|
|
|
|
mutable std::mutex load_mutex;
|
2019-11-09 15:33:07 +00:00
|
|
|
};
|
|
|
|
}
|