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> 2252cc112dSEd Tanous #include <persistent_data.hpp> 23a840879dSEd Tanous #include <utils/json_utils.hpp> 241214b7e7SGunnar Mills 25abf2add6SEd Tanous #include <variant> 26b9b2e0b2SEd Tanous 271abe55efSEd Tanous namespace redfish 281abe55efSEd Tanous { 2988d16c9aSLewanczyk, Dawid 3023a21a1cSEd Tanous constexpr const char* ldapConfigObjectName = 316973a582SRatan Gupta "/xyz/openbmc_project/user/ldap/openldap"; 32*2c70f800SEd Tanous constexpr const char* adConfigObject = 33ab828d7cSRatan Gupta "/xyz/openbmc_project/user/ldap/active_directory"; 34ab828d7cSRatan Gupta 356973a582SRatan Gupta constexpr const char* ldapRootObject = "/xyz/openbmc_project/user/ldap"; 366973a582SRatan Gupta constexpr const char* ldapDbusService = "xyz.openbmc_project.Ldap.Config"; 376973a582SRatan Gupta constexpr const char* ldapConfigInterface = 386973a582SRatan Gupta "xyz.openbmc_project.User.Ldap.Config"; 396973a582SRatan Gupta constexpr const char* ldapCreateInterface = 406973a582SRatan Gupta "xyz.openbmc_project.User.Ldap.Create"; 416973a582SRatan Gupta constexpr const char* ldapEnableInterface = "xyz.openbmc_project.Object.Enable"; 4206785244SRatan Gupta constexpr const char* ldapPrivMapperInterface = 4306785244SRatan Gupta "xyz.openbmc_project.User.PrivilegeMapper"; 446973a582SRatan Gupta constexpr const char* dbusObjManagerIntf = "org.freedesktop.DBus.ObjectManager"; 456973a582SRatan Gupta constexpr const char* propertyInterface = "org.freedesktop.DBus.Properties"; 466973a582SRatan Gupta constexpr const char* mapperBusName = "xyz.openbmc_project.ObjectMapper"; 476973a582SRatan Gupta constexpr const char* mapperObjectPath = "/xyz/openbmc_project/object_mapper"; 486973a582SRatan Gupta constexpr const char* mapperIntf = "xyz.openbmc_project.ObjectMapper"; 496973a582SRatan Gupta 5054fc587aSNagaraju Goruganti struct LDAPRoleMapData 5154fc587aSNagaraju Goruganti { 5254fc587aSNagaraju Goruganti std::string groupName; 5354fc587aSNagaraju Goruganti std::string privilege; 5454fc587aSNagaraju Goruganti }; 5554fc587aSNagaraju Goruganti 566973a582SRatan Gupta struct LDAPConfigData 576973a582SRatan Gupta { 586973a582SRatan Gupta std::string uri{}; 596973a582SRatan Gupta std::string bindDN{}; 606973a582SRatan Gupta std::string baseDN{}; 616973a582SRatan Gupta std::string searchScope{}; 626973a582SRatan Gupta std::string serverType{}; 636973a582SRatan Gupta bool serviceEnabled = false; 646973a582SRatan Gupta std::string userNameAttribute{}; 656973a582SRatan Gupta std::string groupAttribute{}; 6654fc587aSNagaraju Goruganti std::vector<std::pair<std::string, LDAPRoleMapData>> groupRoleList; 676973a582SRatan Gupta }; 686973a582SRatan Gupta 6919bd78d9SPatrick Williams using DbusVariantType = std::variant<bool, int32_t, std::string>; 70107077deSPrzemyslaw Czarnowski 71107077deSPrzemyslaw Czarnowski using DbusInterfaceType = boost::container::flat_map< 72107077deSPrzemyslaw Czarnowski std::string, boost::container::flat_map<std::string, DbusVariantType>>; 73107077deSPrzemyslaw Czarnowski 74107077deSPrzemyslaw Czarnowski using ManagedObjectType = 75107077deSPrzemyslaw Czarnowski std::vector<std::pair<sdbusplus::message::object_path, DbusInterfaceType>>; 76107077deSPrzemyslaw Czarnowski 776973a582SRatan Gupta using GetObjectType = 786973a582SRatan Gupta std::vector<std::pair<std::string, std::vector<std::string>>>; 7984e12cb7SAppaRao Puli 8054fc587aSNagaraju Goruganti inline std::string getRoleIdFromPrivilege(std::string_view role) 8184e12cb7SAppaRao Puli { 8284e12cb7SAppaRao Puli if (role == "priv-admin") 8384e12cb7SAppaRao Puli { 8484e12cb7SAppaRao Puli return "Administrator"; 8584e12cb7SAppaRao Puli } 8684e12cb7SAppaRao Puli else if (role == "priv-user") 8784e12cb7SAppaRao Puli { 88c80fee55SAppaRao Puli return "ReadOnly"; 8984e12cb7SAppaRao Puli } 9084e12cb7SAppaRao Puli else if (role == "priv-operator") 9184e12cb7SAppaRao Puli { 9284e12cb7SAppaRao Puli return "Operator"; 9384e12cb7SAppaRao Puli } 94e9e6d240Sjayaprakash Mutyala else if ((role == "") || (role == "priv-noaccess")) 95e9e6d240Sjayaprakash Mutyala { 96e9e6d240Sjayaprakash Mutyala return "NoAccess"; 97e9e6d240Sjayaprakash Mutyala } 9884e12cb7SAppaRao Puli return ""; 9984e12cb7SAppaRao Puli } 10054fc587aSNagaraju Goruganti inline std::string getPrivilegeFromRoleId(std::string_view role) 10184e12cb7SAppaRao Puli { 10284e12cb7SAppaRao Puli if (role == "Administrator") 10384e12cb7SAppaRao Puli { 10484e12cb7SAppaRao Puli return "priv-admin"; 10584e12cb7SAppaRao Puli } 106c80fee55SAppaRao Puli else if (role == "ReadOnly") 10784e12cb7SAppaRao Puli { 10884e12cb7SAppaRao Puli return "priv-user"; 10984e12cb7SAppaRao Puli } 11084e12cb7SAppaRao Puli else if (role == "Operator") 11184e12cb7SAppaRao Puli { 11284e12cb7SAppaRao Puli return "priv-operator"; 11384e12cb7SAppaRao Puli } 11496200606Sjayaprakash Mutyala else if ((role == "NoAccess") || (role == "")) 115e9e6d240Sjayaprakash Mutyala { 116e9e6d240Sjayaprakash Mutyala return "priv-noaccess"; 117e9e6d240Sjayaprakash Mutyala } 11884e12cb7SAppaRao Puli return ""; 11984e12cb7SAppaRao Puli } 120b9b2e0b2SEd Tanous 12123a21a1cSEd Tanous inline void userErrorMessageHandler(const sd_bus_error* e, 12266b5ca76Sjayaprakash Mutyala std::shared_ptr<AsyncResp> asyncResp, 12366b5ca76Sjayaprakash Mutyala const std::string& newUser, 12466b5ca76Sjayaprakash Mutyala const std::string& username) 12566b5ca76Sjayaprakash Mutyala { 12666b5ca76Sjayaprakash Mutyala const char* errorMessage = e->name; 12766b5ca76Sjayaprakash Mutyala if (e == nullptr) 12866b5ca76Sjayaprakash Mutyala { 12966b5ca76Sjayaprakash Mutyala messages::internalError(asyncResp->res); 13066b5ca76Sjayaprakash Mutyala return; 13166b5ca76Sjayaprakash Mutyala } 13266b5ca76Sjayaprakash Mutyala 13366b5ca76Sjayaprakash Mutyala if (strcmp(errorMessage, 13466b5ca76Sjayaprakash Mutyala "xyz.openbmc_project.User.Common.Error.UserNameExists") == 0) 13566b5ca76Sjayaprakash Mutyala { 13666b5ca76Sjayaprakash Mutyala messages::resourceAlreadyExists(asyncResp->res, 1378114bd4dSGunnar Mills "#ManagerAccount.v1_4_0.ManagerAccount", 13866b5ca76Sjayaprakash Mutyala "UserName", newUser); 13966b5ca76Sjayaprakash Mutyala } 14066b5ca76Sjayaprakash Mutyala else if (strcmp(errorMessage, "xyz.openbmc_project.User.Common.Error." 14166b5ca76Sjayaprakash Mutyala "UserNameDoesNotExist") == 0) 14266b5ca76Sjayaprakash Mutyala { 14366b5ca76Sjayaprakash Mutyala messages::resourceNotFound( 1448114bd4dSGunnar Mills asyncResp->res, "#ManagerAccount.v1_4_0.ManagerAccount", username); 14566b5ca76Sjayaprakash Mutyala } 14666b5ca76Sjayaprakash Mutyala else if (strcmp(errorMessage, 14766b5ca76Sjayaprakash Mutyala "xyz.openbmc_project.Common.Error.InvalidArgument") == 0) 14866b5ca76Sjayaprakash Mutyala { 14966b5ca76Sjayaprakash Mutyala messages::propertyValueFormatError(asyncResp->res, newUser, "UserName"); 15066b5ca76Sjayaprakash Mutyala } 15166b5ca76Sjayaprakash Mutyala else if (strcmp(errorMessage, 15266b5ca76Sjayaprakash Mutyala "xyz.openbmc_project.User.Common.Error.NoResource") == 0) 15366b5ca76Sjayaprakash Mutyala { 15466b5ca76Sjayaprakash Mutyala messages::createLimitReachedForResource(asyncResp->res); 15566b5ca76Sjayaprakash Mutyala } 15666b5ca76Sjayaprakash Mutyala else if (strcmp(errorMessage, "xyz.openbmc_project.User.Common.Error." 15766b5ca76Sjayaprakash Mutyala "UserNameGroupFail") == 0) 15866b5ca76Sjayaprakash Mutyala { 15966b5ca76Sjayaprakash Mutyala messages::propertyValueFormatError(asyncResp->res, newUser, "UserName"); 16066b5ca76Sjayaprakash Mutyala } 16166b5ca76Sjayaprakash Mutyala else 16266b5ca76Sjayaprakash Mutyala { 16366b5ca76Sjayaprakash Mutyala messages::internalError(asyncResp->res); 16466b5ca76Sjayaprakash Mutyala } 16566b5ca76Sjayaprakash Mutyala 16666b5ca76Sjayaprakash Mutyala return; 16766b5ca76Sjayaprakash Mutyala } 16866b5ca76Sjayaprakash Mutyala 16923a21a1cSEd Tanous inline void parseLDAPConfigData(nlohmann::json& json_response, 170ab828d7cSRatan Gupta const LDAPConfigData& confData, 171ab828d7cSRatan Gupta const std::string& ldapType) 1726973a582SRatan Gupta { 173ab828d7cSRatan Gupta std::string service = 174ab828d7cSRatan Gupta (ldapType == "LDAP") ? "LDAPService" : "ActiveDirectoryService"; 17537cce918SMarri Devender Rao nlohmann::json ldap = { 1766973a582SRatan Gupta {"ServiceEnabled", confData.serviceEnabled}, 1776973a582SRatan Gupta {"ServiceAddresses", nlohmann::json::array({confData.uri})}, 1786973a582SRatan Gupta {"Authentication", 1796973a582SRatan Gupta {{"AuthenticationType", "UsernameAndPassword"}, 1806973a582SRatan Gupta {"Username", confData.bindDN}, 1816973a582SRatan Gupta {"Password", nullptr}}}, 1826973a582SRatan Gupta {"LDAPService", 1836973a582SRatan Gupta {{"SearchSettings", 1846973a582SRatan Gupta {{"BaseDistinguishedNames", 1856973a582SRatan Gupta nlohmann::json::array({confData.baseDN})}, 1866973a582SRatan Gupta {"UsernameAttribute", confData.userNameAttribute}, 1876973a582SRatan Gupta {"GroupsAttribute", confData.groupAttribute}}}}}, 1886973a582SRatan Gupta }; 18954fc587aSNagaraju Goruganti 19037cce918SMarri Devender Rao json_response[ldapType].update(std::move(ldap)); 19154fc587aSNagaraju Goruganti 19254fc587aSNagaraju Goruganti nlohmann::json& roleMapArray = json_response[ldapType]["RemoteRoleMapping"]; 19354fc587aSNagaraju Goruganti roleMapArray = nlohmann::json::array(); 19454fc587aSNagaraju Goruganti for (auto& obj : confData.groupRoleList) 19554fc587aSNagaraju Goruganti { 19654fc587aSNagaraju Goruganti BMCWEB_LOG_DEBUG << "Pushing the data groupName=" 19754fc587aSNagaraju Goruganti << obj.second.groupName << "\n"; 19854fc587aSNagaraju Goruganti roleMapArray.push_back( 19954fc587aSNagaraju Goruganti {nlohmann::json::array({"RemoteGroup", obj.second.groupName}), 20054fc587aSNagaraju Goruganti nlohmann::json::array( 20154fc587aSNagaraju Goruganti {"LocalRole", getRoleIdFromPrivilege(obj.second.privilege)})}); 20254fc587aSNagaraju Goruganti } 2036973a582SRatan Gupta } 2046973a582SRatan Gupta 2056973a582SRatan Gupta /** 20606785244SRatan Gupta * @brief validates given JSON input and then calls appropriate method to 20706785244SRatan Gupta * create, to delete or to set Rolemapping object based on the given input. 20806785244SRatan Gupta * 20906785244SRatan Gupta */ 21023a21a1cSEd Tanous inline void handleRoleMapPatch( 21106785244SRatan Gupta const std::shared_ptr<AsyncResp>& asyncResp, 21206785244SRatan Gupta const std::vector<std::pair<std::string, LDAPRoleMapData>>& roleMapObjData, 21306785244SRatan Gupta const std::string& serverType, std::vector<nlohmann::json>& input) 21406785244SRatan Gupta { 21506785244SRatan Gupta for (size_t index = 0; index < input.size(); index++) 21606785244SRatan Gupta { 21706785244SRatan Gupta nlohmann::json& thisJson = input[index]; 21806785244SRatan Gupta 21906785244SRatan Gupta if (thisJson.is_null()) 22006785244SRatan Gupta { 22106785244SRatan Gupta // delete the existing object 22206785244SRatan Gupta if (index < roleMapObjData.size()) 22306785244SRatan Gupta { 22406785244SRatan Gupta crow::connections::systemBus->async_method_call( 22506785244SRatan Gupta [asyncResp, roleMapObjData, serverType, 22606785244SRatan Gupta index](const boost::system::error_code ec) { 22706785244SRatan Gupta if (ec) 22806785244SRatan Gupta { 22906785244SRatan Gupta BMCWEB_LOG_ERROR << "DBUS response error: " << ec; 23006785244SRatan Gupta messages::internalError(asyncResp->res); 23106785244SRatan Gupta return; 23206785244SRatan Gupta } 23306785244SRatan Gupta asyncResp->res 23406785244SRatan Gupta .jsonValue[serverType]["RemoteRoleMapping"][index] = 23506785244SRatan Gupta nullptr; 23606785244SRatan Gupta }, 23706785244SRatan Gupta ldapDbusService, roleMapObjData[index].first, 23806785244SRatan Gupta "xyz.openbmc_project.Object.Delete", "Delete"); 23906785244SRatan Gupta } 24006785244SRatan Gupta else 24106785244SRatan Gupta { 24206785244SRatan Gupta BMCWEB_LOG_ERROR << "Can't delete the object"; 24306785244SRatan Gupta messages::propertyValueTypeError( 24406785244SRatan Gupta asyncResp->res, thisJson.dump(), 24506785244SRatan Gupta "RemoteRoleMapping/" + std::to_string(index)); 24606785244SRatan Gupta return; 24706785244SRatan Gupta } 24806785244SRatan Gupta } 24906785244SRatan Gupta else if (thisJson.empty()) 25006785244SRatan Gupta { 25106785244SRatan Gupta // Don't do anything for the empty objects,parse next json 25206785244SRatan Gupta // eg {"RemoteRoleMapping",[{}]} 25306785244SRatan Gupta } 25406785244SRatan Gupta else 25506785244SRatan Gupta { 25606785244SRatan Gupta // update/create the object 25706785244SRatan Gupta std::optional<std::string> remoteGroup; 25806785244SRatan Gupta std::optional<std::string> localRole; 25906785244SRatan Gupta 26006785244SRatan Gupta if (!json_util::readJson(thisJson, asyncResp->res, "RemoteGroup", 26106785244SRatan Gupta remoteGroup, "LocalRole", localRole)) 26206785244SRatan Gupta { 26306785244SRatan Gupta continue; 26406785244SRatan Gupta } 26506785244SRatan Gupta 26606785244SRatan Gupta // Update existing RoleMapping Object 26706785244SRatan Gupta if (index < roleMapObjData.size()) 26806785244SRatan Gupta { 26906785244SRatan Gupta BMCWEB_LOG_DEBUG << "Update Role Map Object"; 27006785244SRatan Gupta // If "RemoteGroup" info is provided 27106785244SRatan Gupta if (remoteGroup) 27206785244SRatan Gupta { 27306785244SRatan Gupta crow::connections::systemBus->async_method_call( 27406785244SRatan Gupta [asyncResp, roleMapObjData, serverType, index, 27506785244SRatan Gupta remoteGroup](const boost::system::error_code ec) { 27606785244SRatan Gupta if (ec) 27706785244SRatan Gupta { 27806785244SRatan Gupta BMCWEB_LOG_ERROR << "DBUS response error: " 27906785244SRatan Gupta << ec; 28006785244SRatan Gupta messages::internalError(asyncResp->res); 28106785244SRatan Gupta return; 28206785244SRatan Gupta } 28306785244SRatan Gupta asyncResp->res 28406785244SRatan Gupta .jsonValue[serverType]["RemoteRoleMapping"] 28506785244SRatan Gupta [index]["RemoteGroup"] = *remoteGroup; 28606785244SRatan Gupta }, 28706785244SRatan Gupta ldapDbusService, roleMapObjData[index].first, 28806785244SRatan Gupta propertyInterface, "Set", 28906785244SRatan Gupta "xyz.openbmc_project.User.PrivilegeMapperEntry", 29006785244SRatan Gupta "GroupName", 29106785244SRatan Gupta std::variant<std::string>(std::move(*remoteGroup))); 29206785244SRatan Gupta } 29306785244SRatan Gupta 29406785244SRatan Gupta // If "LocalRole" info is provided 29506785244SRatan Gupta if (localRole) 29606785244SRatan Gupta { 29706785244SRatan Gupta crow::connections::systemBus->async_method_call( 29806785244SRatan Gupta [asyncResp, roleMapObjData, serverType, index, 29906785244SRatan Gupta localRole](const boost::system::error_code ec) { 30006785244SRatan Gupta if (ec) 30106785244SRatan Gupta { 30206785244SRatan Gupta BMCWEB_LOG_ERROR << "DBUS response error: " 30306785244SRatan Gupta << ec; 30406785244SRatan Gupta messages::internalError(asyncResp->res); 30506785244SRatan Gupta return; 30606785244SRatan Gupta } 30706785244SRatan Gupta asyncResp->res 30806785244SRatan Gupta .jsonValue[serverType]["RemoteRoleMapping"] 30906785244SRatan Gupta [index]["LocalRole"] = *localRole; 31006785244SRatan Gupta }, 31106785244SRatan Gupta ldapDbusService, roleMapObjData[index].first, 31206785244SRatan Gupta propertyInterface, "Set", 31306785244SRatan Gupta "xyz.openbmc_project.User.PrivilegeMapperEntry", 31406785244SRatan Gupta "Privilege", 31506785244SRatan Gupta std::variant<std::string>( 31606785244SRatan Gupta getPrivilegeFromRoleId(std::move(*localRole)))); 31706785244SRatan Gupta } 31806785244SRatan Gupta } 31906785244SRatan Gupta // Create a new RoleMapping Object. 32006785244SRatan Gupta else 32106785244SRatan Gupta { 32206785244SRatan Gupta BMCWEB_LOG_DEBUG 32306785244SRatan Gupta << "setRoleMappingProperties: Creating new Object"; 32406785244SRatan Gupta std::string pathString = 32506785244SRatan Gupta "RemoteRoleMapping/" + std::to_string(index); 32606785244SRatan Gupta 32706785244SRatan Gupta if (!localRole) 32806785244SRatan Gupta { 32906785244SRatan Gupta messages::propertyMissing(asyncResp->res, 33006785244SRatan Gupta pathString + "/LocalRole"); 33106785244SRatan Gupta continue; 33206785244SRatan Gupta } 33306785244SRatan Gupta if (!remoteGroup) 33406785244SRatan Gupta { 33506785244SRatan Gupta messages::propertyMissing(asyncResp->res, 33606785244SRatan Gupta pathString + "/RemoteGroup"); 33706785244SRatan Gupta continue; 33806785244SRatan Gupta } 33906785244SRatan Gupta 34006785244SRatan Gupta std::string dbusObjectPath; 34106785244SRatan Gupta if (serverType == "ActiveDirectory") 34206785244SRatan Gupta { 343*2c70f800SEd Tanous dbusObjectPath = adConfigObject; 34406785244SRatan Gupta } 34506785244SRatan Gupta else if (serverType == "LDAP") 34606785244SRatan Gupta { 34723a21a1cSEd Tanous dbusObjectPath = ldapConfigObjectName; 34806785244SRatan Gupta } 34906785244SRatan Gupta 35006785244SRatan Gupta BMCWEB_LOG_DEBUG << "Remote Group=" << *remoteGroup 35106785244SRatan Gupta << ",LocalRole=" << *localRole; 35206785244SRatan Gupta 35306785244SRatan Gupta crow::connections::systemBus->async_method_call( 354271584abSEd Tanous [asyncResp, serverType, localRole, 35506785244SRatan Gupta remoteGroup](const boost::system::error_code ec) { 35606785244SRatan Gupta if (ec) 35706785244SRatan Gupta { 35806785244SRatan Gupta BMCWEB_LOG_ERROR << "DBUS response error: " << ec; 35906785244SRatan Gupta messages::internalError(asyncResp->res); 36006785244SRatan Gupta return; 36106785244SRatan Gupta } 36206785244SRatan Gupta nlohmann::json& remoteRoleJson = 36306785244SRatan Gupta asyncResp->res 36406785244SRatan Gupta .jsonValue[serverType]["RemoteRoleMapping"]; 36506785244SRatan Gupta remoteRoleJson.push_back( 36606785244SRatan Gupta {{"LocalRole", *localRole}, 36706785244SRatan Gupta {"RemoteGroup", *remoteGroup}}); 36806785244SRatan Gupta }, 36906785244SRatan Gupta ldapDbusService, dbusObjectPath, ldapPrivMapperInterface, 37006785244SRatan Gupta "Create", std::move(*remoteGroup), 37106785244SRatan Gupta getPrivilegeFromRoleId(std::move(*localRole))); 37206785244SRatan Gupta } 37306785244SRatan Gupta } 37406785244SRatan Gupta } 37506785244SRatan Gupta } 37606785244SRatan Gupta 37706785244SRatan Gupta /** 3786973a582SRatan Gupta * Function that retrieves all properties for LDAP config object 3796973a582SRatan Gupta * into JSON 3806973a582SRatan Gupta */ 3816973a582SRatan Gupta template <typename CallbackFunc> 3826973a582SRatan Gupta inline void getLDAPConfigData(const std::string& ldapType, 3836973a582SRatan Gupta CallbackFunc&& callback) 3846973a582SRatan Gupta { 38554fc587aSNagaraju Goruganti 38654fc587aSNagaraju Goruganti const std::array<const char*, 2> interfaces = {ldapEnableInterface, 38754fc587aSNagaraju Goruganti ldapConfigInterface}; 38854fc587aSNagaraju Goruganti 38954fc587aSNagaraju Goruganti crow::connections::systemBus->async_method_call( 39054fc587aSNagaraju Goruganti [callback, ldapType](const boost::system::error_code ec, 39154fc587aSNagaraju Goruganti const GetObjectType& resp) { 39254fc587aSNagaraju Goruganti if (ec || resp.empty()) 39354fc587aSNagaraju Goruganti { 39454fc587aSNagaraju Goruganti BMCWEB_LOG_ERROR << "DBUS response error during getting of " 39554fc587aSNagaraju Goruganti "service name: " 39654fc587aSNagaraju Goruganti << ec; 39723a21a1cSEd Tanous LDAPConfigData empty{}; 39823a21a1cSEd Tanous callback(false, empty, ldapType); 39954fc587aSNagaraju Goruganti return; 40054fc587aSNagaraju Goruganti } 40154fc587aSNagaraju Goruganti std::string service = resp.begin()->first; 40254fc587aSNagaraju Goruganti crow::connections::systemBus->async_method_call( 40354fc587aSNagaraju Goruganti [callback, ldapType](const boost::system::error_code error_code, 4046973a582SRatan Gupta const ManagedObjectType& ldapObjects) { 4056973a582SRatan Gupta LDAPConfigData confData{}; 4066973a582SRatan Gupta if (error_code) 4076973a582SRatan Gupta { 408ab828d7cSRatan Gupta callback(false, confData, ldapType); 40954fc587aSNagaraju Goruganti BMCWEB_LOG_ERROR << "D-Bus responses error: " 41054fc587aSNagaraju Goruganti << error_code; 4116973a582SRatan Gupta return; 4126973a582SRatan Gupta } 413ab828d7cSRatan Gupta 414ab828d7cSRatan Gupta std::string ldapDbusType; 41554fc587aSNagaraju Goruganti std::string searchString; 41654fc587aSNagaraju Goruganti 417ab828d7cSRatan Gupta if (ldapType == "LDAP") 418ab828d7cSRatan Gupta { 41954fc587aSNagaraju Goruganti ldapDbusType = "xyz.openbmc_project.User.Ldap.Config." 42054fc587aSNagaraju Goruganti "Type.OpenLdap"; 42154fc587aSNagaraju Goruganti searchString = "openldap"; 422ab828d7cSRatan Gupta } 423ab828d7cSRatan Gupta else if (ldapType == "ActiveDirectory") 424ab828d7cSRatan Gupta { 42554fc587aSNagaraju Goruganti ldapDbusType = 42654fc587aSNagaraju Goruganti "xyz.openbmc_project.User.Ldap.Config.Type." 427ab828d7cSRatan Gupta "ActiveDirectory"; 42854fc587aSNagaraju Goruganti searchString = "active_directory"; 429ab828d7cSRatan Gupta } 430ab828d7cSRatan Gupta else 431ab828d7cSRatan Gupta { 43254fc587aSNagaraju Goruganti BMCWEB_LOG_ERROR 43354fc587aSNagaraju Goruganti << "Can't get the DbusType for the given type=" 434ab828d7cSRatan Gupta << ldapType; 435ab828d7cSRatan Gupta callback(false, confData, ldapType); 436ab828d7cSRatan Gupta return; 437ab828d7cSRatan Gupta } 438ab828d7cSRatan Gupta 439ab828d7cSRatan Gupta std::string ldapEnableInterfaceStr = ldapEnableInterface; 440ab828d7cSRatan Gupta std::string ldapConfigInterfaceStr = ldapConfigInterface; 441ab828d7cSRatan Gupta 4426973a582SRatan Gupta for (const auto& object : ldapObjects) 4436973a582SRatan Gupta { 44454fc587aSNagaraju Goruganti // let's find the object whose ldap type is equal to the 44554fc587aSNagaraju Goruganti // given type 44654fc587aSNagaraju Goruganti if (object.first.str.find(searchString) == 44754fc587aSNagaraju Goruganti std::string::npos) 4486973a582SRatan Gupta { 449ab828d7cSRatan Gupta continue; 450ab828d7cSRatan Gupta } 451ab828d7cSRatan Gupta 4526973a582SRatan Gupta for (const auto& interface : object.second) 4536973a582SRatan Gupta { 4546973a582SRatan Gupta if (interface.first == ldapEnableInterfaceStr) 4556973a582SRatan Gupta { 4566973a582SRatan Gupta // rest of the properties are string. 4576973a582SRatan Gupta for (const auto& property : interface.second) 4586973a582SRatan Gupta { 4596973a582SRatan Gupta if (property.first == "Enabled") 4606973a582SRatan Gupta { 4616973a582SRatan Gupta const bool* value = 4626973a582SRatan Gupta std::get_if<bool>(&property.second); 4636973a582SRatan Gupta if (value == nullptr) 4646973a582SRatan Gupta { 4656973a582SRatan Gupta continue; 4666973a582SRatan Gupta } 4676973a582SRatan Gupta confData.serviceEnabled = *value; 4686973a582SRatan Gupta break; 4696973a582SRatan Gupta } 4706973a582SRatan Gupta } 4716973a582SRatan Gupta } 4726973a582SRatan Gupta else if (interface.first == ldapConfigInterfaceStr) 4736973a582SRatan Gupta { 4746973a582SRatan Gupta 4756973a582SRatan Gupta for (const auto& property : interface.second) 4766973a582SRatan Gupta { 477271584abSEd Tanous const std::string* strValue = 47854fc587aSNagaraju Goruganti std::get_if<std::string>( 47954fc587aSNagaraju Goruganti &property.second); 480271584abSEd Tanous if (strValue == nullptr) 4816973a582SRatan Gupta { 4826973a582SRatan Gupta continue; 4836973a582SRatan Gupta } 4846973a582SRatan Gupta if (property.first == "LDAPServerURI") 4856973a582SRatan Gupta { 486271584abSEd Tanous confData.uri = *strValue; 4876973a582SRatan Gupta } 4886973a582SRatan Gupta else if (property.first == "LDAPBindDN") 4896973a582SRatan Gupta { 490271584abSEd Tanous confData.bindDN = *strValue; 4916973a582SRatan Gupta } 4926973a582SRatan Gupta else if (property.first == "LDAPBaseDN") 4936973a582SRatan Gupta { 494271584abSEd Tanous confData.baseDN = *strValue; 4956973a582SRatan Gupta } 49654fc587aSNagaraju Goruganti else if (property.first == 49754fc587aSNagaraju Goruganti "LDAPSearchScope") 4986973a582SRatan Gupta { 499271584abSEd Tanous confData.searchScope = *strValue; 5006973a582SRatan Gupta } 50154fc587aSNagaraju Goruganti else if (property.first == 50254fc587aSNagaraju Goruganti "GroupNameAttribute") 5036973a582SRatan Gupta { 504271584abSEd Tanous confData.groupAttribute = *strValue; 5056973a582SRatan Gupta } 50654fc587aSNagaraju Goruganti else if (property.first == 50754fc587aSNagaraju Goruganti "UserNameAttribute") 5086973a582SRatan Gupta { 509271584abSEd Tanous confData.userNameAttribute = *strValue; 5106973a582SRatan Gupta } 51154fc587aSNagaraju Goruganti else if (property.first == "LDAPType") 512ab828d7cSRatan Gupta { 513271584abSEd Tanous confData.serverType = *strValue; 51454fc587aSNagaraju Goruganti } 51554fc587aSNagaraju Goruganti } 51654fc587aSNagaraju Goruganti } 51754fc587aSNagaraju Goruganti else if (interface.first == 51854fc587aSNagaraju Goruganti "xyz.openbmc_project.User." 51954fc587aSNagaraju Goruganti "PrivilegeMapperEntry") 52054fc587aSNagaraju Goruganti { 52154fc587aSNagaraju Goruganti LDAPRoleMapData roleMapData{}; 52254fc587aSNagaraju Goruganti for (const auto& property : interface.second) 52354fc587aSNagaraju Goruganti { 524271584abSEd Tanous const std::string* strValue = 52554fc587aSNagaraju Goruganti std::get_if<std::string>( 52654fc587aSNagaraju Goruganti &property.second); 52754fc587aSNagaraju Goruganti 528271584abSEd Tanous if (strValue == nullptr) 52954fc587aSNagaraju Goruganti { 53054fc587aSNagaraju Goruganti continue; 53154fc587aSNagaraju Goruganti } 53254fc587aSNagaraju Goruganti 53354fc587aSNagaraju Goruganti if (property.first == "GroupName") 53454fc587aSNagaraju Goruganti { 535271584abSEd Tanous roleMapData.groupName = *strValue; 53654fc587aSNagaraju Goruganti } 53754fc587aSNagaraju Goruganti else if (property.first == "Privilege") 53854fc587aSNagaraju Goruganti { 539271584abSEd Tanous roleMapData.privilege = *strValue; 54054fc587aSNagaraju Goruganti } 54154fc587aSNagaraju Goruganti } 54254fc587aSNagaraju Goruganti 5430f0353b6SEd Tanous confData.groupRoleList.emplace_back( 5440f0353b6SEd Tanous object.first.str, roleMapData); 54554fc587aSNagaraju Goruganti } 54654fc587aSNagaraju Goruganti } 54754fc587aSNagaraju Goruganti } 548ab828d7cSRatan Gupta callback(true, confData, ldapType); 54954fc587aSNagaraju Goruganti }, 55054fc587aSNagaraju Goruganti service, ldapRootObject, dbusObjManagerIntf, 5516973a582SRatan Gupta "GetManagedObjects"); 55254fc587aSNagaraju Goruganti }, 55354fc587aSNagaraju Goruganti mapperBusName, mapperObjectPath, mapperIntf, "GetObject", 55423a21a1cSEd Tanous ldapConfigObjectName, interfaces); 5556973a582SRatan Gupta } 5566973a582SRatan Gupta 5571abe55efSEd Tanous class AccountService : public Node 5581abe55efSEd Tanous { 55988d16c9aSLewanczyk, Dawid public: 56023a21a1cSEd Tanous AccountService(App& app) : Node(app, "/redfish/v1/AccountService/") 5611abe55efSEd Tanous { 5623ebd75f7SEd Tanous entityPrivileges = { 5633c5a376eSGunnar Mills {boost::beast::http::verb::get, {{"Login"}}}, 564e0d918bcSEd Tanous {boost::beast::http::verb::head, {{"Login"}}}, 565e0d918bcSEd Tanous {boost::beast::http::verb::patch, {{"ConfigureUsers"}}}, 566e0d918bcSEd Tanous {boost::beast::http::verb::put, {{"ConfigureUsers"}}}, 567e0d918bcSEd Tanous {boost::beast::http::verb::delete_, {{"ConfigureUsers"}}}, 568e0d918bcSEd Tanous {boost::beast::http::verb::post, {{"ConfigureUsers"}}}}; 56988d16c9aSLewanczyk, Dawid } 57088d16c9aSLewanczyk, Dawid 57188d16c9aSLewanczyk, Dawid private: 5728a07d286SRatan Gupta /** 5738a07d286SRatan Gupta * @brief parses the authentication section under the LDAP 5748a07d286SRatan Gupta * @param input JSON data 5758a07d286SRatan Gupta * @param asyncResp pointer to the JSON response 5768a07d286SRatan Gupta * @param userName userName to be filled from the given JSON. 5778a07d286SRatan Gupta * @param password password to be filled from the given JSON. 5788a07d286SRatan Gupta */ 5798a07d286SRatan Gupta void 5808a07d286SRatan Gupta parseLDAPAuthenticationJson(nlohmann::json input, 5818a07d286SRatan Gupta const std::shared_ptr<AsyncResp>& asyncResp, 5828a07d286SRatan Gupta std::optional<std::string>& username, 5838a07d286SRatan Gupta std::optional<std::string>& password) 5848a07d286SRatan Gupta { 5858a07d286SRatan Gupta std::optional<std::string> authType; 5868a07d286SRatan Gupta 5878a07d286SRatan Gupta if (!json_util::readJson(input, asyncResp->res, "AuthenticationType", 5888a07d286SRatan Gupta authType, "Username", username, "Password", 5898a07d286SRatan Gupta password)) 5908a07d286SRatan Gupta { 5918a07d286SRatan Gupta return; 5928a07d286SRatan Gupta } 5938a07d286SRatan Gupta if (!authType) 5948a07d286SRatan Gupta { 5958a07d286SRatan Gupta return; 5968a07d286SRatan Gupta } 5978a07d286SRatan Gupta if (*authType != "UsernameAndPassword") 5988a07d286SRatan Gupta { 5998a07d286SRatan Gupta messages::propertyValueNotInList(asyncResp->res, *authType, 6008a07d286SRatan Gupta "AuthenticationType"); 6018a07d286SRatan Gupta return; 6028a07d286SRatan Gupta } 6038a07d286SRatan Gupta } 6048a07d286SRatan Gupta /** 6058a07d286SRatan Gupta * @brief parses the LDAPService section under the LDAP 6068a07d286SRatan Gupta * @param input JSON data 6078a07d286SRatan Gupta * @param asyncResp pointer to the JSON response 6088a07d286SRatan Gupta * @param baseDNList baseDN to be filled from the given JSON. 6098a07d286SRatan Gupta * @param userNameAttribute userName to be filled from the given JSON. 6108a07d286SRatan Gupta * @param groupaAttribute password to be filled from the given JSON. 6118a07d286SRatan Gupta */ 6128a07d286SRatan Gupta 6138a07d286SRatan Gupta void parseLDAPServiceJson( 6148a07d286SRatan Gupta nlohmann::json input, const std::shared_ptr<AsyncResp>& asyncResp, 6158a07d286SRatan Gupta std::optional<std::vector<std::string>>& baseDNList, 6168a07d286SRatan Gupta std::optional<std::string>& userNameAttribute, 6178a07d286SRatan Gupta std::optional<std::string>& groupsAttribute) 6188a07d286SRatan Gupta { 6198a07d286SRatan Gupta std::optional<nlohmann::json> searchSettings; 6208a07d286SRatan Gupta 6218a07d286SRatan Gupta if (!json_util::readJson(input, asyncResp->res, "SearchSettings", 6228a07d286SRatan Gupta searchSettings)) 6238a07d286SRatan Gupta { 6248a07d286SRatan Gupta return; 6258a07d286SRatan Gupta } 6268a07d286SRatan Gupta if (!searchSettings) 6278a07d286SRatan Gupta { 6288a07d286SRatan Gupta return; 6298a07d286SRatan Gupta } 6308a07d286SRatan Gupta if (!json_util::readJson(*searchSettings, asyncResp->res, 6318a07d286SRatan Gupta "BaseDistinguishedNames", baseDNList, 6328a07d286SRatan Gupta "UsernameAttribute", userNameAttribute, 6338a07d286SRatan Gupta "GroupsAttribute", groupsAttribute)) 6348a07d286SRatan Gupta { 6358a07d286SRatan Gupta return; 6368a07d286SRatan Gupta } 6378a07d286SRatan Gupta } 6388a07d286SRatan Gupta /** 6398a07d286SRatan Gupta * @brief updates the LDAP server address and updates the 6408a07d286SRatan Gupta json response with the new value. 6418a07d286SRatan Gupta * @param serviceAddressList address to be updated. 6428a07d286SRatan Gupta * @param asyncResp pointer to the JSON response 6438a07d286SRatan Gupta * @param ldapServerElementName Type of LDAP 6448a07d286SRatan Gupta server(openLDAP/ActiveDirectory) 6458a07d286SRatan Gupta */ 6468a07d286SRatan Gupta 6478a07d286SRatan Gupta void handleServiceAddressPatch( 6488a07d286SRatan Gupta const std::vector<std::string>& serviceAddressList, 6498a07d286SRatan Gupta const std::shared_ptr<AsyncResp>& asyncResp, 6508a07d286SRatan Gupta const std::string& ldapServerElementName, 6518a07d286SRatan Gupta const std::string& ldapConfigObject) 6528a07d286SRatan Gupta { 6538a07d286SRatan Gupta crow::connections::systemBus->async_method_call( 6548a07d286SRatan Gupta [asyncResp, ldapServerElementName, 6558a07d286SRatan Gupta serviceAddressList](const boost::system::error_code ec) { 6568a07d286SRatan Gupta if (ec) 6578a07d286SRatan Gupta { 6588a07d286SRatan Gupta BMCWEB_LOG_DEBUG 659c61704abSGunnar Mills << "Error Occurred in updating the service address"; 6608a07d286SRatan Gupta messages::internalError(asyncResp->res); 6618a07d286SRatan Gupta return; 6628a07d286SRatan Gupta } 6638a07d286SRatan Gupta std::vector<std::string> modifiedserviceAddressList = { 6648a07d286SRatan Gupta serviceAddressList.front()}; 6658a07d286SRatan Gupta asyncResp->res 6668a07d286SRatan Gupta .jsonValue[ldapServerElementName]["ServiceAddresses"] = 6678a07d286SRatan Gupta modifiedserviceAddressList; 6688a07d286SRatan Gupta if ((serviceAddressList).size() > 1) 6698a07d286SRatan Gupta { 6708a07d286SRatan Gupta messages::propertyValueModified(asyncResp->res, 6718a07d286SRatan Gupta "ServiceAddresses", 6728a07d286SRatan Gupta serviceAddressList.front()); 6738a07d286SRatan Gupta } 6748a07d286SRatan Gupta BMCWEB_LOG_DEBUG << "Updated the service address"; 6758a07d286SRatan Gupta }, 6768a07d286SRatan Gupta ldapDbusService, ldapConfigObject, propertyInterface, "Set", 6778a07d286SRatan Gupta ldapConfigInterface, "LDAPServerURI", 6788a07d286SRatan Gupta std::variant<std::string>(serviceAddressList.front())); 6798a07d286SRatan Gupta } 6808a07d286SRatan Gupta /** 6818a07d286SRatan Gupta * @brief updates the LDAP Bind DN and updates the 6828a07d286SRatan Gupta json response with the new value. 6838a07d286SRatan Gupta * @param username name of the user which needs to be updated. 6848a07d286SRatan Gupta * @param asyncResp pointer to the JSON response 6858a07d286SRatan Gupta * @param ldapServerElementName Type of LDAP 6868a07d286SRatan Gupta server(openLDAP/ActiveDirectory) 6878a07d286SRatan Gupta */ 6888a07d286SRatan Gupta 6898a07d286SRatan Gupta void handleUserNamePatch(const std::string& username, 6908a07d286SRatan Gupta const std::shared_ptr<AsyncResp>& asyncResp, 6918a07d286SRatan Gupta const std::string& ldapServerElementName, 6928a07d286SRatan Gupta const std::string& ldapConfigObject) 6938a07d286SRatan Gupta { 6948a07d286SRatan Gupta crow::connections::systemBus->async_method_call( 6958a07d286SRatan Gupta [asyncResp, username, 6968a07d286SRatan Gupta ldapServerElementName](const boost::system::error_code ec) { 6978a07d286SRatan Gupta if (ec) 6988a07d286SRatan Gupta { 6998a07d286SRatan Gupta BMCWEB_LOG_DEBUG 700c61704abSGunnar Mills << "Error occurred in updating the username"; 7018a07d286SRatan Gupta messages::internalError(asyncResp->res); 7028a07d286SRatan Gupta return; 7038a07d286SRatan Gupta } 7048a07d286SRatan Gupta asyncResp->res.jsonValue[ldapServerElementName] 7058a07d286SRatan Gupta ["Authentication"]["Username"] = 7068a07d286SRatan Gupta username; 7078a07d286SRatan Gupta BMCWEB_LOG_DEBUG << "Updated the username"; 7088a07d286SRatan Gupta }, 7098a07d286SRatan Gupta ldapDbusService, ldapConfigObject, propertyInterface, "Set", 7108a07d286SRatan Gupta ldapConfigInterface, "LDAPBindDN", 7118a07d286SRatan Gupta std::variant<std::string>(username)); 7128a07d286SRatan Gupta } 7138a07d286SRatan Gupta 7148a07d286SRatan Gupta /** 7158a07d286SRatan Gupta * @brief updates the LDAP password 7168a07d286SRatan Gupta * @param password : ldap password which needs to be updated. 7178a07d286SRatan Gupta * @param asyncResp pointer to the JSON response 7188a07d286SRatan Gupta * @param ldapServerElementName Type of LDAP 7198a07d286SRatan Gupta * server(openLDAP/ActiveDirectory) 7208a07d286SRatan Gupta */ 7218a07d286SRatan Gupta 7228a07d286SRatan Gupta void handlePasswordPatch(const std::string& password, 7238a07d286SRatan Gupta const std::shared_ptr<AsyncResp>& asyncResp, 7248a07d286SRatan Gupta const std::string& ldapServerElementName, 7258a07d286SRatan Gupta const std::string& ldapConfigObject) 7268a07d286SRatan Gupta { 7278a07d286SRatan Gupta crow::connections::systemBus->async_method_call( 7288a07d286SRatan Gupta [asyncResp, password, 7298a07d286SRatan Gupta ldapServerElementName](const boost::system::error_code ec) { 7308a07d286SRatan Gupta if (ec) 7318a07d286SRatan Gupta { 7328a07d286SRatan Gupta BMCWEB_LOG_DEBUG 733c61704abSGunnar Mills << "Error occurred in updating the password"; 7348a07d286SRatan Gupta messages::internalError(asyncResp->res); 7358a07d286SRatan Gupta return; 7368a07d286SRatan Gupta } 7378a07d286SRatan Gupta asyncResp->res.jsonValue[ldapServerElementName] 7388a07d286SRatan Gupta ["Authentication"]["Password"] = ""; 7398a07d286SRatan Gupta BMCWEB_LOG_DEBUG << "Updated the password"; 7408a07d286SRatan Gupta }, 7418a07d286SRatan Gupta ldapDbusService, ldapConfigObject, propertyInterface, "Set", 7428a07d286SRatan Gupta ldapConfigInterface, "LDAPBindDNPassword", 7438a07d286SRatan Gupta std::variant<std::string>(password)); 7448a07d286SRatan Gupta } 7458a07d286SRatan Gupta 7468a07d286SRatan Gupta /** 7478a07d286SRatan Gupta * @brief updates the LDAP BaseDN and updates the 7488a07d286SRatan Gupta json response with the new value. 7498a07d286SRatan Gupta * @param baseDNList baseDN list which needs to be updated. 7508a07d286SRatan Gupta * @param asyncResp pointer to the JSON response 7518a07d286SRatan Gupta * @param ldapServerElementName Type of LDAP 7528a07d286SRatan Gupta server(openLDAP/ActiveDirectory) 7538a07d286SRatan Gupta */ 7548a07d286SRatan Gupta 7558a07d286SRatan Gupta void handleBaseDNPatch(const std::vector<std::string>& baseDNList, 7568a07d286SRatan Gupta const std::shared_ptr<AsyncResp>& asyncResp, 7578a07d286SRatan Gupta const std::string& ldapServerElementName, 7588a07d286SRatan Gupta const std::string& ldapConfigObject) 7598a07d286SRatan Gupta { 7608a07d286SRatan Gupta crow::connections::systemBus->async_method_call( 7618a07d286SRatan Gupta [asyncResp, baseDNList, 7628a07d286SRatan Gupta ldapServerElementName](const boost::system::error_code ec) { 7638a07d286SRatan Gupta if (ec) 7648a07d286SRatan Gupta { 765c61704abSGunnar Mills BMCWEB_LOG_DEBUG 766c61704abSGunnar Mills << "Error Occurred in Updating the base DN"; 7678a07d286SRatan Gupta messages::internalError(asyncResp->res); 7688a07d286SRatan Gupta return; 7698a07d286SRatan Gupta } 7708a07d286SRatan Gupta auto& serverTypeJson = 7718a07d286SRatan Gupta asyncResp->res.jsonValue[ldapServerElementName]; 7728a07d286SRatan Gupta auto& searchSettingsJson = 7738a07d286SRatan Gupta serverTypeJson["LDAPService"]["SearchSettings"]; 7748a07d286SRatan Gupta std::vector<std::string> modifiedBaseDNList = { 7758a07d286SRatan Gupta baseDNList.front()}; 7768a07d286SRatan Gupta searchSettingsJson["BaseDistinguishedNames"] = 7778a07d286SRatan Gupta modifiedBaseDNList; 7788a07d286SRatan Gupta if (baseDNList.size() > 1) 7798a07d286SRatan Gupta { 7808a07d286SRatan Gupta messages::propertyValueModified(asyncResp->res, 7818a07d286SRatan Gupta "BaseDistinguishedNames", 7828a07d286SRatan Gupta baseDNList.front()); 7838a07d286SRatan Gupta } 7848a07d286SRatan Gupta BMCWEB_LOG_DEBUG << "Updated the base DN"; 7858a07d286SRatan Gupta }, 7868a07d286SRatan Gupta ldapDbusService, ldapConfigObject, propertyInterface, "Set", 7878a07d286SRatan Gupta ldapConfigInterface, "LDAPBaseDN", 7888a07d286SRatan Gupta std::variant<std::string>(baseDNList.front())); 7898a07d286SRatan Gupta } 7908a07d286SRatan Gupta /** 7918a07d286SRatan Gupta * @brief updates the LDAP user name attribute and updates the 7928a07d286SRatan Gupta json response with the new value. 7938a07d286SRatan Gupta * @param userNameAttribute attribute to be updated. 7948a07d286SRatan Gupta * @param asyncResp pointer to the JSON response 7958a07d286SRatan Gupta * @param ldapServerElementName Type of LDAP 7968a07d286SRatan Gupta server(openLDAP/ActiveDirectory) 7978a07d286SRatan Gupta */ 7988a07d286SRatan Gupta 7998a07d286SRatan Gupta void handleUserNameAttrPatch(const std::string& userNameAttribute, 8008a07d286SRatan Gupta const std::shared_ptr<AsyncResp>& asyncResp, 8018a07d286SRatan Gupta const std::string& ldapServerElementName, 8028a07d286SRatan Gupta const std::string& ldapConfigObject) 8038a07d286SRatan Gupta { 8048a07d286SRatan Gupta crow::connections::systemBus->async_method_call( 8058a07d286SRatan Gupta [asyncResp, userNameAttribute, 8068a07d286SRatan Gupta ldapServerElementName](const boost::system::error_code ec) { 8078a07d286SRatan Gupta if (ec) 8088a07d286SRatan Gupta { 809c61704abSGunnar Mills BMCWEB_LOG_DEBUG << "Error Occurred in Updating the " 8108a07d286SRatan Gupta "username attribute"; 8118a07d286SRatan Gupta messages::internalError(asyncResp->res); 8128a07d286SRatan Gupta return; 8138a07d286SRatan Gupta } 8148a07d286SRatan Gupta auto& serverTypeJson = 8158a07d286SRatan Gupta asyncResp->res.jsonValue[ldapServerElementName]; 8168a07d286SRatan Gupta auto& searchSettingsJson = 8178a07d286SRatan Gupta serverTypeJson["LDAPService"]["SearchSettings"]; 8188a07d286SRatan Gupta searchSettingsJson["UsernameAttribute"] = userNameAttribute; 8198a07d286SRatan Gupta BMCWEB_LOG_DEBUG << "Updated the user name attr."; 8208a07d286SRatan Gupta }, 8218a07d286SRatan Gupta ldapDbusService, ldapConfigObject, propertyInterface, "Set", 8228a07d286SRatan Gupta ldapConfigInterface, "UserNameAttribute", 8238a07d286SRatan Gupta std::variant<std::string>(userNameAttribute)); 8248a07d286SRatan Gupta } 8258a07d286SRatan Gupta /** 8268a07d286SRatan Gupta * @brief updates the LDAP group attribute and updates the 8278a07d286SRatan Gupta json response with the new value. 8288a07d286SRatan Gupta * @param groupsAttribute attribute to be updated. 8298a07d286SRatan Gupta * @param asyncResp pointer to the JSON response 8308a07d286SRatan Gupta * @param ldapServerElementName Type of LDAP 8318a07d286SRatan Gupta server(openLDAP/ActiveDirectory) 8328a07d286SRatan Gupta */ 8338a07d286SRatan Gupta 8348a07d286SRatan Gupta void handleGroupNameAttrPatch(const std::string& groupsAttribute, 8358a07d286SRatan Gupta const std::shared_ptr<AsyncResp>& asyncResp, 8368a07d286SRatan Gupta const std::string& ldapServerElementName, 8378a07d286SRatan Gupta const std::string& ldapConfigObject) 8388a07d286SRatan Gupta { 8398a07d286SRatan Gupta crow::connections::systemBus->async_method_call( 8408a07d286SRatan Gupta [asyncResp, groupsAttribute, 8418a07d286SRatan Gupta ldapServerElementName](const boost::system::error_code ec) { 8428a07d286SRatan Gupta if (ec) 8438a07d286SRatan Gupta { 844c61704abSGunnar Mills BMCWEB_LOG_DEBUG << "Error Occurred in Updating the " 8458a07d286SRatan Gupta "groupname attribute"; 8468a07d286SRatan Gupta messages::internalError(asyncResp->res); 8478a07d286SRatan Gupta return; 8488a07d286SRatan Gupta } 8498a07d286SRatan Gupta auto& serverTypeJson = 8508a07d286SRatan Gupta asyncResp->res.jsonValue[ldapServerElementName]; 8518a07d286SRatan Gupta auto& searchSettingsJson = 8528a07d286SRatan Gupta serverTypeJson["LDAPService"]["SearchSettings"]; 8538a07d286SRatan Gupta searchSettingsJson["GroupsAttribute"] = groupsAttribute; 8548a07d286SRatan Gupta BMCWEB_LOG_DEBUG << "Updated the groupname attr"; 8558a07d286SRatan Gupta }, 8568a07d286SRatan Gupta ldapDbusService, ldapConfigObject, propertyInterface, "Set", 8578a07d286SRatan Gupta ldapConfigInterface, "GroupNameAttribute", 8588a07d286SRatan Gupta std::variant<std::string>(groupsAttribute)); 8598a07d286SRatan Gupta } 8608a07d286SRatan Gupta /** 8618a07d286SRatan Gupta * @brief updates the LDAP service enable and updates the 8628a07d286SRatan Gupta json response with the new value. 8638a07d286SRatan Gupta * @param input JSON data. 8648a07d286SRatan Gupta * @param asyncResp pointer to the JSON response 8658a07d286SRatan Gupta * @param ldapServerElementName Type of LDAP 8668a07d286SRatan Gupta server(openLDAP/ActiveDirectory) 8678a07d286SRatan Gupta */ 8688a07d286SRatan Gupta 8698a07d286SRatan Gupta void handleServiceEnablePatch(bool serviceEnabled, 8708a07d286SRatan Gupta const std::shared_ptr<AsyncResp>& asyncResp, 8718a07d286SRatan Gupta const std::string& ldapServerElementName, 8728a07d286SRatan Gupta const std::string& ldapConfigObject) 8738a07d286SRatan Gupta { 8748a07d286SRatan Gupta crow::connections::systemBus->async_method_call( 8758a07d286SRatan Gupta [asyncResp, serviceEnabled, 8768a07d286SRatan Gupta ldapServerElementName](const boost::system::error_code ec) { 8778a07d286SRatan Gupta if (ec) 8788a07d286SRatan Gupta { 8798a07d286SRatan Gupta BMCWEB_LOG_DEBUG 880c61704abSGunnar Mills << "Error Occurred in Updating the service enable"; 8818a07d286SRatan Gupta messages::internalError(asyncResp->res); 8828a07d286SRatan Gupta return; 8838a07d286SRatan Gupta } 8848a07d286SRatan Gupta asyncResp->res 8858a07d286SRatan Gupta .jsonValue[ldapServerElementName]["ServiceEnabled"] = 8868a07d286SRatan Gupta serviceEnabled; 8878a07d286SRatan Gupta BMCWEB_LOG_DEBUG << "Updated Service enable = " 8888a07d286SRatan Gupta << serviceEnabled; 8898a07d286SRatan Gupta }, 8908a07d286SRatan Gupta ldapDbusService, ldapConfigObject, propertyInterface, "Set", 8918a07d286SRatan Gupta ldapEnableInterface, "Enabled", std::variant<bool>(serviceEnabled)); 8928a07d286SRatan Gupta } 8938a07d286SRatan Gupta 89478158631SZbigniew Kurzynski void handleAuthMethodsPatch(nlohmann::json& input, 89578158631SZbigniew Kurzynski const std::shared_ptr<AsyncResp>& asyncResp) 89678158631SZbigniew Kurzynski { 89778158631SZbigniew Kurzynski std::optional<bool> basicAuth; 89878158631SZbigniew Kurzynski std::optional<bool> cookie; 89978158631SZbigniew Kurzynski std::optional<bool> sessionToken; 90078158631SZbigniew Kurzynski std::optional<bool> xToken; 901501f1e58SZbigniew Kurzynski std::optional<bool> tls; 90278158631SZbigniew Kurzynski 90378158631SZbigniew Kurzynski if (!json_util::readJson(input, asyncResp->res, "BasicAuth", basicAuth, 90478158631SZbigniew Kurzynski "Cookie", cookie, "SessionToken", sessionToken, 905501f1e58SZbigniew Kurzynski "XToken", xToken, "TLS", tls)) 90678158631SZbigniew Kurzynski { 90778158631SZbigniew Kurzynski BMCWEB_LOG_ERROR << "Cannot read values from AuthMethod tag"; 90878158631SZbigniew Kurzynski return; 90978158631SZbigniew Kurzynski } 91078158631SZbigniew Kurzynski 91178158631SZbigniew Kurzynski // Make a copy of methods configuration 91252cc112dSEd Tanous persistent_data::AuthConfigMethods authMethodsConfig = 91352cc112dSEd Tanous persistent_data::SessionStore::getInstance().getAuthMethodsConfig(); 91478158631SZbigniew Kurzynski 91578158631SZbigniew Kurzynski if (basicAuth) 91678158631SZbigniew Kurzynski { 91778158631SZbigniew Kurzynski authMethodsConfig.basic = *basicAuth; 91878158631SZbigniew Kurzynski } 91978158631SZbigniew Kurzynski 92078158631SZbigniew Kurzynski if (cookie) 92178158631SZbigniew Kurzynski { 92278158631SZbigniew Kurzynski authMethodsConfig.cookie = *cookie; 92378158631SZbigniew Kurzynski } 92478158631SZbigniew Kurzynski 92578158631SZbigniew Kurzynski if (sessionToken) 92678158631SZbigniew Kurzynski { 92778158631SZbigniew Kurzynski authMethodsConfig.sessionToken = *sessionToken; 92878158631SZbigniew Kurzynski } 92978158631SZbigniew Kurzynski 93078158631SZbigniew Kurzynski if (xToken) 93178158631SZbigniew Kurzynski { 93278158631SZbigniew Kurzynski authMethodsConfig.xtoken = *xToken; 93378158631SZbigniew Kurzynski } 93478158631SZbigniew Kurzynski 935501f1e58SZbigniew Kurzynski if (tls) 936501f1e58SZbigniew Kurzynski { 937501f1e58SZbigniew Kurzynski authMethodsConfig.tls = *tls; 938501f1e58SZbigniew Kurzynski } 939501f1e58SZbigniew Kurzynski 94078158631SZbigniew Kurzynski if (!authMethodsConfig.basic && !authMethodsConfig.cookie && 941501f1e58SZbigniew Kurzynski !authMethodsConfig.sessionToken && !authMethodsConfig.xtoken && 942501f1e58SZbigniew Kurzynski !authMethodsConfig.tls) 94378158631SZbigniew Kurzynski { 94478158631SZbigniew Kurzynski // Do not allow user to disable everything 94578158631SZbigniew Kurzynski messages::actionNotSupported(asyncResp->res, 94678158631SZbigniew Kurzynski "of disabling all available methods"); 94778158631SZbigniew Kurzynski return; 94878158631SZbigniew Kurzynski } 94978158631SZbigniew Kurzynski 95052cc112dSEd Tanous persistent_data::SessionStore::getInstance().updateAuthMethodsConfig( 95152cc112dSEd Tanous authMethodsConfig); 95278158631SZbigniew Kurzynski // Save configuration immediately 95352cc112dSEd Tanous persistent_data::getConfig().writeData(); 95478158631SZbigniew Kurzynski 95578158631SZbigniew Kurzynski messages::success(asyncResp->res); 95678158631SZbigniew Kurzynski } 95778158631SZbigniew Kurzynski 9588a07d286SRatan Gupta /** 9598a07d286SRatan Gupta * @brief Get the required values from the given JSON, validates the 9608a07d286SRatan Gupta * value and create the LDAP config object. 9618a07d286SRatan Gupta * @param input JSON data 9628a07d286SRatan Gupta * @param asyncResp pointer to the JSON response 9638a07d286SRatan Gupta * @param serverType Type of LDAP server(openLDAP/ActiveDirectory) 9648a07d286SRatan Gupta */ 9658a07d286SRatan Gupta 9668a07d286SRatan Gupta void handleLDAPPatch(nlohmann::json& input, 9678a07d286SRatan Gupta const std::shared_ptr<AsyncResp>& asyncResp, 9688a07d286SRatan Gupta const std::string& serverType) 9698a07d286SRatan Gupta { 970eb2bbe56SRatan Gupta std::string dbusObjectPath; 971eb2bbe56SRatan Gupta if (serverType == "ActiveDirectory") 972eb2bbe56SRatan Gupta { 973*2c70f800SEd Tanous dbusObjectPath = adConfigObject; 974eb2bbe56SRatan Gupta } 975eb2bbe56SRatan Gupta else if (serverType == "LDAP") 976eb2bbe56SRatan Gupta { 97723a21a1cSEd Tanous dbusObjectPath = ldapConfigObjectName; 978eb2bbe56SRatan Gupta } 979cb13a392SEd Tanous else 980cb13a392SEd Tanous { 981cb13a392SEd Tanous return; 982cb13a392SEd Tanous } 983eb2bbe56SRatan Gupta 9848a07d286SRatan Gupta std::optional<nlohmann::json> authentication; 9858a07d286SRatan Gupta std::optional<nlohmann::json> ldapService; 9868a07d286SRatan Gupta std::optional<std::vector<std::string>> serviceAddressList; 9878a07d286SRatan Gupta std::optional<bool> serviceEnabled; 9888a07d286SRatan Gupta std::optional<std::vector<std::string>> baseDNList; 9898a07d286SRatan Gupta std::optional<std::string> userNameAttribute; 9908a07d286SRatan Gupta std::optional<std::string> groupsAttribute; 9918a07d286SRatan Gupta std::optional<std::string> userName; 9928a07d286SRatan Gupta std::optional<std::string> password; 99306785244SRatan Gupta std::optional<std::vector<nlohmann::json>> remoteRoleMapData; 9948a07d286SRatan Gupta 9958a07d286SRatan Gupta if (!json_util::readJson(input, asyncResp->res, "Authentication", 9968a07d286SRatan Gupta authentication, "LDAPService", ldapService, 9978a07d286SRatan Gupta "ServiceAddresses", serviceAddressList, 99806785244SRatan Gupta "ServiceEnabled", serviceEnabled, 99906785244SRatan Gupta "RemoteRoleMapping", remoteRoleMapData)) 10008a07d286SRatan Gupta { 10018a07d286SRatan Gupta return; 10028a07d286SRatan Gupta } 10038a07d286SRatan Gupta 10048a07d286SRatan Gupta if (authentication) 10058a07d286SRatan Gupta { 10068a07d286SRatan Gupta parseLDAPAuthenticationJson(*authentication, asyncResp, userName, 10078a07d286SRatan Gupta password); 10088a07d286SRatan Gupta } 10098a07d286SRatan Gupta if (ldapService) 10108a07d286SRatan Gupta { 10118a07d286SRatan Gupta parseLDAPServiceJson(*ldapService, asyncResp, baseDNList, 10128a07d286SRatan Gupta userNameAttribute, groupsAttribute); 10138a07d286SRatan Gupta } 10148a07d286SRatan Gupta if (serviceAddressList) 10158a07d286SRatan Gupta { 10168a07d286SRatan Gupta if ((*serviceAddressList).size() == 0) 10178a07d286SRatan Gupta { 10188a07d286SRatan Gupta messages::propertyValueNotInList(asyncResp->res, "[]", 10198a07d286SRatan Gupta "ServiceAddress"); 10208a07d286SRatan Gupta return; 10218a07d286SRatan Gupta } 10228a07d286SRatan Gupta } 10238a07d286SRatan Gupta if (baseDNList) 10248a07d286SRatan Gupta { 10258a07d286SRatan Gupta if ((*baseDNList).size() == 0) 10268a07d286SRatan Gupta { 10278a07d286SRatan Gupta messages::propertyValueNotInList(asyncResp->res, "[]", 10288a07d286SRatan Gupta "BaseDistinguishedNames"); 10298a07d286SRatan Gupta return; 10308a07d286SRatan Gupta } 10318a07d286SRatan Gupta } 10328a07d286SRatan Gupta 10338a07d286SRatan Gupta // nothing to update, then return 10348a07d286SRatan Gupta if (!userName && !password && !serviceAddressList && !baseDNList && 103506785244SRatan Gupta !userNameAttribute && !groupsAttribute && !serviceEnabled && 103606785244SRatan Gupta !remoteRoleMapData) 10378a07d286SRatan Gupta { 10388a07d286SRatan Gupta return; 10398a07d286SRatan Gupta } 10408a07d286SRatan Gupta 10418a07d286SRatan Gupta // Get the existing resource first then keep modifying 10428a07d286SRatan Gupta // whenever any property gets updated. 1043ab828d7cSRatan Gupta getLDAPConfigData(serverType, [this, asyncResp, userName, password, 1044ab828d7cSRatan Gupta baseDNList, userNameAttribute, 1045ba9dd4a8SGunnar Mills groupsAttribute, serviceAddressList, 1046ba9dd4a8SGunnar Mills serviceEnabled, dbusObjectPath, 1047ba9dd4a8SGunnar Mills remoteRoleMapData]( 1048ab828d7cSRatan Gupta bool success, LDAPConfigData confData, 104923a21a1cSEd Tanous const std::string& serverT) { 10508a07d286SRatan Gupta if (!success) 10518a07d286SRatan Gupta { 10528a07d286SRatan Gupta messages::internalError(asyncResp->res); 10538a07d286SRatan Gupta return; 10548a07d286SRatan Gupta } 105523a21a1cSEd Tanous parseLDAPConfigData(asyncResp->res.jsonValue, confData, serverT); 10568a07d286SRatan Gupta if (confData.serviceEnabled) 10578a07d286SRatan Gupta { 10588a07d286SRatan Gupta // Disable the service first and update the rest of 10598a07d286SRatan Gupta // the properties. 106023a21a1cSEd Tanous handleServiceEnablePatch(false, asyncResp, serverT, 1061eb2bbe56SRatan Gupta dbusObjectPath); 10628a07d286SRatan Gupta } 10638a07d286SRatan Gupta 10648a07d286SRatan Gupta if (serviceAddressList) 10658a07d286SRatan Gupta { 10668a07d286SRatan Gupta handleServiceAddressPatch(*serviceAddressList, asyncResp, 106723a21a1cSEd Tanous serverT, dbusObjectPath); 10688a07d286SRatan Gupta } 10698a07d286SRatan Gupta if (userName) 10708a07d286SRatan Gupta { 107123a21a1cSEd Tanous handleUserNamePatch(*userName, asyncResp, serverT, 1072eb2bbe56SRatan Gupta dbusObjectPath); 10738a07d286SRatan Gupta } 10748a07d286SRatan Gupta if (password) 10758a07d286SRatan Gupta { 107623a21a1cSEd Tanous handlePasswordPatch(*password, asyncResp, serverT, 1077eb2bbe56SRatan Gupta dbusObjectPath); 10788a07d286SRatan Gupta } 10798a07d286SRatan Gupta 10808a07d286SRatan Gupta if (baseDNList) 10818a07d286SRatan Gupta { 108223a21a1cSEd Tanous handleBaseDNPatch(*baseDNList, asyncResp, serverT, 1083eb2bbe56SRatan Gupta dbusObjectPath); 10848a07d286SRatan Gupta } 10858a07d286SRatan Gupta if (userNameAttribute) 10868a07d286SRatan Gupta { 108723a21a1cSEd Tanous handleUserNameAttrPatch(*userNameAttribute, asyncResp, serverT, 108823a21a1cSEd Tanous dbusObjectPath); 10898a07d286SRatan Gupta } 10908a07d286SRatan Gupta if (groupsAttribute) 10918a07d286SRatan Gupta { 109223a21a1cSEd Tanous handleGroupNameAttrPatch(*groupsAttribute, asyncResp, serverT, 109323a21a1cSEd Tanous dbusObjectPath); 10948a07d286SRatan Gupta } 10958a07d286SRatan Gupta if (serviceEnabled) 10968a07d286SRatan Gupta { 10978a07d286SRatan Gupta // if user has given the value as true then enable 10988a07d286SRatan Gupta // the service. if user has given false then no-op 10998a07d286SRatan Gupta // as service is already stopped. 11008a07d286SRatan Gupta if (*serviceEnabled) 11018a07d286SRatan Gupta { 11028a07d286SRatan Gupta handleServiceEnablePatch(*serviceEnabled, asyncResp, 110323a21a1cSEd Tanous serverT, dbusObjectPath); 11048a07d286SRatan Gupta } 11058a07d286SRatan Gupta } 11068a07d286SRatan Gupta else 11078a07d286SRatan Gupta { 11088a07d286SRatan Gupta // if user has not given the service enabled value 11098a07d286SRatan Gupta // then revert it to the same state as it was 11108a07d286SRatan Gupta // before. 11118a07d286SRatan Gupta handleServiceEnablePatch(confData.serviceEnabled, asyncResp, 111223a21a1cSEd Tanous serverT, dbusObjectPath); 11138a07d286SRatan Gupta } 111406785244SRatan Gupta 111506785244SRatan Gupta if (remoteRoleMapData) 111606785244SRatan Gupta { 111706785244SRatan Gupta std::vector<nlohmann::json> remoteRoleMap = 111806785244SRatan Gupta std::move(*remoteRoleMapData); 111906785244SRatan Gupta 112023a21a1cSEd Tanous handleRoleMapPatch(asyncResp, confData.groupRoleList, serverT, 112123a21a1cSEd Tanous remoteRoleMap); 112206785244SRatan Gupta } 11238a07d286SRatan Gupta }); 11248a07d286SRatan Gupta } 1125d4b5443fSEd Tanous 1126cb13a392SEd Tanous void doGet(crow::Response& res, const crow::Request&, 1127cb13a392SEd Tanous const std::vector<std::string>&) override 11281abe55efSEd Tanous { 112952cc112dSEd Tanous const persistent_data::AuthConfigMethods& authMethodsConfig = 113052cc112dSEd Tanous persistent_data::SessionStore::getInstance().getAuthMethodsConfig(); 113178158631SZbigniew Kurzynski 11323d958bbcSAppaRao Puli auto asyncResp = std::make_shared<AsyncResp>(res); 11333d958bbcSAppaRao Puli res.jsonValue = { 11343d958bbcSAppaRao Puli {"@odata.id", "/redfish/v1/AccountService"}, 11353d958bbcSAppaRao Puli {"@odata.type", "#AccountService." 1136ba9dd4a8SGunnar Mills "v1_5_0.AccountService"}, 11373d958bbcSAppaRao Puli {"Id", "AccountService"}, 11383d958bbcSAppaRao Puli {"Name", "Account Service"}, 11393d958bbcSAppaRao Puli {"Description", "Account Service"}, 11403d958bbcSAppaRao Puli {"ServiceEnabled", true}, 1141343ff2e1SAppaRao Puli {"MaxPasswordLength", 20}, 11423d958bbcSAppaRao Puli {"Accounts", 11433d958bbcSAppaRao Puli {{"@odata.id", "/redfish/v1/AccountService/Accounts"}}}, 114437cce918SMarri Devender Rao {"Roles", {{"@odata.id", "/redfish/v1/AccountService/Roles"}}}, 114578158631SZbigniew Kurzynski {"Oem", 114678158631SZbigniew Kurzynski {{"OpenBMC", 114778158631SZbigniew Kurzynski {{"@odata.type", "#OemAccountService.v1_0_0.AccountService"}, 114878158631SZbigniew Kurzynski {"AuthMethods", 114978158631SZbigniew Kurzynski { 115078158631SZbigniew Kurzynski {"BasicAuth", authMethodsConfig.basic}, 115178158631SZbigniew Kurzynski {"SessionToken", authMethodsConfig.sessionToken}, 115278158631SZbigniew Kurzynski {"XToken", authMethodsConfig.xtoken}, 115378158631SZbigniew Kurzynski {"Cookie", authMethodsConfig.cookie}, 1154501f1e58SZbigniew Kurzynski {"TLS", authMethodsConfig.tls}, 115578158631SZbigniew Kurzynski }}}}}}, 115637cce918SMarri Devender Rao {"LDAP", 115737cce918SMarri Devender Rao {{"Certificates", 115837cce918SMarri Devender Rao {{"@odata.id", 115937cce918SMarri Devender Rao "/redfish/v1/AccountService/LDAP/Certificates"}}}}}}; 11603d958bbcSAppaRao Puli crow::connections::systemBus->async_method_call( 11613d958bbcSAppaRao Puli [asyncResp]( 11623d958bbcSAppaRao Puli const boost::system::error_code ec, 11633d958bbcSAppaRao Puli const std::vector<std::pair< 1164abf2add6SEd Tanous std::string, std::variant<uint32_t, uint16_t, uint8_t>>>& 11653d958bbcSAppaRao Puli propertiesList) { 11663d958bbcSAppaRao Puli if (ec) 11673d958bbcSAppaRao Puli { 11683d958bbcSAppaRao Puli messages::internalError(asyncResp->res); 11693d958bbcSAppaRao Puli return; 11703d958bbcSAppaRao Puli } 11713d958bbcSAppaRao Puli BMCWEB_LOG_DEBUG << "Got " << propertiesList.size() 11723d958bbcSAppaRao Puli << "properties for AccountService"; 11733d958bbcSAppaRao Puli for (const std::pair<std::string, 1174abf2add6SEd Tanous std::variant<uint32_t, uint16_t, uint8_t>>& 11753d958bbcSAppaRao Puli property : propertiesList) 11763d958bbcSAppaRao Puli { 11773d958bbcSAppaRao Puli if (property.first == "MinPasswordLength") 11783d958bbcSAppaRao Puli { 11793d958bbcSAppaRao Puli const uint8_t* value = 1180abf2add6SEd Tanous std::get_if<uint8_t>(&property.second); 11813d958bbcSAppaRao Puli if (value != nullptr) 11823d958bbcSAppaRao Puli { 11833d958bbcSAppaRao Puli asyncResp->res.jsonValue["MinPasswordLength"] = 11843d958bbcSAppaRao Puli *value; 11853d958bbcSAppaRao Puli } 11863d958bbcSAppaRao Puli } 11873d958bbcSAppaRao Puli if (property.first == "AccountUnlockTimeout") 11883d958bbcSAppaRao Puli { 11893d958bbcSAppaRao Puli const uint32_t* value = 1190abf2add6SEd Tanous std::get_if<uint32_t>(&property.second); 11913d958bbcSAppaRao Puli if (value != nullptr) 11923d958bbcSAppaRao Puli { 11933d958bbcSAppaRao Puli asyncResp->res.jsonValue["AccountLockoutDuration"] = 11943d958bbcSAppaRao Puli *value; 11953d958bbcSAppaRao Puli } 11963d958bbcSAppaRao Puli } 11973d958bbcSAppaRao Puli if (property.first == "MaxLoginAttemptBeforeLockout") 11983d958bbcSAppaRao Puli { 11993d958bbcSAppaRao Puli const uint16_t* value = 1200abf2add6SEd Tanous std::get_if<uint16_t>(&property.second); 12013d958bbcSAppaRao Puli if (value != nullptr) 12023d958bbcSAppaRao Puli { 12033d958bbcSAppaRao Puli asyncResp->res 12043d958bbcSAppaRao Puli .jsonValue["AccountLockoutThreshold"] = *value; 12053d958bbcSAppaRao Puli } 12063d958bbcSAppaRao Puli } 12073d958bbcSAppaRao Puli } 12083d958bbcSAppaRao Puli }, 12093d958bbcSAppaRao Puli "xyz.openbmc_project.User.Manager", "/xyz/openbmc_project/user", 12103d958bbcSAppaRao Puli "org.freedesktop.DBus.Properties", "GetAll", 12113d958bbcSAppaRao Puli "xyz.openbmc_project.User.AccountPolicy"); 12126973a582SRatan Gupta 1213ab828d7cSRatan Gupta auto callback = [asyncResp](bool success, LDAPConfigData& confData, 1214ab828d7cSRatan Gupta const std::string& ldapType) { 1215cb13a392SEd Tanous if (!success) 1216cb13a392SEd Tanous { 1217cb13a392SEd Tanous return; 1218cb13a392SEd Tanous } 1219ab828d7cSRatan Gupta parseLDAPConfigData(asyncResp->res.jsonValue, confData, ldapType); 1220ab828d7cSRatan Gupta }; 1221ab828d7cSRatan Gupta 1222ab828d7cSRatan Gupta getLDAPConfigData("LDAP", callback); 1223ab828d7cSRatan Gupta getLDAPConfigData("ActiveDirectory", callback); 12243d958bbcSAppaRao Puli } 12256973a582SRatan Gupta 12263d958bbcSAppaRao Puli void doPatch(crow::Response& res, const crow::Request& req, 1227cb13a392SEd Tanous const std::vector<std::string>&) override 12283d958bbcSAppaRao Puli { 12293d958bbcSAppaRao Puli auto asyncResp = std::make_shared<AsyncResp>(res); 12303d958bbcSAppaRao Puli 12313d958bbcSAppaRao Puli std::optional<uint32_t> unlockTimeout; 12323d958bbcSAppaRao Puli std::optional<uint16_t> lockoutThreshold; 123319fb6e71SRatan Gupta std::optional<uint16_t> minPasswordLength; 123419fb6e71SRatan Gupta std::optional<uint16_t> maxPasswordLength; 12358a07d286SRatan Gupta std::optional<nlohmann::json> ldapObject; 1236eb2bbe56SRatan Gupta std::optional<nlohmann::json> activeDirectoryObject; 123778158631SZbigniew Kurzynski std::optional<nlohmann::json> oemObject; 123819fb6e71SRatan Gupta 123978158631SZbigniew Kurzynski if (!json_util::readJson( 124078158631SZbigniew Kurzynski req, res, "AccountLockoutDuration", unlockTimeout, 124178158631SZbigniew Kurzynski "AccountLockoutThreshold", lockoutThreshold, 124278158631SZbigniew Kurzynski "MaxPasswordLength", maxPasswordLength, "MinPasswordLength", 124378158631SZbigniew Kurzynski minPasswordLength, "LDAP", ldapObject, "ActiveDirectory", 124478158631SZbigniew Kurzynski activeDirectoryObject, "Oem", oemObject)) 12453d958bbcSAppaRao Puli { 12463d958bbcSAppaRao Puli return; 12473d958bbcSAppaRao Puli } 124819fb6e71SRatan Gupta 124919fb6e71SRatan Gupta if (minPasswordLength) 125019fb6e71SRatan Gupta { 125119fb6e71SRatan Gupta messages::propertyNotWritable(asyncResp->res, "MinPasswordLength"); 125219fb6e71SRatan Gupta } 125319fb6e71SRatan Gupta 125419fb6e71SRatan Gupta if (maxPasswordLength) 125519fb6e71SRatan Gupta { 125619fb6e71SRatan Gupta messages::propertyNotWritable(asyncResp->res, "MaxPasswordLength"); 125719fb6e71SRatan Gupta } 125819fb6e71SRatan Gupta 12598a07d286SRatan Gupta if (ldapObject) 12608a07d286SRatan Gupta { 1261cb13a392SEd Tanous handleLDAPPatch(*ldapObject, asyncResp, "LDAP"); 12628a07d286SRatan Gupta } 12638a07d286SRatan Gupta 126478158631SZbigniew Kurzynski if (std::optional<nlohmann::json> oemOpenBMCObject; 126578158631SZbigniew Kurzynski oemObject && 126678158631SZbigniew Kurzynski json_util::readJson(*oemObject, res, "OpenBMC", oemOpenBMCObject)) 126778158631SZbigniew Kurzynski { 126878158631SZbigniew Kurzynski if (std::optional<nlohmann::json> authMethodsObject; 126978158631SZbigniew Kurzynski oemOpenBMCObject && 127078158631SZbigniew Kurzynski json_util::readJson(*oemOpenBMCObject, res, "AuthMethods", 127178158631SZbigniew Kurzynski authMethodsObject)) 127278158631SZbigniew Kurzynski { 127378158631SZbigniew Kurzynski if (authMethodsObject) 127478158631SZbigniew Kurzynski { 127578158631SZbigniew Kurzynski handleAuthMethodsPatch(*authMethodsObject, asyncResp); 127678158631SZbigniew Kurzynski } 127778158631SZbigniew Kurzynski } 127878158631SZbigniew Kurzynski } 127978158631SZbigniew Kurzynski 1280eb2bbe56SRatan Gupta if (activeDirectoryObject) 1281eb2bbe56SRatan Gupta { 1282cb13a392SEd Tanous handleLDAPPatch(*activeDirectoryObject, asyncResp, 1283eb2bbe56SRatan Gupta "ActiveDirectory"); 1284eb2bbe56SRatan Gupta } 1285eb2bbe56SRatan Gupta 12863d958bbcSAppaRao Puli if (unlockTimeout) 12873d958bbcSAppaRao Puli { 12883d958bbcSAppaRao Puli crow::connections::systemBus->async_method_call( 12893d958bbcSAppaRao Puli [asyncResp](const boost::system::error_code ec) { 12903d958bbcSAppaRao Puli if (ec) 12913d958bbcSAppaRao Puli { 12923d958bbcSAppaRao Puli messages::internalError(asyncResp->res); 12933d958bbcSAppaRao Puli return; 12943d958bbcSAppaRao Puli } 1295add6133bSRatan Gupta messages::success(asyncResp->res); 12963d958bbcSAppaRao Puli }, 12973d958bbcSAppaRao Puli "xyz.openbmc_project.User.Manager", "/xyz/openbmc_project/user", 12983d958bbcSAppaRao Puli "org.freedesktop.DBus.Properties", "Set", 12993d958bbcSAppaRao Puli "xyz.openbmc_project.User.AccountPolicy", 1300abf2add6SEd Tanous "AccountUnlockTimeout", std::variant<uint32_t>(*unlockTimeout)); 13013d958bbcSAppaRao Puli } 13023d958bbcSAppaRao Puli if (lockoutThreshold) 13033d958bbcSAppaRao Puli { 13043d958bbcSAppaRao Puli crow::connections::systemBus->async_method_call( 13053d958bbcSAppaRao Puli [asyncResp](const boost::system::error_code ec) { 13063d958bbcSAppaRao Puli if (ec) 13073d958bbcSAppaRao Puli { 13083d958bbcSAppaRao Puli messages::internalError(asyncResp->res); 13093d958bbcSAppaRao Puli return; 13103d958bbcSAppaRao Puli } 1311add6133bSRatan Gupta messages::success(asyncResp->res); 13123d958bbcSAppaRao Puli }, 13133d958bbcSAppaRao Puli "xyz.openbmc_project.User.Manager", "/xyz/openbmc_project/user", 13143d958bbcSAppaRao Puli "org.freedesktop.DBus.Properties", "Set", 13153d958bbcSAppaRao Puli "xyz.openbmc_project.User.AccountPolicy", 13163d958bbcSAppaRao Puli "MaxLoginAttemptBeforeLockout", 1317abf2add6SEd Tanous std::variant<uint16_t>(*lockoutThreshold)); 13183d958bbcSAppaRao Puli } 131988d16c9aSLewanczyk, Dawid } 132088d16c9aSLewanczyk, Dawid }; 1321f00032dbSTanous 1322b9b2e0b2SEd Tanous class AccountsCollection : public Node 1323b9b2e0b2SEd Tanous { 1324b9b2e0b2SEd Tanous public: 132552cc112dSEd Tanous AccountsCollection(App& app) : 1326b9b2e0b2SEd Tanous Node(app, "/redfish/v1/AccountService/Accounts/") 1327b9b2e0b2SEd Tanous { 1328b9b2e0b2SEd Tanous entityPrivileges = { 1329f365910cSGunnar Mills // According to the PrivilegeRegistry, GET should actually be 1330f365910cSGunnar Mills // "Login". A "Login" only privilege would return an empty "Members" 1331f365910cSGunnar Mills // list. Not going to worry about this since none of the defined 1332f365910cSGunnar Mills // roles are just "Login". E.g. Readonly is {"Login", 1333f365910cSGunnar Mills // "ConfigureSelf"}. In the rare event anyone defines a role that 1334f365910cSGunnar Mills // has Login but not ConfigureSelf, implement this. 1335b9b2e0b2SEd Tanous {boost::beast::http::verb::get, 1336f365910cSGunnar Mills {{"ConfigureUsers"}, {"ConfigureSelf"}}}, 1337b9b2e0b2SEd Tanous {boost::beast::http::verb::head, {{"Login"}}}, 1338b9b2e0b2SEd Tanous {boost::beast::http::verb::patch, {{"ConfigureUsers"}}}, 1339b9b2e0b2SEd Tanous {boost::beast::http::verb::put, {{"ConfigureUsers"}}}, 1340b9b2e0b2SEd Tanous {boost::beast::http::verb::delete_, {{"ConfigureUsers"}}}, 1341b9b2e0b2SEd Tanous {boost::beast::http::verb::post, {{"ConfigureUsers"}}}}; 1342b9b2e0b2SEd Tanous } 1343b9b2e0b2SEd Tanous 1344b9b2e0b2SEd Tanous private: 1345b9b2e0b2SEd Tanous void doGet(crow::Response& res, const crow::Request& req, 1346cb13a392SEd Tanous const std::vector<std::string>&) override 1347b9b2e0b2SEd Tanous { 1348b9b2e0b2SEd Tanous auto asyncResp = std::make_shared<AsyncResp>(res); 134994400960SGunnar Mills res.jsonValue = {{"@odata.id", "/redfish/v1/AccountService/Accounts"}, 13500f74e643SEd Tanous {"@odata.type", "#ManagerAccountCollection." 13510f74e643SEd Tanous "ManagerAccountCollection"}, 13520f74e643SEd Tanous {"Name", "Accounts Collection"}, 13530f74e643SEd Tanous {"Description", "BMC User Accounts"}}; 13540f74e643SEd Tanous 1355b9b2e0b2SEd Tanous crow::connections::systemBus->async_method_call( 1356f365910cSGunnar Mills [asyncResp, &req, this](const boost::system::error_code ec, 1357b9b2e0b2SEd Tanous const ManagedObjectType& users) { 1358b9b2e0b2SEd Tanous if (ec) 1359b9b2e0b2SEd Tanous { 1360f12894f8SJason M. Bills messages::internalError(asyncResp->res); 1361b9b2e0b2SEd Tanous return; 1362b9b2e0b2SEd Tanous } 1363b9b2e0b2SEd Tanous 1364b9b2e0b2SEd Tanous nlohmann::json& memberArray = 1365b9b2e0b2SEd Tanous asyncResp->res.jsonValue["Members"]; 1366b9b2e0b2SEd Tanous memberArray = nlohmann::json::array(); 1367b9b2e0b2SEd Tanous 1368b9b2e0b2SEd Tanous for (auto& user : users) 1369b9b2e0b2SEd Tanous { 1370b9b2e0b2SEd Tanous const std::string& path = 1371b9b2e0b2SEd Tanous static_cast<const std::string&>(user.first); 1372b9b2e0b2SEd Tanous std::size_t lastIndex = path.rfind("/"); 1373b9b2e0b2SEd Tanous if (lastIndex == std::string::npos) 1374b9b2e0b2SEd Tanous { 1375b9b2e0b2SEd Tanous lastIndex = 0; 1376b9b2e0b2SEd Tanous } 1377b9b2e0b2SEd Tanous else 1378b9b2e0b2SEd Tanous { 1379b9b2e0b2SEd Tanous lastIndex += 1; 1380b9b2e0b2SEd Tanous } 1381f365910cSGunnar Mills 1382f365910cSGunnar Mills // As clarified by Redfish here: 1383f365910cSGunnar Mills // https://redfishforum.com/thread/281/manageraccountcollection-change-allows-account-enumeration 1384f365910cSGunnar Mills // Users without ConfigureUsers, only see their own account. 1385f365910cSGunnar Mills // Users with ConfigureUsers, see all accounts. 1386f365910cSGunnar Mills if (req.session->username == path.substr(lastIndex) || 1387f365910cSGunnar Mills isAllowedWithoutConfigureSelf(req)) 1388f365910cSGunnar Mills { 1389b9b2e0b2SEd Tanous memberArray.push_back( 1390f365910cSGunnar Mills {{"@odata.id", 1391f365910cSGunnar Mills "/redfish/v1/AccountService/Accounts/" + 1392b9b2e0b2SEd Tanous path.substr(lastIndex)}}); 1393b9b2e0b2SEd Tanous } 1394f365910cSGunnar Mills } 1395f365910cSGunnar Mills asyncResp->res.jsonValue["Members@odata.count"] = 1396f365910cSGunnar Mills memberArray.size(); 1397b9b2e0b2SEd Tanous }, 1398b9b2e0b2SEd Tanous "xyz.openbmc_project.User.Manager", "/xyz/openbmc_project/user", 1399b9b2e0b2SEd Tanous "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); 1400b9b2e0b2SEd Tanous } 140104ae99ecSEd Tanous void doPost(crow::Response& res, const crow::Request& req, 1402cb13a392SEd Tanous const std::vector<std::string>&) override 140304ae99ecSEd Tanous { 140404ae99ecSEd Tanous auto asyncResp = std::make_shared<AsyncResp>(res); 140504ae99ecSEd Tanous 14069712f8acSEd Tanous std::string username; 14079712f8acSEd Tanous std::string password; 1408a24526dcSEd Tanous std::optional<std::string> roleId("User"); 1409a24526dcSEd Tanous std::optional<bool> enabled = true; 14109712f8acSEd Tanous if (!json_util::readJson(req, res, "UserName", username, "Password", 14119712f8acSEd Tanous password, "RoleId", roleId, "Enabled", 14129712f8acSEd Tanous enabled)) 141304ae99ecSEd Tanous { 141404ae99ecSEd Tanous return; 141504ae99ecSEd Tanous } 141604ae99ecSEd Tanous 141754fc587aSNagaraju Goruganti std::string priv = getPrivilegeFromRoleId(*roleId); 141884e12cb7SAppaRao Puli if (priv.empty()) 141904ae99ecSEd Tanous { 1420f12894f8SJason M. Bills messages::propertyValueNotInList(asyncResp->res, *roleId, "RoleId"); 142104ae99ecSEd Tanous return; 142204ae99ecSEd Tanous } 142396200606Sjayaprakash Mutyala // TODO: Following override will be reverted once support in 142496200606Sjayaprakash Mutyala // phosphor-user-manager is added. In order to avoid dependency issues, 142596200606Sjayaprakash Mutyala // this is added in bmcweb, which will removed, once 142696200606Sjayaprakash Mutyala // phosphor-user-manager supports priv-noaccess. 142796200606Sjayaprakash Mutyala if (priv == "priv-noaccess") 142896200606Sjayaprakash Mutyala { 142996200606Sjayaprakash Mutyala roleId = ""; 143096200606Sjayaprakash Mutyala } 143196200606Sjayaprakash Mutyala else 143296200606Sjayaprakash Mutyala { 14339712f8acSEd Tanous roleId = priv; 143496200606Sjayaprakash Mutyala } 143504ae99ecSEd Tanous 1436599c71d8SAyushi Smriti // Reading AllGroups property 1437599c71d8SAyushi Smriti crow::connections::systemBus->async_method_call( 1438599c71d8SAyushi Smriti [asyncResp, username, password{std::move(password)}, roleId, 1439599c71d8SAyushi Smriti enabled](const boost::system::error_code ec, 1440599c71d8SAyushi Smriti const std::variant<std::vector<std::string>>& allGroups) { 1441599c71d8SAyushi Smriti if (ec) 1442599c71d8SAyushi Smriti { 1443599c71d8SAyushi Smriti BMCWEB_LOG_DEBUG << "ERROR with async_method_call"; 1444599c71d8SAyushi Smriti messages::internalError(asyncResp->res); 1445599c71d8SAyushi Smriti return; 1446599c71d8SAyushi Smriti } 1447599c71d8SAyushi Smriti 1448599c71d8SAyushi Smriti const std::vector<std::string>* allGroupsList = 1449599c71d8SAyushi Smriti std::get_if<std::vector<std::string>>(&allGroups); 1450599c71d8SAyushi Smriti 1451599c71d8SAyushi Smriti if (allGroupsList == nullptr || allGroupsList->empty()) 1452599c71d8SAyushi Smriti { 1453599c71d8SAyushi Smriti messages::internalError(asyncResp->res); 1454599c71d8SAyushi Smriti return; 1455599c71d8SAyushi Smriti } 1456599c71d8SAyushi Smriti 145704ae99ecSEd Tanous crow::connections::systemBus->async_method_call( 14589712f8acSEd Tanous [asyncResp, username, password{std::move(password)}]( 145923a21a1cSEd Tanous const boost::system::error_code ec2, 14600d4197e0Sanil kumar appana sdbusplus::message::message& m) { 146123a21a1cSEd Tanous if (ec2) 146204ae99ecSEd Tanous { 14630d4197e0Sanil kumar appana userErrorMessageHandler(m.get_error(), asyncResp, 14640d4197e0Sanil kumar appana username, ""); 146504ae99ecSEd Tanous return; 146604ae99ecSEd Tanous } 146704ae99ecSEd Tanous 146866b5ca76Sjayaprakash Mutyala if (pamUpdatePassword(username, password) != 146966b5ca76Sjayaprakash Mutyala PAM_SUCCESS) 147004ae99ecSEd Tanous { 1471599c71d8SAyushi Smriti // At this point we have a user that's been created, 1472599c71d8SAyushi Smriti // but the password set failed.Something is wrong, 1473599c71d8SAyushi Smriti // so delete the user that we've already created 147404ae99ecSEd Tanous crow::connections::systemBus->async_method_call( 147523a21a1cSEd Tanous [asyncResp, password]( 147623a21a1cSEd Tanous const boost::system::error_code ec3) { 147723a21a1cSEd Tanous if (ec3) 147804ae99ecSEd Tanous { 1479f12894f8SJason M. Bills messages::internalError(asyncResp->res); 148004ae99ecSEd Tanous return; 148104ae99ecSEd Tanous } 148204ae99ecSEd Tanous 14830d4197e0Sanil kumar appana // If password is invalid 14840d4197e0Sanil kumar appana messages::propertyValueFormatError( 14850d4197e0Sanil kumar appana asyncResp->res, password, "Password"); 148604ae99ecSEd Tanous }, 148704ae99ecSEd Tanous "xyz.openbmc_project.User.Manager", 148804ae99ecSEd Tanous "/xyz/openbmc_project/user/" + username, 148904ae99ecSEd Tanous "xyz.openbmc_project.Object.Delete", "Delete"); 149004ae99ecSEd Tanous 149104ae99ecSEd Tanous BMCWEB_LOG_ERROR << "pamUpdatePassword Failed"; 149204ae99ecSEd Tanous return; 149304ae99ecSEd Tanous } 149404ae99ecSEd Tanous 1495f12894f8SJason M. Bills messages::created(asyncResp->res); 149604ae99ecSEd Tanous asyncResp->res.addHeader( 149704ae99ecSEd Tanous "Location", 149804ae99ecSEd Tanous "/redfish/v1/AccountService/Accounts/" + username); 149904ae99ecSEd Tanous }, 1500599c71d8SAyushi Smriti "xyz.openbmc_project.User.Manager", 1501599c71d8SAyushi Smriti "/xyz/openbmc_project/user", 15029712f8acSEd Tanous "xyz.openbmc_project.User.Manager", "CreateUser", username, 1503599c71d8SAyushi Smriti *allGroupsList, *roleId, *enabled); 1504599c71d8SAyushi Smriti }, 1505599c71d8SAyushi Smriti "xyz.openbmc_project.User.Manager", "/xyz/openbmc_project/user", 1506599c71d8SAyushi Smriti "org.freedesktop.DBus.Properties", "Get", 1507599c71d8SAyushi Smriti "xyz.openbmc_project.User.Manager", "AllGroups"); 150804ae99ecSEd Tanous } 1509b9b2e0b2SEd Tanous }; 1510b9b2e0b2SEd Tanous 1511b9b2e0b2SEd Tanous class ManagerAccount : public Node 1512b9b2e0b2SEd Tanous { 1513b9b2e0b2SEd Tanous public: 151452cc112dSEd Tanous ManagerAccount(App& app) : 1515b9b2e0b2SEd Tanous Node(app, "/redfish/v1/AccountService/Accounts/<str>/", std::string()) 1516b9b2e0b2SEd Tanous { 1517b9b2e0b2SEd Tanous entityPrivileges = { 1518b9b2e0b2SEd Tanous {boost::beast::http::verb::get, 1519b9b2e0b2SEd Tanous {{"ConfigureUsers"}, {"ConfigureManager"}, {"ConfigureSelf"}}}, 1520b9b2e0b2SEd Tanous {boost::beast::http::verb::head, {{"Login"}}}, 1521900f9497SJoseph Reynolds {boost::beast::http::verb::patch, 1522900f9497SJoseph Reynolds {{"ConfigureUsers"}, {"ConfigureSelf"}}}, 1523b9b2e0b2SEd Tanous {boost::beast::http::verb::put, {{"ConfigureUsers"}}}, 1524b9b2e0b2SEd Tanous {boost::beast::http::verb::delete_, {{"ConfigureUsers"}}}, 1525b9b2e0b2SEd Tanous {boost::beast::http::verb::post, {{"ConfigureUsers"}}}}; 1526b9b2e0b2SEd Tanous } 1527b9b2e0b2SEd Tanous 1528b9b2e0b2SEd Tanous private: 1529b9b2e0b2SEd Tanous void doGet(crow::Response& res, const crow::Request& req, 1530b9b2e0b2SEd Tanous const std::vector<std::string>& params) override 1531b9b2e0b2SEd Tanous { 1532b9b2e0b2SEd Tanous auto asyncResp = std::make_shared<AsyncResp>(res); 1533b9b2e0b2SEd Tanous 1534b9b2e0b2SEd Tanous if (params.size() != 1) 1535b9b2e0b2SEd Tanous { 1536f12894f8SJason M. Bills messages::internalError(asyncResp->res); 1537b9b2e0b2SEd Tanous return; 1538b9b2e0b2SEd Tanous } 1539b9b2e0b2SEd Tanous 1540900f9497SJoseph Reynolds // Perform a proper ConfigureSelf authority check. If the 1541900f9497SJoseph Reynolds // user is operating on an account not their own, then their 1542900f9497SJoseph Reynolds // ConfigureSelf privilege does not apply. In this case, 1543900f9497SJoseph Reynolds // perform the authority check again without the user's 1544900f9497SJoseph Reynolds // ConfigureSelf privilege. 1545900f9497SJoseph Reynolds if (req.session->username != params[0]) 1546900f9497SJoseph Reynolds { 1547900f9497SJoseph Reynolds if (!isAllowedWithoutConfigureSelf(req)) 1548900f9497SJoseph Reynolds { 1549900f9497SJoseph Reynolds BMCWEB_LOG_DEBUG << "GET Account denied access"; 1550900f9497SJoseph Reynolds messages::insufficientPrivilege(asyncResp->res); 1551900f9497SJoseph Reynolds return; 1552900f9497SJoseph Reynolds } 1553900f9497SJoseph Reynolds } 1554900f9497SJoseph Reynolds 1555b9b2e0b2SEd Tanous crow::connections::systemBus->async_method_call( 1556b9b2e0b2SEd Tanous [asyncResp, accountName{std::string(params[0])}]( 1557b9b2e0b2SEd Tanous const boost::system::error_code ec, 1558b9b2e0b2SEd Tanous const ManagedObjectType& users) { 1559b9b2e0b2SEd Tanous if (ec) 1560b9b2e0b2SEd Tanous { 1561f12894f8SJason M. Bills messages::internalError(asyncResp->res); 1562b9b2e0b2SEd Tanous return; 1563b9b2e0b2SEd Tanous } 156484e12cb7SAppaRao Puli auto userIt = users.begin(); 1565b9b2e0b2SEd Tanous 156684e12cb7SAppaRao Puli for (; userIt != users.end(); userIt++) 1567b9b2e0b2SEd Tanous { 156884e12cb7SAppaRao Puli if (boost::ends_with(userIt->first.str, "/" + accountName)) 1569b9b2e0b2SEd Tanous { 157084e12cb7SAppaRao Puli break; 1571b9b2e0b2SEd Tanous } 1572b9b2e0b2SEd Tanous } 157384e12cb7SAppaRao Puli if (userIt == users.end()) 1574b9b2e0b2SEd Tanous { 157584e12cb7SAppaRao Puli messages::resourceNotFound(asyncResp->res, "ManagerAccount", 157684e12cb7SAppaRao Puli accountName); 157784e12cb7SAppaRao Puli return; 157884e12cb7SAppaRao Puli } 15794e68c45bSAyushi Smriti 15804e68c45bSAyushi Smriti asyncResp->res.jsonValue = { 15818114bd4dSGunnar Mills {"@odata.type", "#ManagerAccount.v1_4_0.ManagerAccount"}, 15824e68c45bSAyushi Smriti {"Name", "User Account"}, 15834e68c45bSAyushi Smriti {"Description", "User Account"}, 15848114bd4dSGunnar Mills {"Password", nullptr}, 15858114bd4dSGunnar Mills {"AccountTypes", {"Redfish"}}}; 15864e68c45bSAyushi Smriti 158784e12cb7SAppaRao Puli for (const auto& interface : userIt->second) 158865b0dc32SEd Tanous { 158965b0dc32SEd Tanous if (interface.first == 159065b0dc32SEd Tanous "xyz.openbmc_project.User.Attributes") 159165b0dc32SEd Tanous { 159265b0dc32SEd Tanous for (const auto& property : interface.second) 159365b0dc32SEd Tanous { 159465b0dc32SEd Tanous if (property.first == "UserEnabled") 159565b0dc32SEd Tanous { 159665b0dc32SEd Tanous const bool* userEnabled = 1597abf2add6SEd Tanous std::get_if<bool>(&property.second); 159865b0dc32SEd Tanous if (userEnabled == nullptr) 159965b0dc32SEd Tanous { 160065b0dc32SEd Tanous BMCWEB_LOG_ERROR 160165b0dc32SEd Tanous << "UserEnabled wasn't a bool"; 160284e12cb7SAppaRao Puli messages::internalError(asyncResp->res); 160384e12cb7SAppaRao Puli return; 160465b0dc32SEd Tanous } 160565b0dc32SEd Tanous asyncResp->res.jsonValue["Enabled"] = 160665b0dc32SEd Tanous *userEnabled; 160765b0dc32SEd Tanous } 160865b0dc32SEd Tanous else if (property.first == 160965b0dc32SEd Tanous "UserLockedForFailedAttempt") 161065b0dc32SEd Tanous { 161165b0dc32SEd Tanous const bool* userLocked = 1612abf2add6SEd Tanous std::get_if<bool>(&property.second); 161365b0dc32SEd Tanous if (userLocked == nullptr) 161465b0dc32SEd Tanous { 161584e12cb7SAppaRao Puli BMCWEB_LOG_ERROR << "UserLockedForF" 161684e12cb7SAppaRao Puli "ailedAttempt " 161784e12cb7SAppaRao Puli "wasn't a bool"; 161884e12cb7SAppaRao Puli messages::internalError(asyncResp->res); 161984e12cb7SAppaRao Puli return; 162065b0dc32SEd Tanous } 162165b0dc32SEd Tanous asyncResp->res.jsonValue["Locked"] = 162265b0dc32SEd Tanous *userLocked; 162324c8542dSRatan Gupta asyncResp->res.jsonValue 162424c8542dSRatan Gupta ["Locked@Redfish.AllowableValues"] = { 16253bf4e632SJoseph Reynolds "false"}; // can only unlock accounts 162665b0dc32SEd Tanous } 162784e12cb7SAppaRao Puli else if (property.first == "UserPrivilege") 162884e12cb7SAppaRao Puli { 162954fc587aSNagaraju Goruganti const std::string* userPrivPtr = 1630abf2add6SEd Tanous std::get_if<std::string>(&property.second); 163154fc587aSNagaraju Goruganti if (userPrivPtr == nullptr) 163284e12cb7SAppaRao Puli { 163384e12cb7SAppaRao Puli BMCWEB_LOG_ERROR 163484e12cb7SAppaRao Puli << "UserPrivilege wasn't a " 163584e12cb7SAppaRao Puli "string"; 163684e12cb7SAppaRao Puli messages::internalError(asyncResp->res); 163784e12cb7SAppaRao Puli return; 163884e12cb7SAppaRao Puli } 163954fc587aSNagaraju Goruganti std::string role = 164054fc587aSNagaraju Goruganti getRoleIdFromPrivilege(*userPrivPtr); 164154fc587aSNagaraju Goruganti if (role.empty()) 164284e12cb7SAppaRao Puli { 164384e12cb7SAppaRao Puli BMCWEB_LOG_ERROR << "Invalid user role"; 164484e12cb7SAppaRao Puli messages::internalError(asyncResp->res); 164584e12cb7SAppaRao Puli return; 164684e12cb7SAppaRao Puli } 164754fc587aSNagaraju Goruganti asyncResp->res.jsonValue["RoleId"] = role; 164884e12cb7SAppaRao Puli 164984e12cb7SAppaRao Puli asyncResp->res.jsonValue["Links"]["Role"] = { 165084e12cb7SAppaRao Puli {"@odata.id", "/redfish/v1/AccountService/" 165184e12cb7SAppaRao Puli "Roles/" + 165254fc587aSNagaraju Goruganti role}}; 165384e12cb7SAppaRao Puli } 16543bf4e632SJoseph Reynolds else if (property.first == "UserPasswordExpired") 16553bf4e632SJoseph Reynolds { 16563bf4e632SJoseph Reynolds const bool* userPasswordExpired = 16573bf4e632SJoseph Reynolds std::get_if<bool>(&property.second); 16583bf4e632SJoseph Reynolds if (userPasswordExpired == nullptr) 16593bf4e632SJoseph Reynolds { 16603bf4e632SJoseph Reynolds BMCWEB_LOG_ERROR << "UserPassword" 16613bf4e632SJoseph Reynolds "Expired " 16623bf4e632SJoseph Reynolds "wasn't a bool"; 16633bf4e632SJoseph Reynolds messages::internalError(asyncResp->res); 16643bf4e632SJoseph Reynolds return; 16653bf4e632SJoseph Reynolds } 16663bf4e632SJoseph Reynolds asyncResp->res 16673bf4e632SJoseph Reynolds .jsonValue["PasswordChangeRequired"] = 16683bf4e632SJoseph Reynolds *userPasswordExpired; 16693bf4e632SJoseph Reynolds } 167065b0dc32SEd Tanous } 167165b0dc32SEd Tanous } 167265b0dc32SEd Tanous } 167365b0dc32SEd Tanous 1674b9b2e0b2SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 167584e12cb7SAppaRao Puli "/redfish/v1/AccountService/Accounts/" + accountName; 1676b9b2e0b2SEd Tanous asyncResp->res.jsonValue["Id"] = accountName; 1677b9b2e0b2SEd Tanous asyncResp->res.jsonValue["UserName"] = accountName; 1678b9b2e0b2SEd Tanous }, 1679b9b2e0b2SEd Tanous "xyz.openbmc_project.User.Manager", "/xyz/openbmc_project/user", 1680b9b2e0b2SEd Tanous "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); 1681b9b2e0b2SEd Tanous } 1682a840879dSEd Tanous 1683a840879dSEd Tanous void doPatch(crow::Response& res, const crow::Request& req, 1684a840879dSEd Tanous const std::vector<std::string>& params) override 1685a840879dSEd Tanous { 1686a840879dSEd Tanous auto asyncResp = std::make_shared<AsyncResp>(res); 1687a840879dSEd Tanous if (params.size() != 1) 1688a840879dSEd Tanous { 1689f12894f8SJason M. Bills messages::internalError(asyncResp->res); 1690a840879dSEd Tanous return; 1691a840879dSEd Tanous } 1692a840879dSEd Tanous 1693a24526dcSEd Tanous std::optional<std::string> newUserName; 1694a24526dcSEd Tanous std::optional<std::string> password; 1695a24526dcSEd Tanous std::optional<bool> enabled; 1696a24526dcSEd Tanous std::optional<std::string> roleId; 169724c8542dSRatan Gupta std::optional<bool> locked; 169884e12cb7SAppaRao Puli if (!json_util::readJson(req, res, "UserName", newUserName, "Password", 169924c8542dSRatan Gupta password, "RoleId", roleId, "Enabled", enabled, 170024c8542dSRatan Gupta "Locked", locked)) 1701a840879dSEd Tanous { 1702a840879dSEd Tanous return; 1703a840879dSEd Tanous } 1704a840879dSEd Tanous 170584e12cb7SAppaRao Puli const std::string& username = params[0]; 170684e12cb7SAppaRao Puli 1707900f9497SJoseph Reynolds // Perform a proper ConfigureSelf authority check. If the 1708900f9497SJoseph Reynolds // session is being used to PATCH a property other than 1709900f9497SJoseph Reynolds // Password, then the ConfigureSelf privilege does not apply. 1710900f9497SJoseph Reynolds // If the user is operating on an account not their own, then 1711900f9497SJoseph Reynolds // their ConfigureSelf privilege does not apply. In either 1712900f9497SJoseph Reynolds // case, perform the authority check again without the user's 1713900f9497SJoseph Reynolds // ConfigureSelf privilege. 1714900f9497SJoseph Reynolds if ((username != req.session->username) || 1715900f9497SJoseph Reynolds (newUserName || enabled || roleId || locked)) 1716900f9497SJoseph Reynolds { 1717900f9497SJoseph Reynolds if (!isAllowedWithoutConfigureSelf(req)) 1718900f9497SJoseph Reynolds { 1719900f9497SJoseph Reynolds BMCWEB_LOG_WARNING << "PATCH Password denied access"; 1720900f9497SJoseph Reynolds asyncResp->res.clear(); 1721900f9497SJoseph Reynolds messages::insufficientPrivilege(asyncResp->res); 1722900f9497SJoseph Reynolds return; 1723900f9497SJoseph Reynolds } 1724900f9497SJoseph Reynolds } 1725900f9497SJoseph Reynolds 172666b5ca76Sjayaprakash Mutyala // if user name is not provided in the patch method or if it 172766b5ca76Sjayaprakash Mutyala // matches the user name in the URI, then we are treating it as updating 172866b5ca76Sjayaprakash Mutyala // user properties other then username. If username provided doesn't 172966b5ca76Sjayaprakash Mutyala // match the URI, then we are treating this as user rename request. 173066b5ca76Sjayaprakash Mutyala if (!newUserName || (newUserName.value() == username)) 1731a840879dSEd Tanous { 173224c8542dSRatan Gupta updateUserProperties(asyncResp, username, password, enabled, roleId, 173324c8542dSRatan Gupta locked); 173484e12cb7SAppaRao Puli return; 173584e12cb7SAppaRao Puli } 173684e12cb7SAppaRao Puli else 173784e12cb7SAppaRao Puli { 173884e12cb7SAppaRao Puli crow::connections::systemBus->async_method_call( 173984e12cb7SAppaRao Puli [this, asyncResp, username, password(std::move(password)), 174084e12cb7SAppaRao Puli roleId(std::move(roleId)), enabled(std::move(enabled)), 174166b5ca76Sjayaprakash Mutyala newUser{std::string(*newUserName)}, 174266b5ca76Sjayaprakash Mutyala locked(std::move(locked))](const boost::system::error_code ec, 174366b5ca76Sjayaprakash Mutyala sdbusplus::message::message& m) { 174484e12cb7SAppaRao Puli if (ec) 174584e12cb7SAppaRao Puli { 174666b5ca76Sjayaprakash Mutyala userErrorMessageHandler(m.get_error(), asyncResp, 174766b5ca76Sjayaprakash Mutyala newUser, username); 1748a840879dSEd Tanous return; 1749a840879dSEd Tanous } 1750a840879dSEd Tanous 175184e12cb7SAppaRao Puli updateUserProperties(asyncResp, newUser, password, enabled, 175224c8542dSRatan Gupta roleId, locked); 175384e12cb7SAppaRao Puli }, 175484e12cb7SAppaRao Puli "xyz.openbmc_project.User.Manager", "/xyz/openbmc_project/user", 175584e12cb7SAppaRao Puli "xyz.openbmc_project.User.Manager", "RenameUser", username, 175684e12cb7SAppaRao Puli *newUserName); 175784e12cb7SAppaRao Puli } 175884e12cb7SAppaRao Puli } 175984e12cb7SAppaRao Puli 176084e12cb7SAppaRao Puli void updateUserProperties(std::shared_ptr<AsyncResp> asyncResp, 176184e12cb7SAppaRao Puli const std::string& username, 1762a24526dcSEd Tanous std::optional<std::string> password, 1763a24526dcSEd Tanous std::optional<bool> enabled, 176424c8542dSRatan Gupta std::optional<std::string> roleId, 176524c8542dSRatan Gupta std::optional<bool> locked) 176684e12cb7SAppaRao Puli { 176724c8542dSRatan Gupta std::string dbusObjectPath = "/xyz/openbmc_project/user/" + username; 176824c8542dSRatan Gupta dbus::utility::escapePathForDbus(dbusObjectPath); 176924c8542dSRatan Gupta 177022c33710SRatan Gupta dbus::utility::checkDbusPathExists( 177124c8542dSRatan Gupta dbusObjectPath, 177224c8542dSRatan Gupta [dbusObjectPath(std::move(dbusObjectPath)), username, 177324c8542dSRatan Gupta password(std::move(password)), roleId(std::move(roleId)), 177424c8542dSRatan Gupta enabled(std::move(enabled)), locked(std::move(locked)), 177524c8542dSRatan Gupta asyncResp{std::move(asyncResp)}](int rc) { 177624c8542dSRatan Gupta if (!rc) 177724c8542dSRatan Gupta { 177866b5ca76Sjayaprakash Mutyala messages::resourceNotFound( 17798114bd4dSGunnar Mills asyncResp->res, "#ManagerAccount.v1_4_0.ManagerAccount", 178066b5ca76Sjayaprakash Mutyala username); 178124c8542dSRatan Gupta return; 178224c8542dSRatan Gupta } 178366b5ca76Sjayaprakash Mutyala 178466b5ca76Sjayaprakash Mutyala if (password) 178566b5ca76Sjayaprakash Mutyala { 178666b5ca76Sjayaprakash Mutyala int retval = pamUpdatePassword(username, *password); 178766b5ca76Sjayaprakash Mutyala 178866b5ca76Sjayaprakash Mutyala if (retval == PAM_USER_UNKNOWN) 178966b5ca76Sjayaprakash Mutyala { 179066b5ca76Sjayaprakash Mutyala messages::resourceNotFound( 179166b5ca76Sjayaprakash Mutyala asyncResp->res, 17928114bd4dSGunnar Mills "#ManagerAccount.v1_4_0.ManagerAccount", username); 179366b5ca76Sjayaprakash Mutyala } 179466b5ca76Sjayaprakash Mutyala else if (retval == PAM_AUTHTOK_ERR) 179566b5ca76Sjayaprakash Mutyala { 179666b5ca76Sjayaprakash Mutyala // If password is invalid 179766b5ca76Sjayaprakash Mutyala messages::propertyValueFormatError( 179866b5ca76Sjayaprakash Mutyala asyncResp->res, *password, "Password"); 179966b5ca76Sjayaprakash Mutyala BMCWEB_LOG_ERROR << "pamUpdatePassword Failed"; 180066b5ca76Sjayaprakash Mutyala } 180166b5ca76Sjayaprakash Mutyala else if (retval != PAM_SUCCESS) 180266b5ca76Sjayaprakash Mutyala { 180366b5ca76Sjayaprakash Mutyala messages::internalError(asyncResp->res); 180466b5ca76Sjayaprakash Mutyala return; 180566b5ca76Sjayaprakash Mutyala } 180666b5ca76Sjayaprakash Mutyala } 180766b5ca76Sjayaprakash Mutyala 18089712f8acSEd Tanous if (enabled) 1809a840879dSEd Tanous { 1810a840879dSEd Tanous crow::connections::systemBus->async_method_call( 1811a840879dSEd Tanous [asyncResp](const boost::system::error_code ec) { 1812a840879dSEd Tanous if (ec) 1813a840879dSEd Tanous { 181424c8542dSRatan Gupta BMCWEB_LOG_ERROR << "D-Bus responses error: " 181524c8542dSRatan Gupta << ec; 1816f12894f8SJason M. Bills messages::internalError(asyncResp->res); 1817a840879dSEd Tanous return; 1818a840879dSEd Tanous } 181984e12cb7SAppaRao Puli messages::success(asyncResp->res); 182084e12cb7SAppaRao Puli return; 182184e12cb7SAppaRao Puli }, 182284e12cb7SAppaRao Puli "xyz.openbmc_project.User.Manager", 182324c8542dSRatan Gupta dbusObjectPath.c_str(), 182484e12cb7SAppaRao Puli "org.freedesktop.DBus.Properties", "Set", 182584e12cb7SAppaRao Puli "xyz.openbmc_project.User.Attributes", "UserEnabled", 1826abf2add6SEd Tanous std::variant<bool>{*enabled}); 182784e12cb7SAppaRao Puli } 182884e12cb7SAppaRao Puli 182984e12cb7SAppaRao Puli if (roleId) 183084e12cb7SAppaRao Puli { 183154fc587aSNagaraju Goruganti std::string priv = getPrivilegeFromRoleId(*roleId); 183284e12cb7SAppaRao Puli if (priv.empty()) 183384e12cb7SAppaRao Puli { 183424c8542dSRatan Gupta messages::propertyValueNotInList(asyncResp->res, 183524c8542dSRatan Gupta *roleId, "RoleId"); 183684e12cb7SAppaRao Puli return; 183784e12cb7SAppaRao Puli } 183896200606Sjayaprakash Mutyala if (priv == "priv-noaccess") 183996200606Sjayaprakash Mutyala { 184096200606Sjayaprakash Mutyala priv = ""; 184196200606Sjayaprakash Mutyala } 184284e12cb7SAppaRao Puli 184384e12cb7SAppaRao Puli crow::connections::systemBus->async_method_call( 184484e12cb7SAppaRao Puli [asyncResp](const boost::system::error_code ec) { 184584e12cb7SAppaRao Puli if (ec) 184684e12cb7SAppaRao Puli { 184724c8542dSRatan Gupta BMCWEB_LOG_ERROR << "D-Bus responses error: " 184824c8542dSRatan Gupta << ec; 184984e12cb7SAppaRao Puli messages::internalError(asyncResp->res); 185084e12cb7SAppaRao Puli return; 185184e12cb7SAppaRao Puli } 1852f12894f8SJason M. Bills messages::success(asyncResp->res); 1853a840879dSEd Tanous }, 1854a840879dSEd Tanous "xyz.openbmc_project.User.Manager", 185524c8542dSRatan Gupta dbusObjectPath.c_str(), 1856a840879dSEd Tanous "org.freedesktop.DBus.Properties", "Set", 185784e12cb7SAppaRao Puli "xyz.openbmc_project.User.Attributes", "UserPrivilege", 1858abf2add6SEd Tanous std::variant<std::string>{priv}); 1859a840879dSEd Tanous } 186024c8542dSRatan Gupta 186124c8542dSRatan Gupta if (locked) 186224c8542dSRatan Gupta { 186324c8542dSRatan Gupta // admin can unlock the account which is locked by 186454fc587aSNagaraju Goruganti // successive authentication failures but admin should 186554fc587aSNagaraju Goruganti // not be allowed to lock an account. 186624c8542dSRatan Gupta if (*locked) 186724c8542dSRatan Gupta { 186824c8542dSRatan Gupta messages::propertyValueNotInList(asyncResp->res, "true", 186924c8542dSRatan Gupta "Locked"); 187024c8542dSRatan Gupta return; 187124c8542dSRatan Gupta } 187224c8542dSRatan Gupta 187324c8542dSRatan Gupta crow::connections::systemBus->async_method_call( 187424c8542dSRatan Gupta [asyncResp](const boost::system::error_code ec) { 187524c8542dSRatan Gupta if (ec) 187624c8542dSRatan Gupta { 187724c8542dSRatan Gupta BMCWEB_LOG_ERROR << "D-Bus responses error: " 187824c8542dSRatan Gupta << ec; 187924c8542dSRatan Gupta messages::internalError(asyncResp->res); 188024c8542dSRatan Gupta return; 188124c8542dSRatan Gupta } 188224c8542dSRatan Gupta messages::success(asyncResp->res); 188324c8542dSRatan Gupta return; 188424c8542dSRatan Gupta }, 188524c8542dSRatan Gupta "xyz.openbmc_project.User.Manager", 188624c8542dSRatan Gupta dbusObjectPath.c_str(), 188724c8542dSRatan Gupta "org.freedesktop.DBus.Properties", "Set", 188824c8542dSRatan Gupta "xyz.openbmc_project.User.Attributes", 188924c8542dSRatan Gupta "UserLockedForFailedAttempt", 189019bd78d9SPatrick Williams std::variant<bool>{*locked}); 189124c8542dSRatan Gupta } 189224c8542dSRatan Gupta }); 1893a840879dSEd Tanous } 189406e086d9SEd Tanous 1895cb13a392SEd Tanous void doDelete(crow::Response& res, const crow::Request&, 189606e086d9SEd Tanous const std::vector<std::string>& params) override 189706e086d9SEd Tanous { 189806e086d9SEd Tanous auto asyncResp = std::make_shared<AsyncResp>(res); 189906e086d9SEd Tanous 190006e086d9SEd Tanous if (params.size() != 1) 190106e086d9SEd Tanous { 1902f12894f8SJason M. Bills messages::internalError(asyncResp->res); 190306e086d9SEd Tanous return; 190406e086d9SEd Tanous } 190506e086d9SEd Tanous 190606e086d9SEd Tanous const std::string userPath = "/xyz/openbmc_project/user/" + params[0]; 190706e086d9SEd Tanous 190806e086d9SEd Tanous crow::connections::systemBus->async_method_call( 190906e086d9SEd Tanous [asyncResp, username{std::move(params[0])}]( 191006e086d9SEd Tanous const boost::system::error_code ec) { 191106e086d9SEd Tanous if (ec) 191206e086d9SEd Tanous { 191306e086d9SEd Tanous messages::resourceNotFound( 19148114bd4dSGunnar Mills asyncResp->res, "#ManagerAccount.v1_4_0.ManagerAccount", 1915f12894f8SJason M. Bills username); 191606e086d9SEd Tanous return; 191706e086d9SEd Tanous } 191806e086d9SEd Tanous 1919f12894f8SJason M. Bills messages::accountRemoved(asyncResp->res); 192006e086d9SEd Tanous }, 192106e086d9SEd Tanous "xyz.openbmc_project.User.Manager", userPath, 192206e086d9SEd Tanous "xyz.openbmc_project.Object.Delete", "Delete"); 192306e086d9SEd Tanous } 192484e12cb7SAppaRao Puli }; 192588d16c9aSLewanczyk, Dawid 192688d16c9aSLewanczyk, Dawid } // namespace redfish 1927