blob: 8af4e4d00b8ff6553354b69909176b4c32952e8a [file] [log] [blame]
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -05001#pragma once
2
Nagaraju Gorugantif1940d92018-09-18 05:05:50 -05003#include "config.h"
Nagaraju Goruganti24194bd2018-09-18 09:55:09 -05004#include <xyz/openbmc_project/Object/Delete/server.hpp>
Ratan Guptaaeaf9412019-02-11 04:41:52 -06005#include <xyz/openbmc_project/Object/Enable/server.hpp>
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -05006#include <xyz/openbmc_project/User/Ldap/Create/server.hpp>
Ratan Guptae1f4db62019-04-11 18:57:42 +05307#include <xyz/openbmc_project/User/Ldap/Config/server.hpp>
Nagaraju Gorugantif1940d92018-09-18 05:05:50 -05008#include <xyz/openbmc_project/Common/error.hpp>
9#include <phosphor-logging/log.hpp>
10#include <phosphor-logging/elog.hpp>
11#include <phosphor-logging/elog-errors.hpp>
12#include <sdbusplus/bus.hpp>
13#include <sdbusplus/server/object.hpp>
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -050014#include <string>
15
16namespace phosphor
17{
18namespace ldap
19{
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -050020
Nagaraju Gorugantif1940d92018-09-18 05:05:50 -050021using namespace phosphor::logging;
22using namespace sdbusplus::xyz::openbmc_project::Common::Error;
Ratan Guptaaeaf9412019-02-11 04:41:52 -060023using ConfigIface = sdbusplus::xyz::openbmc_project::User::Ldap::server::Config;
24using EnableIface = sdbusplus::xyz::openbmc_project::Object::server::Enable;
25using DeleteIface = sdbusplus::xyz::openbmc_project::Object::server::Delete;
26using Ifaces =
27 sdbusplus::server::object::object<ConfigIface, EnableIface, DeleteIface>;
28using CreateIface = sdbusplus::server::object::object<
29 sdbusplus::xyz::openbmc_project::User::Ldap::server::Create>;
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -050030
31class ConfigMgr;
Ratan Gupta3a1c2742019-03-20 06:49:42 +053032class MockConfigMgr;
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -050033
34/** @class Config
35 * @brief Configuration for LDAP.
36 * @details concrete implementation of xyz.openbmc_project.User.Ldap.Config
37 * API, in order to provide LDAP configuration.
38 */
Ratan Guptaaeaf9412019-02-11 04:41:52 -060039class Config : public Ifaces
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -050040{
41 public:
42 Config() = delete;
43 ~Config() = default;
44 Config(const Config&) = delete;
45 Config& operator=(const Config&) = delete;
46 Config(Config&&) = default;
47 Config& operator=(Config&&) = default;
48
49 /** @brief Constructor to put object onto bus at a D-Bus path.
50 * @param[in] bus - Bus to attach to.
51 * @param[in] path - The D-Bus object path to attach at.
52 * @param[in] filePath - LDAP configuration file.
Nagaraju Goruganti3b4d06a2018-11-08 03:13:38 -060053 * @param[in] caCertFile - LDAP's CA certificate file.
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -050054 * @param[in] secureLDAP - Specifies whether to use SSL or not.
55 * @param[in] lDAPServerURI - LDAP URI of the server.
56 * @param[in] lDAPBindDN - distinguished name with which to bind.
57 * @param[in] lDAPBaseDN - distinguished name to use as search base.
Nagaraju Gorugantidb60f582018-11-08 03:14:48 -060058 * @param[in] lDAPBindDNPassword - credentials with which to bind.
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -050059 * @param[in] lDAPSearchScope - the search scope.
60 * @param[in] lDAPType - Specifies the LDAP server type which can be AD
Ratan Guptaaeaf9412019-02-11 04:41:52 -060061 * or openLDAP.
62 * @param[in] lDAPServiceEnabled - Specifies whether the service would be
63 * enabled or not.
64 * @param[in] groupNameAttribute - Specifies attribute name that contains
65 * the name of the Group in the LDAP server.
66 * @param[in] userNameAttribute - Specifies attribute name that contains
67 * the username in the LDAP server.
68 *
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -050069 * @param[in] parent - parent of config object.
70 */
71
72 Config(sdbusplus::bus::bus& bus, const char* path, const char* filePath,
Nagaraju Goruganti3b4d06a2018-11-08 03:13:38 -060073 const char* caCertFile, bool secureLDAP, std::string lDAPServerURI,
74 std::string lDAPBindDN, std::string lDAPBaseDN,
75 std::string&& lDAPBindDNPassword,
Ratan Guptaaeaf9412019-02-11 04:41:52 -060076 ConfigIface::SearchScope lDAPSearchScope, ConfigIface::Type lDAPType,
77 bool lDAPServiceEnabled, std::string groupNameAttribute,
78 std::string userNameAttribute, ConfigMgr& parent);
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -050079
Ratan Guptaaeaf9412019-02-11 04:41:52 -060080 using ConfigIface::groupNameAttribute;
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -050081 using ConfigIface::lDAPBaseDN;
82 using ConfigIface::lDAPBindDN;
Ratan Gupta3a1c2742019-03-20 06:49:42 +053083 using ConfigIface::lDAPBindDNPassword;
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -050084 using ConfigIface::lDAPSearchScope;
85 using ConfigIface::lDAPServerURI;
86 using ConfigIface::lDAPType;
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -050087 using ConfigIface::setPropertyByName;
Ratan Guptaaeaf9412019-02-11 04:41:52 -060088 using ConfigIface::userNameAttribute;
89 using EnableIface::enabled;
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -050090
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -050091 /** @brief Update the Server URI property.
92 * @param[in] value - lDAPServerURI value to be updated.
93 * @returns value of changed lDAPServerURI.
94 */
95 std::string lDAPServerURI(std::string value) override;
96
97 /** @brief Update the BindDN property.
98 * @param[in] value - lDAPBindDN value to be updated.
99 * @returns value of changed lDAPBindDN.
100 */
101 std::string lDAPBindDN(std::string value) override;
102
103 /** @brief Update the BaseDN property.
104 * @param[in] value - lDAPBaseDN value to be updated.
105 * @returns value of changed lDAPBaseDN.
106 */
107 std::string lDAPBaseDN(std::string value) override;
108
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -0500109 /** @brief Update the Search scope property.
110 * @param[in] value - lDAPSearchScope value to be updated.
111 * @returns value of changed lDAPSearchScope.
112 */
Ratan Guptaaeaf9412019-02-11 04:41:52 -0600113 ConfigIface::SearchScope
114 lDAPSearchScope(ConfigIface::SearchScope value) override;
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -0500115
116 /** @brief Update the LDAP Type property.
117 * @param[in] value - lDAPType value to be updated.
118 * @returns value of changed lDAPType.
119 */
Ratan Guptaaeaf9412019-02-11 04:41:52 -0600120 ConfigIface::Type lDAPType(ConfigIface::Type value) override;
121
122 /** @brief Update the ldapServiceEnabled property.
123 * @param[in] value - ldapServiceEnabled value to be updated.
124 * @returns value of changed ldapServiceEnabled.
125 */
126 bool enabled(bool value) override;
127
128 /** @brief Update the userNameAttribute property.
129 * @param[in] value - userNameAttribute value to be updated.
130 * @returns value of changed userNameAttribute.
131 */
132 std::string userNameAttribute(std::string value) override;
133
134 /** @brief Update the groupNameAttribute property.
135 * @param[in] value - groupNameAttribute value to be updated.
136 * @returns value of changed groupNameAttribute.
137 */
138 std::string groupNameAttribute(std::string value) override;
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -0500139
Ratan Gupta3a1c2742019-03-20 06:49:42 +0530140 /** @brief Update the BindDNPasword property.
141 * @param[in] value - lDAPBindDNPassword value to be updated.
142 * @returns value of changed lDAPBindDNPassword.
143 */
144 std::string lDAPBindDNPassword(std::string value) override;
145
Nagaraju Goruganti24194bd2018-09-18 09:55:09 -0500146 /** @brief Delete this D-bus object.
147 */
148 void delete_() override;
149
Nagaraju Gorugantidb60f582018-11-08 03:14:48 -0600150 bool secureLDAP;
151
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -0500152 private:
Ratan Gupta3a1c2742019-03-20 06:49:42 +0530153 std::string lDAPBindPassword{};
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -0500154 std::string configFilePath{};
Nagaraju Goruganti3b4d06a2018-11-08 03:13:38 -0600155 std::string tlsCacertFile{};
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -0500156
157 /** @brief Persistent sdbusplus D-Bus bus connection. */
158 sdbusplus::bus::bus& bus;
159
160 /** @brief Create a new LDAP config file.
161 */
162 virtual void writeConfig();
163
164 /** @brief reference to config manager object */
165 ConfigMgr& parent;
Ratan Gupta3a1c2742019-03-20 06:49:42 +0530166
167 friend class MockConfigMgr;
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -0500168};
169
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -0500170} // namespace ldap
171} // namespace phosphor