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
12namespace SlKernCVS {
13
15class LDAPUsers {
16public:
18 using UserSet = std::unordered_set<std::string, SlHelpers::String::Hash,
20
21 LDAPUsers() = delete;
28 LDAPUsers(const std::string &dn, const std::string &password);
29
31 const UserSet &userSet() const & { return m_userSet; }
32
34 UserSet userSet() && { return std::move(m_userSet); }
35
37 bool contains(const std::string &key) const noexcept { return m_userSet.contains(key); }
38private:
39 friend void testLDAP();
40
41 using UserMap = std::unordered_map<std::string, std::string>;
42
43 UserSet m_userSet;
44
45 static void addUserMapCond(UserMap &userMap, std::string_view logname,
46 std::string_view email);
47 static UserMap parseMap(std::string_view mapData);
48 UserMap getMap();
49 void buildSet(const std::string &dn, const std::string &password, const UserMap &userMap);
50
51 static std::pair<std::string_view, bool>
52 getMappedUser(const UserMap &userMap, const std::string &user) {
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:18
const UserSet & userSet() const &
Get the set of users fetched from LDAP.
Definition LDAP.h:31
UserSet userSet() &&
Get the set of users fetched from LDAP (rvalue).
Definition LDAP.h:34
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:37
Equality test for string and string_view to be used in containers.
Definition String.h:281
Hash for string and string_view to be used in hashing containers.
Definition String.h:254