Skip to content

Commit 229eb98

Browse files
alexey-milovidovzvonand
authored andcommitted
Merge pull request ClickHouse#88412 from ilejn/no_role_hash_ldap
No role hash in LDAP
1 parent d2f1112 commit 229eb98

File tree

2 files changed

+9
-20
lines changed

2 files changed

+9
-20
lines changed

src/Access/LDAPAccessStorage.cpp

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ void LDAPAccessStorage::setConfiguration(const Poco::Util::AbstractConfiguration
8484
role_search_params.swap(role_search_params_cfg);
8585
common_role_names.swap(common_roles_cfg);
8686

87-
external_role_hashes.clear();
87+
users_external_roles.clear();
8888
users_per_roles.clear();
8989
roles_per_users.clear();
9090
granted_role_names.clear();
@@ -197,13 +197,6 @@ void LDAPAccessStorage::applyRoleChangeNoLock(bool grant, const UUID & role_id,
197197

198198

199199
void LDAPAccessStorage::assignRolesNoLock(User & user, const LDAPClient::SearchResultsList & external_roles) const
200-
{
201-
const auto external_roles_hash = boost::hash<LDAPClient::SearchResultsList>{}(external_roles);
202-
assignRolesNoLock(user, external_roles, external_roles_hash);
203-
}
204-
205-
206-
void LDAPAccessStorage::assignRolesNoLock(User & user, const LDAPClient::SearchResultsList & external_roles, std::size_t external_roles_hash) const
207200
{
208201
const auto & user_name = user.getName();
209202
auto & granted_roles = user.granted_roles;
@@ -232,7 +225,7 @@ void LDAPAccessStorage::assignRolesNoLock(User & user, const LDAPClient::SearchR
232225
}
233226
};
234227

235-
external_role_hashes.erase(user_name);
228+
users_external_roles.erase(user_name);
236229
granted_roles = {};
237230
const auto old_role_names = std::move(roles_per_users[user_name]);
238231

@@ -280,32 +273,29 @@ void LDAPAccessStorage::assignRolesNoLock(User & user, const LDAPClient::SearchR
280273
granted_role_ids.erase(iit);
281274
}
282275

283-
// Actualize roles_per_users mapping and external_role_hashes cache.
276+
// Actualize roles_per_users mapping and users_external_roles cache.
284277
if (local_role_names.empty())
285278
roles_per_users.erase(user_name);
286279
else
287280
roles_per_users[user_name] = std::move(local_role_names);
288281

289-
external_role_hashes[user_name] = external_roles_hash;
282+
users_external_roles[user_name] = external_roles;
290283
}
291284

292285

293286
void LDAPAccessStorage::updateAssignedRolesNoLock(const UUID & id, const String & user_name, const LDAPClient::SearchResultsList & external_roles) const
294287
{
295-
// No need to include common_role_names in this hash each time, since they don't change.
296-
const auto external_roles_hash = boost::hash<LDAPClient::SearchResultsList>{}(external_roles);
297-
298288
// Map and grant the roles from scratch only if the list of external role has changed.
299-
const auto it = external_role_hashes.find(user_name);
300-
if (it != external_role_hashes.end() && it->second == external_roles_hash)
289+
const auto it = users_external_roles.find(user_name);
290+
if (it != users_external_roles.end() && it->second == external_roles)
301291
return;
302292

303-
auto update_func = [this, &external_roles, external_roles_hash] (const AccessEntityPtr & entity_, const UUID &) -> AccessEntityPtr
293+
auto update_func = [this, &external_roles] (const AccessEntityPtr & entity_, const UUID &) -> AccessEntityPtr
304294
{
305295
if (auto user = typeid_cast<std::shared_ptr<const User>>(entity_))
306296
{
307297
auto changed_user = typeid_cast<std::shared_ptr<User>>(user->clone());
308-
assignRolesNoLock(*changed_user, external_roles, external_roles_hash);
298+
assignRolesNoLock(*changed_user, external_roles);
309299
return changed_user;
310300
}
311301
return entity_;

src/Access/LDAPAccessStorage.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ class LDAPAccessStorage : public IAccessStorage
5555

5656
void applyRoleChangeNoLock(bool grant, const UUID & role_id, const String & role_name);
5757
void assignRolesNoLock(User & user, const LDAPClient::SearchResultsList & external_roles) const;
58-
void assignRolesNoLock(User & user, const LDAPClient::SearchResultsList & external_roles, std::size_t external_roles_hash) const;
5958
void updateAssignedRolesNoLock(const UUID & id, const String & user_name, const LDAPClient::SearchResultsList & external_roles) const;
6059
std::set<String> mapExternalRolesNoLock(const LDAPClient::SearchResultsList & external_roles) const;
6160
bool areLDAPCredentialsValidNoLock(const User & user, const Credentials & credentials,
@@ -66,7 +65,7 @@ class LDAPAccessStorage : public IAccessStorage
6665
String ldap_server_name;
6766
LDAPClient::RoleSearchParamsList role_search_params;
6867
std::set<String> common_role_names; // role name that should be granted to all users at all times
69-
mutable std::map<String, std::size_t> external_role_hashes; // user name -> LDAPClient::SearchResultsList hash (most recently retrieved and processed)
68+
mutable std::map<String, LDAPClient::SearchResultsList> users_external_roles; // user name -> LDAPClient::SearchResultsList (most recently retrieved and processed)
7069
mutable std::map<String, std::set<String>> users_per_roles; // role name -> user names (...it should be granted to; may but don't have to exist for common roles)
7170
mutable std::map<String, std::set<String>> roles_per_users; // user name -> role names (...that should be granted to it; may but don't have to include common roles)
7271
mutable std::map<UUID, String> granted_role_names; // (currently granted) role id -> its name

0 commit comments

Comments
 (0)