blob: 7b3013d85f7369a381d89d2825026336f4973f82 [file] [log] [blame]
Tom Joseph536ea322018-09-14 10:02:20 +05301#pragma once
2
3#include <sdbusplus/bus.hpp>
4#include <sdbusplus/server/object.hpp>
5#include "ldap_mapper_entry.hpp"
6#include <xyz/openbmc_project/User/PrivilegeMapper/server.hpp>
7#include <map>
8#include <set>
9
10namespace phosphor
11{
12
13namespace user
14{
15
16using MapperMgrIface =
17 sdbusplus::xyz::openbmc_project::User::server::PrivilegeMapper;
18using ObjectPath = sdbusplus::message::object_path;
19
20// D-Bus root for LDAP privilege mapper
21constexpr auto mapperMgrRoot = "/xyz/openbmc_project/user/ldap";
22
23/** @class LDAPMapperMgr
24 *
25 * @brief Responsible for managing LDAP groups to privilege mapping.
26 */
27class LDAPMapperMgr : public MapperMgrIface
28{
29 public:
30 LDAPMapperMgr() = delete;
31 ~LDAPMapperMgr() = default;
32 LDAPMapperMgr(const LDAPMapperMgr &) = delete;
33 LDAPMapperMgr &operator=(const LDAPMapperMgr &) = delete;
34 LDAPMapperMgr(LDAPMapperMgr &&) = delete;
35 LDAPMapperMgr &operator=(LDAPMapperMgr &&) = delete;
36
37 /** @brief Constructs LDAPMapperMgr object.
38 *
39 * @param[in] bus - sdbusplus handler
40 * @param[in] path - D-Bus path
Tom Josephf5bd8912018-11-19 09:49:21 +053041 * @param[in] filePath - serialization directory path
Tom Joseph536ea322018-09-14 10:02:20 +053042 */
Tom Josephf5bd8912018-11-19 09:49:21 +053043 LDAPMapperMgr(sdbusplus::bus::bus &bus, const char *path,
44 const char *filePath);
Tom Joseph536ea322018-09-14 10:02:20 +053045
46 /** @brief Creates a mapping for the group to the privilege
47 *
48 * @param[in] groupName - Group Name to which the privilege needs to be
49 * assigned.
50 * @param[in] privilege - The privilege role associated with the group.
51 *
52 * @return On success return the D-Bus object path of the created privilege
53 * mapper entry.
54 */
55 ObjectPath create(std::string groupName, std::string privilege) override;
56
57 /** @brief Delete privilege mapping for LDAP group
58 *
59 * This method deletes the privilege mapping
60 *
61 * @param[in] groupName - name of the LDAP group for which privilege
62 * mapping is to be deleted.
63 */
64 void deletePrivilegeMapper(Id id);
65
66 /** @brief Check if LDAP group privilege mapping requested is valid
67 *
68 * Check if the privilege mapping already exists for the LDAP group name
69 * and group name is empty.
70 *
71 * @param[in] groupName - LDAP group name
72 *
73 * @return throw exception if the conditions are not met.
74 */
75 void checkPrivilegeMapper(const std::string &groupName);
76
77 /** @brief Check if the privilege level is a valid one
78 *
79 * @param[in] privilege - Privilege level
80 *
81 * @return throw exception if the conditions are not met.
82 */
83 void checkPrivilegeLevel(const std::string &privilege);
84
Tom Joseph0b14c472018-09-30 01:42:59 +053085 /** @brief Construct LDAP mapper entry D-Bus objects from their persisted
86 * representations.
87 */
88 void restore();
89
Tom Joseph536ea322018-09-14 10:02:20 +053090 private:
91 /** @brief sdbusplus handler */
92 sdbusplus::bus::bus &bus;
93
94 /** @brief object path for the manager object*/
95 const std::string path;
96
Tom Josephf5bd8912018-11-19 09:49:21 +053097 /** @brief serialization directory path */
98 std::string persistPath;
99
Tom Joseph536ea322018-09-14 10:02:20 +0530100 /** @brief available privileges container */
Richard Marian Thomaiyar32be2962019-11-08 17:21:53 +0530101 std::set<std::string> privMgr = {
102 "priv-admin",
103 "priv-operator",
104 "priv-user",
105 };
Tom Joseph536ea322018-09-14 10:02:20 +0530106
107 /** @brief Id of the last privilege mapper entry */
108 Id entryId = 0;
109
110 /** @brief container to hold privilege mapper objects */
111 std::map<Id, std::unique_ptr<phosphor::user::LDAPMapperEntry>>
112 PrivilegeMapperList;
113};
114
115} // namespace user
116} // namespace phosphor