2013-08-10 07:46:45 +00:00
|
|
|
#pragma once
|
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Core/Types.h>
|
2017-03-25 05:46:50 +00:00
|
|
|
|
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>
|
2013-08-10 07:46:45 +00:00
|
|
|
|
|
|
|
|
2017-03-25 05:55:49 +00:00
|
|
|
namespace Poco
|
2016-01-11 21:46:36 +00:00
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
namespace Net
|
|
|
|
{
|
|
|
|
class IPAddress;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace Util
|
|
|
|
{
|
|
|
|
class AbstractConfiguration;
|
|
|
|
}
|
2017-03-25 05:55:49 +00:00
|
|
|
}
|
2013-08-10 07:46:45 +00:00
|
|
|
|
|
|
|
|
2017-03-25 05:55:49 +00:00
|
|
|
namespace DB
|
2013-08-10 07:46:45 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
|
2017-03-25 05:55:49 +00:00
|
|
|
/// Allow to check that address matches a pattern.
|
|
|
|
class IAddressPattern
|
2013-08-10 07:46:45 +00:00
|
|
|
{
|
2015-09-27 02:18:00 +00:00
|
|
|
public:
|
2017-04-01 07:20:54 +00:00
|
|
|
virtual bool contains(const Poco::Net::IPAddress & addr) const = 0;
|
|
|
|
virtual ~IAddressPattern() {}
|
2013-08-10 07:46:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class AddressPatterns
|
|
|
|
{
|
|
|
|
private:
|
2017-04-01 07:20:54 +00:00
|
|
|
using Container = std::vector<std::unique_ptr<IAddressPattern>>;
|
|
|
|
Container patterns;
|
2013-08-10 07:46:45 +00:00
|
|
|
|
|
|
|
public:
|
2017-04-01 07:20:54 +00:00
|
|
|
bool contains(const Poco::Net::IPAddress & addr) const;
|
|
|
|
void addFromConfig(const String & config_elem, Poco::Util::AbstractConfiguration & config);
|
2013-08-10 07:46:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-01-14 02:53:40 +00:00
|
|
|
/** User and ACL.
|
2013-08-10 07:46:45 +00:00
|
|
|
*/
|
|
|
|
struct User
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
String name;
|
2013-08-10 07:46:45 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
/// Required password. Could be stored in plaintext or in SHA256.
|
|
|
|
String password;
|
|
|
|
String password_sha256_hex;
|
2013-08-10 07:46:45 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
String profile;
|
|
|
|
String quota;
|
2013-08-10 07:46:45 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
AddressPatterns addresses;
|
2013-08-10 07:46:45 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
/// List of allowed databases.
|
|
|
|
using DatabaseSet = std::unordered_set<std::string>;
|
|
|
|
DatabaseSet databases;
|
2015-10-01 15:10:41 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
User(const String & name_, const String & config_elem, Poco::Util::AbstractConfiguration & config);
|
2013-08-10 07:46:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-01-14 02:53:40 +00:00
|
|
|
/// Known users.
|
2013-08-10 07:46:45 +00:00
|
|
|
class Users
|
|
|
|
{
|
|
|
|
private:
|
2017-04-01 07:20:54 +00:00
|
|
|
using Container = std::map<String, User>;
|
|
|
|
Container cont;
|
2015-09-24 07:18:05 +00:00
|
|
|
|
2013-08-10 07:46:45 +00:00
|
|
|
public:
|
2017-04-01 07:20:54 +00:00
|
|
|
void loadFromConfig(Poco::Util::AbstractConfiguration & config);
|
2013-08-10 07:46:45 +00:00
|
|
|
|
2017-06-07 12:54:35 +00:00
|
|
|
/// Find user and make authorize checks
|
|
|
|
const User & get(const String & user_name, const String & password, const Poco::Net::IPAddress & address) const;
|
|
|
|
|
|
|
|
/// Just find user
|
|
|
|
const User & get(const String & user_name);
|
2015-10-01 15:10:41 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
/// Check if the user has access to the database.
|
2017-06-07 12:54:35 +00:00
|
|
|
bool isAllowedDatabase(const String & user_name, const String & database_name) const;
|
2013-08-10 07:46:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
}
|