#pragma once #include #include #include namespace DB { /// InterserverCredentials implements authentication using a CurrentCredentials, which /// is configured, e.g. /// /// admin /// 222 /// /// /// /// /// admin /// qqq /// /// /// /// johny /// 333 /// /// class InterserverCredentials { public: using UserWithPassword = std::pair; using CheckResult = std::pair; using CurrentCredentials = std::vector; InterserverCredentials(const InterserverCredentials &) = delete; static std::unique_ptr make(const Poco::Util::AbstractConfiguration & config, const std::string & root_tag); InterserverCredentials(const std::string & current_user_, const std::string & current_password_, const CurrentCredentials & all_users_store_) : current_user(current_user_) , current_password(current_password_) , all_users_store(all_users_store_) {} CheckResult isValidUser(const UserWithPassword & credentials) const; CheckResult isValidUser(const std::string & user, const std::string & password) const; std::string getUser() const { return current_user; } std::string getPassword() const { return current_password; } private: std::string current_user; std::string current_password; /// In common situation this store contains one record CurrentCredentials all_users_store; static CurrentCredentials parseCredentialsFromConfig( const std::string & current_user_, const std::string & current_password_, const Poco::Util::AbstractConfiguration & config, const std::string & root_tag); }; using InterserverCredentialsPtr = std::shared_ptr; }