SlHelpers
Loading...
Searching...
No Matches
LDAP.h
1// SPDX-License-Identifier: GPL-2.0-only
2
3#pragma once
4
5#include <string>
6#include <string_view>
7#include <unordered_map>
8#include <unordered_set>
9
10#include "../helpers/String.h"
11
12class INIReader;
13
14namespace SlKernCVS {
15
17class LDAPUsers {
18public:
20 using UserSet = std::unordered_set<std::string, SlHelpers::String::Hash,
22
23 LDAPUsers() = delete;
30 LDAPUsers(const std::string &dn, const std::string &password);
31
33 const UserSet &userSet() const & { return m_userSet; }
34
36 UserSet userSet() && { return std::move(m_userSet); }
37
39 bool contains(const std::string &key) const noexcept { return m_userSet.contains(key); }
40private:
41 using UserMap = std::unordered_map<std::string, std::string>;
42
43 UserSet m_userSet;
44
45 static void walkSection(UserMap &userMap, const INIReader &reader,
46 const std::string &section, bool lognameIsKey);
47 static void addUserMapCond(UserMap &userMap, std::string &&logname, std::string &&email);
48 UserMap getMap();
49 void buildSet(const std::string &dn, const std::string &password, const UserMap &userMap);
50
51 std::pair<std::string_view, bool>
52 getMappedUser(const UserMap &userMap, const std::string &user) const {
53 auto it = userMap.find(user);
54 if (it != userMap.end())
55 return { it->second, true };
56 return { user, false };
57 }
58};
59
60} // namespace
std::unordered_set< std::string, SlHelpers::String::Hash, SlHelpers::String::Eq > UserSet
Set of users.
Definition LDAP.h:20
const UserSet & userSet() const &
Get the set of users fetched from LDAP.
Definition LDAP.h:33
UserSet userSet() &&
Get the set of users fetched from LDAP (rvalue).
Definition LDAP.h:36
LDAPUsers(const std::string &dn, const std::string &password)
Construct a new LDAPUsers object.
bool contains(const std::string &key) const noexcept
Check if a user is in the set of users fetched from LDAP.
Definition LDAP.h:39
Equality test for string and string_view to be used in containers.
Definition String.h:258
Hash for string and string_view to be used in hashing containers.
Definition String.h:231