2020-05-27 21:06:33 +00:00
|
|
|
#pragma once
|
|
|
|
|
2021-03-11 20:41:10 +00:00
|
|
|
#include <Access/LDAPClient.h>
|
|
|
|
#include <Access/Credentials.h>
|
|
|
|
#include <Access/GSSAcceptor.h>
|
2021-10-02 07:13:14 +00:00
|
|
|
#include <base/types.h>
|
2020-05-27 21:06:33 +00:00
|
|
|
|
2020-12-24 21:49:19 +00:00
|
|
|
#include <chrono>
|
2020-05-27 21:06:33 +00:00
|
|
|
#include <map>
|
|
|
|
#include <mutex>
|
2021-03-11 20:41:10 +00:00
|
|
|
#include <optional>
|
2020-12-24 21:49:19 +00:00
|
|
|
#include <unordered_map>
|
2020-05-27 21:06:33 +00:00
|
|
|
|
|
|
|
|
2020-05-29 12:14:42 +00:00
|
|
|
namespace Poco
|
|
|
|
{
|
2020-05-29 07:47:01 +00:00
|
|
|
class Logger;
|
2020-05-29 12:14:42 +00:00
|
|
|
|
2020-05-29 07:47:01 +00:00
|
|
|
namespace Util
|
|
|
|
{
|
|
|
|
class AbstractConfiguration;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-27 21:06:33 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
class ExternalAuthenticators
|
|
|
|
{
|
|
|
|
public:
|
2020-07-11 17:06:01 +00:00
|
|
|
void reset();
|
2020-07-23 17:55:24 +00:00
|
|
|
void setConfiguration(const Poco::Util::AbstractConfiguration & config, Poco::Logger * log);
|
2021-03-11 20:41:10 +00:00
|
|
|
|
|
|
|
// The name and readiness of the credentials must be verified before calling these.
|
|
|
|
bool checkLDAPCredentials(const String & server, const BasicCredentials & credentials,
|
2021-03-28 22:23:20 +00:00
|
|
|
const LDAPClient::RoleSearchParamsList * role_search_params = nullptr, LDAPClient::SearchResultsList * role_search_results = nullptr) const;
|
2021-03-11 20:41:10 +00:00
|
|
|
bool checkKerberosCredentials(const String & realm, const GSSAcceptorContext & credentials) const;
|
|
|
|
|
|
|
|
GSSAcceptorContext::Params getKerberosParams() const;
|
2020-06-02 09:37:02 +00:00
|
|
|
|
2020-12-24 21:49:19 +00:00
|
|
|
private:
|
|
|
|
struct LDAPCacheEntry
|
|
|
|
{
|
2020-12-24 23:46:08 +00:00
|
|
|
std::size_t last_successful_params_hash = 0;
|
|
|
|
std::chrono::steady_clock::time_point last_successful_authentication_timestamp;
|
2021-03-28 22:23:20 +00:00
|
|
|
LDAPClient::SearchResultsList last_successful_role_search_results;
|
2020-12-24 21:49:19 +00:00
|
|
|
};
|
|
|
|
|
2021-03-11 20:41:10 +00:00
|
|
|
using LDAPCache = std::unordered_map<String, LDAPCacheEntry>; // user name -> cache entry
|
|
|
|
using LDAPCaches = std::map<String, LDAPCache>; // server name -> cache
|
|
|
|
using LDAPParams = std::map<String, LDAPClient::Params>; // server name -> params
|
2020-05-27 21:06:33 +00:00
|
|
|
|
2020-07-11 17:06:01 +00:00
|
|
|
mutable std::recursive_mutex mutex;
|
2021-03-11 20:41:10 +00:00
|
|
|
LDAPParams ldap_client_params_blueprint;
|
|
|
|
mutable LDAPCaches ldap_caches;
|
|
|
|
std::optional<GSSAcceptorContext::Params> kerberos_params;
|
2020-05-27 21:06:33 +00:00
|
|
|
};
|
|
|
|
|
2021-03-28 22:23:20 +00:00
|
|
|
void parseLDAPRoleSearchParams(LDAPClient::RoleSearchParams & params, const Poco::Util::AbstractConfiguration & config, const String & prefix);
|
|
|
|
|
2020-05-27 21:06:33 +00:00
|
|
|
}
|