Tom Joseph | 536ea32 | 2018-09-14 10:02:20 +0530 | [diff] [blame] | 1 | #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 | |
| 10 | namespace phosphor |
| 11 | { |
| 12 | |
| 13 | namespace user |
| 14 | { |
| 15 | |
| 16 | using MapperMgrIface = |
| 17 | sdbusplus::xyz::openbmc_project::User::server::PrivilegeMapper; |
| 18 | using ObjectPath = sdbusplus::message::object_path; |
| 19 | |
| 20 | // D-Bus root for LDAP privilege mapper |
| 21 | constexpr auto mapperMgrRoot = "/xyz/openbmc_project/user/ldap"; |
| 22 | |
| 23 | /** @class LDAPMapperMgr |
| 24 | * |
| 25 | * @brief Responsible for managing LDAP groups to privilege mapping. |
| 26 | */ |
| 27 | class 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 Joseph | f5bd891 | 2018-11-19 09:49:21 +0530 | [diff] [blame] | 41 | * @param[in] filePath - serialization directory path |
Tom Joseph | 536ea32 | 2018-09-14 10:02:20 +0530 | [diff] [blame] | 42 | */ |
Tom Joseph | f5bd891 | 2018-11-19 09:49:21 +0530 | [diff] [blame] | 43 | LDAPMapperMgr(sdbusplus::bus::bus &bus, const char *path, |
| 44 | const char *filePath); |
Tom Joseph | 536ea32 | 2018-09-14 10:02:20 +0530 | [diff] [blame] | 45 | |
| 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 Joseph | 0b14c47 | 2018-09-30 01:42:59 +0530 | [diff] [blame] | 85 | /** @brief Construct LDAP mapper entry D-Bus objects from their persisted |
| 86 | * representations. |
| 87 | */ |
| 88 | void restore(); |
| 89 | |
Tom Joseph | 536ea32 | 2018-09-14 10:02:20 +0530 | [diff] [blame] | 90 | 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 Joseph | f5bd891 | 2018-11-19 09:49:21 +0530 | [diff] [blame] | 97 | /** @brief serialization directory path */ |
| 98 | std::string persistPath; |
| 99 | |
Tom Joseph | 536ea32 | 2018-09-14 10:02:20 +0530 | [diff] [blame] | 100 | /** @brief available privileges container */ |
Richard Marian Thomaiyar | 32be296 | 2019-11-08 17:21:53 +0530 | [diff] [blame^] | 101 | std::set<std::string> privMgr = { |
| 102 | "priv-admin", |
| 103 | "priv-operator", |
| 104 | "priv-user", |
| 105 | }; |
Tom Joseph | 536ea32 | 2018-09-14 10:02:20 +0530 | [diff] [blame] | 106 | |
| 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 |