ClickHouse/dbms/include/DB/Interpreters/Users.h

94 lines
1.6 KiB
C++
Raw Normal View History

#pragma once
#include <DB/Core/Types.h>
2017-03-25 05:55:49 +00:00
#include <map>
#include <vector>
2015-10-01 15:10:41 +00:00
#include <unordered_set>
2017-03-25 05:55:49 +00:00
#include <memory>
2017-03-25 05:55:49 +00:00
namespace Poco
{
2017-03-25 05:55:49 +00:00
namespace Net
{
2017-03-25 05:55:49 +00:00
class IPAddress;
}
2017-03-25 05:55:49 +00:00
namespace Util
{
2017-03-25 05:55:49 +00:00
class AbstractConfiguration;
}
2017-03-25 05:55:49 +00:00
}
2017-03-25 05:55:49 +00:00
namespace DB
{
2017-03-25 05:55:49 +00:00
/// Allow to check that address matches a pattern.
class IAddressPattern
{
public:
2017-03-25 05:55:49 +00:00
virtual bool contains(const Poco::Net::IPAddress & addr) const = 0;
virtual ~IAddressPattern() {}
};
class AddressPatterns
{
private:
using Container = std::vector<std::unique_ptr<IAddressPattern>>;
Container patterns;
public:
2017-03-25 05:55:49 +00:00
bool contains(const Poco::Net::IPAddress & addr) const;
void addFromConfig(const String & config_elem, Poco::Util::AbstractConfiguration & config);
};
2017-01-14 02:53:40 +00:00
/** User and ACL.
*/
struct User
{
String name;
2017-01-14 02:53:40 +00:00
/// Required password. Could be stored in plaintext or in SHA256.
String password;
String password_sha256_hex;
String profile;
String quota;
AddressPatterns addresses;
2017-01-14 02:53:40 +00:00
/// List of allowed databases.
2015-10-01 15:10:41 +00:00
using DatabaseSet = std::unordered_set<std::string>;
DatabaseSet databases;
2017-03-25 05:55:49 +00:00
User(const String & name_, const String & config_elem, Poco::Util::AbstractConfiguration & config);
2017-01-14 02:53:40 +00:00
/// For insertion to containers.
User() {}
};
2017-01-14 02:53:40 +00:00
/// Known users.
class Users
{
private:
using Container = std::map<String, User>;
Container cont;
public:
2017-03-25 05:55:49 +00:00
void loadFromConfig(Poco::Util::AbstractConfiguration & config);
2017-03-25 05:55:49 +00:00
const User & get(const String & name, const String & password, const Poco::Net::IPAddress & address) const;
2015-10-01 15:10:41 +00:00
2017-01-14 02:53:40 +00:00
/// Check if the user has access to the database.
2017-03-25 05:55:49 +00:00
bool isAllowedDatabase(const std::string & user_name, const std::string & database_name) const;
};
}