xref: /openbmc/bmcweb/features/redfish/lib/account_service.hpp (revision 599c71d8dcc62cf6244abdf48c93c5f76a0ddc7d)
188d16c9aSLewanczyk, Dawid /*
288d16c9aSLewanczyk, Dawid // Copyright (c) 2018 Intel Corporation
388d16c9aSLewanczyk, Dawid //
488d16c9aSLewanczyk, Dawid // Licensed under the Apache License, Version 2.0 (the "License");
588d16c9aSLewanczyk, Dawid // you may not use this file except in compliance with the License.
688d16c9aSLewanczyk, Dawid // You may obtain a copy of the License at
788d16c9aSLewanczyk, Dawid //
888d16c9aSLewanczyk, Dawid //      http://www.apache.org/licenses/LICENSE-2.0
988d16c9aSLewanczyk, Dawid //
1088d16c9aSLewanczyk, Dawid // Unless required by applicable law or agreed to in writing, software
1188d16c9aSLewanczyk, Dawid // distributed under the License is distributed on an "AS IS" BASIS,
1288d16c9aSLewanczyk, Dawid // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1388d16c9aSLewanczyk, Dawid // See the License for the specific language governing permissions and
1488d16c9aSLewanczyk, Dawid // limitations under the License.
1588d16c9aSLewanczyk, Dawid */
1688d16c9aSLewanczyk, Dawid #pragma once
1788d16c9aSLewanczyk, Dawid #include "node.hpp"
1888d16c9aSLewanczyk, Dawid 
1924c8542dSRatan Gupta #include <dbus_utility.hpp>
2065b0dc32SEd Tanous #include <error_messages.hpp>
21b9b2e0b2SEd Tanous #include <openbmc_dbus_rest.hpp>
22a840879dSEd Tanous #include <utils/json_utils.hpp>
23abf2add6SEd Tanous #include <variant>
24b9b2e0b2SEd Tanous 
251abe55efSEd Tanous namespace redfish
261abe55efSEd Tanous {
2788d16c9aSLewanczyk, Dawid 
286973a582SRatan Gupta constexpr const char* ldapConfigObject =
296973a582SRatan Gupta     "/xyz/openbmc_project/user/ldap/openldap";
30ab828d7cSRatan Gupta constexpr const char* ADConfigObject =
31ab828d7cSRatan Gupta     "/xyz/openbmc_project/user/ldap/active_directory";
32ab828d7cSRatan Gupta 
336973a582SRatan Gupta constexpr const char* ldapRootObject = "/xyz/openbmc_project/user/ldap";
346973a582SRatan Gupta constexpr const char* ldapDbusService = "xyz.openbmc_project.Ldap.Config";
356973a582SRatan Gupta constexpr const char* ldapConfigInterface =
366973a582SRatan Gupta     "xyz.openbmc_project.User.Ldap.Config";
376973a582SRatan Gupta constexpr const char* ldapCreateInterface =
386973a582SRatan Gupta     "xyz.openbmc_project.User.Ldap.Create";
396973a582SRatan Gupta constexpr const char* ldapEnableInterface = "xyz.openbmc_project.Object.Enable";
406973a582SRatan Gupta constexpr const char* dbusObjManagerIntf = "org.freedesktop.DBus.ObjectManager";
416973a582SRatan Gupta constexpr const char* propertyInterface = "org.freedesktop.DBus.Properties";
426973a582SRatan Gupta constexpr const char* mapperBusName = "xyz.openbmc_project.ObjectMapper";
436973a582SRatan Gupta constexpr const char* mapperObjectPath = "/xyz/openbmc_project/object_mapper";
446973a582SRatan Gupta constexpr const char* mapperIntf = "xyz.openbmc_project.ObjectMapper";
456973a582SRatan Gupta 
4654fc587aSNagaraju Goruganti struct LDAPRoleMapData
4754fc587aSNagaraju Goruganti {
4854fc587aSNagaraju Goruganti     std::string groupName;
4954fc587aSNagaraju Goruganti     std::string privilege;
5054fc587aSNagaraju Goruganti };
5154fc587aSNagaraju Goruganti 
526973a582SRatan Gupta struct LDAPConfigData
536973a582SRatan Gupta {
546973a582SRatan Gupta     std::string uri{};
556973a582SRatan Gupta     std::string bindDN{};
566973a582SRatan Gupta     std::string baseDN{};
576973a582SRatan Gupta     std::string searchScope{};
586973a582SRatan Gupta     std::string serverType{};
596973a582SRatan Gupta     bool serviceEnabled = false;
606973a582SRatan Gupta     std::string userNameAttribute{};
616973a582SRatan Gupta     std::string groupAttribute{};
6254fc587aSNagaraju Goruganti     std::vector<std::pair<std::string, LDAPRoleMapData>> groupRoleList;
636973a582SRatan Gupta };
646973a582SRatan Gupta 
65b9b2e0b2SEd Tanous using ManagedObjectType = std::vector<std::pair<
66b9b2e0b2SEd Tanous     sdbusplus::message::object_path,
67b9b2e0b2SEd Tanous     boost::container::flat_map<
68abf2add6SEd Tanous         std::string, boost::container::flat_map<
69abf2add6SEd Tanous                          std::string, std::variant<bool, std::string>>>>>;
706973a582SRatan Gupta using GetObjectType =
716973a582SRatan Gupta     std::vector<std::pair<std::string, std::vector<std::string>>>;
7284e12cb7SAppaRao Puli 
7354fc587aSNagaraju Goruganti inline std::string getRoleIdFromPrivilege(std::string_view role)
7484e12cb7SAppaRao Puli {
7584e12cb7SAppaRao Puli     if (role == "priv-admin")
7684e12cb7SAppaRao Puli     {
7784e12cb7SAppaRao Puli         return "Administrator";
7884e12cb7SAppaRao Puli     }
7984e12cb7SAppaRao Puli     else if (role == "priv-callback")
8084e12cb7SAppaRao Puli     {
8184e12cb7SAppaRao Puli         return "Callback";
8284e12cb7SAppaRao Puli     }
8384e12cb7SAppaRao Puli     else if (role == "priv-user")
8484e12cb7SAppaRao Puli     {
8584e12cb7SAppaRao Puli         return "User";
8684e12cb7SAppaRao Puli     }
8784e12cb7SAppaRao Puli     else if (role == "priv-operator")
8884e12cb7SAppaRao Puli     {
8984e12cb7SAppaRao Puli         return "Operator";
9084e12cb7SAppaRao Puli     }
9184e12cb7SAppaRao Puli     return "";
9284e12cb7SAppaRao Puli }
9354fc587aSNagaraju Goruganti inline std::string getPrivilegeFromRoleId(std::string_view role)
9484e12cb7SAppaRao Puli {
9584e12cb7SAppaRao Puli     if (role == "Administrator")
9684e12cb7SAppaRao Puli     {
9784e12cb7SAppaRao Puli         return "priv-admin";
9884e12cb7SAppaRao Puli     }
9984e12cb7SAppaRao Puli     else if (role == "Callback")
10084e12cb7SAppaRao Puli     {
10184e12cb7SAppaRao Puli         return "priv-callback";
10284e12cb7SAppaRao Puli     }
10384e12cb7SAppaRao Puli     else if (role == "User")
10484e12cb7SAppaRao Puli     {
10584e12cb7SAppaRao Puli         return "priv-user";
10684e12cb7SAppaRao Puli     }
10784e12cb7SAppaRao Puli     else if (role == "Operator")
10884e12cb7SAppaRao Puli     {
10984e12cb7SAppaRao Puli         return "priv-operator";
11084e12cb7SAppaRao Puli     }
11184e12cb7SAppaRao Puli     return "";
11284e12cb7SAppaRao Puli }
113b9b2e0b2SEd Tanous 
1146973a582SRatan Gupta void parseLDAPConfigData(nlohmann::json& json_response,
115ab828d7cSRatan Gupta                          const LDAPConfigData& confData,
116ab828d7cSRatan Gupta                          const std::string& ldapType)
1176973a582SRatan Gupta {
118ab828d7cSRatan Gupta     std::string service =
119ab828d7cSRatan Gupta         (ldapType == "LDAP") ? "LDAPService" : "ActiveDirectoryService";
12037cce918SMarri Devender Rao     nlohmann::json ldap = {
1216973a582SRatan Gupta         {"AccountProviderType", service},
1226973a582SRatan Gupta         {"ServiceEnabled", confData.serviceEnabled},
1236973a582SRatan Gupta         {"ServiceAddresses", nlohmann::json::array({confData.uri})},
1246973a582SRatan Gupta         {"Authentication",
1256973a582SRatan Gupta          {{"AuthenticationType", "UsernameAndPassword"},
1266973a582SRatan Gupta           {"Username", confData.bindDN},
1276973a582SRatan Gupta           {"Password", nullptr}}},
1286973a582SRatan Gupta         {"LDAPService",
1296973a582SRatan Gupta          {{"SearchSettings",
1306973a582SRatan Gupta            {{"BaseDistinguishedNames",
1316973a582SRatan Gupta              nlohmann::json::array({confData.baseDN})},
1326973a582SRatan Gupta             {"UsernameAttribute", confData.userNameAttribute},
1336973a582SRatan Gupta             {"GroupsAttribute", confData.groupAttribute}}}}},
1346973a582SRatan Gupta     };
13554fc587aSNagaraju Goruganti 
13637cce918SMarri Devender Rao     json_response[ldapType].update(std::move(ldap));
13754fc587aSNagaraju Goruganti 
13854fc587aSNagaraju Goruganti     nlohmann::json& roleMapArray = json_response[ldapType]["RemoteRoleMapping"];
13954fc587aSNagaraju Goruganti     roleMapArray = nlohmann::json::array();
14054fc587aSNagaraju Goruganti     for (auto& obj : confData.groupRoleList)
14154fc587aSNagaraju Goruganti     {
14254fc587aSNagaraju Goruganti         BMCWEB_LOG_DEBUG << "Pushing the data groupName="
14354fc587aSNagaraju Goruganti                          << obj.second.groupName << "\n";
14454fc587aSNagaraju Goruganti         roleMapArray.push_back(
14554fc587aSNagaraju Goruganti             {nlohmann::json::array({"RemoteGroup", obj.second.groupName}),
14654fc587aSNagaraju Goruganti              nlohmann::json::array(
14754fc587aSNagaraju Goruganti                  {"LocalRole", getRoleIdFromPrivilege(obj.second.privilege)})});
14854fc587aSNagaraju Goruganti     }
1496973a582SRatan Gupta }
1506973a582SRatan Gupta 
1516973a582SRatan Gupta /**
1526973a582SRatan Gupta  * Function that retrieves all properties for LDAP config object
1536973a582SRatan Gupta  * into JSON
1546973a582SRatan Gupta  */
1556973a582SRatan Gupta template <typename CallbackFunc>
1566973a582SRatan Gupta inline void getLDAPConfigData(const std::string& ldapType,
1576973a582SRatan Gupta                               CallbackFunc&& callback)
1586973a582SRatan Gupta {
15954fc587aSNagaraju Goruganti 
16054fc587aSNagaraju Goruganti     const std::array<const char*, 2> interfaces = {ldapEnableInterface,
16154fc587aSNagaraju Goruganti                                                    ldapConfigInterface};
16254fc587aSNagaraju Goruganti 
16354fc587aSNagaraju Goruganti     crow::connections::systemBus->async_method_call(
16454fc587aSNagaraju Goruganti         [callback, ldapType](const boost::system::error_code ec,
16554fc587aSNagaraju Goruganti                              const GetObjectType& resp) {
16654fc587aSNagaraju Goruganti             LDAPConfigData confData{};
16754fc587aSNagaraju Goruganti             if (ec || resp.empty())
16854fc587aSNagaraju Goruganti             {
16954fc587aSNagaraju Goruganti                 BMCWEB_LOG_ERROR << "DBUS response error during getting of "
17054fc587aSNagaraju Goruganti                                     "service name: "
17154fc587aSNagaraju Goruganti                                  << ec;
17254fc587aSNagaraju Goruganti                 callback(false, confData, ldapType);
17354fc587aSNagaraju Goruganti                 return;
17454fc587aSNagaraju Goruganti             }
17554fc587aSNagaraju Goruganti             std::string service = resp.begin()->first;
17654fc587aSNagaraju Goruganti             crow::connections::systemBus->async_method_call(
17754fc587aSNagaraju Goruganti                 [callback, ldapType](const boost::system::error_code error_code,
1786973a582SRatan Gupta                                      const ManagedObjectType& ldapObjects) {
1796973a582SRatan Gupta                     LDAPConfigData confData{};
1806973a582SRatan Gupta                     if (error_code)
1816973a582SRatan Gupta                     {
182ab828d7cSRatan Gupta                         callback(false, confData, ldapType);
18354fc587aSNagaraju Goruganti                         BMCWEB_LOG_ERROR << "D-Bus responses error: "
18454fc587aSNagaraju Goruganti                                          << error_code;
1856973a582SRatan Gupta                         return;
1866973a582SRatan Gupta                     }
187ab828d7cSRatan Gupta 
188ab828d7cSRatan Gupta                     std::string ldapDbusType;
18954fc587aSNagaraju Goruganti                     std::string searchString;
19054fc587aSNagaraju Goruganti 
191ab828d7cSRatan Gupta                     if (ldapType == "LDAP")
192ab828d7cSRatan Gupta                     {
19354fc587aSNagaraju Goruganti                         ldapDbusType = "xyz.openbmc_project.User.Ldap.Config."
19454fc587aSNagaraju Goruganti                                        "Type.OpenLdap";
19554fc587aSNagaraju Goruganti                         searchString = "openldap";
196ab828d7cSRatan Gupta                     }
197ab828d7cSRatan Gupta                     else if (ldapType == "ActiveDirectory")
198ab828d7cSRatan Gupta                     {
19954fc587aSNagaraju Goruganti                         ldapDbusType =
20054fc587aSNagaraju Goruganti                             "xyz.openbmc_project.User.Ldap.Config.Type."
201ab828d7cSRatan Gupta                             "ActiveDirectory";
20254fc587aSNagaraju Goruganti                         searchString = "active_directory";
203ab828d7cSRatan Gupta                     }
204ab828d7cSRatan Gupta                     else
205ab828d7cSRatan Gupta                     {
20654fc587aSNagaraju Goruganti                         BMCWEB_LOG_ERROR
20754fc587aSNagaraju Goruganti                             << "Can't get the DbusType for the given type="
208ab828d7cSRatan Gupta                             << ldapType;
209ab828d7cSRatan Gupta                         callback(false, confData, ldapType);
210ab828d7cSRatan Gupta                         return;
211ab828d7cSRatan Gupta                     }
212ab828d7cSRatan Gupta 
213ab828d7cSRatan Gupta                     std::string ldapEnableInterfaceStr = ldapEnableInterface;
214ab828d7cSRatan Gupta                     std::string ldapConfigInterfaceStr = ldapConfigInterface;
215ab828d7cSRatan Gupta 
2166973a582SRatan Gupta                     for (const auto& object : ldapObjects)
2176973a582SRatan Gupta                     {
21854fc587aSNagaraju Goruganti                         // let's find the object whose ldap type is equal to the
21954fc587aSNagaraju Goruganti                         // given type
22054fc587aSNagaraju Goruganti                         if (object.first.str.find(searchString) ==
22154fc587aSNagaraju Goruganti                             std::string::npos)
2226973a582SRatan Gupta                         {
223ab828d7cSRatan Gupta                             continue;
224ab828d7cSRatan Gupta                         }
225ab828d7cSRatan Gupta 
2266973a582SRatan Gupta                         for (const auto& interface : object.second)
2276973a582SRatan Gupta                         {
2286973a582SRatan Gupta                             if (interface.first == ldapEnableInterfaceStr)
2296973a582SRatan Gupta                             {
2306973a582SRatan Gupta                                 // rest of the properties are string.
2316973a582SRatan Gupta                                 for (const auto& property : interface.second)
2326973a582SRatan Gupta                                 {
2336973a582SRatan Gupta                                     if (property.first == "Enabled")
2346973a582SRatan Gupta                                     {
2356973a582SRatan Gupta                                         const bool* value =
2366973a582SRatan Gupta                                             std::get_if<bool>(&property.second);
2376973a582SRatan Gupta                                         if (value == nullptr)
2386973a582SRatan Gupta                                         {
2396973a582SRatan Gupta                                             continue;
2406973a582SRatan Gupta                                         }
2416973a582SRatan Gupta                                         confData.serviceEnabled = *value;
2426973a582SRatan Gupta                                         break;
2436973a582SRatan Gupta                                     }
2446973a582SRatan Gupta                                 }
2456973a582SRatan Gupta                             }
2466973a582SRatan Gupta                             else if (interface.first == ldapConfigInterfaceStr)
2476973a582SRatan Gupta                             {
2486973a582SRatan Gupta 
2496973a582SRatan Gupta                                 for (const auto& property : interface.second)
2506973a582SRatan Gupta                                 {
2516973a582SRatan Gupta                                     const std::string* value =
25254fc587aSNagaraju Goruganti                                         std::get_if<std::string>(
25354fc587aSNagaraju Goruganti                                             &property.second);
2546973a582SRatan Gupta                                     if (value == nullptr)
2556973a582SRatan Gupta                                     {
2566973a582SRatan Gupta                                         continue;
2576973a582SRatan Gupta                                     }
2586973a582SRatan Gupta                                     if (property.first == "LDAPServerURI")
2596973a582SRatan Gupta                                     {
2606973a582SRatan Gupta                                         confData.uri = *value;
2616973a582SRatan Gupta                                     }
2626973a582SRatan Gupta                                     else if (property.first == "LDAPBindDN")
2636973a582SRatan Gupta                                     {
2646973a582SRatan Gupta                                         confData.bindDN = *value;
2656973a582SRatan Gupta                                     }
2666973a582SRatan Gupta                                     else if (property.first == "LDAPBaseDN")
2676973a582SRatan Gupta                                     {
2686973a582SRatan Gupta                                         confData.baseDN = *value;
2696973a582SRatan Gupta                                     }
27054fc587aSNagaraju Goruganti                                     else if (property.first ==
27154fc587aSNagaraju Goruganti                                              "LDAPSearchScope")
2726973a582SRatan Gupta                                     {
2736973a582SRatan Gupta                                         confData.searchScope = *value;
2746973a582SRatan Gupta                                     }
27554fc587aSNagaraju Goruganti                                     else if (property.first ==
27654fc587aSNagaraju Goruganti                                              "GroupNameAttribute")
2776973a582SRatan Gupta                                     {
2786973a582SRatan Gupta                                         confData.groupAttribute = *value;
2796973a582SRatan Gupta                                     }
28054fc587aSNagaraju Goruganti                                     else if (property.first ==
28154fc587aSNagaraju Goruganti                                              "UserNameAttribute")
2826973a582SRatan Gupta                                     {
2836973a582SRatan Gupta                                         confData.userNameAttribute = *value;
2846973a582SRatan Gupta                                     }
28554fc587aSNagaraju Goruganti                                     else if (property.first == "LDAPType")
286ab828d7cSRatan Gupta                                     {
28754fc587aSNagaraju Goruganti                                         confData.serverType = *value;
28854fc587aSNagaraju Goruganti                                     }
28954fc587aSNagaraju Goruganti                                 }
29054fc587aSNagaraju Goruganti                             }
29154fc587aSNagaraju Goruganti                             else if (interface.first ==
29254fc587aSNagaraju Goruganti                                      "xyz.openbmc_project.User."
29354fc587aSNagaraju Goruganti                                      "PrivilegeMapperEntry")
29454fc587aSNagaraju Goruganti                             {
29554fc587aSNagaraju Goruganti                                 LDAPRoleMapData roleMapData{};
29654fc587aSNagaraju Goruganti                                 for (const auto& property : interface.second)
29754fc587aSNagaraju Goruganti                                 {
29854fc587aSNagaraju Goruganti                                     const std::string* value =
29954fc587aSNagaraju Goruganti                                         std::get_if<std::string>(
30054fc587aSNagaraju Goruganti                                             &property.second);
30154fc587aSNagaraju Goruganti 
30254fc587aSNagaraju Goruganti                                     if (value == nullptr)
30354fc587aSNagaraju Goruganti                                     {
30454fc587aSNagaraju Goruganti                                         continue;
30554fc587aSNagaraju Goruganti                                     }
30654fc587aSNagaraju Goruganti 
30754fc587aSNagaraju Goruganti                                     if (property.first == "GroupName")
30854fc587aSNagaraju Goruganti                                     {
30954fc587aSNagaraju Goruganti                                         roleMapData.groupName = *value;
31054fc587aSNagaraju Goruganti                                     }
31154fc587aSNagaraju Goruganti                                     else if (property.first == "Privilege")
31254fc587aSNagaraju Goruganti                                     {
31354fc587aSNagaraju Goruganti                                         roleMapData.privilege = *value;
31454fc587aSNagaraju Goruganti                                     }
31554fc587aSNagaraju Goruganti                                 }
31654fc587aSNagaraju Goruganti 
31754fc587aSNagaraju Goruganti                                 confData.groupRoleList.push_back(std::make_pair(
31854fc587aSNagaraju Goruganti                                     object.first.str, roleMapData));
31954fc587aSNagaraju Goruganti                             }
32054fc587aSNagaraju Goruganti                         }
32154fc587aSNagaraju Goruganti                     }
322ab828d7cSRatan Gupta                     callback(true, confData, ldapType);
32354fc587aSNagaraju Goruganti                 },
32454fc587aSNagaraju Goruganti                 service, ldapRootObject, dbusObjManagerIntf,
3256973a582SRatan Gupta                 "GetManagedObjects");
32654fc587aSNagaraju Goruganti         },
32754fc587aSNagaraju Goruganti         mapperBusName, mapperObjectPath, mapperIntf, "GetObject",
32854fc587aSNagaraju Goruganti         ldapConfigObject, interfaces);
3296973a582SRatan Gupta }
3306973a582SRatan Gupta 
3311abe55efSEd Tanous class AccountService : public Node
3321abe55efSEd Tanous {
33388d16c9aSLewanczyk, Dawid   public:
3341abe55efSEd Tanous     AccountService(CrowApp& app) : Node(app, "/redfish/v1/AccountService/")
3351abe55efSEd Tanous     {
3363ebd75f7SEd Tanous         entityPrivileges = {
3374b1b8683SBorawski.Lukasz             {boost::beast::http::verb::get,
3384b1b8683SBorawski.Lukasz              {{"ConfigureUsers"}, {"ConfigureManager"}}},
339e0d918bcSEd Tanous             {boost::beast::http::verb::head, {{"Login"}}},
340e0d918bcSEd Tanous             {boost::beast::http::verb::patch, {{"ConfigureUsers"}}},
341e0d918bcSEd Tanous             {boost::beast::http::verb::put, {{"ConfigureUsers"}}},
342e0d918bcSEd Tanous             {boost::beast::http::verb::delete_, {{"ConfigureUsers"}}},
343e0d918bcSEd Tanous             {boost::beast::http::verb::post, {{"ConfigureUsers"}}}};
34488d16c9aSLewanczyk, Dawid     }
34588d16c9aSLewanczyk, Dawid 
34688d16c9aSLewanczyk, Dawid   private:
3478a07d286SRatan Gupta     /**
3488a07d286SRatan Gupta      * @brief parses the authentication section under the LDAP
3498a07d286SRatan Gupta      * @param input JSON data
3508a07d286SRatan Gupta      * @param asyncResp pointer to the JSON response
3518a07d286SRatan Gupta      * @param userName  userName to be filled from the given JSON.
3528a07d286SRatan Gupta      * @param password  password to be filled from the given JSON.
3538a07d286SRatan Gupta      */
3548a07d286SRatan Gupta     void
3558a07d286SRatan Gupta         parseLDAPAuthenticationJson(nlohmann::json input,
3568a07d286SRatan Gupta                                     const std::shared_ptr<AsyncResp>& asyncResp,
3578a07d286SRatan Gupta                                     std::optional<std::string>& username,
3588a07d286SRatan Gupta                                     std::optional<std::string>& password)
3598a07d286SRatan Gupta     {
3608a07d286SRatan Gupta         std::optional<std::string> authType;
3618a07d286SRatan Gupta 
3628a07d286SRatan Gupta         if (!json_util::readJson(input, asyncResp->res, "AuthenticationType",
3638a07d286SRatan Gupta                                  authType, "Username", username, "Password",
3648a07d286SRatan Gupta                                  password))
3658a07d286SRatan Gupta         {
3668a07d286SRatan Gupta             return;
3678a07d286SRatan Gupta         }
3688a07d286SRatan Gupta         if (!authType)
3698a07d286SRatan Gupta         {
3708a07d286SRatan Gupta             return;
3718a07d286SRatan Gupta         }
3728a07d286SRatan Gupta         if (*authType != "UsernameAndPassword")
3738a07d286SRatan Gupta         {
3748a07d286SRatan Gupta             messages::propertyValueNotInList(asyncResp->res, *authType,
3758a07d286SRatan Gupta                                              "AuthenticationType");
3768a07d286SRatan Gupta             return;
3778a07d286SRatan Gupta         }
3788a07d286SRatan Gupta     }
3798a07d286SRatan Gupta     /**
3808a07d286SRatan Gupta      * @brief parses the LDAPService section under the LDAP
3818a07d286SRatan Gupta      * @param input JSON data
3828a07d286SRatan Gupta      * @param asyncResp pointer to the JSON response
3838a07d286SRatan Gupta      * @param baseDNList baseDN to be filled from the given JSON.
3848a07d286SRatan Gupta      * @param userNameAttribute  userName to be filled from the given JSON.
3858a07d286SRatan Gupta      * @param groupaAttribute  password to be filled from the given JSON.
3868a07d286SRatan Gupta      */
3878a07d286SRatan Gupta 
3888a07d286SRatan Gupta     void parseLDAPServiceJson(
3898a07d286SRatan Gupta         nlohmann::json input, const std::shared_ptr<AsyncResp>& asyncResp,
3908a07d286SRatan Gupta         std::optional<std::vector<std::string>>& baseDNList,
3918a07d286SRatan Gupta         std::optional<std::string>& userNameAttribute,
3928a07d286SRatan Gupta         std::optional<std::string>& groupsAttribute)
3938a07d286SRatan Gupta     {
3948a07d286SRatan Gupta         std::optional<nlohmann::json> searchSettings;
3958a07d286SRatan Gupta 
3968a07d286SRatan Gupta         if (!json_util::readJson(input, asyncResp->res, "SearchSettings",
3978a07d286SRatan Gupta                                  searchSettings))
3988a07d286SRatan Gupta         {
3998a07d286SRatan Gupta             return;
4008a07d286SRatan Gupta         }
4018a07d286SRatan Gupta         if (!searchSettings)
4028a07d286SRatan Gupta         {
4038a07d286SRatan Gupta             return;
4048a07d286SRatan Gupta         }
4058a07d286SRatan Gupta         if (!json_util::readJson(*searchSettings, asyncResp->res,
4068a07d286SRatan Gupta                                  "BaseDistinguishedNames", baseDNList,
4078a07d286SRatan Gupta                                  "UsernameAttribute", userNameAttribute,
4088a07d286SRatan Gupta                                  "GroupsAttribute", groupsAttribute))
4098a07d286SRatan Gupta         {
4108a07d286SRatan Gupta             return;
4118a07d286SRatan Gupta         }
4128a07d286SRatan Gupta     }
4138a07d286SRatan Gupta     /**
4148a07d286SRatan Gupta      * @brief updates the LDAP server address and updates the
4158a07d286SRatan Gupta               json response with the new value.
4168a07d286SRatan Gupta      * @param serviceAddressList address to be updated.
4178a07d286SRatan Gupta      * @param asyncResp pointer to the JSON response
4188a07d286SRatan Gupta      * @param ldapServerElementName Type of LDAP
4198a07d286SRatan Gupta      server(openLDAP/ActiveDirectory)
4208a07d286SRatan Gupta      */
4218a07d286SRatan Gupta 
4228a07d286SRatan Gupta     void handleServiceAddressPatch(
4238a07d286SRatan Gupta         const std::vector<std::string>& serviceAddressList,
4248a07d286SRatan Gupta         const std::shared_ptr<AsyncResp>& asyncResp,
4258a07d286SRatan Gupta         const std::string& ldapServerElementName,
4268a07d286SRatan Gupta         const std::string& ldapConfigObject)
4278a07d286SRatan Gupta     {
4288a07d286SRatan Gupta         crow::connections::systemBus->async_method_call(
4298a07d286SRatan Gupta             [asyncResp, ldapServerElementName,
4308a07d286SRatan Gupta              serviceAddressList](const boost::system::error_code ec) {
4318a07d286SRatan Gupta                 if (ec)
4328a07d286SRatan Gupta                 {
4338a07d286SRatan Gupta                     BMCWEB_LOG_DEBUG
4348a07d286SRatan Gupta                         << "Error Occured in updating the service address";
4358a07d286SRatan Gupta                     messages::internalError(asyncResp->res);
4368a07d286SRatan Gupta                     return;
4378a07d286SRatan Gupta                 }
4388a07d286SRatan Gupta                 std::vector<std::string> modifiedserviceAddressList = {
4398a07d286SRatan Gupta                     serviceAddressList.front()};
4408a07d286SRatan Gupta                 asyncResp->res
4418a07d286SRatan Gupta                     .jsonValue[ldapServerElementName]["ServiceAddresses"] =
4428a07d286SRatan Gupta                     modifiedserviceAddressList;
4438a07d286SRatan Gupta                 if ((serviceAddressList).size() > 1)
4448a07d286SRatan Gupta                 {
4458a07d286SRatan Gupta                     messages::propertyValueModified(asyncResp->res,
4468a07d286SRatan Gupta                                                     "ServiceAddresses",
4478a07d286SRatan Gupta                                                     serviceAddressList.front());
4488a07d286SRatan Gupta                 }
4498a07d286SRatan Gupta                 BMCWEB_LOG_DEBUG << "Updated the service address";
4508a07d286SRatan Gupta             },
4518a07d286SRatan Gupta             ldapDbusService, ldapConfigObject, propertyInterface, "Set",
4528a07d286SRatan Gupta             ldapConfigInterface, "LDAPServerURI",
4538a07d286SRatan Gupta             std::variant<std::string>(serviceAddressList.front()));
4548a07d286SRatan Gupta     }
4558a07d286SRatan Gupta     /**
4568a07d286SRatan Gupta      * @brief updates the LDAP Bind DN and updates the
4578a07d286SRatan Gupta               json response with the new value.
4588a07d286SRatan Gupta      * @param username name of the user which needs to be updated.
4598a07d286SRatan Gupta      * @param asyncResp pointer to the JSON response
4608a07d286SRatan Gupta      * @param ldapServerElementName Type of LDAP
4618a07d286SRatan Gupta      server(openLDAP/ActiveDirectory)
4628a07d286SRatan Gupta      */
4638a07d286SRatan Gupta 
4648a07d286SRatan Gupta     void handleUserNamePatch(const std::string& username,
4658a07d286SRatan Gupta                              const std::shared_ptr<AsyncResp>& asyncResp,
4668a07d286SRatan Gupta                              const std::string& ldapServerElementName,
4678a07d286SRatan Gupta                              const std::string& ldapConfigObject)
4688a07d286SRatan Gupta     {
4698a07d286SRatan Gupta         crow::connections::systemBus->async_method_call(
4708a07d286SRatan Gupta             [asyncResp, username,
4718a07d286SRatan Gupta              ldapServerElementName](const boost::system::error_code ec) {
4728a07d286SRatan Gupta                 if (ec)
4738a07d286SRatan Gupta                 {
4748a07d286SRatan Gupta                     BMCWEB_LOG_DEBUG
4758a07d286SRatan Gupta                         << "Error occured in updating the username";
4768a07d286SRatan Gupta                     messages::internalError(asyncResp->res);
4778a07d286SRatan Gupta                     return;
4788a07d286SRatan Gupta                 }
4798a07d286SRatan Gupta                 asyncResp->res.jsonValue[ldapServerElementName]
4808a07d286SRatan Gupta                                         ["Authentication"]["Username"] =
4818a07d286SRatan Gupta                     username;
4828a07d286SRatan Gupta                 BMCWEB_LOG_DEBUG << "Updated the username";
4838a07d286SRatan Gupta             },
4848a07d286SRatan Gupta             ldapDbusService, ldapConfigObject, propertyInterface, "Set",
4858a07d286SRatan Gupta             ldapConfigInterface, "LDAPBindDN",
4868a07d286SRatan Gupta             std::variant<std::string>(username));
4878a07d286SRatan Gupta     }
4888a07d286SRatan Gupta 
4898a07d286SRatan Gupta     /**
4908a07d286SRatan Gupta      * @brief updates the LDAP password
4918a07d286SRatan Gupta      * @param password : ldap password which needs to be updated.
4928a07d286SRatan Gupta      * @param asyncResp pointer to the JSON response
4938a07d286SRatan Gupta      * @param ldapServerElementName Type of LDAP
4948a07d286SRatan Gupta      *        server(openLDAP/ActiveDirectory)
4958a07d286SRatan Gupta      */
4968a07d286SRatan Gupta 
4978a07d286SRatan Gupta     void handlePasswordPatch(const std::string& password,
4988a07d286SRatan Gupta                              const std::shared_ptr<AsyncResp>& asyncResp,
4998a07d286SRatan Gupta                              const std::string& ldapServerElementName,
5008a07d286SRatan Gupta                              const std::string& ldapConfigObject)
5018a07d286SRatan Gupta     {
5028a07d286SRatan Gupta         crow::connections::systemBus->async_method_call(
5038a07d286SRatan Gupta             [asyncResp, password,
5048a07d286SRatan Gupta              ldapServerElementName](const boost::system::error_code ec) {
5058a07d286SRatan Gupta                 if (ec)
5068a07d286SRatan Gupta                 {
5078a07d286SRatan Gupta                     BMCWEB_LOG_DEBUG
5088a07d286SRatan Gupta                         << "Error occured in updating the password";
5098a07d286SRatan Gupta                     messages::internalError(asyncResp->res);
5108a07d286SRatan Gupta                     return;
5118a07d286SRatan Gupta                 }
5128a07d286SRatan Gupta                 asyncResp->res.jsonValue[ldapServerElementName]
5138a07d286SRatan Gupta                                         ["Authentication"]["Password"] = "";
5148a07d286SRatan Gupta                 BMCWEB_LOG_DEBUG << "Updated the password";
5158a07d286SRatan Gupta             },
5168a07d286SRatan Gupta             ldapDbusService, ldapConfigObject, propertyInterface, "Set",
5178a07d286SRatan Gupta             ldapConfigInterface, "LDAPBindDNPassword",
5188a07d286SRatan Gupta             std::variant<std::string>(password));
5198a07d286SRatan Gupta     }
5208a07d286SRatan Gupta 
5218a07d286SRatan Gupta     /**
5228a07d286SRatan Gupta      * @brief updates the LDAP BaseDN and updates the
5238a07d286SRatan Gupta               json response with the new value.
5248a07d286SRatan Gupta      * @param baseDNList baseDN list which needs to be updated.
5258a07d286SRatan Gupta      * @param asyncResp pointer to the JSON response
5268a07d286SRatan Gupta      * @param ldapServerElementName Type of LDAP
5278a07d286SRatan Gupta      server(openLDAP/ActiveDirectory)
5288a07d286SRatan Gupta      */
5298a07d286SRatan Gupta 
5308a07d286SRatan Gupta     void handleBaseDNPatch(const std::vector<std::string>& baseDNList,
5318a07d286SRatan Gupta                            const std::shared_ptr<AsyncResp>& asyncResp,
5328a07d286SRatan Gupta                            const std::string& ldapServerElementName,
5338a07d286SRatan Gupta                            const std::string& ldapConfigObject)
5348a07d286SRatan Gupta     {
5358a07d286SRatan Gupta         crow::connections::systemBus->async_method_call(
5368a07d286SRatan Gupta             [asyncResp, baseDNList,
5378a07d286SRatan Gupta              ldapServerElementName](const boost::system::error_code ec) {
5388a07d286SRatan Gupta                 if (ec)
5398a07d286SRatan Gupta                 {
5408a07d286SRatan Gupta                     BMCWEB_LOG_DEBUG << "Error Occured in Updating the base DN";
5418a07d286SRatan Gupta                     messages::internalError(asyncResp->res);
5428a07d286SRatan Gupta                     return;
5438a07d286SRatan Gupta                 }
5448a07d286SRatan Gupta                 auto& serverTypeJson =
5458a07d286SRatan Gupta                     asyncResp->res.jsonValue[ldapServerElementName];
5468a07d286SRatan Gupta                 auto& searchSettingsJson =
5478a07d286SRatan Gupta                     serverTypeJson["LDAPService"]["SearchSettings"];
5488a07d286SRatan Gupta                 std::vector<std::string> modifiedBaseDNList = {
5498a07d286SRatan Gupta                     baseDNList.front()};
5508a07d286SRatan Gupta                 searchSettingsJson["BaseDistinguishedNames"] =
5518a07d286SRatan Gupta                     modifiedBaseDNList;
5528a07d286SRatan Gupta                 if (baseDNList.size() > 1)
5538a07d286SRatan Gupta                 {
5548a07d286SRatan Gupta                     messages::propertyValueModified(asyncResp->res,
5558a07d286SRatan Gupta                                                     "BaseDistinguishedNames",
5568a07d286SRatan Gupta                                                     baseDNList.front());
5578a07d286SRatan Gupta                 }
5588a07d286SRatan Gupta                 BMCWEB_LOG_DEBUG << "Updated the base DN";
5598a07d286SRatan Gupta             },
5608a07d286SRatan Gupta             ldapDbusService, ldapConfigObject, propertyInterface, "Set",
5618a07d286SRatan Gupta             ldapConfigInterface, "LDAPBaseDN",
5628a07d286SRatan Gupta             std::variant<std::string>(baseDNList.front()));
5638a07d286SRatan Gupta     }
5648a07d286SRatan Gupta     /**
5658a07d286SRatan Gupta      * @brief updates the LDAP user name attribute and updates the
5668a07d286SRatan Gupta               json response with the new value.
5678a07d286SRatan Gupta      * @param userNameAttribute attribute to be updated.
5688a07d286SRatan Gupta      * @param asyncResp pointer to the JSON response
5698a07d286SRatan Gupta      * @param ldapServerElementName Type of LDAP
5708a07d286SRatan Gupta      server(openLDAP/ActiveDirectory)
5718a07d286SRatan Gupta      */
5728a07d286SRatan Gupta 
5738a07d286SRatan Gupta     void handleUserNameAttrPatch(const std::string& userNameAttribute,
5748a07d286SRatan Gupta                                  const std::shared_ptr<AsyncResp>& asyncResp,
5758a07d286SRatan Gupta                                  const std::string& ldapServerElementName,
5768a07d286SRatan Gupta                                  const std::string& ldapConfigObject)
5778a07d286SRatan Gupta     {
5788a07d286SRatan Gupta         crow::connections::systemBus->async_method_call(
5798a07d286SRatan Gupta             [asyncResp, userNameAttribute,
5808a07d286SRatan Gupta              ldapServerElementName](const boost::system::error_code ec) {
5818a07d286SRatan Gupta                 if (ec)
5828a07d286SRatan Gupta                 {
5838a07d286SRatan Gupta                     BMCWEB_LOG_DEBUG << "Error Occured in Updating the "
5848a07d286SRatan Gupta                                         "username attribute";
5858a07d286SRatan Gupta                     messages::internalError(asyncResp->res);
5868a07d286SRatan Gupta                     return;
5878a07d286SRatan Gupta                 }
5888a07d286SRatan Gupta                 auto& serverTypeJson =
5898a07d286SRatan Gupta                     asyncResp->res.jsonValue[ldapServerElementName];
5908a07d286SRatan Gupta                 auto& searchSettingsJson =
5918a07d286SRatan Gupta                     serverTypeJson["LDAPService"]["SearchSettings"];
5928a07d286SRatan Gupta                 searchSettingsJson["UsernameAttribute"] = userNameAttribute;
5938a07d286SRatan Gupta                 BMCWEB_LOG_DEBUG << "Updated the user name attr.";
5948a07d286SRatan Gupta             },
5958a07d286SRatan Gupta             ldapDbusService, ldapConfigObject, propertyInterface, "Set",
5968a07d286SRatan Gupta             ldapConfigInterface, "UserNameAttribute",
5978a07d286SRatan Gupta             std::variant<std::string>(userNameAttribute));
5988a07d286SRatan Gupta     }
5998a07d286SRatan Gupta     /**
6008a07d286SRatan Gupta      * @brief updates the LDAP group attribute and updates the
6018a07d286SRatan Gupta               json response with the new value.
6028a07d286SRatan Gupta      * @param groupsAttribute attribute to be updated.
6038a07d286SRatan Gupta      * @param asyncResp pointer to the JSON response
6048a07d286SRatan Gupta      * @param ldapServerElementName Type of LDAP
6058a07d286SRatan Gupta      server(openLDAP/ActiveDirectory)
6068a07d286SRatan Gupta      */
6078a07d286SRatan Gupta 
6088a07d286SRatan Gupta     void handleGroupNameAttrPatch(const std::string& groupsAttribute,
6098a07d286SRatan Gupta                                   const std::shared_ptr<AsyncResp>& asyncResp,
6108a07d286SRatan Gupta                                   const std::string& ldapServerElementName,
6118a07d286SRatan Gupta                                   const std::string& ldapConfigObject)
6128a07d286SRatan Gupta     {
6138a07d286SRatan Gupta         crow::connections::systemBus->async_method_call(
6148a07d286SRatan Gupta             [asyncResp, groupsAttribute,
6158a07d286SRatan Gupta              ldapServerElementName](const boost::system::error_code ec) {
6168a07d286SRatan Gupta                 if (ec)
6178a07d286SRatan Gupta                 {
6188a07d286SRatan Gupta                     BMCWEB_LOG_DEBUG << "Error Occured in Updating the "
6198a07d286SRatan Gupta                                         "groupname attribute";
6208a07d286SRatan Gupta                     messages::internalError(asyncResp->res);
6218a07d286SRatan Gupta                     return;
6228a07d286SRatan Gupta                 }
6238a07d286SRatan Gupta                 auto& serverTypeJson =
6248a07d286SRatan Gupta                     asyncResp->res.jsonValue[ldapServerElementName];
6258a07d286SRatan Gupta                 auto& searchSettingsJson =
6268a07d286SRatan Gupta                     serverTypeJson["LDAPService"]["SearchSettings"];
6278a07d286SRatan Gupta                 searchSettingsJson["GroupsAttribute"] = groupsAttribute;
6288a07d286SRatan Gupta                 BMCWEB_LOG_DEBUG << "Updated the groupname attr";
6298a07d286SRatan Gupta             },
6308a07d286SRatan Gupta             ldapDbusService, ldapConfigObject, propertyInterface, "Set",
6318a07d286SRatan Gupta             ldapConfigInterface, "GroupNameAttribute",
6328a07d286SRatan Gupta             std::variant<std::string>(groupsAttribute));
6338a07d286SRatan Gupta     }
6348a07d286SRatan Gupta     /**
6358a07d286SRatan Gupta      * @brief updates the LDAP service enable and updates the
6368a07d286SRatan Gupta               json response with the new value.
6378a07d286SRatan Gupta      * @param input JSON data.
6388a07d286SRatan Gupta      * @param asyncResp pointer to the JSON response
6398a07d286SRatan Gupta      * @param ldapServerElementName Type of LDAP
6408a07d286SRatan Gupta      server(openLDAP/ActiveDirectory)
6418a07d286SRatan Gupta      */
6428a07d286SRatan Gupta 
6438a07d286SRatan Gupta     void handleServiceEnablePatch(bool serviceEnabled,
6448a07d286SRatan Gupta                                   const std::shared_ptr<AsyncResp>& asyncResp,
6458a07d286SRatan Gupta                                   const std::string& ldapServerElementName,
6468a07d286SRatan Gupta                                   const std::string& ldapConfigObject)
6478a07d286SRatan Gupta     {
6488a07d286SRatan Gupta         crow::connections::systemBus->async_method_call(
6498a07d286SRatan Gupta             [asyncResp, serviceEnabled,
6508a07d286SRatan Gupta              ldapServerElementName](const boost::system::error_code ec) {
6518a07d286SRatan Gupta                 if (ec)
6528a07d286SRatan Gupta                 {
6538a07d286SRatan Gupta                     BMCWEB_LOG_DEBUG
6548a07d286SRatan Gupta                         << "Error Occured in Updating the service enable";
6558a07d286SRatan Gupta                     messages::internalError(asyncResp->res);
6568a07d286SRatan Gupta                     return;
6578a07d286SRatan Gupta                 }
6588a07d286SRatan Gupta                 asyncResp->res
6598a07d286SRatan Gupta                     .jsonValue[ldapServerElementName]["ServiceEnabled"] =
6608a07d286SRatan Gupta                     serviceEnabled;
6618a07d286SRatan Gupta                 BMCWEB_LOG_DEBUG << "Updated Service enable = "
6628a07d286SRatan Gupta                                  << serviceEnabled;
6638a07d286SRatan Gupta             },
6648a07d286SRatan Gupta             ldapDbusService, ldapConfigObject, propertyInterface, "Set",
6658a07d286SRatan Gupta             ldapEnableInterface, "Enabled", std::variant<bool>(serviceEnabled));
6668a07d286SRatan Gupta     }
6678a07d286SRatan Gupta 
6688a07d286SRatan Gupta     /**
6698a07d286SRatan Gupta      * @brief Get the required values from the given JSON, validates the
6708a07d286SRatan Gupta      *        value and create the LDAP config object.
6718a07d286SRatan Gupta      * @param input JSON data
6728a07d286SRatan Gupta      * @param asyncResp pointer to the JSON response
6738a07d286SRatan Gupta      * @param serverType Type of LDAP server(openLDAP/ActiveDirectory)
6748a07d286SRatan Gupta      */
6758a07d286SRatan Gupta 
6768a07d286SRatan Gupta     void handleLDAPPatch(nlohmann::json& input,
6778a07d286SRatan Gupta                          const std::shared_ptr<AsyncResp>& asyncResp,
6788a07d286SRatan Gupta                          const crow::Request& req,
6798a07d286SRatan Gupta                          const std::vector<std::string>& params,
6808a07d286SRatan Gupta                          const std::string& serverType)
6818a07d286SRatan Gupta     {
682eb2bbe56SRatan Gupta         std::string dbusObjectPath;
683eb2bbe56SRatan Gupta         if (serverType == "ActiveDirectory")
684eb2bbe56SRatan Gupta         {
685eb2bbe56SRatan Gupta             dbusObjectPath = ADConfigObject;
686eb2bbe56SRatan Gupta         }
687eb2bbe56SRatan Gupta         else if (serverType == "LDAP")
688eb2bbe56SRatan Gupta         {
689eb2bbe56SRatan Gupta             dbusObjectPath = ldapConfigObject;
690eb2bbe56SRatan Gupta         }
691eb2bbe56SRatan Gupta 
6928a07d286SRatan Gupta         std::optional<nlohmann::json> authentication;
6938a07d286SRatan Gupta         std::optional<nlohmann::json> ldapService;
6948a07d286SRatan Gupta         std::optional<std::string> accountProviderType;
6958a07d286SRatan Gupta         std::optional<std::vector<std::string>> serviceAddressList;
6968a07d286SRatan Gupta         std::optional<bool> serviceEnabled;
6978a07d286SRatan Gupta         std::optional<std::vector<std::string>> baseDNList;
6988a07d286SRatan Gupta         std::optional<std::string> userNameAttribute;
6998a07d286SRatan Gupta         std::optional<std::string> groupsAttribute;
7008a07d286SRatan Gupta         std::optional<std::string> userName;
7018a07d286SRatan Gupta         std::optional<std::string> password;
7028a07d286SRatan Gupta 
7038a07d286SRatan Gupta         if (!json_util::readJson(input, asyncResp->res, "Authentication",
7048a07d286SRatan Gupta                                  authentication, "LDAPService", ldapService,
7058a07d286SRatan Gupta                                  "ServiceAddresses", serviceAddressList,
7068a07d286SRatan Gupta                                  "AccountProviderType", accountProviderType,
707d4b5443fSEd Tanous                                  "ServiceEnabled", serviceEnabled))
7088a07d286SRatan Gupta         {
7098a07d286SRatan Gupta             return;
7108a07d286SRatan Gupta         }
7118a07d286SRatan Gupta 
7128a07d286SRatan Gupta         if (authentication)
7138a07d286SRatan Gupta         {
7148a07d286SRatan Gupta             parseLDAPAuthenticationJson(*authentication, asyncResp, userName,
7158a07d286SRatan Gupta                                         password);
7168a07d286SRatan Gupta         }
7178a07d286SRatan Gupta         if (ldapService)
7188a07d286SRatan Gupta         {
7198a07d286SRatan Gupta             parseLDAPServiceJson(*ldapService, asyncResp, baseDNList,
7208a07d286SRatan Gupta                                  userNameAttribute, groupsAttribute);
7218a07d286SRatan Gupta         }
7228a07d286SRatan Gupta         if (accountProviderType)
7238a07d286SRatan Gupta         {
7248a07d286SRatan Gupta             messages::propertyNotWritable(asyncResp->res,
7258a07d286SRatan Gupta                                           "AccountProviderType");
7268a07d286SRatan Gupta         }
7278a07d286SRatan Gupta         if (serviceAddressList)
7288a07d286SRatan Gupta         {
7298a07d286SRatan Gupta             if ((*serviceAddressList).size() == 0)
7308a07d286SRatan Gupta             {
7318a07d286SRatan Gupta                 messages::propertyValueNotInList(asyncResp->res, "[]",
7328a07d286SRatan Gupta                                                  "ServiceAddress");
7338a07d286SRatan Gupta                 return;
7348a07d286SRatan Gupta             }
7358a07d286SRatan Gupta         }
7368a07d286SRatan Gupta         if (baseDNList)
7378a07d286SRatan Gupta         {
7388a07d286SRatan Gupta             if ((*baseDNList).size() == 0)
7398a07d286SRatan Gupta             {
7408a07d286SRatan Gupta                 messages::propertyValueNotInList(asyncResp->res, "[]",
7418a07d286SRatan Gupta                                                  "BaseDistinguishedNames");
7428a07d286SRatan Gupta                 return;
7438a07d286SRatan Gupta             }
7448a07d286SRatan Gupta         }
7458a07d286SRatan Gupta 
7468a07d286SRatan Gupta         // nothing to update, then return
7478a07d286SRatan Gupta         if (!userName && !password && !serviceAddressList && !baseDNList &&
748d4b5443fSEd Tanous             !userNameAttribute && !groupsAttribute && !serviceEnabled)
7498a07d286SRatan Gupta         {
7508a07d286SRatan Gupta             return;
7518a07d286SRatan Gupta         }
7528a07d286SRatan Gupta 
7538a07d286SRatan Gupta         // Get the existing resource first then keep modifying
7548a07d286SRatan Gupta         // whenever any property gets updated.
755ab828d7cSRatan Gupta         getLDAPConfigData(serverType, [this, asyncResp, userName, password,
756ab828d7cSRatan Gupta                                        baseDNList, userNameAttribute,
757ab828d7cSRatan Gupta                                        groupsAttribute, accountProviderType,
758eb2bbe56SRatan Gupta                                        serviceAddressList, serviceEnabled,
759d4b5443fSEd Tanous                                        dbusObjectPath](
760ab828d7cSRatan Gupta                                           bool success, LDAPConfigData confData,
761ab828d7cSRatan Gupta                                           const std::string& serverType) {
7628a07d286SRatan Gupta             if (!success)
7638a07d286SRatan Gupta             {
7648a07d286SRatan Gupta                 messages::internalError(asyncResp->res);
7658a07d286SRatan Gupta                 return;
7668a07d286SRatan Gupta             }
767ab828d7cSRatan Gupta             parseLDAPConfigData(asyncResp->res.jsonValue, confData, serverType);
7688a07d286SRatan Gupta             if (confData.serviceEnabled)
7698a07d286SRatan Gupta             {
7708a07d286SRatan Gupta                 // Disable the service first and update the rest of
7718a07d286SRatan Gupta                 // the properties.
7728a07d286SRatan Gupta                 handleServiceEnablePatch(false, asyncResp, serverType,
773eb2bbe56SRatan Gupta                                          dbusObjectPath);
7748a07d286SRatan Gupta             }
7758a07d286SRatan Gupta 
7768a07d286SRatan Gupta             if (serviceAddressList)
7778a07d286SRatan Gupta             {
7788a07d286SRatan Gupta                 handleServiceAddressPatch(*serviceAddressList, asyncResp,
779eb2bbe56SRatan Gupta                                           serverType, dbusObjectPath);
7808a07d286SRatan Gupta             }
7818a07d286SRatan Gupta             if (userName)
7828a07d286SRatan Gupta             {
7838a07d286SRatan Gupta                 handleUserNamePatch(*userName, asyncResp, serverType,
784eb2bbe56SRatan Gupta                                     dbusObjectPath);
7858a07d286SRatan Gupta             }
7868a07d286SRatan Gupta             if (password)
7878a07d286SRatan Gupta             {
7888a07d286SRatan Gupta                 handlePasswordPatch(*password, asyncResp, serverType,
789eb2bbe56SRatan Gupta                                     dbusObjectPath);
7908a07d286SRatan Gupta             }
7918a07d286SRatan Gupta 
7928a07d286SRatan Gupta             if (baseDNList)
7938a07d286SRatan Gupta             {
7948a07d286SRatan Gupta                 handleBaseDNPatch(*baseDNList, asyncResp, serverType,
795eb2bbe56SRatan Gupta                                   dbusObjectPath);
7968a07d286SRatan Gupta             }
7978a07d286SRatan Gupta             if (userNameAttribute)
7988a07d286SRatan Gupta             {
7998a07d286SRatan Gupta                 handleUserNameAttrPatch(*userNameAttribute, asyncResp,
800eb2bbe56SRatan Gupta                                         serverType, dbusObjectPath);
8018a07d286SRatan Gupta             }
8028a07d286SRatan Gupta             if (groupsAttribute)
8038a07d286SRatan Gupta             {
8048a07d286SRatan Gupta                 handleGroupNameAttrPatch(*groupsAttribute, asyncResp,
805eb2bbe56SRatan Gupta                                          serverType, dbusObjectPath);
8068a07d286SRatan Gupta             }
8078a07d286SRatan Gupta             if (serviceEnabled)
8088a07d286SRatan Gupta             {
8098a07d286SRatan Gupta                 // if user has given the value as true then enable
8108a07d286SRatan Gupta                 // the service. if user has given false then no-op
8118a07d286SRatan Gupta                 // as service is already stopped.
8128a07d286SRatan Gupta                 if (*serviceEnabled)
8138a07d286SRatan Gupta                 {
8148a07d286SRatan Gupta                     handleServiceEnablePatch(*serviceEnabled, asyncResp,
815eb2bbe56SRatan Gupta                                              serverType, dbusObjectPath);
8168a07d286SRatan Gupta                 }
8178a07d286SRatan Gupta             }
8188a07d286SRatan Gupta             else
8198a07d286SRatan Gupta             {
8208a07d286SRatan Gupta                 // if user has not given the service enabled value
8218a07d286SRatan Gupta                 // then revert it to the same state as it was
8228a07d286SRatan Gupta                 // before.
8238a07d286SRatan Gupta                 handleServiceEnablePatch(confData.serviceEnabled, asyncResp,
824eb2bbe56SRatan Gupta                                          serverType, dbusObjectPath);
8258a07d286SRatan Gupta             }
8268a07d286SRatan Gupta         });
8278a07d286SRatan Gupta     }
828d4b5443fSEd Tanous 
82955c7b7a2SEd Tanous     void doGet(crow::Response& res, const crow::Request& req,
8301abe55efSEd Tanous                const std::vector<std::string>& params) override
8311abe55efSEd Tanous     {
8323d958bbcSAppaRao Puli         auto asyncResp = std::make_shared<AsyncResp>(res);
8333d958bbcSAppaRao Puli         res.jsonValue = {
8343d958bbcSAppaRao Puli             {"@odata.context", "/redfish/v1/"
8353d958bbcSAppaRao Puli                                "$metadata#AccountService.AccountService"},
8363d958bbcSAppaRao Puli             {"@odata.id", "/redfish/v1/AccountService"},
8373d958bbcSAppaRao Puli             {"@odata.type", "#AccountService."
83837cce918SMarri Devender Rao                             "v1_4_0.AccountService"},
8393d958bbcSAppaRao Puli             {"Id", "AccountService"},
8403d958bbcSAppaRao Puli             {"Name", "Account Service"},
8413d958bbcSAppaRao Puli             {"Description", "Account Service"},
8423d958bbcSAppaRao Puli             {"ServiceEnabled", true},
843343ff2e1SAppaRao Puli             {"MaxPasswordLength", 20},
8443d958bbcSAppaRao Puli             {"Accounts",
8453d958bbcSAppaRao Puli              {{"@odata.id", "/redfish/v1/AccountService/Accounts"}}},
84637cce918SMarri Devender Rao             {"Roles", {{"@odata.id", "/redfish/v1/AccountService/Roles"}}},
84737cce918SMarri Devender Rao             {"LDAP",
84837cce918SMarri Devender Rao              {{"Certificates",
84937cce918SMarri Devender Rao                {{"@odata.id",
85037cce918SMarri Devender Rao                  "/redfish/v1/AccountService/LDAP/Certificates"}}}}}};
8513d958bbcSAppaRao Puli         crow::connections::systemBus->async_method_call(
8523d958bbcSAppaRao Puli             [asyncResp](
8533d958bbcSAppaRao Puli                 const boost::system::error_code ec,
8543d958bbcSAppaRao Puli                 const std::vector<std::pair<
855abf2add6SEd Tanous                     std::string, std::variant<uint32_t, uint16_t, uint8_t>>>&
8563d958bbcSAppaRao Puli                     propertiesList) {
8573d958bbcSAppaRao Puli                 if (ec)
8583d958bbcSAppaRao Puli                 {
8593d958bbcSAppaRao Puli                     messages::internalError(asyncResp->res);
8603d958bbcSAppaRao Puli                     return;
8613d958bbcSAppaRao Puli                 }
8623d958bbcSAppaRao Puli                 BMCWEB_LOG_DEBUG << "Got " << propertiesList.size()
8633d958bbcSAppaRao Puli                                  << "properties for AccountService";
8643d958bbcSAppaRao Puli                 for (const std::pair<std::string,
865abf2add6SEd Tanous                                      std::variant<uint32_t, uint16_t, uint8_t>>&
8663d958bbcSAppaRao Puli                          property : propertiesList)
8673d958bbcSAppaRao Puli                 {
8683d958bbcSAppaRao Puli                     if (property.first == "MinPasswordLength")
8693d958bbcSAppaRao Puli                     {
8703d958bbcSAppaRao Puli                         const uint8_t* value =
871abf2add6SEd Tanous                             std::get_if<uint8_t>(&property.second);
8723d958bbcSAppaRao Puli                         if (value != nullptr)
8733d958bbcSAppaRao Puli                         {
8743d958bbcSAppaRao Puli                             asyncResp->res.jsonValue["MinPasswordLength"] =
8753d958bbcSAppaRao Puli                                 *value;
8763d958bbcSAppaRao Puli                         }
8773d958bbcSAppaRao Puli                     }
8783d958bbcSAppaRao Puli                     if (property.first == "AccountUnlockTimeout")
8793d958bbcSAppaRao Puli                     {
8803d958bbcSAppaRao Puli                         const uint32_t* value =
881abf2add6SEd Tanous                             std::get_if<uint32_t>(&property.second);
8823d958bbcSAppaRao Puli                         if (value != nullptr)
8833d958bbcSAppaRao Puli                         {
8843d958bbcSAppaRao Puli                             asyncResp->res.jsonValue["AccountLockoutDuration"] =
8853d958bbcSAppaRao Puli                                 *value;
8863d958bbcSAppaRao Puli                         }
8873d958bbcSAppaRao Puli                     }
8883d958bbcSAppaRao Puli                     if (property.first == "MaxLoginAttemptBeforeLockout")
8893d958bbcSAppaRao Puli                     {
8903d958bbcSAppaRao Puli                         const uint16_t* value =
891abf2add6SEd Tanous                             std::get_if<uint16_t>(&property.second);
8923d958bbcSAppaRao Puli                         if (value != nullptr)
8933d958bbcSAppaRao Puli                         {
8943d958bbcSAppaRao Puli                             asyncResp->res
8953d958bbcSAppaRao Puli                                 .jsonValue["AccountLockoutThreshold"] = *value;
8963d958bbcSAppaRao Puli                         }
8973d958bbcSAppaRao Puli                     }
8983d958bbcSAppaRao Puli                 }
8993d958bbcSAppaRao Puli             },
9003d958bbcSAppaRao Puli             "xyz.openbmc_project.User.Manager", "/xyz/openbmc_project/user",
9013d958bbcSAppaRao Puli             "org.freedesktop.DBus.Properties", "GetAll",
9023d958bbcSAppaRao Puli             "xyz.openbmc_project.User.AccountPolicy");
9036973a582SRatan Gupta 
904ab828d7cSRatan Gupta         auto callback = [asyncResp](bool success, LDAPConfigData& confData,
905ab828d7cSRatan Gupta                                     const std::string& ldapType) {
906ab828d7cSRatan Gupta             parseLDAPConfigData(asyncResp->res.jsonValue, confData, ldapType);
907ab828d7cSRatan Gupta         };
908ab828d7cSRatan Gupta 
909ab828d7cSRatan Gupta         getLDAPConfigData("LDAP", callback);
910ab828d7cSRatan Gupta         getLDAPConfigData("ActiveDirectory", callback);
9113d958bbcSAppaRao Puli     }
9126973a582SRatan Gupta 
9133d958bbcSAppaRao Puli     void doPatch(crow::Response& res, const crow::Request& req,
9143d958bbcSAppaRao Puli                  const std::vector<std::string>& params) override
9153d958bbcSAppaRao Puli     {
9163d958bbcSAppaRao Puli         auto asyncResp = std::make_shared<AsyncResp>(res);
9173d958bbcSAppaRao Puli 
9183d958bbcSAppaRao Puli         std::optional<uint32_t> unlockTimeout;
9193d958bbcSAppaRao Puli         std::optional<uint16_t> lockoutThreshold;
92019fb6e71SRatan Gupta         std::optional<uint16_t> minPasswordLength;
92119fb6e71SRatan Gupta         std::optional<uint16_t> maxPasswordLength;
9228a07d286SRatan Gupta         std::optional<nlohmann::json> ldapObject;
923eb2bbe56SRatan Gupta         std::optional<nlohmann::json> activeDirectoryObject;
92419fb6e71SRatan Gupta 
9253d958bbcSAppaRao Puli         if (!json_util::readJson(req, res, "AccountLockoutDuration",
9263d958bbcSAppaRao Puli                                  unlockTimeout, "AccountLockoutThreshold",
92719fb6e71SRatan Gupta                                  lockoutThreshold, "MaxPasswordLength",
92819fb6e71SRatan Gupta                                  maxPasswordLength, "MinPasswordLength",
929eb2bbe56SRatan Gupta                                  minPasswordLength, "LDAP", ldapObject,
930eb2bbe56SRatan Gupta                                  "ActiveDirectory", activeDirectoryObject))
9313d958bbcSAppaRao Puli         {
9323d958bbcSAppaRao Puli             return;
9333d958bbcSAppaRao Puli         }
93419fb6e71SRatan Gupta 
93519fb6e71SRatan Gupta         if (minPasswordLength)
93619fb6e71SRatan Gupta         {
93719fb6e71SRatan Gupta             messages::propertyNotWritable(asyncResp->res, "MinPasswordLength");
93819fb6e71SRatan Gupta         }
93919fb6e71SRatan Gupta 
94019fb6e71SRatan Gupta         if (maxPasswordLength)
94119fb6e71SRatan Gupta         {
94219fb6e71SRatan Gupta             messages::propertyNotWritable(asyncResp->res, "MaxPasswordLength");
94319fb6e71SRatan Gupta         }
94419fb6e71SRatan Gupta 
9458a07d286SRatan Gupta         if (ldapObject)
9468a07d286SRatan Gupta         {
9478a07d286SRatan Gupta             handleLDAPPatch(*ldapObject, asyncResp, req, params, "LDAP");
9488a07d286SRatan Gupta         }
9498a07d286SRatan Gupta 
950eb2bbe56SRatan Gupta         if (activeDirectoryObject)
951eb2bbe56SRatan Gupta         {
952eb2bbe56SRatan Gupta             handleLDAPPatch(*activeDirectoryObject, asyncResp, req, params,
953eb2bbe56SRatan Gupta                             "ActiveDirectory");
954eb2bbe56SRatan Gupta         }
955eb2bbe56SRatan Gupta 
9563d958bbcSAppaRao Puli         if (unlockTimeout)
9573d958bbcSAppaRao Puli         {
9583d958bbcSAppaRao Puli             crow::connections::systemBus->async_method_call(
9593d958bbcSAppaRao Puli                 [asyncResp](const boost::system::error_code ec) {
9603d958bbcSAppaRao Puli                     if (ec)
9613d958bbcSAppaRao Puli                     {
9623d958bbcSAppaRao Puli                         messages::internalError(asyncResp->res);
9633d958bbcSAppaRao Puli                         return;
9643d958bbcSAppaRao Puli                     }
965add6133bSRatan Gupta                     messages::success(asyncResp->res);
9663d958bbcSAppaRao Puli                 },
9673d958bbcSAppaRao Puli                 "xyz.openbmc_project.User.Manager", "/xyz/openbmc_project/user",
9683d958bbcSAppaRao Puli                 "org.freedesktop.DBus.Properties", "Set",
9693d958bbcSAppaRao Puli                 "xyz.openbmc_project.User.AccountPolicy",
970abf2add6SEd Tanous                 "AccountUnlockTimeout", std::variant<uint32_t>(*unlockTimeout));
9713d958bbcSAppaRao Puli         }
9723d958bbcSAppaRao Puli         if (lockoutThreshold)
9733d958bbcSAppaRao Puli         {
9743d958bbcSAppaRao Puli             crow::connections::systemBus->async_method_call(
9753d958bbcSAppaRao Puli                 [asyncResp](const boost::system::error_code ec) {
9763d958bbcSAppaRao Puli                     if (ec)
9773d958bbcSAppaRao Puli                     {
9783d958bbcSAppaRao Puli                         messages::internalError(asyncResp->res);
9793d958bbcSAppaRao Puli                         return;
9803d958bbcSAppaRao Puli                     }
981add6133bSRatan Gupta                     messages::success(asyncResp->res);
9823d958bbcSAppaRao Puli                 },
9833d958bbcSAppaRao Puli                 "xyz.openbmc_project.User.Manager", "/xyz/openbmc_project/user",
9843d958bbcSAppaRao Puli                 "org.freedesktop.DBus.Properties", "Set",
9853d958bbcSAppaRao Puli                 "xyz.openbmc_project.User.AccountPolicy",
9863d958bbcSAppaRao Puli                 "MaxLoginAttemptBeforeLockout",
987abf2add6SEd Tanous                 std::variant<uint16_t>(*lockoutThreshold));
9883d958bbcSAppaRao Puli         }
98988d16c9aSLewanczyk, Dawid     }
99088d16c9aSLewanczyk, Dawid };
991f00032dbSTanous 
992b9b2e0b2SEd Tanous class AccountsCollection : public Node
993b9b2e0b2SEd Tanous {
994b9b2e0b2SEd Tanous   public:
995b9b2e0b2SEd Tanous     AccountsCollection(CrowApp& app) :
996b9b2e0b2SEd Tanous         Node(app, "/redfish/v1/AccountService/Accounts/")
997b9b2e0b2SEd Tanous     {
998b9b2e0b2SEd Tanous         entityPrivileges = {
999b9b2e0b2SEd Tanous             {boost::beast::http::verb::get,
1000b9b2e0b2SEd Tanous              {{"ConfigureUsers"}, {"ConfigureManager"}}},
1001b9b2e0b2SEd Tanous             {boost::beast::http::verb::head, {{"Login"}}},
1002b9b2e0b2SEd Tanous             {boost::beast::http::verb::patch, {{"ConfigureUsers"}}},
1003b9b2e0b2SEd Tanous             {boost::beast::http::verb::put, {{"ConfigureUsers"}}},
1004b9b2e0b2SEd Tanous             {boost::beast::http::verb::delete_, {{"ConfigureUsers"}}},
1005b9b2e0b2SEd Tanous             {boost::beast::http::verb::post, {{"ConfigureUsers"}}}};
1006b9b2e0b2SEd Tanous     }
1007b9b2e0b2SEd Tanous 
1008b9b2e0b2SEd Tanous   private:
1009b9b2e0b2SEd Tanous     void doGet(crow::Response& res, const crow::Request& req,
1010b9b2e0b2SEd Tanous                const std::vector<std::string>& params) override
1011b9b2e0b2SEd Tanous     {
1012b9b2e0b2SEd Tanous         auto asyncResp = std::make_shared<AsyncResp>(res);
10130f74e643SEd Tanous         res.jsonValue = {{"@odata.context",
10140f74e643SEd Tanous                           "/redfish/v1/"
10150f74e643SEd Tanous                           "$metadata#ManagerAccountCollection."
10160f74e643SEd Tanous                           "ManagerAccountCollection"},
10170f74e643SEd Tanous                          {"@odata.id", "/redfish/v1/AccountService/Accounts"},
10180f74e643SEd Tanous                          {"@odata.type", "#ManagerAccountCollection."
10190f74e643SEd Tanous                                          "ManagerAccountCollection"},
10200f74e643SEd Tanous                          {"Name", "Accounts Collection"},
10210f74e643SEd Tanous                          {"Description", "BMC User Accounts"}};
10220f74e643SEd Tanous 
1023b9b2e0b2SEd Tanous         crow::connections::systemBus->async_method_call(
1024b9b2e0b2SEd Tanous             [asyncResp](const boost::system::error_code ec,
1025b9b2e0b2SEd Tanous                         const ManagedObjectType& users) {
1026b9b2e0b2SEd Tanous                 if (ec)
1027b9b2e0b2SEd Tanous                 {
1028f12894f8SJason M. Bills                     messages::internalError(asyncResp->res);
1029b9b2e0b2SEd Tanous                     return;
1030b9b2e0b2SEd Tanous                 }
1031b9b2e0b2SEd Tanous 
1032b9b2e0b2SEd Tanous                 nlohmann::json& memberArray =
1033b9b2e0b2SEd Tanous                     asyncResp->res.jsonValue["Members"];
1034b9b2e0b2SEd Tanous                 memberArray = nlohmann::json::array();
1035b9b2e0b2SEd Tanous 
1036b9b2e0b2SEd Tanous                 asyncResp->res.jsonValue["Members@odata.count"] = users.size();
1037b9b2e0b2SEd Tanous                 for (auto& user : users)
1038b9b2e0b2SEd Tanous                 {
1039b9b2e0b2SEd Tanous                     const std::string& path =
1040b9b2e0b2SEd Tanous                         static_cast<const std::string&>(user.first);
1041b9b2e0b2SEd Tanous                     std::size_t lastIndex = path.rfind("/");
1042b9b2e0b2SEd Tanous                     if (lastIndex == std::string::npos)
1043b9b2e0b2SEd Tanous                     {
1044b9b2e0b2SEd Tanous                         lastIndex = 0;
1045b9b2e0b2SEd Tanous                     }
1046b9b2e0b2SEd Tanous                     else
1047b9b2e0b2SEd Tanous                     {
1048b9b2e0b2SEd Tanous                         lastIndex += 1;
1049b9b2e0b2SEd Tanous                     }
1050b9b2e0b2SEd Tanous                     memberArray.push_back(
1051b9b2e0b2SEd Tanous                         {{"@odata.id", "/redfish/v1/AccountService/Accounts/" +
1052b9b2e0b2SEd Tanous                                            path.substr(lastIndex)}});
1053b9b2e0b2SEd Tanous                 }
1054b9b2e0b2SEd Tanous             },
1055b9b2e0b2SEd Tanous             "xyz.openbmc_project.User.Manager", "/xyz/openbmc_project/user",
1056b9b2e0b2SEd Tanous             "org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
1057b9b2e0b2SEd Tanous     }
105804ae99ecSEd Tanous     void doPost(crow::Response& res, const crow::Request& req,
105904ae99ecSEd Tanous                 const std::vector<std::string>& params) override
106004ae99ecSEd Tanous     {
106104ae99ecSEd Tanous         auto asyncResp = std::make_shared<AsyncResp>(res);
106204ae99ecSEd Tanous 
10639712f8acSEd Tanous         std::string username;
10649712f8acSEd Tanous         std::string password;
1065a24526dcSEd Tanous         std::optional<std::string> roleId("User");
1066a24526dcSEd Tanous         std::optional<bool> enabled = true;
10679712f8acSEd Tanous         if (!json_util::readJson(req, res, "UserName", username, "Password",
10689712f8acSEd Tanous                                  password, "RoleId", roleId, "Enabled",
10699712f8acSEd Tanous                                  enabled))
107004ae99ecSEd Tanous         {
107104ae99ecSEd Tanous             return;
107204ae99ecSEd Tanous         }
107304ae99ecSEd Tanous 
107454fc587aSNagaraju Goruganti         std::string priv = getPrivilegeFromRoleId(*roleId);
107584e12cb7SAppaRao Puli         if (priv.empty())
107604ae99ecSEd Tanous         {
1077f12894f8SJason M. Bills             messages::propertyValueNotInList(asyncResp->res, *roleId, "RoleId");
107804ae99ecSEd Tanous             return;
107904ae99ecSEd Tanous         }
10809712f8acSEd Tanous         roleId = priv;
108104ae99ecSEd Tanous 
1082*599c71d8SAyushi Smriti         // Reading AllGroups property
1083*599c71d8SAyushi Smriti         crow::connections::systemBus->async_method_call(
1084*599c71d8SAyushi Smriti             [asyncResp, username, password{std::move(password)}, roleId,
1085*599c71d8SAyushi Smriti              enabled](const boost::system::error_code ec,
1086*599c71d8SAyushi Smriti                       const std::variant<std::vector<std::string>>& allGroups) {
1087*599c71d8SAyushi Smriti                 if (ec)
1088*599c71d8SAyushi Smriti                 {
1089*599c71d8SAyushi Smriti                     BMCWEB_LOG_DEBUG << "ERROR with async_method_call";
1090*599c71d8SAyushi Smriti                     messages::internalError(asyncResp->res);
1091*599c71d8SAyushi Smriti                     return;
1092*599c71d8SAyushi Smriti                 }
1093*599c71d8SAyushi Smriti 
1094*599c71d8SAyushi Smriti                 const std::vector<std::string>* allGroupsList =
1095*599c71d8SAyushi Smriti                     std::get_if<std::vector<std::string>>(&allGroups);
1096*599c71d8SAyushi Smriti 
1097*599c71d8SAyushi Smriti                 if (allGroupsList == nullptr || allGroupsList->empty())
1098*599c71d8SAyushi Smriti                 {
1099*599c71d8SAyushi Smriti                     messages::internalError(asyncResp->res);
1100*599c71d8SAyushi Smriti                     return;
1101*599c71d8SAyushi Smriti                 }
1102*599c71d8SAyushi Smriti 
110304ae99ecSEd Tanous                 crow::connections::systemBus->async_method_call(
11049712f8acSEd Tanous                     [asyncResp, username, password{std::move(password)}](
110504ae99ecSEd Tanous                         const boost::system::error_code ec) {
110604ae99ecSEd Tanous                         if (ec)
110704ae99ecSEd Tanous                         {
110804ae99ecSEd Tanous                             messages::resourceAlreadyExists(
1109*599c71d8SAyushi Smriti                                 asyncResp->res,
1110*599c71d8SAyushi Smriti                                 "#ManagerAccount.v1_0_3.ManagerAccount",
1111f12894f8SJason M. Bills                                 "UserName", username);
111204ae99ecSEd Tanous                             return;
111304ae99ecSEd Tanous                         }
111404ae99ecSEd Tanous 
111504ae99ecSEd Tanous                         if (!pamUpdatePassword(username, password))
111604ae99ecSEd Tanous                         {
1117*599c71d8SAyushi Smriti                             // At this point we have a user that's been created,
1118*599c71d8SAyushi Smriti                             // but the password set failed.Something is wrong,
1119*599c71d8SAyushi Smriti                             // so delete the user that we've already created
112004ae99ecSEd Tanous                             crow::connections::systemBus->async_method_call(
1121*599c71d8SAyushi Smriti                                 [asyncResp](
1122*599c71d8SAyushi Smriti                                     const boost::system::error_code ec) {
112304ae99ecSEd Tanous                                     if (ec)
112404ae99ecSEd Tanous                                     {
1125f12894f8SJason M. Bills                                         messages::internalError(asyncResp->res);
112604ae99ecSEd Tanous                                         return;
112704ae99ecSEd Tanous                                     }
112804ae99ecSEd Tanous 
1129*599c71d8SAyushi Smriti                                     messages::invalidObject(asyncResp->res,
1130*599c71d8SAyushi Smriti                                                             "Password");
113104ae99ecSEd Tanous                                 },
113204ae99ecSEd Tanous                                 "xyz.openbmc_project.User.Manager",
113304ae99ecSEd Tanous                                 "/xyz/openbmc_project/user/" + username,
113404ae99ecSEd Tanous                                 "xyz.openbmc_project.Object.Delete", "Delete");
113504ae99ecSEd Tanous 
113604ae99ecSEd Tanous                             BMCWEB_LOG_ERROR << "pamUpdatePassword Failed";
113704ae99ecSEd Tanous                             return;
113804ae99ecSEd Tanous                         }
113904ae99ecSEd Tanous 
1140f12894f8SJason M. Bills                         messages::created(asyncResp->res);
114104ae99ecSEd Tanous                         asyncResp->res.addHeader(
114204ae99ecSEd Tanous                             "Location",
114304ae99ecSEd Tanous                             "/redfish/v1/AccountService/Accounts/" + username);
114404ae99ecSEd Tanous                     },
1145*599c71d8SAyushi Smriti                     "xyz.openbmc_project.User.Manager",
1146*599c71d8SAyushi Smriti                     "/xyz/openbmc_project/user",
11479712f8acSEd Tanous                     "xyz.openbmc_project.User.Manager", "CreateUser", username,
1148*599c71d8SAyushi Smriti                     *allGroupsList, *roleId, *enabled);
1149*599c71d8SAyushi Smriti             },
1150*599c71d8SAyushi Smriti             "xyz.openbmc_project.User.Manager", "/xyz/openbmc_project/user",
1151*599c71d8SAyushi Smriti             "org.freedesktop.DBus.Properties", "Get",
1152*599c71d8SAyushi Smriti             "xyz.openbmc_project.User.Manager", "AllGroups");
115304ae99ecSEd Tanous     }
1154b9b2e0b2SEd Tanous };
1155b9b2e0b2SEd Tanous 
1156b9b2e0b2SEd Tanous class ManagerAccount : public Node
1157b9b2e0b2SEd Tanous {
1158b9b2e0b2SEd Tanous   public:
1159b9b2e0b2SEd Tanous     ManagerAccount(CrowApp& app) :
1160b9b2e0b2SEd Tanous         Node(app, "/redfish/v1/AccountService/Accounts/<str>/", std::string())
1161b9b2e0b2SEd Tanous     {
1162b9b2e0b2SEd Tanous         entityPrivileges = {
1163b9b2e0b2SEd Tanous             {boost::beast::http::verb::get,
1164b9b2e0b2SEd Tanous              {{"ConfigureUsers"}, {"ConfigureManager"}, {"ConfigureSelf"}}},
1165b9b2e0b2SEd Tanous             {boost::beast::http::verb::head, {{"Login"}}},
1166b9b2e0b2SEd Tanous             {boost::beast::http::verb::patch, {{"ConfigureUsers"}}},
1167b9b2e0b2SEd Tanous             {boost::beast::http::verb::put, {{"ConfigureUsers"}}},
1168b9b2e0b2SEd Tanous             {boost::beast::http::verb::delete_, {{"ConfigureUsers"}}},
1169b9b2e0b2SEd Tanous             {boost::beast::http::verb::post, {{"ConfigureUsers"}}}};
1170b9b2e0b2SEd Tanous     }
1171b9b2e0b2SEd Tanous 
1172b9b2e0b2SEd Tanous   private:
1173b9b2e0b2SEd Tanous     void doGet(crow::Response& res, const crow::Request& req,
1174b9b2e0b2SEd Tanous                const std::vector<std::string>& params) override
1175b9b2e0b2SEd Tanous     {
11760f74e643SEd Tanous         res.jsonValue = {
11770f74e643SEd Tanous             {"@odata.context",
11780f74e643SEd Tanous              "/redfish/v1/$metadata#ManagerAccount.ManagerAccount"},
11790f74e643SEd Tanous             {"@odata.type", "#ManagerAccount.v1_0_3.ManagerAccount"},
11800f74e643SEd Tanous             {"Name", "User Account"},
11810f74e643SEd Tanous             {"Description", "User Account"},
11820f74e643SEd Tanous             {"Password", nullptr},
118384e12cb7SAppaRao Puli             {"RoleId", "Administrator"}};
11840f74e643SEd Tanous 
1185b9b2e0b2SEd Tanous         auto asyncResp = std::make_shared<AsyncResp>(res);
1186b9b2e0b2SEd Tanous 
1187b9b2e0b2SEd Tanous         if (params.size() != 1)
1188b9b2e0b2SEd Tanous         {
1189f12894f8SJason M. Bills             messages::internalError(asyncResp->res);
1190b9b2e0b2SEd Tanous             return;
1191b9b2e0b2SEd Tanous         }
1192b9b2e0b2SEd Tanous 
1193b9b2e0b2SEd Tanous         crow::connections::systemBus->async_method_call(
1194b9b2e0b2SEd Tanous             [asyncResp, accountName{std::string(params[0])}](
1195b9b2e0b2SEd Tanous                 const boost::system::error_code ec,
1196b9b2e0b2SEd Tanous                 const ManagedObjectType& users) {
1197b9b2e0b2SEd Tanous                 if (ec)
1198b9b2e0b2SEd Tanous                 {
1199f12894f8SJason M. Bills                     messages::internalError(asyncResp->res);
1200b9b2e0b2SEd Tanous                     return;
1201b9b2e0b2SEd Tanous                 }
120284e12cb7SAppaRao Puli                 auto userIt = users.begin();
1203b9b2e0b2SEd Tanous 
120484e12cb7SAppaRao Puli                 for (; userIt != users.end(); userIt++)
1205b9b2e0b2SEd Tanous                 {
120684e12cb7SAppaRao Puli                     if (boost::ends_with(userIt->first.str, "/" + accountName))
1207b9b2e0b2SEd Tanous                     {
120884e12cb7SAppaRao Puli                         break;
1209b9b2e0b2SEd Tanous                     }
1210b9b2e0b2SEd Tanous                 }
121184e12cb7SAppaRao Puli                 if (userIt == users.end())
1212b9b2e0b2SEd Tanous                 {
121384e12cb7SAppaRao Puli                     messages::resourceNotFound(asyncResp->res, "ManagerAccount",
121484e12cb7SAppaRao Puli                                                accountName);
121584e12cb7SAppaRao Puli                     return;
121684e12cb7SAppaRao Puli                 }
121784e12cb7SAppaRao Puli                 for (const auto& interface : userIt->second)
121865b0dc32SEd Tanous                 {
121965b0dc32SEd Tanous                     if (interface.first ==
122065b0dc32SEd Tanous                         "xyz.openbmc_project.User.Attributes")
122165b0dc32SEd Tanous                     {
122265b0dc32SEd Tanous                         for (const auto& property : interface.second)
122365b0dc32SEd Tanous                         {
122465b0dc32SEd Tanous                             if (property.first == "UserEnabled")
122565b0dc32SEd Tanous                             {
122665b0dc32SEd Tanous                                 const bool* userEnabled =
1227abf2add6SEd Tanous                                     std::get_if<bool>(&property.second);
122865b0dc32SEd Tanous                                 if (userEnabled == nullptr)
122965b0dc32SEd Tanous                                 {
123065b0dc32SEd Tanous                                     BMCWEB_LOG_ERROR
123165b0dc32SEd Tanous                                         << "UserEnabled wasn't a bool";
123284e12cb7SAppaRao Puli                                     messages::internalError(asyncResp->res);
123384e12cb7SAppaRao Puli                                     return;
123465b0dc32SEd Tanous                                 }
123565b0dc32SEd Tanous                                 asyncResp->res.jsonValue["Enabled"] =
123665b0dc32SEd Tanous                                     *userEnabled;
123765b0dc32SEd Tanous                             }
123865b0dc32SEd Tanous                             else if (property.first ==
123965b0dc32SEd Tanous                                      "UserLockedForFailedAttempt")
124065b0dc32SEd Tanous                             {
124165b0dc32SEd Tanous                                 const bool* userLocked =
1242abf2add6SEd Tanous                                     std::get_if<bool>(&property.second);
124365b0dc32SEd Tanous                                 if (userLocked == nullptr)
124465b0dc32SEd Tanous                                 {
124584e12cb7SAppaRao Puli                                     BMCWEB_LOG_ERROR << "UserLockedForF"
124684e12cb7SAppaRao Puli                                                         "ailedAttempt "
124784e12cb7SAppaRao Puli                                                         "wasn't a bool";
124884e12cb7SAppaRao Puli                                     messages::internalError(asyncResp->res);
124984e12cb7SAppaRao Puli                                     return;
125065b0dc32SEd Tanous                                 }
125165b0dc32SEd Tanous                                 asyncResp->res.jsonValue["Locked"] =
125265b0dc32SEd Tanous                                     *userLocked;
125324c8542dSRatan Gupta                                 asyncResp->res.jsonValue
125424c8542dSRatan Gupta                                     ["Locked@Redfish.AllowableValues"] = {
12554d64ce34SGunnar Mills                                     "false"};
125665b0dc32SEd Tanous                             }
125784e12cb7SAppaRao Puli                             else if (property.first == "UserPrivilege")
125884e12cb7SAppaRao Puli                             {
125954fc587aSNagaraju Goruganti                                 const std::string* userPrivPtr =
1260abf2add6SEd Tanous                                     std::get_if<std::string>(&property.second);
126154fc587aSNagaraju Goruganti                                 if (userPrivPtr == nullptr)
126284e12cb7SAppaRao Puli                                 {
126384e12cb7SAppaRao Puli                                     BMCWEB_LOG_ERROR
126484e12cb7SAppaRao Puli                                         << "UserPrivilege wasn't a "
126584e12cb7SAppaRao Puli                                            "string";
126684e12cb7SAppaRao Puli                                     messages::internalError(asyncResp->res);
126784e12cb7SAppaRao Puli                                     return;
126884e12cb7SAppaRao Puli                                 }
126954fc587aSNagaraju Goruganti                                 std::string role =
127054fc587aSNagaraju Goruganti                                     getRoleIdFromPrivilege(*userPrivPtr);
127154fc587aSNagaraju Goruganti                                 if (role.empty())
127284e12cb7SAppaRao Puli                                 {
127384e12cb7SAppaRao Puli                                     BMCWEB_LOG_ERROR << "Invalid user role";
127484e12cb7SAppaRao Puli                                     messages::internalError(asyncResp->res);
127584e12cb7SAppaRao Puli                                     return;
127684e12cb7SAppaRao Puli                                 }
127754fc587aSNagaraju Goruganti                                 asyncResp->res.jsonValue["RoleId"] = role;
127884e12cb7SAppaRao Puli 
127984e12cb7SAppaRao Puli                                 asyncResp->res.jsonValue["Links"]["Role"] = {
128084e12cb7SAppaRao Puli                                     {"@odata.id", "/redfish/v1/AccountService/"
128184e12cb7SAppaRao Puli                                                   "Roles/" +
128254fc587aSNagaraju Goruganti                                                       role}};
128384e12cb7SAppaRao Puli                             }
128465b0dc32SEd Tanous                         }
128565b0dc32SEd Tanous                     }
128665b0dc32SEd Tanous                 }
128765b0dc32SEd Tanous 
1288b9b2e0b2SEd Tanous                 asyncResp->res.jsonValue["@odata.id"] =
128984e12cb7SAppaRao Puli                     "/redfish/v1/AccountService/Accounts/" + accountName;
1290b9b2e0b2SEd Tanous                 asyncResp->res.jsonValue["Id"] = accountName;
1291b9b2e0b2SEd Tanous                 asyncResp->res.jsonValue["UserName"] = accountName;
1292b9b2e0b2SEd Tanous             },
1293b9b2e0b2SEd Tanous             "xyz.openbmc_project.User.Manager", "/xyz/openbmc_project/user",
1294b9b2e0b2SEd Tanous             "org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
1295b9b2e0b2SEd Tanous     }
1296a840879dSEd Tanous 
1297a840879dSEd Tanous     void doPatch(crow::Response& res, const crow::Request& req,
1298a840879dSEd Tanous                  const std::vector<std::string>& params) override
1299a840879dSEd Tanous     {
1300a840879dSEd Tanous         auto asyncResp = std::make_shared<AsyncResp>(res);
1301a840879dSEd Tanous         if (params.size() != 1)
1302a840879dSEd Tanous         {
1303f12894f8SJason M. Bills             messages::internalError(asyncResp->res);
1304a840879dSEd Tanous             return;
1305a840879dSEd Tanous         }
1306a840879dSEd Tanous 
1307a24526dcSEd Tanous         std::optional<std::string> newUserName;
1308a24526dcSEd Tanous         std::optional<std::string> password;
1309a24526dcSEd Tanous         std::optional<bool> enabled;
1310a24526dcSEd Tanous         std::optional<std::string> roleId;
131124c8542dSRatan Gupta         std::optional<bool> locked;
131284e12cb7SAppaRao Puli         if (!json_util::readJson(req, res, "UserName", newUserName, "Password",
131324c8542dSRatan Gupta                                  password, "RoleId", roleId, "Enabled", enabled,
131424c8542dSRatan Gupta                                  "Locked", locked))
1315a840879dSEd Tanous         {
1316a840879dSEd Tanous             return;
1317a840879dSEd Tanous         }
1318a840879dSEd Tanous 
131984e12cb7SAppaRao Puli         const std::string& username = params[0];
132084e12cb7SAppaRao Puli 
132184e12cb7SAppaRao Puli         if (!newUserName)
1322a840879dSEd Tanous         {
132354fc587aSNagaraju Goruganti             // If the username isn't being updated, we can update the
132454fc587aSNagaraju Goruganti             // properties directly
132524c8542dSRatan Gupta             updateUserProperties(asyncResp, username, password, enabled, roleId,
132624c8542dSRatan Gupta                                  locked);
132784e12cb7SAppaRao Puli             return;
132884e12cb7SAppaRao Puli         }
132984e12cb7SAppaRao Puli         else
133084e12cb7SAppaRao Puli         {
133184e12cb7SAppaRao Puli             crow::connections::systemBus->async_method_call(
133284e12cb7SAppaRao Puli                 [this, asyncResp, username, password(std::move(password)),
133384e12cb7SAppaRao Puli                  roleId(std::move(roleId)), enabled(std::move(enabled)),
133424c8542dSRatan Gupta                  newUser{std::string(*newUserName)}, locked(std::move(locked))](
133584e12cb7SAppaRao Puli                     const boost::system::error_code ec) {
133684e12cb7SAppaRao Puli                     if (ec)
133784e12cb7SAppaRao Puli                     {
133884e12cb7SAppaRao Puli                         BMCWEB_LOG_ERROR << "D-Bus responses error: " << ec;
1339a840879dSEd Tanous                         messages::resourceNotFound(
134084e12cb7SAppaRao Puli                             asyncResp->res,
134184e12cb7SAppaRao Puli                             "#ManagerAccount.v1_0_3.ManagerAccount", username);
1342a840879dSEd Tanous                         return;
1343a840879dSEd Tanous                     }
1344a840879dSEd Tanous 
134584e12cb7SAppaRao Puli                     updateUserProperties(asyncResp, newUser, password, enabled,
134624c8542dSRatan Gupta                                          roleId, locked);
134784e12cb7SAppaRao Puli                 },
134884e12cb7SAppaRao Puli                 "xyz.openbmc_project.User.Manager", "/xyz/openbmc_project/user",
134984e12cb7SAppaRao Puli                 "xyz.openbmc_project.User.Manager", "RenameUser", username,
135084e12cb7SAppaRao Puli                 *newUserName);
135184e12cb7SAppaRao Puli         }
135284e12cb7SAppaRao Puli     }
135384e12cb7SAppaRao Puli 
135484e12cb7SAppaRao Puli     void updateUserProperties(std::shared_ptr<AsyncResp> asyncResp,
135584e12cb7SAppaRao Puli                               const std::string& username,
1356a24526dcSEd Tanous                               std::optional<std::string> password,
1357a24526dcSEd Tanous                               std::optional<bool> enabled,
135824c8542dSRatan Gupta                               std::optional<std::string> roleId,
135924c8542dSRatan Gupta                               std::optional<bool> locked)
136084e12cb7SAppaRao Puli     {
13619712f8acSEd Tanous         if (password)
1362a840879dSEd Tanous         {
13639712f8acSEd Tanous             if (!pamUpdatePassword(username, *password))
1364a840879dSEd Tanous             {
1365a840879dSEd Tanous                 BMCWEB_LOG_ERROR << "pamUpdatePassword Failed";
1366f12894f8SJason M. Bills                 messages::internalError(asyncResp->res);
1367a840879dSEd Tanous                 return;
1368a840879dSEd Tanous             }
1369a840879dSEd Tanous         }
1370a840879dSEd Tanous 
137124c8542dSRatan Gupta         std::string dbusObjectPath = "/xyz/openbmc_project/user/" + username;
137224c8542dSRatan Gupta         dbus::utility::escapePathForDbus(dbusObjectPath);
137324c8542dSRatan Gupta 
137422c33710SRatan Gupta         dbus::utility::checkDbusPathExists(
137524c8542dSRatan Gupta             dbusObjectPath,
137624c8542dSRatan Gupta             [dbusObjectPath(std::move(dbusObjectPath)), username,
137724c8542dSRatan Gupta              password(std::move(password)), roleId(std::move(roleId)),
137824c8542dSRatan Gupta              enabled(std::move(enabled)), locked(std::move(locked)),
137924c8542dSRatan Gupta              asyncResp{std::move(asyncResp)}](int rc) {
138024c8542dSRatan Gupta                 if (!rc)
138124c8542dSRatan Gupta                 {
138224c8542dSRatan Gupta                     messages::invalidObject(asyncResp->res, username.c_str());
138324c8542dSRatan Gupta                     return;
138424c8542dSRatan Gupta                 }
13859712f8acSEd Tanous                 if (enabled)
1386a840879dSEd Tanous                 {
1387a840879dSEd Tanous                     crow::connections::systemBus->async_method_call(
1388a840879dSEd Tanous                         [asyncResp](const boost::system::error_code ec) {
1389a840879dSEd Tanous                             if (ec)
1390a840879dSEd Tanous                             {
139124c8542dSRatan Gupta                                 BMCWEB_LOG_ERROR << "D-Bus responses error: "
139224c8542dSRatan Gupta                                                  << ec;
1393f12894f8SJason M. Bills                                 messages::internalError(asyncResp->res);
1394a840879dSEd Tanous                                 return;
1395a840879dSEd Tanous                             }
139684e12cb7SAppaRao Puli                             messages::success(asyncResp->res);
139784e12cb7SAppaRao Puli                             return;
139884e12cb7SAppaRao Puli                         },
139984e12cb7SAppaRao Puli                         "xyz.openbmc_project.User.Manager",
140024c8542dSRatan Gupta                         dbusObjectPath.c_str(),
140184e12cb7SAppaRao Puli                         "org.freedesktop.DBus.Properties", "Set",
140284e12cb7SAppaRao Puli                         "xyz.openbmc_project.User.Attributes", "UserEnabled",
1403abf2add6SEd Tanous                         std::variant<bool>{*enabled});
140484e12cb7SAppaRao Puli                 }
140584e12cb7SAppaRao Puli 
140684e12cb7SAppaRao Puli                 if (roleId)
140784e12cb7SAppaRao Puli                 {
140854fc587aSNagaraju Goruganti                     std::string priv = getPrivilegeFromRoleId(*roleId);
140984e12cb7SAppaRao Puli                     if (priv.empty())
141084e12cb7SAppaRao Puli                     {
141124c8542dSRatan Gupta                         messages::propertyValueNotInList(asyncResp->res,
141224c8542dSRatan Gupta                                                          *roleId, "RoleId");
141384e12cb7SAppaRao Puli                         return;
141484e12cb7SAppaRao Puli                     }
141584e12cb7SAppaRao Puli 
141684e12cb7SAppaRao Puli                     crow::connections::systemBus->async_method_call(
141784e12cb7SAppaRao Puli                         [asyncResp](const boost::system::error_code ec) {
141884e12cb7SAppaRao Puli                             if (ec)
141984e12cb7SAppaRao Puli                             {
142024c8542dSRatan Gupta                                 BMCWEB_LOG_ERROR << "D-Bus responses error: "
142124c8542dSRatan Gupta                                                  << ec;
142284e12cb7SAppaRao Puli                                 messages::internalError(asyncResp->res);
142384e12cb7SAppaRao Puli                                 return;
142484e12cb7SAppaRao Puli                             }
1425f12894f8SJason M. Bills                             messages::success(asyncResp->res);
1426a840879dSEd Tanous                         },
1427a840879dSEd Tanous                         "xyz.openbmc_project.User.Manager",
142824c8542dSRatan Gupta                         dbusObjectPath.c_str(),
1429a840879dSEd Tanous                         "org.freedesktop.DBus.Properties", "Set",
143084e12cb7SAppaRao Puli                         "xyz.openbmc_project.User.Attributes", "UserPrivilege",
1431abf2add6SEd Tanous                         std::variant<std::string>{priv});
1432a840879dSEd Tanous                 }
143324c8542dSRatan Gupta 
143424c8542dSRatan Gupta                 if (locked)
143524c8542dSRatan Gupta                 {
143624c8542dSRatan Gupta                     // admin can unlock the account which is locked by
143754fc587aSNagaraju Goruganti                     // successive authentication failures but admin should
143854fc587aSNagaraju Goruganti                     // not be allowed to lock an account.
143924c8542dSRatan Gupta                     if (*locked)
144024c8542dSRatan Gupta                     {
144124c8542dSRatan Gupta                         messages::propertyValueNotInList(asyncResp->res, "true",
144224c8542dSRatan Gupta                                                          "Locked");
144324c8542dSRatan Gupta                         return;
144424c8542dSRatan Gupta                     }
144524c8542dSRatan Gupta 
144624c8542dSRatan Gupta                     crow::connections::systemBus->async_method_call(
144724c8542dSRatan Gupta                         [asyncResp](const boost::system::error_code ec) {
144824c8542dSRatan Gupta                             if (ec)
144924c8542dSRatan Gupta                             {
145024c8542dSRatan Gupta                                 BMCWEB_LOG_ERROR << "D-Bus responses error: "
145124c8542dSRatan Gupta                                                  << ec;
145224c8542dSRatan Gupta                                 messages::internalError(asyncResp->res);
145324c8542dSRatan Gupta                                 return;
145424c8542dSRatan Gupta                             }
145524c8542dSRatan Gupta                             messages::success(asyncResp->res);
145624c8542dSRatan Gupta                             return;
145724c8542dSRatan Gupta                         },
145824c8542dSRatan Gupta                         "xyz.openbmc_project.User.Manager",
145924c8542dSRatan Gupta                         dbusObjectPath.c_str(),
146024c8542dSRatan Gupta                         "org.freedesktop.DBus.Properties", "Set",
146124c8542dSRatan Gupta                         "xyz.openbmc_project.User.Attributes",
146224c8542dSRatan Gupta                         "UserLockedForFailedAttempt",
146324c8542dSRatan Gupta                         sdbusplus::message::variant<bool>{*locked});
146424c8542dSRatan Gupta                 }
146524c8542dSRatan Gupta             });
1466a840879dSEd Tanous     }
146706e086d9SEd Tanous 
146806e086d9SEd Tanous     void doDelete(crow::Response& res, const crow::Request& req,
146906e086d9SEd Tanous                   const std::vector<std::string>& params) override
147006e086d9SEd Tanous     {
147106e086d9SEd Tanous         auto asyncResp = std::make_shared<AsyncResp>(res);
147206e086d9SEd Tanous 
147306e086d9SEd Tanous         if (params.size() != 1)
147406e086d9SEd Tanous         {
1475f12894f8SJason M. Bills             messages::internalError(asyncResp->res);
147606e086d9SEd Tanous             return;
147706e086d9SEd Tanous         }
147806e086d9SEd Tanous 
147906e086d9SEd Tanous         const std::string userPath = "/xyz/openbmc_project/user/" + params[0];
148006e086d9SEd Tanous 
148106e086d9SEd Tanous         crow::connections::systemBus->async_method_call(
148206e086d9SEd Tanous             [asyncResp, username{std::move(params[0])}](
148306e086d9SEd Tanous                 const boost::system::error_code ec) {
148406e086d9SEd Tanous                 if (ec)
148506e086d9SEd Tanous                 {
148606e086d9SEd Tanous                     messages::resourceNotFound(
1487f12894f8SJason M. Bills                         asyncResp->res, "#ManagerAccount.v1_0_3.ManagerAccount",
1488f12894f8SJason M. Bills                         username);
148906e086d9SEd Tanous                     return;
149006e086d9SEd Tanous                 }
149106e086d9SEd Tanous 
1492f12894f8SJason M. Bills                 messages::accountRemoved(asyncResp->res);
149306e086d9SEd Tanous             },
149406e086d9SEd Tanous             "xyz.openbmc_project.User.Manager", userPath,
149506e086d9SEd Tanous             "xyz.openbmc_project.Object.Delete", "Delete");
149606e086d9SEd Tanous     }
149784e12cb7SAppaRao Puli };
149888d16c9aSLewanczyk, Dawid 
149988d16c9aSLewanczyk, Dawid } // namespace redfish
1500