blob: 3792f0a848f9be8c8be8abb6fffbeba12fb14749 [file] [log] [blame]
Tom Joseph536ea322018-09-14 10:02:20 +05301#pragma once
2
Patrick Williams9638afb2021-02-22 17:16:24 -06003#include "ldap_mapper_entry.hpp"
4
Tom Joseph536ea322018-09-14 10:02:20 +05305#include <sdbusplus/bus.hpp>
6#include <sdbusplus/server/object.hpp>
Tom Joseph536ea322018-09-14 10:02:20 +05307#include <xyz/openbmc_project/User/PrivilegeMapper/server.hpp>
Patrick Williams9638afb2021-02-22 17:16:24 -06008
Tom Joseph536ea322018-09-14 10:02:20 +05309#include <map>
10#include <set>
11
12namespace phosphor
13{
14
15namespace user
16{
17
18using MapperMgrIface =
19 sdbusplus::xyz::openbmc_project::User::server::PrivilegeMapper;
20using ObjectPath = sdbusplus::message::object_path;
21
22// D-Bus root for LDAP privilege mapper
23constexpr auto mapperMgrRoot = "/xyz/openbmc_project/user/ldap";
24
25/** @class LDAPMapperMgr
26 *
27 * @brief Responsible for managing LDAP groups to privilege mapping.
28 */
29class LDAPMapperMgr : public MapperMgrIface
30{
31 public:
32 LDAPMapperMgr() = delete;
33 ~LDAPMapperMgr() = default;
Patrick Williams9638afb2021-02-22 17:16:24 -060034 LDAPMapperMgr(const LDAPMapperMgr&) = delete;
35 LDAPMapperMgr& operator=(const LDAPMapperMgr&) = delete;
36 LDAPMapperMgr(LDAPMapperMgr&&) = delete;
37 LDAPMapperMgr& operator=(LDAPMapperMgr&&) = delete;
Tom Joseph536ea322018-09-14 10:02:20 +053038
39 /** @brief Constructs LDAPMapperMgr object.
40 *
41 * @param[in] bus - sdbusplus handler
42 * @param[in] path - D-Bus path
Tom Josephf5bd8912018-11-19 09:49:21 +053043 * @param[in] filePath - serialization directory path
Tom Joseph536ea322018-09-14 10:02:20 +053044 */
Patrick Williams9638afb2021-02-22 17:16:24 -060045 LDAPMapperMgr(sdbusplus::bus::bus& bus, const char* path,
46 const char* filePath);
Tom Joseph536ea322018-09-14 10:02:20 +053047
48 /** @brief Creates a mapping for the group to the privilege
49 *
50 * @param[in] groupName - Group Name to which the privilege needs to be
51 * assigned.
52 * @param[in] privilege - The privilege role associated with the group.
53 *
54 * @return On success return the D-Bus object path of the created privilege
55 * mapper entry.
56 */
57 ObjectPath create(std::string groupName, std::string privilege) override;
58
59 /** @brief Delete privilege mapping for LDAP group
60 *
61 * This method deletes the privilege mapping
62 *
63 * @param[in] groupName - name of the LDAP group for which privilege
64 * mapping is to be deleted.
65 */
66 void deletePrivilegeMapper(Id id);
67
68 /** @brief Check if LDAP group privilege mapping requested is valid
69 *
70 * Check if the privilege mapping already exists for the LDAP group name
71 * and group name is empty.
72 *
73 * @param[in] groupName - LDAP group name
74 *
75 * @return throw exception if the conditions are not met.
76 */
Patrick Williams9638afb2021-02-22 17:16:24 -060077 void checkPrivilegeMapper(const std::string& groupName);
Tom Joseph536ea322018-09-14 10:02:20 +053078
79 /** @brief Check if the privilege level is a valid one
80 *
81 * @param[in] privilege - Privilege level
82 *
83 * @return throw exception if the conditions are not met.
84 */
Patrick Williams9638afb2021-02-22 17:16:24 -060085 void checkPrivilegeLevel(const std::string& privilege);
Tom Joseph536ea322018-09-14 10:02:20 +053086
Tom Joseph0b14c472018-09-30 01:42:59 +053087 /** @brief Construct LDAP mapper entry D-Bus objects from their persisted
88 * representations.
89 */
90 void restore();
91
Tom Joseph536ea322018-09-14 10:02:20 +053092 private:
93 /** @brief sdbusplus handler */
Patrick Williams9638afb2021-02-22 17:16:24 -060094 sdbusplus::bus::bus& bus;
Tom Joseph536ea322018-09-14 10:02:20 +053095
96 /** @brief object path for the manager object*/
97 const std::string path;
98
Tom Josephf5bd8912018-11-19 09:49:21 +053099 /** @brief serialization directory path */
100 std::string persistPath;
101
Tom Joseph536ea322018-09-14 10:02:20 +0530102 /** @brief available privileges container */
Richard Marian Thomaiyar32be2962019-11-08 17:21:53 +0530103 std::set<std::string> privMgr = {
104 "priv-admin",
105 "priv-operator",
106 "priv-user",
raviteja-bfe720ff2020-01-31 03:38:23 -0600107 "priv-noaccess",
Richard Marian Thomaiyar32be2962019-11-08 17:21:53 +0530108 };
Tom Joseph536ea322018-09-14 10:02:20 +0530109
110 /** @brief Id of the last privilege mapper entry */
111 Id entryId = 0;
112
113 /** @brief container to hold privilege mapper objects */
114 std::map<Id, std::unique_ptr<phosphor::user::LDAPMapperEntry>>
115 PrivilegeMapperList;
116};
117
118} // namespace user
119} // namespace phosphor