blob: e16751b8e17cfa6739f411fc7579c0ba9bbd8e63 [file] [log] [blame]
Ed Tanous40e9b922024-09-10 13:50:16 -07001// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright OpenBMC Authors
3// SPDX-FileCopyrightText: Copyright 2018 Intel Corporation
Lewanczyk, Dawid88d16c92018-02-02 14:51:09 +01004#pragma once
Lewanczyk, Dawid88d16c92018-02-02 14:51:09 +01005
Ed Tanousd7857202025-01-28 15:32:26 -08006#include "bmcweb_config.h"
7
Ed Tanous3ccb3ad2023-01-13 17:40:03 -08008#include "app.hpp"
Ed Tanousd7857202025-01-28 15:32:26 -08009#include "async_resp.hpp"
Gunnar Millsa0735a42024-09-06 12:51:11 -050010#include "boost_formatters.hpp"
Ed Tanous1aa375b2024-04-13 11:51:10 -070011#include "certificate_service.hpp"
Ed Tanousd7857202025-01-28 15:32:26 -080012#include "dbus_singleton.hpp"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080013#include "dbus_utility.hpp"
14#include "error_messages.hpp"
Ed Tanous0ec8b832022-03-14 14:56:47 -070015#include "generated/enums/account_service.hpp"
Ed Tanousd7857202025-01-28 15:32:26 -080016#include "http_request.hpp"
17#include "http_response.hpp"
18#include "logging.hpp"
19#include "pam_authenticate.hpp"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080020#include "persistent_data.hpp"
Ed Tanousd7857202025-01-28 15:32:26 -080021#include "privileges.hpp"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080022#include "query.hpp"
Ed Tanous0ec8b832022-03-14 14:56:47 -070023#include "registries/privilege_registry.hpp"
Ed Tanous3281bcf2024-06-25 16:02:05 -070024#include "sessions.hpp"
Ed Tanous1aa375b2024-04-13 11:51:10 -070025#include "utils/collection.hpp"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080026#include "utils/dbus_utils.hpp"
27#include "utils/json_utils.hpp"
Ed Tanous0ec8b832022-03-14 14:56:47 -070028
Ed Tanousd7857202025-01-28 15:32:26 -080029#include <security/_pam_types.h>
30#include <systemd/sd-bus.h>
31
32#include <boost/beast/http/field.hpp>
33#include <boost/beast/http/status.hpp>
34#include <boost/beast/http/verb.hpp>
Ed Tanous1aa375b2024-04-13 11:51:10 -070035#include <boost/url/format.hpp>
36#include <boost/url/url.hpp>
Ed Tanousd7857202025-01-28 15:32:26 -080037#include <nlohmann/json.hpp>
38#include <sdbusplus/message.hpp>
Krzysztof Grobelnyd1bde9e2022-09-07 10:40:51 +020039#include <sdbusplus/unpack_properties.hpp>
Gunnar Mills1214b7e2020-06-04 10:11:30 -050040
Ed Tanousd7857202025-01-28 15:32:26 -080041#include <algorithm>
George Liu2b731192023-01-11 16:27:13 +080042#include <array>
Ed Tanousd7857202025-01-28 15:32:26 -080043#include <cstddef>
44#include <cstdint>
45#include <cstring>
46#include <format>
47#include <functional>
Ed Tanous1aa375b2024-04-13 11:51:10 -070048#include <memory>
Abhishek Patelc7229812022-02-01 10:07:15 -060049#include <optional>
Ed Tanous3544d2a2023-08-06 18:12:20 -070050#include <ranges>
Abhishek Patelc7229812022-02-01 10:07:15 -060051#include <string>
George Liu2b731192023-01-11 16:27:13 +080052#include <string_view>
Ed Tanous20fa6a22024-05-20 18:02:58 -070053#include <utility>
Ed Tanousd7857202025-01-28 15:32:26 -080054#include <variant>
Abhishek Patelc7229812022-02-01 10:07:15 -060055#include <vector>
56
Ed Tanous1abe55e2018-09-05 08:30:59 -070057namespace redfish
58{
Lewanczyk, Dawid88d16c92018-02-02 14:51:09 +010059
Ed Tanous23a21a12020-07-25 04:45:05 +000060constexpr const char* ldapConfigObjectName =
Ratan Gupta6973a582018-12-13 18:25:44 +053061 "/xyz/openbmc_project/user/ldap/openldap";
Ed Tanous2c70f802020-09-28 14:29:23 -070062constexpr const char* adConfigObject =
Ratan Guptaab828d72019-04-22 14:18:33 +053063 "/xyz/openbmc_project/user/ldap/active_directory";
64
P Dheeraj Srujan Kumarb477fd42021-12-16 07:17:51 +053065constexpr const char* rootUserDbusPath = "/xyz/openbmc_project/user/";
Ratan Gupta6973a582018-12-13 18:25:44 +053066constexpr const char* ldapRootObject = "/xyz/openbmc_project/user/ldap";
67constexpr const char* ldapDbusService = "xyz.openbmc_project.Ldap.Config";
68constexpr const char* ldapConfigInterface =
69 "xyz.openbmc_project.User.Ldap.Config";
70constexpr const char* ldapCreateInterface =
71 "xyz.openbmc_project.User.Ldap.Create";
72constexpr const char* ldapEnableInterface = "xyz.openbmc_project.Object.Enable";
Ratan Gupta06785242019-07-26 22:30:16 +053073constexpr const char* ldapPrivMapperInterface =
74 "xyz.openbmc_project.User.PrivilegeMapper";
Ratan Gupta6973a582018-12-13 18:25:44 +053075
Nagaraju Goruganti54fc5872019-01-30 05:11:00 -060076struct LDAPRoleMapData
77{
78 std::string groupName;
79 std::string privilege;
80};
81
Ratan Gupta6973a582018-12-13 18:25:44 +053082struct LDAPConfigData
83{
Ed Tanous47f29342024-03-19 12:18:06 -070084 std::string uri;
85 std::string bindDN;
86 std::string baseDN;
87 std::string searchScope;
88 std::string serverType;
Ratan Gupta6973a582018-12-13 18:25:44 +053089 bool serviceEnabled = false;
Ed Tanous47f29342024-03-19 12:18:06 -070090 std::string userNameAttribute;
91 std::string groupAttribute;
Nagaraju Goruganti54fc5872019-01-30 05:11:00 -060092 std::vector<std::pair<std::string, LDAPRoleMapData>> groupRoleList;
Ratan Gupta6973a582018-12-13 18:25:44 +053093};
94
Nagaraju Goruganti54fc5872019-01-30 05:11:00 -060095inline std::string getRoleIdFromPrivilege(std::string_view role)
AppaRao Puli84e12cb2018-10-11 01:28:15 +053096{
97 if (role == "priv-admin")
98 {
99 return "Administrator";
100 }
Ed Tanous3174e4d2020-10-07 11:41:22 -0700101 if (role == "priv-user")
AppaRao Puli84e12cb2018-10-11 01:28:15 +0530102 {
AppaRao Pulic80fee52019-10-16 14:49:36 +0530103 return "ReadOnly";
AppaRao Puli84e12cb2018-10-11 01:28:15 +0530104 }
Ed Tanous3174e4d2020-10-07 11:41:22 -0700105 if (role == "priv-operator")
AppaRao Puli84e12cb2018-10-11 01:28:15 +0530106 {
107 return "Operator";
108 }
109 return "";
110}
Nagaraju Goruganti54fc5872019-01-30 05:11:00 -0600111inline std::string getPrivilegeFromRoleId(std::string_view role)
AppaRao Puli84e12cb2018-10-11 01:28:15 +0530112{
113 if (role == "Administrator")
114 {
115 return "priv-admin";
116 }
Ed Tanous3174e4d2020-10-07 11:41:22 -0700117 if (role == "ReadOnly")
AppaRao Puli84e12cb2018-10-11 01:28:15 +0530118 {
119 return "priv-user";
120 }
Ed Tanous3174e4d2020-10-07 11:41:22 -0700121 if (role == "Operator")
AppaRao Puli84e12cb2018-10-11 01:28:15 +0530122 {
123 return "priv-operator";
124 }
125 return "";
126}
Ed Tanousb9b2e0b2018-09-13 13:47:50 -0700127
Abhishek Patelc7229812022-02-01 10:07:15 -0600128/**
129 * @brief Maps user group names retrieved from D-Bus object to
130 * Account Types.
131 *
132 * @param[in] userGroups List of User groups
133 * @param[out] res AccountTypes populated
134 *
135 * @return true in case of success, false if UserGroups contains
136 * invalid group name(s).
137 */
138inline bool translateUserGroup(const std::vector<std::string>& userGroups,
139 crow::Response& res)
140{
141 std::vector<std::string> accountTypes;
142 for (const auto& userGroup : userGroups)
143 {
144 if (userGroup == "redfish")
145 {
146 accountTypes.emplace_back("Redfish");
147 accountTypes.emplace_back("WebUI");
148 }
149 else if (userGroup == "ipmi")
150 {
151 accountTypes.emplace_back("IPMI");
152 }
153 else if (userGroup == "ssh")
154 {
Abhishek Patelc7229812022-02-01 10:07:15 -0600155 accountTypes.emplace_back("ManagerConsole");
156 }
Ninad Palsule3e72c202023-03-27 17:19:55 -0500157 else if (userGroup == "hostconsole")
158 {
159 // The hostconsole group controls who can access the host console
160 // port via ssh and websocket.
161 accountTypes.emplace_back("HostConsole");
162 }
Abhishek Patelc7229812022-02-01 10:07:15 -0600163 else if (userGroup == "web")
164 {
165 // 'web' is one of the valid groups in the UserGroups property of
166 // the user account in the D-Bus object. This group is currently not
167 // doing anything, and is considered to be equivalent to 'redfish'.
168 // 'redfish' user group is mapped to 'Redfish'and 'WebUI'
169 // AccountTypes, so do nothing here...
170 }
171 else
172 {
Ed Tanous8ece0e42024-01-02 13:16:50 -0800173 // Invalid user group name. Caller throws an exception.
Abhishek Patelc7229812022-02-01 10:07:15 -0600174 return false;
175 }
176 }
177
178 res.jsonValue["AccountTypes"] = std::move(accountTypes);
179 return true;
180}
181
Abhishek Patel58345852022-02-02 08:54:25 -0600182/**
183 * @brief Builds User Groups from the Account Types
184 *
185 * @param[in] asyncResp Async Response
186 * @param[in] accountTypes List of Account Types
187 * @param[out] userGroups List of User Groups mapped from Account Types
188 *
189 * @return true if Account Types mapped to User Groups, false otherwise.
190 */
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400191inline bool getUserGroupFromAccountType(
192 crow::Response& res, const std::vector<std::string>& accountTypes,
193 std::vector<std::string>& userGroups)
Abhishek Patel58345852022-02-02 08:54:25 -0600194{
195 // Need both Redfish and WebUI Account Types to map to 'redfish' User Group
196 bool redfishType = false;
197 bool webUIType = false;
198
199 for (const auto& accountType : accountTypes)
200 {
201 if (accountType == "Redfish")
202 {
203 redfishType = true;
204 }
205 else if (accountType == "WebUI")
206 {
207 webUIType = true;
208 }
209 else if (accountType == "IPMI")
210 {
211 userGroups.emplace_back("ipmi");
212 }
213 else if (accountType == "HostConsole")
214 {
215 userGroups.emplace_back("hostconsole");
216 }
217 else if (accountType == "ManagerConsole")
218 {
219 userGroups.emplace_back("ssh");
220 }
221 else
222 {
223 // Invalid Account Type
224 messages::propertyValueNotInList(res, "AccountTypes", accountType);
225 return false;
226 }
227 }
228
229 // Both Redfish and WebUI Account Types are needed to PATCH
230 if (redfishType ^ webUIType)
231 {
Ed Tanous62598e32023-07-17 17:06:25 -0700232 BMCWEB_LOG_ERROR(
233 "Missing Redfish or WebUI Account Type to set redfish User Group");
Abhishek Patel58345852022-02-02 08:54:25 -0600234 messages::strictAccountTypes(res, "AccountTypes");
235 return false;
236 }
237
238 if (redfishType && webUIType)
239 {
240 userGroups.emplace_back("redfish");
241 }
242
243 return true;
244}
245
246/**
247 * @brief Sets UserGroups property of the user based on the Account Types
248 *
249 * @param[in] accountTypes List of User Account Types
250 * @param[in] asyncResp Async Response
251 * @param[in] dbusObjectPath D-Bus Object Path
252 * @param[in] userSelf true if User is updating OWN Account Types
253 */
Patrick Williams504af5a2025-02-03 14:29:03 -0500254inline void patchAccountTypes(
255 const std::vector<std::string>& accountTypes,
256 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
257 const std::string& dbusObjectPath, bool userSelf)
Abhishek Patel58345852022-02-02 08:54:25 -0600258{
259 // Check if User is disabling own Redfish Account Type
260 if (userSelf &&
261 (accountTypes.cend() ==
262 std::find(accountTypes.cbegin(), accountTypes.cend(), "Redfish")))
263 {
Ed Tanous62598e32023-07-17 17:06:25 -0700264 BMCWEB_LOG_ERROR(
265 "User disabling OWN Redfish Account Type is not allowed");
Abhishek Patel58345852022-02-02 08:54:25 -0600266 messages::strictAccountTypes(asyncResp->res, "AccountTypes");
267 return;
268 }
269
270 std::vector<std::string> updatedUserGroups;
271 if (!getUserGroupFromAccountType(asyncResp->res, accountTypes,
272 updatedUserGroups))
273 {
274 // Problem in mapping Account Types to User Groups, Error already
275 // logged.
276 return;
277 }
Ginu Georgee93abac2024-06-14 17:35:27 +0530278 setDbusProperty(asyncResp, "AccountTypes",
279 "xyz.openbmc_project.User.Manager", dbusObjectPath,
280 "xyz.openbmc_project.User.Attributes", "UserGroups",
281 updatedUserGroups);
Abhishek Patel58345852022-02-02 08:54:25 -0600282}
283
zhanghch058d1b46d2021-04-01 11:18:24 +0800284inline void userErrorMessageHandler(
285 const sd_bus_error* e, const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
286 const std::string& newUser, const std::string& username)
jayaprakash Mutyala66b5ca72019-08-07 20:26:37 +0000287{
jayaprakash Mutyala66b5ca72019-08-07 20:26:37 +0000288 if (e == nullptr)
289 {
290 messages::internalError(asyncResp->res);
291 return;
292 }
293
Manojkiran Eda055806b2020-11-03 09:36:28 +0530294 const char* errorMessage = e->name;
jayaprakash Mutyala66b5ca72019-08-07 20:26:37 +0000295 if (strcmp(errorMessage,
296 "xyz.openbmc_project.User.Common.Error.UserNameExists") == 0)
297 {
Jiaqing Zhaod8a5d5d2022-08-05 16:21:51 +0800298 messages::resourceAlreadyExists(asyncResp->res, "ManagerAccount",
jayaprakash Mutyala66b5ca72019-08-07 20:26:37 +0000299 "UserName", newUser);
300 }
301 else if (strcmp(errorMessage, "xyz.openbmc_project.User.Common.Error."
302 "UserNameDoesNotExist") == 0)
303 {
Jiaqing Zhaod8a5d5d2022-08-05 16:21:51 +0800304 messages::resourceNotFound(asyncResp->res, "ManagerAccount", username);
jayaprakash Mutyala66b5ca72019-08-07 20:26:37 +0000305 }
Ed Tanousd4d25792020-09-29 15:15:03 -0700306 else if ((strcmp(errorMessage,
307 "xyz.openbmc_project.Common.Error.InvalidArgument") ==
308 0) ||
George Liu0fda0f12021-11-16 10:06:17 +0800309 (strcmp(
310 errorMessage,
311 "xyz.openbmc_project.User.Common.Error.UserNameGroupFail") ==
312 0))
jayaprakash Mutyala66b5ca72019-08-07 20:26:37 +0000313 {
314 messages::propertyValueFormatError(asyncResp->res, newUser, "UserName");
315 }
316 else if (strcmp(errorMessage,
317 "xyz.openbmc_project.User.Common.Error.NoResource") == 0)
318 {
319 messages::createLimitReachedForResource(asyncResp->res);
320 }
jayaprakash Mutyala66b5ca72019-08-07 20:26:37 +0000321 else
322 {
Gunnar Millsb8ad5832023-10-02 16:26:07 -0500323 BMCWEB_LOG_ERROR("DBUS response error {}", errorMessage);
jayaprakash Mutyala66b5ca72019-08-07 20:26:37 +0000324 messages::internalError(asyncResp->res);
325 }
jayaprakash Mutyala66b5ca72019-08-07 20:26:37 +0000326}
327
Ed Tanous81ce6092020-12-17 16:54:55 +0000328inline void parseLDAPConfigData(nlohmann::json& jsonResponse,
Ed Tanous23a21a12020-07-25 04:45:05 +0000329 const LDAPConfigData& confData,
330 const std::string& ldapType)
Ratan Gupta6973a582018-12-13 18:25:44 +0530331{
Ed Tanous49cc2632024-03-20 12:49:15 -0700332 nlohmann::json::object_t ldap;
Ed Tanous14766872022-03-15 10:44:42 -0700333 ldap["ServiceEnabled"] = confData.serviceEnabled;
Ed Tanous49cc2632024-03-20 12:49:15 -0700334 nlohmann::json::array_t serviceAddresses;
335 serviceAddresses.emplace_back(confData.uri);
336 ldap["ServiceAddresses"] = std::move(serviceAddresses);
337
338 nlohmann::json::object_t authentication;
339 authentication["AuthenticationType"] =
Ed Tanous0ec8b832022-03-14 14:56:47 -0700340 account_service::AuthenticationTypes::UsernameAndPassword;
Ed Tanous49cc2632024-03-20 12:49:15 -0700341 authentication["Username"] = confData.bindDN;
342 authentication["Password"] = nullptr;
343 ldap["Authentication"] = std::move(authentication);
Ed Tanous14766872022-03-15 10:44:42 -0700344
Ed Tanous49cc2632024-03-20 12:49:15 -0700345 nlohmann::json::object_t ldapService;
346 nlohmann::json::object_t searchSettings;
347 nlohmann::json::array_t baseDistinguishedNames;
348 baseDistinguishedNames.emplace_back(confData.baseDN);
Ed Tanous14766872022-03-15 10:44:42 -0700349
Ed Tanous49cc2632024-03-20 12:49:15 -0700350 searchSettings["BaseDistinguishedNames"] =
351 std::move(baseDistinguishedNames);
352 searchSettings["UsernameAttribute"] = confData.userNameAttribute;
353 searchSettings["GroupsAttribute"] = confData.groupAttribute;
354 ldapService["SearchSettings"] = std::move(searchSettings);
355 ldap["LDAPService"] = std::move(ldapService);
356
357 nlohmann::json::array_t roleMapArray;
Ed Tanous9eb808c2022-01-25 10:19:23 -0800358 for (const auto& obj : confData.groupRoleList)
Nagaraju Goruganti54fc5872019-01-30 05:11:00 -0600359 {
Ed Tanous62598e32023-07-17 17:06:25 -0700360 BMCWEB_LOG_DEBUG("Pushing the data groupName={}", obj.second.groupName);
Ed Tanous613dabe2022-07-09 11:17:36 -0700361
Ed Tanous613dabe2022-07-09 11:17:36 -0700362 nlohmann::json::object_t remoteGroup;
363 remoteGroup["RemoteGroup"] = obj.second.groupName;
Jorge Cisneros329f0342022-11-04 16:26:25 +0000364 remoteGroup["LocalRole"] = getRoleIdFromPrivilege(obj.second.privilege);
365 roleMapArray.emplace_back(std::move(remoteGroup));
Nagaraju Goruganti54fc5872019-01-30 05:11:00 -0600366 }
Ed Tanous49cc2632024-03-20 12:49:15 -0700367
368 ldap["RemoteRoleMapping"] = std::move(roleMapArray);
369
370 jsonResponse[ldapType].update(ldap);
Ratan Gupta6973a582018-12-13 18:25:44 +0530371}
372
373/**
Ratan Gupta06785242019-07-26 22:30:16 +0530374 * @brief validates given JSON input and then calls appropriate method to
375 * create, to delete or to set Rolemapping object based on the given input.
376 *
377 */
Ed Tanous23a21a12020-07-25 04:45:05 +0000378inline void handleRoleMapPatch(
zhanghch058d1b46d2021-04-01 11:18:24 +0800379 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ratan Gupta06785242019-07-26 22:30:16 +0530380 const std::vector<std::pair<std::string, LDAPRoleMapData>>& roleMapObjData,
Ed Tanousc1019822024-03-06 12:54:38 -0800381 const std::string& serverType,
382 std::vector<std::variant<nlohmann::json::object_t, std::nullptr_t>>& input)
Ratan Gupta06785242019-07-26 22:30:16 +0530383{
384 for (size_t index = 0; index < input.size(); index++)
385 {
Ed Tanousc1019822024-03-06 12:54:38 -0800386 std::variant<nlohmann::json::object_t, std::nullptr_t>& thisJson =
387 input[index];
388 nlohmann::json::object_t* obj =
389 std::get_if<nlohmann::json::object_t>(&thisJson);
390 if (obj == nullptr)
Ratan Gupta06785242019-07-26 22:30:16 +0530391 {
392 // delete the existing object
393 if (index < roleMapObjData.size())
394 {
395 crow::connections::systemBus->async_method_call(
396 [asyncResp, roleMapObjData, serverType,
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800397 index](const boost::system::error_code& ec) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400398 if (ec)
399 {
400 BMCWEB_LOG_ERROR("DBUS response error: {}", ec);
401 messages::internalError(asyncResp->res);
402 return;
403 }
404 asyncResp->res
405 .jsonValue[serverType]["RemoteRoleMapping"][index] =
406 nullptr;
407 },
Ratan Gupta06785242019-07-26 22:30:16 +0530408 ldapDbusService, roleMapObjData[index].first,
409 "xyz.openbmc_project.Object.Delete", "Delete");
410 }
411 else
412 {
Ed Tanous62598e32023-07-17 17:06:25 -0700413 BMCWEB_LOG_ERROR("Can't delete the object");
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400414 messages::propertyValueTypeError(
415 asyncResp->res, "null",
416 "RemoteRoleMapping/" + std::to_string(index));
Ratan Gupta06785242019-07-26 22:30:16 +0530417 return;
418 }
419 }
Ed Tanousc1019822024-03-06 12:54:38 -0800420 else if (obj->empty())
Ratan Gupta06785242019-07-26 22:30:16 +0530421 {
422 // Don't do anything for the empty objects,parse next json
423 // eg {"RemoteRoleMapping",[{}]}
424 }
425 else
426 {
427 // update/create the object
428 std::optional<std::string> remoteGroup;
429 std::optional<std::string> localRole;
430
Patrick Williams504af5a2025-02-03 14:29:03 -0500431 if (!json_util::readJsonObject( //
432 *obj, asyncResp->res, //
433 "LocalRole", localRole, //
Myung Baeafc474a2024-10-09 00:53:29 -0700434 "RemoteGroup", remoteGroup //
435 ))
Ratan Gupta06785242019-07-26 22:30:16 +0530436 {
437 continue;
438 }
439
440 // Update existing RoleMapping Object
441 if (index < roleMapObjData.size())
442 {
Ed Tanous62598e32023-07-17 17:06:25 -0700443 BMCWEB_LOG_DEBUG("Update Role Map Object");
Ratan Gupta06785242019-07-26 22:30:16 +0530444 // If "RemoteGroup" info is provided
445 if (remoteGroup)
446 {
Ed Tanousd02aad32024-02-13 14:43:34 -0800447 setDbusProperty(
Ginu Georgee93abac2024-06-14 17:35:27 +0530448 asyncResp,
Ed Tanousd02aad32024-02-13 14:43:34 -0800449 std::format("RemoteRoleMapping/{}/RemoteGroup", index),
Ginu Georgee93abac2024-06-14 17:35:27 +0530450 ldapDbusService, roleMapObjData[index].first,
451 "xyz.openbmc_project.User.PrivilegeMapperEntry",
452 "GroupName", *remoteGroup);
Ratan Gupta06785242019-07-26 22:30:16 +0530453 }
454
455 // If "LocalRole" info is provided
456 if (localRole)
457 {
Ravi Teja6d0b80b2024-07-28 06:09:15 -0500458 std::string priv = getPrivilegeFromRoleId(*localRole);
459 if (priv.empty())
460 {
461 messages::propertyValueNotInList(
462 asyncResp->res, *localRole,
463 std::format("RemoteRoleMapping/{}/LocalRole",
464 index));
465 return;
466 }
Ed Tanousd02aad32024-02-13 14:43:34 -0800467 setDbusProperty(
Ginu Georgee93abac2024-06-14 17:35:27 +0530468 asyncResp,
Ed Tanousd02aad32024-02-13 14:43:34 -0800469 std::format("RemoteRoleMapping/{}/LocalRole", index),
Ginu Georgee93abac2024-06-14 17:35:27 +0530470 ldapDbusService, roleMapObjData[index].first,
471 "xyz.openbmc_project.User.PrivilegeMapperEntry",
Ravi Teja6d0b80b2024-07-28 06:09:15 -0500472 "Privilege", priv);
Ratan Gupta06785242019-07-26 22:30:16 +0530473 }
474 }
475 // Create a new RoleMapping Object.
476 else
477 {
Ed Tanous62598e32023-07-17 17:06:25 -0700478 BMCWEB_LOG_DEBUG(
479 "setRoleMappingProperties: Creating new Object");
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400480 std::string pathString =
481 "RemoteRoleMapping/" + std::to_string(index);
Ratan Gupta06785242019-07-26 22:30:16 +0530482
483 if (!localRole)
484 {
485 messages::propertyMissing(asyncResp->res,
486 pathString + "/LocalRole");
487 continue;
488 }
489 if (!remoteGroup)
490 {
491 messages::propertyMissing(asyncResp->res,
492 pathString + "/RemoteGroup");
493 continue;
494 }
495
496 std::string dbusObjectPath;
497 if (serverType == "ActiveDirectory")
498 {
Ed Tanous2c70f802020-09-28 14:29:23 -0700499 dbusObjectPath = adConfigObject;
Ratan Gupta06785242019-07-26 22:30:16 +0530500 }
501 else if (serverType == "LDAP")
502 {
Ed Tanous23a21a12020-07-25 04:45:05 +0000503 dbusObjectPath = ldapConfigObjectName;
Ratan Gupta06785242019-07-26 22:30:16 +0530504 }
505
Ed Tanous62598e32023-07-17 17:06:25 -0700506 BMCWEB_LOG_DEBUG("Remote Group={},LocalRole={}", *remoteGroup,
507 *localRole);
Ratan Gupta06785242019-07-26 22:30:16 +0530508
509 crow::connections::systemBus->async_method_call(
Ed Tanous271584a2019-07-09 16:24:22 -0700510 [asyncResp, serverType, localRole,
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800511 remoteGroup](const boost::system::error_code& ec) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400512 if (ec)
513 {
514 BMCWEB_LOG_ERROR("DBUS response error: {}", ec);
515 messages::internalError(asyncResp->res);
516 return;
517 }
518 nlohmann::json& remoteRoleJson =
519 asyncResp->res
520 .jsonValue[serverType]["RemoteRoleMapping"];
521 nlohmann::json::object_t roleMapEntry;
522 roleMapEntry["LocalRole"] = *localRole;
523 roleMapEntry["RemoteGroup"] = *remoteGroup;
524 remoteRoleJson.emplace_back(std::move(roleMapEntry));
525 },
Ratan Gupta06785242019-07-26 22:30:16 +0530526 ldapDbusService, dbusObjectPath, ldapPrivMapperInterface,
Ed Tanous3174e4d2020-10-07 11:41:22 -0700527 "Create", *remoteGroup,
Ratan Gupta06785242019-07-26 22:30:16 +0530528 getPrivilegeFromRoleId(std::move(*localRole)));
529 }
530 }
531 }
532}
533
534/**
Ratan Gupta6973a582018-12-13 18:25:44 +0530535 * Function that retrieves all properties for LDAP config object
536 * into JSON
537 */
538template <typename CallbackFunc>
Patrick Williams504af5a2025-02-03 14:29:03 -0500539inline void getLDAPConfigData(const std::string& ldapType,
540 CallbackFunc&& callback)
Ratan Gupta6973a582018-12-13 18:25:44 +0530541{
George Liu2b731192023-01-11 16:27:13 +0800542 constexpr std::array<std::string_view, 2> interfaces = {
543 ldapEnableInterface, ldapConfigInterface};
Ratan Gupta6973a582018-12-13 18:25:44 +0530544
George Liu2b731192023-01-11 16:27:13 +0800545 dbus::utility::getDbusObject(
546 ldapConfigObjectName, interfaces,
Ed Tanous8cb2c022024-03-27 16:31:46 -0700547 [callback = std::forward<CallbackFunc>(callback),
Ed Tanousc1019822024-03-06 12:54:38 -0800548 ldapType](const boost::system::error_code& ec,
549 const dbus::utility::MapperGetObject& resp) mutable {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400550 if (ec || resp.empty())
Nagaraju Goruganti54fc5872019-01-30 05:11:00 -0600551 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400552 BMCWEB_LOG_WARNING(
553 "DBUS response error during getting of service name: {}",
554 ec);
555 LDAPConfigData empty{};
556 callback(false, empty, ldapType);
Nagaraju Goruganti54fc5872019-01-30 05:11:00 -0600557 return;
558 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400559 std::string service = resp.begin()->first;
560 sdbusplus::message::object_path path(ldapRootObject);
561 dbus::utility::getManagedObjects(
562 service, path,
563 [callback, ldapType](const boost::system::error_code& ec2,
564 const dbus::utility::ManagedObjectType&
565 ldapObjects) mutable {
566 LDAPConfigData confData{};
567 if (ec2)
Nagaraju Goruganti54fc5872019-01-30 05:11:00 -0600568 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400569 callback(false, confData, ldapType);
570 BMCWEB_LOG_WARNING("D-Bus responses error: {}", ec2);
571 return;
572 }
573
574 std::string ldapDbusType;
575 std::string searchString;
576
577 if (ldapType == "LDAP")
578 {
579 ldapDbusType =
580 "xyz.openbmc_project.User.Ldap.Config.Type.OpenLdap";
581 searchString = "openldap";
582 }
583 else if (ldapType == "ActiveDirectory")
584 {
585 ldapDbusType =
586 "xyz.openbmc_project.User.Ldap.Config.Type.ActiveDirectory";
587 searchString = "active_directory";
588 }
589 else
590 {
591 BMCWEB_LOG_ERROR(
592 "Can't get the DbusType for the given type={}",
593 ldapType);
594 callback(false, confData, ldapType);
595 return;
596 }
597
598 std::string ldapEnableInterfaceStr = ldapEnableInterface;
599 std::string ldapConfigInterfaceStr = ldapConfigInterface;
600
601 for (const auto& object : ldapObjects)
602 {
603 // let's find the object whose ldap type is equal to the
604 // given type
605 if (object.first.str.find(searchString) ==
606 std::string::npos)
Nagaraju Goruganti54fc5872019-01-30 05:11:00 -0600607 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400608 continue;
609 }
610
611 for (const auto& interface : object.second)
612 {
613 if (interface.first == ldapEnableInterfaceStr)
Nagaraju Goruganti54fc5872019-01-30 05:11:00 -0600614 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400615 // rest of the properties are string.
616 for (const auto& property : interface.second)
Nagaraju Goruganti54fc5872019-01-30 05:11:00 -0600617 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400618 if (property.first == "Enabled")
619 {
620 const bool* value =
621 std::get_if<bool>(&property.second);
622 if (value == nullptr)
623 {
624 continue;
625 }
626 confData.serviceEnabled = *value;
627 break;
628 }
Nagaraju Goruganti54fc5872019-01-30 05:11:00 -0600629 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400630 }
631 else if (interface.first == ldapConfigInterfaceStr)
632 {
633 for (const auto& property : interface.second)
634 {
635 const std::string* strValue =
636 std::get_if<std::string>(
637 &property.second);
638 if (strValue == nullptr)
639 {
640 continue;
641 }
642 if (property.first == "LDAPServerURI")
643 {
644 confData.uri = *strValue;
645 }
646 else if (property.first == "LDAPBindDN")
647 {
648 confData.bindDN = *strValue;
649 }
650 else if (property.first == "LDAPBaseDN")
651 {
652 confData.baseDN = *strValue;
653 }
654 else if (property.first ==
655 "LDAPSearchScope")
656 {
657 confData.searchScope = *strValue;
658 }
659 else if (property.first ==
660 "GroupNameAttribute")
661 {
662 confData.groupAttribute = *strValue;
663 }
664 else if (property.first ==
665 "UserNameAttribute")
666 {
667 confData.userNameAttribute = *strValue;
668 }
669 else if (property.first == "LDAPType")
670 {
671 confData.serverType = *strValue;
672 }
673 }
674 }
675 else if (
676 interface.first ==
677 "xyz.openbmc_project.User.PrivilegeMapperEntry")
678 {
679 LDAPRoleMapData roleMapData{};
680 for (const auto& property : interface.second)
681 {
682 const std::string* strValue =
683 std::get_if<std::string>(
684 &property.second);
685
686 if (strValue == nullptr)
687 {
688 continue;
689 }
690
691 if (property.first == "GroupName")
692 {
693 roleMapData.groupName = *strValue;
694 }
695 else if (property.first == "Privilege")
696 {
697 roleMapData.privilege = *strValue;
698 }
699 }
700
701 confData.groupRoleList.emplace_back(
702 object.first.str, roleMapData);
Nagaraju Goruganti54fc5872019-01-30 05:11:00 -0600703 }
704 }
705 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400706 callback(true, confData, ldapType);
707 });
George Liu2b731192023-01-11 16:27:13 +0800708 });
Ratan Gupta6973a582018-12-13 18:25:44 +0530709}
710
Ed Tanous6c51eab2021-06-03 12:30:29 -0700711/**
Ed Tanous6c51eab2021-06-03 12:30:29 -0700712 * @brief updates the LDAP server address and updates the
713 json response with the new value.
714 * @param serviceAddressList address to be updated.
715 * @param asyncResp pointer to the JSON response
716 * @param ldapServerElementName Type of LDAP
717 server(openLDAP/ActiveDirectory)
718 */
Ratan Gupta8a07d282019-03-16 08:33:47 +0530719
Ed Tanous4f48d5f2021-06-21 08:27:45 -0700720inline void handleServiceAddressPatch(
Ed Tanous6c51eab2021-06-03 12:30:29 -0700721 const std::vector<std::string>& serviceAddressList,
722 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
723 const std::string& ldapServerElementName,
724 const std::string& ldapConfigObject)
725{
Ginu Georgee93abac2024-06-14 17:35:27 +0530726 setDbusProperty(asyncResp, ldapServerElementName + "/ServiceAddress",
727 ldapDbusService, ldapConfigObject, ldapConfigInterface,
728 "LDAPServerURI", serviceAddressList.front());
Ed Tanous6c51eab2021-06-03 12:30:29 -0700729}
730/**
731 * @brief updates the LDAP Bind DN and updates the
732 json response with the new value.
733 * @param username name of the user which needs to be updated.
734 * @param asyncResp pointer to the JSON response
735 * @param ldapServerElementName Type of LDAP
736 server(openLDAP/ActiveDirectory)
737 */
Ratan Gupta8a07d282019-03-16 08:33:47 +0530738
Patrick Williams504af5a2025-02-03 14:29:03 -0500739inline void handleUserNamePatch(
740 const std::string& username,
741 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
742 const std::string& ldapServerElementName,
743 const std::string& ldapConfigObject)
Ed Tanous6c51eab2021-06-03 12:30:29 -0700744{
Ginu Georgee93abac2024-06-14 17:35:27 +0530745 setDbusProperty(asyncResp,
Ed Tanousd02aad32024-02-13 14:43:34 -0800746 ldapServerElementName + "/Authentication/Username",
Ginu Georgee93abac2024-06-14 17:35:27 +0530747 ldapDbusService, ldapConfigObject, ldapConfigInterface,
748 "LDAPBindDN", username);
Ed Tanous6c51eab2021-06-03 12:30:29 -0700749}
750
751/**
752 * @brief updates the LDAP password
753 * @param password : ldap password which needs to be updated.
754 * @param asyncResp pointer to the JSON response
755 * @param ldapServerElementName Type of LDAP
756 * server(openLDAP/ActiveDirectory)
757 */
758
Patrick Williams504af5a2025-02-03 14:29:03 -0500759inline void handlePasswordPatch(
760 const std::string& password,
761 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
762 const std::string& ldapServerElementName,
763 const std::string& ldapConfigObject)
Ed Tanous6c51eab2021-06-03 12:30:29 -0700764{
Ginu Georgee93abac2024-06-14 17:35:27 +0530765 setDbusProperty(asyncResp,
Ed Tanousd02aad32024-02-13 14:43:34 -0800766 ldapServerElementName + "/Authentication/Password",
Ginu Georgee93abac2024-06-14 17:35:27 +0530767 ldapDbusService, ldapConfigObject, ldapConfigInterface,
768 "LDAPBindDNPassword", password);
Ed Tanous6c51eab2021-06-03 12:30:29 -0700769}
770
771/**
772 * @brief updates the LDAP BaseDN and updates the
773 json response with the new value.
774 * @param baseDNList baseDN list which needs to be updated.
775 * @param asyncResp pointer to the JSON response
776 * @param ldapServerElementName Type of LDAP
777 server(openLDAP/ActiveDirectory)
778 */
779
Patrick Williams504af5a2025-02-03 14:29:03 -0500780inline void handleBaseDNPatch(
781 const std::vector<std::string>& baseDNList,
782 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
783 const std::string& ldapServerElementName,
784 const std::string& ldapConfigObject)
Ed Tanous6c51eab2021-06-03 12:30:29 -0700785{
Ginu Georgee93abac2024-06-14 17:35:27 +0530786 setDbusProperty(asyncResp,
Ed Tanousd02aad32024-02-13 14:43:34 -0800787 ldapServerElementName +
788 "/LDAPService/SearchSettings/BaseDistinguishedNames",
Ginu Georgee93abac2024-06-14 17:35:27 +0530789 ldapDbusService, ldapConfigObject, ldapConfigInterface,
790 "LDAPBaseDN", baseDNList.front());
Ed Tanous6c51eab2021-06-03 12:30:29 -0700791}
792/**
793 * @brief updates the LDAP user name attribute and updates the
794 json response with the new value.
795 * @param userNameAttribute attribute to be updated.
796 * @param asyncResp pointer to the JSON response
797 * @param ldapServerElementName Type of LDAP
798 server(openLDAP/ActiveDirectory)
799 */
800
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400801inline void handleUserNameAttrPatch(
802 const std::string& userNameAttribute,
803 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
804 const std::string& ldapServerElementName,
805 const std::string& ldapConfigObject)
Ed Tanous6c51eab2021-06-03 12:30:29 -0700806{
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400807 setDbusProperty(
808 asyncResp,
809 ldapServerElementName + "LDAPService/SearchSettings/UsernameAttribute",
810 ldapDbusService, ldapConfigObject, ldapConfigInterface,
811 "UserNameAttribute", userNameAttribute);
Ed Tanous6c51eab2021-06-03 12:30:29 -0700812}
813/**
814 * @brief updates the LDAP group attribute and updates the
815 json response with the new value.
816 * @param groupsAttribute attribute to be updated.
817 * @param asyncResp pointer to the JSON response
818 * @param ldapServerElementName Type of LDAP
819 server(openLDAP/ActiveDirectory)
820 */
821
Ed Tanous4f48d5f2021-06-21 08:27:45 -0700822inline void handleGroupNameAttrPatch(
Ed Tanous6c51eab2021-06-03 12:30:29 -0700823 const std::string& groupsAttribute,
824 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
825 const std::string& ldapServerElementName,
826 const std::string& ldapConfigObject)
827{
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400828 setDbusProperty(
829 asyncResp,
830 ldapServerElementName + "/LDAPService/SearchSettings/GroupsAttribute",
831 ldapDbusService, ldapConfigObject, ldapConfigInterface,
832 "GroupNameAttribute", groupsAttribute);
Ed Tanous6c51eab2021-06-03 12:30:29 -0700833}
834/**
835 * @brief updates the LDAP service enable and updates the
836 json response with the new value.
837 * @param input JSON data.
838 * @param asyncResp pointer to the JSON response
839 * @param ldapServerElementName Type of LDAP
840 server(openLDAP/ActiveDirectory)
841 */
842
Ed Tanous4f48d5f2021-06-21 08:27:45 -0700843inline void handleServiceEnablePatch(
Ed Tanous6c51eab2021-06-03 12:30:29 -0700844 bool serviceEnabled, const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
845 const std::string& ldapServerElementName,
846 const std::string& ldapConfigObject)
847{
Ginu Georgee93abac2024-06-14 17:35:27 +0530848 setDbusProperty(asyncResp, ldapServerElementName + "/ServiceEnabled",
849 ldapDbusService, ldapConfigObject, ldapEnableInterface,
850 "Enabled", serviceEnabled);
Ed Tanous6c51eab2021-06-03 12:30:29 -0700851}
852
Ed Tanousc1019822024-03-06 12:54:38 -0800853struct AuthMethods
Ed Tanous6c51eab2021-06-03 12:30:29 -0700854{
855 std::optional<bool> basicAuth;
856 std::optional<bool> cookie;
857 std::optional<bool> sessionToken;
858 std::optional<bool> xToken;
859 std::optional<bool> tls;
Ed Tanousc1019822024-03-06 12:54:38 -0800860};
Ed Tanous6c51eab2021-06-03 12:30:29 -0700861
Patrick Williams504af5a2025-02-03 14:29:03 -0500862inline void handleAuthMethodsPatch(
863 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
864 const AuthMethods& auth)
Ed Tanousc1019822024-03-06 12:54:38 -0800865{
866 persistent_data::AuthConfigMethods& authMethodsConfig =
Ed Tanous6c51eab2021-06-03 12:30:29 -0700867 persistent_data::SessionStore::getInstance().getAuthMethodsConfig();
868
Ed Tanousc1019822024-03-06 12:54:38 -0800869 if (auth.basicAuth)
Ed Tanous6c51eab2021-06-03 12:30:29 -0700870 {
Ed Tanous25b54db2024-04-17 15:40:31 -0700871 if constexpr (!BMCWEB_BASIC_AUTH)
872 {
873 messages::actionNotSupported(
874 asyncResp->res,
875 "Setting BasicAuth when basic-auth feature is disabled");
876 return;
877 }
878
Ed Tanousc1019822024-03-06 12:54:38 -0800879 authMethodsConfig.basic = *auth.basicAuth;
Ed Tanous6c51eab2021-06-03 12:30:29 -0700880 }
881
Ed Tanousc1019822024-03-06 12:54:38 -0800882 if (auth.cookie)
Ed Tanous6c51eab2021-06-03 12:30:29 -0700883 {
Ed Tanous25b54db2024-04-17 15:40:31 -0700884 if constexpr (!BMCWEB_COOKIE_AUTH)
885 {
886 messages::actionNotSupported(
887 asyncResp->res,
888 "Setting Cookie when cookie-auth feature is disabled");
889 return;
890 }
Ed Tanousc1019822024-03-06 12:54:38 -0800891 authMethodsConfig.cookie = *auth.cookie;
Ed Tanous6c51eab2021-06-03 12:30:29 -0700892 }
893
Ed Tanousc1019822024-03-06 12:54:38 -0800894 if (auth.sessionToken)
Ed Tanous6c51eab2021-06-03 12:30:29 -0700895 {
Ed Tanous25b54db2024-04-17 15:40:31 -0700896 if constexpr (!BMCWEB_SESSION_AUTH)
897 {
898 messages::actionNotSupported(
899 asyncResp->res,
900 "Setting SessionToken when session-auth feature is disabled");
901 return;
902 }
Ed Tanousc1019822024-03-06 12:54:38 -0800903 authMethodsConfig.sessionToken = *auth.sessionToken;
Ed Tanous6c51eab2021-06-03 12:30:29 -0700904 }
905
Ed Tanousc1019822024-03-06 12:54:38 -0800906 if (auth.xToken)
Ed Tanous6c51eab2021-06-03 12:30:29 -0700907 {
Ed Tanous25b54db2024-04-17 15:40:31 -0700908 if constexpr (!BMCWEB_XTOKEN_AUTH)
909 {
910 messages::actionNotSupported(
911 asyncResp->res,
912 "Setting XToken when xtoken-auth feature is disabled");
913 return;
914 }
Ed Tanousc1019822024-03-06 12:54:38 -0800915 authMethodsConfig.xtoken = *auth.xToken;
Ed Tanous6c51eab2021-06-03 12:30:29 -0700916 }
917
Ed Tanousc1019822024-03-06 12:54:38 -0800918 if (auth.tls)
Ed Tanous6c51eab2021-06-03 12:30:29 -0700919 {
Ed Tanous25b54db2024-04-17 15:40:31 -0700920 if constexpr (!BMCWEB_MUTUAL_TLS_AUTH)
921 {
922 messages::actionNotSupported(
923 asyncResp->res,
924 "Setting TLS when mutual-tls-auth feature is disabled");
925 return;
926 }
Ed Tanousc1019822024-03-06 12:54:38 -0800927 authMethodsConfig.tls = *auth.tls;
Ed Tanous6c51eab2021-06-03 12:30:29 -0700928 }
929
930 if (!authMethodsConfig.basic && !authMethodsConfig.cookie &&
931 !authMethodsConfig.sessionToken && !authMethodsConfig.xtoken &&
932 !authMethodsConfig.tls)
933 {
934 // Do not allow user to disable everything
935 messages::actionNotSupported(asyncResp->res,
936 "of disabling all available methods");
937 return;
938 }
939
940 persistent_data::SessionStore::getInstance().updateAuthMethodsConfig(
941 authMethodsConfig);
942 // Save configuration immediately
943 persistent_data::getConfig().writeData();
944
945 messages::success(asyncResp->res);
946}
947
948/**
949 * @brief Get the required values from the given JSON, validates the
950 * value and create the LDAP config object.
951 * @param input JSON data
952 * @param asyncResp pointer to the JSON response
953 * @param serverType Type of LDAP server(openLDAP/ActiveDirectory)
954 */
955
Ed Tanous10cb44f2024-04-11 13:05:20 -0700956struct LdapPatchParams
957{
958 std::optional<std::string> authType;
959 std::optional<std::vector<std::string>> serviceAddressList;
960 std::optional<bool> serviceEnabled;
961 std::optional<std::vector<std::string>> baseDNList;
962 std::optional<std::string> userNameAttribute;
963 std::optional<std::string> groupsAttribute;
964 std::optional<std::string> userName;
965 std::optional<std::string> password;
966 std::optional<
967 std::vector<std::variant<nlohmann::json::object_t, std::nullptr_t>>>
968 remoteRoleMapData;
969};
970
971inline void handleLDAPPatch(LdapPatchParams&& input,
Ed Tanous6c51eab2021-06-03 12:30:29 -0700972 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
973 const std::string& serverType)
974{
975 std::string dbusObjectPath;
976 if (serverType == "ActiveDirectory")
977 {
978 dbusObjectPath = adConfigObject;
979 }
980 else if (serverType == "LDAP")
981 {
982 dbusObjectPath = ldapConfigObjectName;
983 }
984 else
985 {
Ed Tanous10cb44f2024-04-11 13:05:20 -0700986 BMCWEB_LOG_ERROR("serverType wasn't AD or LDAP but was {}????",
987 serverType);
Ed Tanous6c51eab2021-06-03 12:30:29 -0700988 return;
989 }
990
Ed Tanous10cb44f2024-04-11 13:05:20 -0700991 if (input.authType && *input.authType != "UsernameAndPassword")
Ed Tanous6c51eab2021-06-03 12:30:29 -0700992 {
Ed Tanous10cb44f2024-04-11 13:05:20 -0700993 messages::propertyValueNotInList(asyncResp->res, *input.authType,
Ed Tanousc1019822024-03-06 12:54:38 -0800994 "AuthenticationType");
995 return;
Ed Tanous6c51eab2021-06-03 12:30:29 -0700996 }
Ed Tanousc1019822024-03-06 12:54:38 -0800997
Ed Tanous10cb44f2024-04-11 13:05:20 -0700998 if (input.serviceAddressList)
Ed Tanous6c51eab2021-06-03 12:30:29 -0700999 {
Ed Tanous10cb44f2024-04-11 13:05:20 -07001000 if (input.serviceAddressList->empty())
Ratan Guptaeb2bbe52019-04-22 14:27:01 +05301001 {
Ed Tanouse2616cc2022-06-27 12:45:55 -07001002 messages::propertyValueNotInList(
Ed Tanous10cb44f2024-04-11 13:05:20 -07001003 asyncResp->res, *input.serviceAddressList, "ServiceAddress");
Ed Tanouscb13a392020-07-25 19:02:03 +00001004 return;
1005 }
Ed Tanous6c51eab2021-06-03 12:30:29 -07001006 }
Ed Tanous10cb44f2024-04-11 13:05:20 -07001007 if (input.baseDNList)
Ed Tanous6c51eab2021-06-03 12:30:29 -07001008 {
Ed Tanous10cb44f2024-04-11 13:05:20 -07001009 if (input.baseDNList->empty())
Ratan Gupta8a07d282019-03-16 08:33:47 +05301010 {
Ed Tanous10cb44f2024-04-11 13:05:20 -07001011 messages::propertyValueNotInList(asyncResp->res, *input.baseDNList,
Ed Tanous6c51eab2021-06-03 12:30:29 -07001012 "BaseDistinguishedNames");
Ratan Gupta8a07d282019-03-16 08:33:47 +05301013 return;
1014 }
Ed Tanous6c51eab2021-06-03 12:30:29 -07001015 }
Ratan Gupta8a07d282019-03-16 08:33:47 +05301016
Ed Tanous6c51eab2021-06-03 12:30:29 -07001017 // nothing to update, then return
Ed Tanous10cb44f2024-04-11 13:05:20 -07001018 if (!input.userName && !input.password && !input.serviceAddressList &&
1019 !input.baseDNList && !input.userNameAttribute &&
1020 !input.groupsAttribute && !input.serviceEnabled &&
1021 !input.remoteRoleMapData)
Ed Tanous6c51eab2021-06-03 12:30:29 -07001022 {
1023 return;
1024 }
1025
1026 // Get the existing resource first then keep modifying
1027 // whenever any property gets updated.
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001028 getLDAPConfigData(serverType, [asyncResp, input = std::move(input),
1029 dbusObjectPath = std::move(dbusObjectPath)](
1030 bool success,
1031 const LDAPConfigData& confData,
1032 const std::string& serverT) mutable {
Ed Tanous6c51eab2021-06-03 12:30:29 -07001033 if (!success)
Ratan Gupta8a07d282019-03-16 08:33:47 +05301034 {
Ed Tanous6c51eab2021-06-03 12:30:29 -07001035 messages::internalError(asyncResp->res);
1036 return;
Ratan Gupta8a07d282019-03-16 08:33:47 +05301037 }
Ed Tanous6c51eab2021-06-03 12:30:29 -07001038 parseLDAPConfigData(asyncResp->res.jsonValue, confData, serverT);
1039 if (confData.serviceEnabled)
Ratan Gupta8a07d282019-03-16 08:33:47 +05301040 {
Ed Tanous6c51eab2021-06-03 12:30:29 -07001041 // Disable the service first and update the rest of
1042 // the properties.
1043 handleServiceEnablePatch(false, asyncResp, serverT, dbusObjectPath);
Ratan Gupta8a07d282019-03-16 08:33:47 +05301044 }
Ed Tanous6c51eab2021-06-03 12:30:29 -07001045
Ed Tanous10cb44f2024-04-11 13:05:20 -07001046 if (input.serviceAddressList)
Ratan Gupta8a07d282019-03-16 08:33:47 +05301047 {
Ed Tanous10cb44f2024-04-11 13:05:20 -07001048 handleServiceAddressPatch(*input.serviceAddressList, asyncResp,
1049 serverT, dbusObjectPath);
Ratan Gupta8a07d282019-03-16 08:33:47 +05301050 }
Ed Tanous10cb44f2024-04-11 13:05:20 -07001051 if (input.userName)
Ed Tanous6c51eab2021-06-03 12:30:29 -07001052 {
Ed Tanous10cb44f2024-04-11 13:05:20 -07001053 handleUserNamePatch(*input.userName, asyncResp, serverT,
1054 dbusObjectPath);
Ed Tanous6c51eab2021-06-03 12:30:29 -07001055 }
Ed Tanous10cb44f2024-04-11 13:05:20 -07001056 if (input.password)
Ed Tanous6c51eab2021-06-03 12:30:29 -07001057 {
Ed Tanous10cb44f2024-04-11 13:05:20 -07001058 handlePasswordPatch(*input.password, asyncResp, serverT,
1059 dbusObjectPath);
Ed Tanous6c51eab2021-06-03 12:30:29 -07001060 }
1061
Ed Tanous10cb44f2024-04-11 13:05:20 -07001062 if (input.baseDNList)
Ratan Gupta8a07d282019-03-16 08:33:47 +05301063 {
Ed Tanous10cb44f2024-04-11 13:05:20 -07001064 handleBaseDNPatch(*input.baseDNList, asyncResp, serverT,
1065 dbusObjectPath);
Ed Tanous6c51eab2021-06-03 12:30:29 -07001066 }
Ed Tanous10cb44f2024-04-11 13:05:20 -07001067 if (input.userNameAttribute)
Ed Tanous6c51eab2021-06-03 12:30:29 -07001068 {
Ed Tanous10cb44f2024-04-11 13:05:20 -07001069 handleUserNameAttrPatch(*input.userNameAttribute, asyncResp,
1070 serverT, dbusObjectPath);
Ed Tanous6c51eab2021-06-03 12:30:29 -07001071 }
Ed Tanous10cb44f2024-04-11 13:05:20 -07001072 if (input.groupsAttribute)
Ed Tanous6c51eab2021-06-03 12:30:29 -07001073 {
Ed Tanous10cb44f2024-04-11 13:05:20 -07001074 handleGroupNameAttrPatch(*input.groupsAttribute, asyncResp, serverT,
Ed Tanous6c51eab2021-06-03 12:30:29 -07001075 dbusObjectPath);
1076 }
Ed Tanous10cb44f2024-04-11 13:05:20 -07001077 if (input.serviceEnabled)
Ed Tanous6c51eab2021-06-03 12:30:29 -07001078 {
1079 // if user has given the value as true then enable
1080 // the service. if user has given false then no-op
1081 // as service is already stopped.
Ed Tanous10cb44f2024-04-11 13:05:20 -07001082 if (*input.serviceEnabled)
Ratan Gupta8a07d282019-03-16 08:33:47 +05301083 {
Ed Tanous10cb44f2024-04-11 13:05:20 -07001084 handleServiceEnablePatch(*input.serviceEnabled, asyncResp,
1085 serverT, dbusObjectPath);
Ratan Gupta8a07d282019-03-16 08:33:47 +05301086 }
1087 }
jayaprakash Mutyala96200602020-04-08 11:09:10 +00001088 else
1089 {
Ed Tanous6c51eab2021-06-03 12:30:29 -07001090 // if user has not given the service enabled value
1091 // then revert it to the same state as it was
1092 // before.
1093 handleServiceEnablePatch(confData.serviceEnabled, asyncResp,
1094 serverT, dbusObjectPath);
jayaprakash Mutyala96200602020-04-08 11:09:10 +00001095 }
Ed Tanous04ae99e2018-09-20 15:54:36 -07001096
Ed Tanous10cb44f2024-04-11 13:05:20 -07001097 if (input.remoteRoleMapData)
Ed Tanous6c51eab2021-06-03 12:30:29 -07001098 {
1099 handleRoleMapPatch(asyncResp, confData.groupRoleList, serverT,
Ed Tanous10cb44f2024-04-11 13:05:20 -07001100 *input.remoteRoleMapData);
Ed Tanous6c51eab2021-06-03 12:30:29 -07001101 }
Patrick Williams5a39f772023-10-20 11:20:21 -05001102 });
Ed Tanous6c51eab2021-06-03 12:30:29 -07001103}
1104
Ed Tanous492ec932024-12-09 15:42:19 -08001105struct UserUpdateParams
1106{
1107 std::string username;
1108 std::optional<std::string> password;
1109 std::optional<bool> enabled;
1110 std::optional<std::string> roleId;
1111 std::optional<bool> locked;
1112 std::optional<std::vector<std::string>> accountTypes;
1113 bool userSelf;
1114 std::shared_ptr<persistent_data::UserSession> session;
1115 std::string dbusObjectPath;
1116};
1117
Patrick Williams504af5a2025-02-03 14:29:03 -05001118inline void afterVerifyUserExists(
1119 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1120 const UserUpdateParams& params, int rc)
Ed Tanous492ec932024-12-09 15:42:19 -08001121{
1122 if (rc <= 0)
1123 {
1124 messages::resourceNotFound(asyncResp->res, "ManagerAccount",
1125 params.username);
1126 return;
1127 }
1128
1129 if (params.password)
1130 {
1131 int retval = pamUpdatePassword(params.username, *params.password);
1132
1133 if (retval == PAM_USER_UNKNOWN)
1134 {
1135 messages::resourceNotFound(asyncResp->res, "ManagerAccount",
1136 params.username);
1137 }
1138 else if (retval == PAM_AUTHTOK_ERR)
1139 {
1140 // If password is invalid
1141 messages::propertyValueFormatError(asyncResp->res, nullptr,
1142 "Password");
1143 BMCWEB_LOG_ERROR("pamUpdatePassword Failed");
1144 }
1145 else if (retval != PAM_SUCCESS)
1146 {
1147 messages::internalError(asyncResp->res);
1148 return;
1149 }
1150 else
1151 {
1152 // Remove existing sessions of the user when password
1153 // changed
1154 persistent_data::SessionStore::getInstance()
1155 .removeSessionsByUsernameExceptSession(params.username,
1156 params.session);
1157 messages::success(asyncResp->res);
1158 }
1159 }
1160
1161 if (params.enabled)
1162 {
1163 setDbusProperty(
1164 asyncResp, "Enabled", "xyz.openbmc_project.User.Manager",
1165 params.dbusObjectPath, "xyz.openbmc_project.User.Attributes",
1166 "UserEnabled", *params.enabled);
1167 }
1168
1169 if (params.roleId)
1170 {
1171 std::string priv = getPrivilegeFromRoleId(*params.roleId);
1172 if (priv.empty())
1173 {
1174 messages::propertyValueNotInList(asyncResp->res, true, "Locked");
1175 return;
1176 }
1177 setDbusProperty(asyncResp, "RoleId", "xyz.openbmc_project.User.Manager",
1178 params.dbusObjectPath,
1179 "xyz.openbmc_project.User.Attributes", "UserPrivilege",
1180 priv);
1181 }
1182
1183 if (params.locked)
1184 {
1185 // admin can unlock the account which is locked by
1186 // successive authentication failures but admin should
1187 // not be allowed to lock an account.
1188 if (*params.locked)
1189 {
1190 messages::propertyValueNotInList(asyncResp->res, "true", "Locked");
1191 return;
1192 }
1193 setDbusProperty(asyncResp, "Locked", "xyz.openbmc_project.User.Manager",
1194 params.dbusObjectPath,
1195 "xyz.openbmc_project.User.Attributes",
1196 "UserLockedForFailedAttempt", *params.locked);
1197 }
1198
1199 if (params.accountTypes)
1200 {
1201 patchAccountTypes(*params.accountTypes, asyncResp,
1202 params.dbusObjectPath, params.userSelf);
1203 }
1204}
1205
Abhishek Patel58345852022-02-02 08:54:25 -06001206inline void updateUserProperties(
Ed Tanous492ec932024-12-09 15:42:19 -08001207 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1208 const std::string& username, const std::optional<std::string>& password,
Abhishek Patel58345852022-02-02 08:54:25 -06001209 const std::optional<bool>& enabled,
1210 const std::optional<std::string>& roleId, const std::optional<bool>& locked,
Ed Tanous492ec932024-12-09 15:42:19 -08001211 const std::optional<std::vector<std::string>>& accountTypes, bool userSelf,
Ravi Tejae518ef32024-05-16 10:33:08 -05001212 const std::shared_ptr<persistent_data::UserSession>& session)
Ed Tanous6c51eab2021-06-03 12:30:29 -07001213{
P Dheeraj Srujan Kumarb477fd42021-12-16 07:17:51 +05301214 sdbusplus::message::object_path tempObjPath(rootUserDbusPath);
1215 tempObjPath /= username;
1216 std::string dbusObjectPath(tempObjPath);
Ed Tanous6c51eab2021-06-03 12:30:29 -07001217
Ed Tanous492ec932024-12-09 15:42:19 -08001218 UserUpdateParams params{username, password, enabled,
1219 roleId, locked, accountTypes,
1220 userSelf, session, dbusObjectPath};
1221
Ed Tanous6c51eab2021-06-03 12:30:29 -07001222 dbus::utility::checkDbusPathExists(
Ravi Tejae518ef32024-05-16 10:33:08 -05001223 dbusObjectPath,
Ed Tanous492ec932024-12-09 15:42:19 -08001224 std::bind_front(afterVerifyUserExists, asyncResp, std::move(params)));
Ed Tanous6c51eab2021-06-03 12:30:29 -07001225}
Ed Tanousb9b2e0b2018-09-13 13:47:50 -07001226
Ed Tanous4c7d4d32022-07-07 15:29:35 -07001227inline void handleAccountServiceHead(
1228 App& app, const crow::Request& req,
1229 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
Ed Tanous1ef4c342022-05-12 16:12:36 -07001230{
1231 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1232 {
1233 return;
1234 }
Ed Tanous4c7d4d32022-07-07 15:29:35 -07001235 asyncResp->res.addHeader(
1236 boost::beast::http::field::link,
1237 "</redfish/v1/JsonSchemas/AccountService/AccountService.json>; rel=describedby");
1238}
1239
Patrick Williams504af5a2025-02-03 14:29:03 -05001240inline void getClientCertificates(
1241 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1242 const nlohmann::json::json_pointer& keyLocation)
Ed Tanous1aa375b2024-04-13 11:51:10 -07001243{
1244 boost::urls::url url(
1245 "/redfish/v1/AccountService/MultiFactorAuth/ClientCertificate/Certificates");
1246 std::array<std::string_view, 1> interfaces = {
1247 "xyz.openbmc_project.Certs.Certificate"};
1248 std::string path = "/xyz/openbmc_project/certs/authority/truststore";
1249
1250 collection_util::getCollectionToKey(asyncResp, url, interfaces, path,
1251 keyLocation);
1252}
1253
1254inline void handleAccountServiceClientCertificatesInstanceHead(
1255 App& app, const crow::Request& req,
1256 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1257 const std::string& /*id*/)
1258{
1259 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1260 {
1261 return;
1262 }
1263
1264 asyncResp->res.addHeader(
1265 boost::beast::http::field::link,
1266 "</redfish/v1/JsonSchemas/Certificate/Certificate.json>; rel=describedby");
1267}
1268
1269inline void handleAccountServiceClientCertificatesInstanceGet(
1270 App& app, const crow::Request& req,
1271 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, const std::string& id)
1272{
1273 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1274 {
1275 return;
1276 }
1277 BMCWEB_LOG_DEBUG("ClientCertificate Certificate ID={}", id);
1278 const boost::urls::url certURL = boost::urls::format(
1279 "/redfish/v1/AccountService/MultiFactorAuth/ClientCertificate/Certificates/{}",
1280 id);
1281 std::string objPath =
1282 sdbusplus::message::object_path(certs::authorityObjectPath) / id;
1283 getCertificateProperties(
1284 asyncResp, objPath,
1285 "xyz.openbmc_project.Certs.Manager.Authority.Truststore", id, certURL,
1286 "Client Certificate");
1287}
1288
1289inline void handleAccountServiceClientCertificatesHead(
1290 App& app, const crow::Request& req,
1291 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1292{
1293 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1294 {
1295 return;
1296 }
1297
1298 asyncResp->res.addHeader(
1299 boost::beast::http::field::link,
1300 "</redfish/v1/JsonSchemas/CertificateCollection/CertificateCollection.json>; rel=describedby");
1301}
1302
1303inline void handleAccountServiceClientCertificatesGet(
1304 App& app, const crow::Request& req,
1305 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1306{
1307 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1308 {
1309 return;
1310 }
1311 getClientCertificates(asyncResp, "/Members"_json_pointer);
1312}
1313
Ed Tanous3ce36882024-06-09 10:58:16 -07001314using account_service::CertificateMappingAttribute;
1315using persistent_data::MTLSCommonNameParseMode;
Patrick Williams504af5a2025-02-03 14:29:03 -05001316inline CertificateMappingAttribute getCertificateMapping(
1317 MTLSCommonNameParseMode parse)
Ed Tanous3ce36882024-06-09 10:58:16 -07001318{
1319 switch (parse)
1320 {
1321 case MTLSCommonNameParseMode::CommonName:
1322 {
1323 return CertificateMappingAttribute::CommonName;
1324 }
1325 break;
1326 case MTLSCommonNameParseMode::Whole:
1327 {
1328 return CertificateMappingAttribute::Whole;
1329 }
1330 break;
1331 case MTLSCommonNameParseMode::UserPrincipalName:
1332 {
1333 return CertificateMappingAttribute::UserPrincipalName;
1334 }
1335 break;
1336
1337 case MTLSCommonNameParseMode::Meta:
1338 {
1339 if constexpr (BMCWEB_META_TLS_COMMON_NAME_PARSING)
1340 {
1341 return CertificateMappingAttribute::CommonName;
1342 }
1343 }
1344 break;
1345 default:
1346 {
1347 return CertificateMappingAttribute::Invalid;
1348 }
1349 break;
1350 }
1351}
1352
Patrick Williams504af5a2025-02-03 14:29:03 -05001353inline void handleAccountServiceGet(
1354 App& app, const crow::Request& req,
1355 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
Ed Tanous4c7d4d32022-07-07 15:29:35 -07001356{
Jiaqing Zhaoafd369c2023-03-07 15:12:22 +08001357 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1358 {
1359 return;
1360 }
Ninad Palsule3e72c202023-03-27 17:19:55 -05001361
1362 if (req.session == nullptr)
1363 {
1364 messages::internalError(asyncResp->res);
1365 return;
1366 }
1367
Ed Tanousc1019822024-03-06 12:54:38 -08001368 const persistent_data::AuthConfigMethods& authMethodsConfig =
1369 persistent_data::SessionStore::getInstance().getAuthMethodsConfig();
1370
Jiaqing Zhaoafd369c2023-03-07 15:12:22 +08001371 asyncResp->res.addHeader(
1372 boost::beast::http::field::link,
1373 "</redfish/v1/JsonSchemas/AccountService/AccountService.json>; rel=describedby");
1374
Ed Tanous1ef4c342022-05-12 16:12:36 -07001375 nlohmann::json& json = asyncResp->res.jsonValue;
1376 json["@odata.id"] = "/redfish/v1/AccountService";
Ravi Teja482a69e2024-04-22 06:56:13 -05001377 json["@odata.type"] = "#AccountService.v1_15_0.AccountService";
Ed Tanous1ef4c342022-05-12 16:12:36 -07001378 json["Id"] = "AccountService";
1379 json["Name"] = "Account Service";
1380 json["Description"] = "Account Service";
1381 json["ServiceEnabled"] = true;
1382 json["MaxPasswordLength"] = 20;
1383 json["Accounts"]["@odata.id"] = "/redfish/v1/AccountService/Accounts";
1384 json["Roles"]["@odata.id"] = "/redfish/v1/AccountService/Roles";
Ravi Teja482a69e2024-04-22 06:56:13 -05001385 json["HTTPBasicAuth"] = authMethodsConfig.basic
1386 ? account_service::BasicAuthState::Enabled
1387 : account_service::BasicAuthState::Disabled;
1388
1389 nlohmann::json::array_t allowed;
1390 allowed.emplace_back(account_service::BasicAuthState::Enabled);
1391 allowed.emplace_back(account_service::BasicAuthState::Disabled);
1392 json["HTTPBasicAuth@AllowableValues"] = std::move(allowed);
1393
Ed Tanous1aa375b2024-04-13 11:51:10 -07001394 nlohmann::json::object_t clientCertificate;
1395 clientCertificate["Enabled"] = authMethodsConfig.tls;
Ed Tanous3281bcf2024-06-25 16:02:05 -07001396 clientCertificate["RespondToUnauthenticatedClients"] =
1397 !authMethodsConfig.tlsStrict;
Ed Tanous3ce36882024-06-09 10:58:16 -07001398
1399 using account_service::CertificateMappingAttribute;
1400
1401 CertificateMappingAttribute mapping =
1402 getCertificateMapping(authMethodsConfig.mTLSCommonNameParsingMode);
1403 if (mapping == CertificateMappingAttribute::Invalid)
1404 {
1405 messages::internalError(asyncResp->res);
1406 }
1407 else
1408 {
1409 clientCertificate["CertificateMappingAttribute"] = mapping;
1410 }
Ed Tanous1aa375b2024-04-13 11:51:10 -07001411 nlohmann::json::object_t certificates;
1412 certificates["@odata.id"] =
1413 "/redfish/v1/AccountService/MultiFactorAuth/ClientCertificate/Certificates";
1414 certificates["@odata.type"] =
1415 "#CertificateCollection.CertificateCollection";
1416 clientCertificate["Certificates"] = std::move(certificates);
1417 json["MultiFactorAuth"]["ClientCertificate"] = std::move(clientCertificate);
1418
1419 getClientCertificates(
1420 asyncResp,
1421 "/MultiFactorAuth/ClientCertificate/Certificates/Members"_json_pointer);
1422
Ed Tanous1ef4c342022-05-12 16:12:36 -07001423 json["Oem"]["OpenBMC"]["@odata.type"] =
Ed Tanous5b5574a2022-09-26 19:53:36 -07001424 "#OpenBMCAccountService.v1_0_0.AccountService";
Ed Tanous1ef4c342022-05-12 16:12:36 -07001425 json["Oem"]["OpenBMC"]["@odata.id"] =
1426 "/redfish/v1/AccountService#/Oem/OpenBMC";
1427 json["Oem"]["OpenBMC"]["AuthMethods"]["BasicAuth"] =
1428 authMethodsConfig.basic;
1429 json["Oem"]["OpenBMC"]["AuthMethods"]["SessionToken"] =
1430 authMethodsConfig.sessionToken;
1431 json["Oem"]["OpenBMC"]["AuthMethods"]["XToken"] = authMethodsConfig.xtoken;
1432 json["Oem"]["OpenBMC"]["AuthMethods"]["Cookie"] = authMethodsConfig.cookie;
1433 json["Oem"]["OpenBMC"]["AuthMethods"]["TLS"] = authMethodsConfig.tls;
1434
1435 // /redfish/v1/AccountService/LDAP/Certificates is something only
1436 // ConfigureManager can access then only display when the user has
1437 // permissions ConfigureManager
1438 Privileges effectiveUserPrivileges =
Ninad Palsule3e72c202023-03-27 17:19:55 -05001439 redfish::getUserPrivileges(*req.session);
Ed Tanous1ef4c342022-05-12 16:12:36 -07001440
1441 if (isOperationAllowedWithPrivileges({{"ConfigureManager"}},
1442 effectiveUserPrivileges))
1443 {
1444 asyncResp->res.jsonValue["LDAP"]["Certificates"]["@odata.id"] =
1445 "/redfish/v1/AccountService/LDAP/Certificates";
1446 }
Ed Tanousdeae6a72024-11-11 21:58:57 -08001447 dbus::utility::getAllProperties(
1448 "xyz.openbmc_project.User.Manager", "/xyz/openbmc_project/user",
1449 "xyz.openbmc_project.User.AccountPolicy",
Ed Tanous5e7e2dc2023-02-16 10:37:01 -08001450 [asyncResp](const boost::system::error_code& ec,
Ed Tanous1ef4c342022-05-12 16:12:36 -07001451 const dbus::utility::DBusPropertiesMap& propertiesList) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001452 if (ec)
1453 {
1454 messages::internalError(asyncResp->res);
1455 return;
1456 }
Krzysztof Grobelnyd1bde9e2022-09-07 10:40:51 +02001457
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001458 BMCWEB_LOG_DEBUG("Got {} properties for AccountService",
1459 propertiesList.size());
Krzysztof Grobelnyd1bde9e2022-09-07 10:40:51 +02001460
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001461 const uint8_t* minPasswordLength = nullptr;
1462 const uint32_t* accountUnlockTimeout = nullptr;
1463 const uint16_t* maxLoginAttemptBeforeLockout = nullptr;
Krzysztof Grobelnyd1bde9e2022-09-07 10:40:51 +02001464
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001465 const bool success = sdbusplus::unpackPropertiesNoThrow(
1466 dbus_utils::UnpackErrorPrinter(), propertiesList,
1467 "MinPasswordLength", minPasswordLength, "AccountUnlockTimeout",
1468 accountUnlockTimeout, "MaxLoginAttemptBeforeLockout",
1469 maxLoginAttemptBeforeLockout);
Krzysztof Grobelnyd1bde9e2022-09-07 10:40:51 +02001470
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001471 if (!success)
1472 {
1473 messages::internalError(asyncResp->res);
1474 return;
1475 }
Krzysztof Grobelnyd1bde9e2022-09-07 10:40:51 +02001476
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001477 if (minPasswordLength != nullptr)
1478 {
1479 asyncResp->res.jsonValue["MinPasswordLength"] =
1480 *minPasswordLength;
1481 }
Krzysztof Grobelnyd1bde9e2022-09-07 10:40:51 +02001482
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001483 if (accountUnlockTimeout != nullptr)
1484 {
1485 asyncResp->res.jsonValue["AccountLockoutDuration"] =
1486 *accountUnlockTimeout;
1487 }
Krzysztof Grobelnyd1bde9e2022-09-07 10:40:51 +02001488
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001489 if (maxLoginAttemptBeforeLockout != nullptr)
1490 {
1491 asyncResp->res.jsonValue["AccountLockoutThreshold"] =
1492 *maxLoginAttemptBeforeLockout;
1493 }
1494 });
Ed Tanous1ef4c342022-05-12 16:12:36 -07001495
Ed Tanous02cad962022-06-30 16:50:15 -07001496 auto callback = [asyncResp](bool success, const LDAPConfigData& confData,
Ed Tanous1ef4c342022-05-12 16:12:36 -07001497 const std::string& ldapType) {
1498 if (!success)
1499 {
1500 return;
1501 }
1502 parseLDAPConfigData(asyncResp->res.jsonValue, confData, ldapType);
1503 };
1504
1505 getLDAPConfigData("LDAP", callback);
1506 getLDAPConfigData("ActiveDirectory", callback);
1507}
1508
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001509inline void handleCertificateMappingAttributePatch(
1510 crow::Response& res, const std::string& certMapAttribute)
Ed Tanous3ce36882024-06-09 10:58:16 -07001511{
1512 MTLSCommonNameParseMode parseMode =
1513 persistent_data::getMTLSCommonNameParseMode(certMapAttribute);
1514 if (parseMode == MTLSCommonNameParseMode::Invalid)
1515 {
1516 messages::propertyValueNotInList(res, "CertificateMappingAttribute",
1517 certMapAttribute);
1518 return;
1519 }
1520
1521 persistent_data::AuthConfigMethods& authMethodsConfig =
1522 persistent_data::SessionStore::getInstance().getAuthMethodsConfig();
1523 authMethodsConfig.mTLSCommonNameParsingMode = parseMode;
1524}
1525
Ed Tanous3281bcf2024-06-25 16:02:05 -07001526inline void handleRespondToUnauthenticatedClientsPatch(
1527 App& app, const crow::Request& req, crow::Response& res,
1528 bool respondToUnauthenticatedClients)
1529{
1530 if (req.session != nullptr)
1531 {
1532 // Sanity check. If the user isn't currently authenticated with mutual
1533 // TLS, they very likely are about to permanently lock themselves out.
1534 // Make sure they're using mutual TLS before allowing locking.
1535 if (req.session->sessionType != persistent_data::SessionType::MutualTLS)
1536 {
1537 messages::propertyValueExternalConflict(
1538 res,
1539 "MultiFactorAuth/ClientCertificate/RespondToUnauthenticatedClients",
1540 respondToUnauthenticatedClients);
1541 return;
1542 }
1543 }
1544
1545 persistent_data::AuthConfigMethods& authMethodsConfig =
1546 persistent_data::SessionStore::getInstance().getAuthMethodsConfig();
1547
1548 // Change the settings
1549 authMethodsConfig.tlsStrict = !respondToUnauthenticatedClients;
1550
1551 // Write settings to disk
1552 persistent_data::getConfig().writeData();
1553
1554 // Trigger a reload, to apply the new settings to new connections
1555 app.loadCertificate();
1556}
1557
Ed Tanous1ef4c342022-05-12 16:12:36 -07001558inline void handleAccountServicePatch(
1559 App& app, const crow::Request& req,
1560 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1561{
1562 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1563 {
1564 return;
1565 }
1566 std::optional<uint32_t> unlockTimeout;
1567 std::optional<uint16_t> lockoutThreshold;
1568 std::optional<uint8_t> minPasswordLength;
1569 std::optional<uint16_t> maxPasswordLength;
Ed Tanous10cb44f2024-04-11 13:05:20 -07001570 LdapPatchParams ldapObject;
Ed Tanous3ce36882024-06-09 10:58:16 -07001571 std::optional<std::string> certificateMappingAttribute;
Ed Tanous3281bcf2024-06-25 16:02:05 -07001572 std::optional<bool> respondToUnauthenticatedClients;
Ed Tanous10cb44f2024-04-11 13:05:20 -07001573 LdapPatchParams activeDirectoryObject;
Ed Tanousc1019822024-03-06 12:54:38 -08001574 AuthMethods auth;
Ravi Teja482a69e2024-04-22 06:56:13 -05001575 std::optional<std::string> httpBasicAuth;
Ed Tanous3ce36882024-06-09 10:58:16 -07001576
Patrick Williams504af5a2025-02-03 14:29:03 -05001577 if (!json_util::readJsonPatch( //
1578 req, asyncResp->res, //
1579 "AccountLockoutDuration", unlockTimeout, //
1580 "AccountLockoutThreshold", lockoutThreshold, //
Myung Baeafc474a2024-10-09 00:53:29 -07001581 "ActiveDirectory/Authentication/AuthenticationType",
Patrick Williams504af5a2025-02-03 14:29:03 -05001582 activeDirectoryObject.authType, //
Myung Baeafc474a2024-10-09 00:53:29 -07001583 "ActiveDirectory/Authentication/Password",
Patrick Williams504af5a2025-02-03 14:29:03 -05001584 activeDirectoryObject.password, //
Myung Baeafc474a2024-10-09 00:53:29 -07001585 "ActiveDirectory/Authentication/Username",
Patrick Williams504af5a2025-02-03 14:29:03 -05001586 activeDirectoryObject.userName, //
Myung Baeafc474a2024-10-09 00:53:29 -07001587 "ActiveDirectory/LDAPService/SearchSettings/BaseDistinguishedNames",
Patrick Williams504af5a2025-02-03 14:29:03 -05001588 activeDirectoryObject.baseDNList, //
Myung Baeafc474a2024-10-09 00:53:29 -07001589 "ActiveDirectory/LDAPService/SearchSettings/GroupsAttribute",
Patrick Williams504af5a2025-02-03 14:29:03 -05001590 activeDirectoryObject.groupsAttribute, //
Myung Baeafc474a2024-10-09 00:53:29 -07001591 "ActiveDirectory/LDAPService/SearchSettings/UsernameAttribute",
Patrick Williams504af5a2025-02-03 14:29:03 -05001592 activeDirectoryObject.userNameAttribute, //
Myung Baeafc474a2024-10-09 00:53:29 -07001593 "ActiveDirectory/RemoteRoleMapping",
Patrick Williams504af5a2025-02-03 14:29:03 -05001594 activeDirectoryObject.remoteRoleMapData, //
Myung Baeafc474a2024-10-09 00:53:29 -07001595 "ActiveDirectory/ServiceAddresses",
Patrick Williams504af5a2025-02-03 14:29:03 -05001596 activeDirectoryObject.serviceAddressList, //
Myung Baeafc474a2024-10-09 00:53:29 -07001597 "ActiveDirectory/ServiceEnabled",
Patrick Williams504af5a2025-02-03 14:29:03 -05001598 activeDirectoryObject.serviceEnabled, //
1599 "HTTPBasicAuth", httpBasicAuth, //
Myung Baeafc474a2024-10-09 00:53:29 -07001600 "LDAP/Authentication/AuthenticationType", ldapObject.authType, //
Patrick Williams504af5a2025-02-03 14:29:03 -05001601 "LDAP/Authentication/Password", ldapObject.password, //
1602 "LDAP/Authentication/Username", ldapObject.userName, //
Myung Baeafc474a2024-10-09 00:53:29 -07001603 "LDAP/LDAPService/SearchSettings/BaseDistinguishedNames",
Patrick Williams504af5a2025-02-03 14:29:03 -05001604 ldapObject.baseDNList, //
Myung Baeafc474a2024-10-09 00:53:29 -07001605 "LDAP/LDAPService/SearchSettings/GroupsAttribute",
Patrick Williams504af5a2025-02-03 14:29:03 -05001606 ldapObject.groupsAttribute, //
Myung Baeafc474a2024-10-09 00:53:29 -07001607 "LDAP/LDAPService/SearchSettings/UsernameAttribute",
Patrick Williams504af5a2025-02-03 14:29:03 -05001608 ldapObject.userNameAttribute, //
1609 "LDAP/RemoteRoleMapping", ldapObject.remoteRoleMapData, //
1610 "LDAP/ServiceAddresses", ldapObject.serviceAddressList, //
1611 "LDAP/ServiceEnabled", ldapObject.serviceEnabled, //
1612 "MaxPasswordLength", maxPasswordLength, //
1613 "MinPasswordLength", minPasswordLength, //
Myung Baeafc474a2024-10-09 00:53:29 -07001614 "MultiFactorAuth/ClientCertificate/CertificateMappingAttribute",
Patrick Williams504af5a2025-02-03 14:29:03 -05001615 certificateMappingAttribute, //
Myung Baeafc474a2024-10-09 00:53:29 -07001616 "MultiFactorAuth/ClientCertificate/RespondToUnauthenticatedClients",
Patrick Williams504af5a2025-02-03 14:29:03 -05001617 respondToUnauthenticatedClients, //
1618 "Oem/OpenBMC/AuthMethods/BasicAuth", auth.basicAuth, //
1619 "Oem/OpenBMC/AuthMethods/Cookie", auth.cookie, //
1620 "Oem/OpenBMC/AuthMethods/SessionToken", auth.sessionToken, //
1621 "Oem/OpenBMC/AuthMethods/TLS", auth.tls, //
1622 "Oem/OpenBMC/AuthMethods/XToken", auth.xToken //
Myung Baeafc474a2024-10-09 00:53:29 -07001623 ))
Ed Tanous1ef4c342022-05-12 16:12:36 -07001624 {
1625 return;
1626 }
1627
Ravi Teja482a69e2024-04-22 06:56:13 -05001628 if (httpBasicAuth)
1629 {
1630 if (*httpBasicAuth == "Enabled")
1631 {
1632 auth.basicAuth = true;
1633 }
1634 else if (*httpBasicAuth == "Disabled")
1635 {
1636 auth.basicAuth = false;
1637 }
1638 else
1639 {
1640 messages::propertyValueNotInList(asyncResp->res, "HttpBasicAuth",
1641 *httpBasicAuth);
1642 }
1643 }
1644
Ed Tanous3281bcf2024-06-25 16:02:05 -07001645 if (respondToUnauthenticatedClients)
1646 {
1647 handleRespondToUnauthenticatedClientsPatch(
1648 app, req, asyncResp->res, *respondToUnauthenticatedClients);
1649 }
1650
Ed Tanous3ce36882024-06-09 10:58:16 -07001651 if (certificateMappingAttribute)
1652 {
1653 handleCertificateMappingAttributePatch(asyncResp->res,
1654 *certificateMappingAttribute);
1655 }
1656
Ed Tanous1ef4c342022-05-12 16:12:36 -07001657 if (minPasswordLength)
1658 {
Ed Tanousd02aad32024-02-13 14:43:34 -08001659 setDbusProperty(
Ginu Georgee93abac2024-06-14 17:35:27 +05301660 asyncResp, "MinPasswordLength", "xyz.openbmc_project.User.Manager",
Ed Tanousd02aad32024-02-13 14:43:34 -08001661 sdbusplus::message::object_path("/xyz/openbmc_project/user"),
George Liu9ae226f2023-06-21 17:56:46 +08001662 "xyz.openbmc_project.User.AccountPolicy", "MinPasswordLength",
Ginu Georgee93abac2024-06-14 17:35:27 +05301663 *minPasswordLength);
Ed Tanous1ef4c342022-05-12 16:12:36 -07001664 }
1665
1666 if (maxPasswordLength)
1667 {
1668 messages::propertyNotWritable(asyncResp->res, "MaxPasswordLength");
1669 }
1670
Ed Tanous10cb44f2024-04-11 13:05:20 -07001671 handleLDAPPatch(std::move(activeDirectoryObject), asyncResp,
1672 "ActiveDirectory");
1673 handleLDAPPatch(std::move(ldapObject), asyncResp, "LDAP");
Ed Tanous1ef4c342022-05-12 16:12:36 -07001674
Ed Tanousc1019822024-03-06 12:54:38 -08001675 handleAuthMethodsPatch(asyncResp, auth);
Ed Tanous1ef4c342022-05-12 16:12:36 -07001676
Ed Tanous1ef4c342022-05-12 16:12:36 -07001677 if (unlockTimeout)
1678 {
Ed Tanousd02aad32024-02-13 14:43:34 -08001679 setDbusProperty(
Ginu Georgee93abac2024-06-14 17:35:27 +05301680 asyncResp, "AccountLockoutDuration",
1681 "xyz.openbmc_project.User.Manager",
Ed Tanousd02aad32024-02-13 14:43:34 -08001682 sdbusplus::message::object_path("/xyz/openbmc_project/user"),
Ed Tanous1ef4c342022-05-12 16:12:36 -07001683 "xyz.openbmc_project.User.AccountPolicy", "AccountUnlockTimeout",
Ginu Georgee93abac2024-06-14 17:35:27 +05301684 *unlockTimeout);
Ed Tanous1ef4c342022-05-12 16:12:36 -07001685 }
1686 if (lockoutThreshold)
1687 {
Ed Tanousd02aad32024-02-13 14:43:34 -08001688 setDbusProperty(
Ginu Georgee93abac2024-06-14 17:35:27 +05301689 asyncResp, "AccountLockoutThreshold",
1690 "xyz.openbmc_project.User.Manager",
Ed Tanousd02aad32024-02-13 14:43:34 -08001691 sdbusplus::message::object_path("/xyz/openbmc_project/user"),
George Liu9ae226f2023-06-21 17:56:46 +08001692 "xyz.openbmc_project.User.AccountPolicy",
Ginu Georgee93abac2024-06-14 17:35:27 +05301693 "MaxLoginAttemptBeforeLockout", *lockoutThreshold);
Ed Tanous1ef4c342022-05-12 16:12:36 -07001694 }
1695}
1696
Ed Tanous4c7d4d32022-07-07 15:29:35 -07001697inline void handleAccountCollectionHead(
Ed Tanous1ef4c342022-05-12 16:12:36 -07001698 App& app, const crow::Request& req,
1699 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1700{
1701 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1702 {
1703 return;
1704 }
Ed Tanous4c7d4d32022-07-07 15:29:35 -07001705 asyncResp->res.addHeader(
1706 boost::beast::http::field::link,
1707 "</redfish/v1/JsonSchemas/ManagerAccountCollection.json>; rel=describedby");
1708}
1709
1710inline void handleAccountCollectionGet(
1711 App& app, const crow::Request& req,
1712 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1713{
Jiaqing Zhaoafd369c2023-03-07 15:12:22 +08001714 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1715 {
1716 return;
1717 }
Ninad Palsule3e72c202023-03-27 17:19:55 -05001718
1719 if (req.session == nullptr)
1720 {
1721 messages::internalError(asyncResp->res);
1722 return;
1723 }
1724
Jiaqing Zhaoafd369c2023-03-07 15:12:22 +08001725 asyncResp->res.addHeader(
1726 boost::beast::http::field::link,
1727 "</redfish/v1/JsonSchemas/ManagerAccountCollection.json>; rel=describedby");
Ed Tanous1ef4c342022-05-12 16:12:36 -07001728
1729 asyncResp->res.jsonValue["@odata.id"] =
1730 "/redfish/v1/AccountService/Accounts";
1731 asyncResp->res.jsonValue["@odata.type"] = "#ManagerAccountCollection."
1732 "ManagerAccountCollection";
1733 asyncResp->res.jsonValue["Name"] = "Accounts Collection";
1734 asyncResp->res.jsonValue["Description"] = "BMC User Accounts";
1735
1736 Privileges effectiveUserPrivileges =
Ninad Palsule3e72c202023-03-27 17:19:55 -05001737 redfish::getUserPrivileges(*req.session);
Ed Tanous1ef4c342022-05-12 16:12:36 -07001738
1739 std::string thisUser;
1740 if (req.session)
1741 {
1742 thisUser = req.session->username;
1743 }
George Liu5eb468d2023-06-20 17:03:24 +08001744 sdbusplus::message::object_path path("/xyz/openbmc_project/user");
1745 dbus::utility::getManagedObjects(
1746 "xyz.openbmc_project.User.Manager", path,
Ed Tanous1ef4c342022-05-12 16:12:36 -07001747 [asyncResp, thisUser, effectiveUserPrivileges](
Ed Tanous5e7e2dc2023-02-16 10:37:01 -08001748 const boost::system::error_code& ec,
Ed Tanous1ef4c342022-05-12 16:12:36 -07001749 const dbus::utility::ManagedObjectType& users) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001750 if (ec)
Ed Tanous1ef4c342022-05-12 16:12:36 -07001751 {
1752 messages::internalError(asyncResp->res);
Ed Tanous1ef4c342022-05-12 16:12:36 -07001753 return;
1754 }
1755
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001756 bool userCanSeeAllAccounts =
1757 effectiveUserPrivileges.isSupersetOf({"ConfigureUsers"});
1758
1759 bool userCanSeeSelf =
1760 effectiveUserPrivileges.isSupersetOf({"ConfigureSelf"});
1761
1762 nlohmann::json& memberArray = asyncResp->res.jsonValue["Members"];
1763 memberArray = nlohmann::json::array();
1764
1765 for (const auto& userpath : users)
Ed Tanous1ef4c342022-05-12 16:12:36 -07001766 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001767 std::string user = userpath.first.filename();
1768 if (user.empty())
1769 {
1770 messages::internalError(asyncResp->res);
1771 BMCWEB_LOG_ERROR("Invalid firmware ID");
1772
1773 return;
1774 }
1775
1776 // As clarified by Redfish here:
1777 // https://redfishforum.com/thread/281/manageraccountcollection-change-allows-account-enumeration
1778 // Users without ConfigureUsers, only see their own
1779 // account. Users with ConfigureUsers, see all
1780 // accounts.
1781 if (userCanSeeAllAccounts ||
1782 (thisUser == user && userCanSeeSelf))
1783 {
1784 nlohmann::json::object_t member;
1785 member["@odata.id"] = boost::urls::format(
1786 "/redfish/v1/AccountService/Accounts/{}", user);
1787 memberArray.emplace_back(std::move(member));
1788 }
Ed Tanous1ef4c342022-05-12 16:12:36 -07001789 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001790 asyncResp->res.jsonValue["Members@odata.count"] =
1791 memberArray.size();
1792 });
Ed Tanous1ef4c342022-05-12 16:12:36 -07001793}
1794
Ninad Palsule97e90da2023-05-17 14:04:52 -05001795inline void processAfterCreateUser(
1796 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1797 const std::string& username, const std::string& password,
1798 const boost::system::error_code& ec, sdbusplus::message_t& m)
1799{
1800 if (ec)
1801 {
1802 userErrorMessageHandler(m.get_error(), asyncResp, username, "");
1803 return;
1804 }
1805
1806 if (pamUpdatePassword(username, password) != PAM_SUCCESS)
1807 {
1808 // At this point we have a user that's been
1809 // created, but the password set
1810 // failed.Something is wrong, so delete the user
1811 // that we've already created
1812 sdbusplus::message::object_path tempObjPath(rootUserDbusPath);
1813 tempObjPath /= username;
1814 const std::string userPath(tempObjPath);
1815
1816 crow::connections::systemBus->async_method_call(
1817 [asyncResp, password](const boost::system::error_code& ec3) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001818 if (ec3)
1819 {
1820 messages::internalError(asyncResp->res);
1821 return;
1822 }
Ninad Palsule97e90da2023-05-17 14:04:52 -05001823
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001824 // If password is invalid
1825 messages::propertyValueFormatError(asyncResp->res, nullptr,
1826 "Password");
1827 },
Ninad Palsule97e90da2023-05-17 14:04:52 -05001828 "xyz.openbmc_project.User.Manager", userPath,
1829 "xyz.openbmc_project.Object.Delete", "Delete");
1830
Ed Tanous62598e32023-07-17 17:06:25 -07001831 BMCWEB_LOG_ERROR("pamUpdatePassword Failed");
Ninad Palsule97e90da2023-05-17 14:04:52 -05001832 return;
1833 }
1834
1835 messages::created(asyncResp->res);
1836 asyncResp->res.addHeader("Location",
1837 "/redfish/v1/AccountService/Accounts/" + username);
1838}
1839
1840inline void processAfterGetAllGroups(
1841 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1842 const std::string& username, const std::string& password,
Ed Tanouse01d0c32023-06-30 13:21:32 -07001843 const std::string& roleId, bool enabled,
Ninad Palsule9ba73932023-06-01 16:38:57 -05001844 std::optional<std::vector<std::string>> accountTypes,
Ninad Palsule97e90da2023-05-17 14:04:52 -05001845 const std::vector<std::string>& allGroupsList)
Ninad Palsule97e90da2023-05-17 14:04:52 -05001846{
Ninad Palsule3e72c202023-03-27 17:19:55 -05001847 std::vector<std::string> userGroups;
Ninad Palsule9ba73932023-06-01 16:38:57 -05001848 std::vector<std::string> accountTypeUserGroups;
1849
1850 // If user specified account types then convert them to unix user groups
1851 if (accountTypes)
1852 {
1853 if (!getUserGroupFromAccountType(asyncResp->res, *accountTypes,
1854 accountTypeUserGroups))
1855 {
1856 // Problem in mapping Account Types to User Groups, Error already
1857 // logged.
1858 return;
1859 }
1860 }
1861
Ninad Palsule3e72c202023-03-27 17:19:55 -05001862 for (const auto& grp : allGroupsList)
1863 {
Ninad Palsule9ba73932023-06-01 16:38:57 -05001864 // If user specified the account type then only accept groups which are
1865 // in the account types group list.
1866 if (!accountTypeUserGroups.empty())
1867 {
1868 bool found = false;
1869 for (const auto& grp1 : accountTypeUserGroups)
1870 {
1871 if (grp == grp1)
1872 {
1873 found = true;
1874 break;
1875 }
1876 }
1877 if (!found)
1878 {
1879 continue;
1880 }
1881 }
1882
Ninad Palsule3e72c202023-03-27 17:19:55 -05001883 // Console access is provided to the user who is a member of
1884 // hostconsole group and has a administrator role. So, set
1885 // hostconsole group only for the administrator.
Ninad Palsule9ba73932023-06-01 16:38:57 -05001886 if ((grp == "hostconsole") && (roleId != "priv-admin"))
Ninad Palsule3e72c202023-03-27 17:19:55 -05001887 {
Ninad Palsule9ba73932023-06-01 16:38:57 -05001888 if (!accountTypeUserGroups.empty())
1889 {
Ed Tanous62598e32023-07-17 17:06:25 -07001890 BMCWEB_LOG_ERROR(
1891 "Only administrator can get HostConsole access");
Ninad Palsule9ba73932023-06-01 16:38:57 -05001892 asyncResp->res.result(boost::beast::http::status::bad_request);
1893 return;
1894 }
1895 continue;
Ninad Palsule3e72c202023-03-27 17:19:55 -05001896 }
Ninad Palsule9ba73932023-06-01 16:38:57 -05001897 userGroups.emplace_back(grp);
1898 }
1899
1900 // Make sure user specified groups are valid. This is internal error because
1901 // it some inconsistencies between user manager and bmcweb.
1902 if (!accountTypeUserGroups.empty() &&
1903 accountTypeUserGroups.size() != userGroups.size())
1904 {
1905 messages::internalError(asyncResp->res);
1906 return;
Ninad Palsule3e72c202023-03-27 17:19:55 -05001907 }
Ninad Palsule97e90da2023-05-17 14:04:52 -05001908 crow::connections::systemBus->async_method_call(
1909 [asyncResp, username, password](const boost::system::error_code& ec2,
1910 sdbusplus::message_t& m) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001911 processAfterCreateUser(asyncResp, username, password, ec2, m);
1912 },
Ninad Palsule97e90da2023-05-17 14:04:52 -05001913 "xyz.openbmc_project.User.Manager", "/xyz/openbmc_project/user",
Ninad Palsule3e72c202023-03-27 17:19:55 -05001914 "xyz.openbmc_project.User.Manager", "CreateUser", username, userGroups,
Ed Tanouse01d0c32023-06-30 13:21:32 -07001915 roleId, enabled);
Ninad Palsule97e90da2023-05-17 14:04:52 -05001916}
1917
Ed Tanous1ef4c342022-05-12 16:12:36 -07001918inline void handleAccountCollectionPost(
1919 App& app, const crow::Request& req,
1920 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1921{
1922 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1923 {
1924 return;
1925 }
1926 std::string username;
1927 std::string password;
Ed Tanouse01d0c32023-06-30 13:21:32 -07001928 std::optional<std::string> roleIdJson;
1929 std::optional<bool> enabledJson;
Ninad Palsule9ba73932023-06-01 16:38:57 -05001930 std::optional<std::vector<std::string>> accountTypes;
Patrick Williams504af5a2025-02-03 14:29:03 -05001931 if (!json_util::readJsonPatch( //
1932 req, asyncResp->res, //
Myung Baeafc474a2024-10-09 00:53:29 -07001933 "AccountTypes", accountTypes, //
Patrick Williams504af5a2025-02-03 14:29:03 -05001934 "Enabled", enabledJson, //
1935 "Password", password, //
1936 "RoleId", roleIdJson, //
1937 "UserName", username //
Myung Baeafc474a2024-10-09 00:53:29 -07001938 ))
Ed Tanous1ef4c342022-05-12 16:12:36 -07001939 {
1940 return;
1941 }
1942
Ed Tanouse01d0c32023-06-30 13:21:32 -07001943 std::string roleId = roleIdJson.value_or("User");
1944 std::string priv = getPrivilegeFromRoleId(roleId);
Ed Tanous1ef4c342022-05-12 16:12:36 -07001945 if (priv.empty())
1946 {
Ed Tanouse01d0c32023-06-30 13:21:32 -07001947 messages::propertyValueNotInList(asyncResp->res, roleId, "RoleId");
Ed Tanous1ef4c342022-05-12 16:12:36 -07001948 return;
1949 }
Asmitha Karunanithi239adf82022-03-25 02:59:03 -05001950 roleId = priv;
Ed Tanous1ef4c342022-05-12 16:12:36 -07001951
Ed Tanouse01d0c32023-06-30 13:21:32 -07001952 bool enabled = enabledJson.value_or(true);
1953
Ed Tanous1ef4c342022-05-12 16:12:36 -07001954 // Reading AllGroups property
Ed Tanousdeae6a72024-11-11 21:58:57 -08001955 dbus::utility::getProperty<std::vector<std::string>>(
1956 "xyz.openbmc_project.User.Manager", "/xyz/openbmc_project/user",
1957 "xyz.openbmc_project.User.Manager", "AllGroups",
Ninad Palsule9ba73932023-06-01 16:38:57 -05001958 [asyncResp, username, password{std::move(password)}, roleId, enabled,
1959 accountTypes](const boost::system::error_code& ec,
1960 const std::vector<std::string>& allGroupsList) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001961 if (ec)
1962 {
Gunnar Millsa0735a42024-09-06 12:51:11 -05001963 BMCWEB_LOG_ERROR("D-Bus response error {}", ec);
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001964 messages::internalError(asyncResp->res);
1965 return;
1966 }
Ed Tanous1ef4c342022-05-12 16:12:36 -07001967
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001968 if (allGroupsList.empty())
1969 {
1970 messages::internalError(asyncResp->res);
1971 return;
1972 }
Ed Tanous1ef4c342022-05-12 16:12:36 -07001973
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001974 processAfterGetAllGroups(asyncResp, username, password, roleId,
1975 enabled, accountTypes, allGroupsList);
1976 });
Ed Tanous1ef4c342022-05-12 16:12:36 -07001977}
1978
Patrick Williams504af5a2025-02-03 14:29:03 -05001979inline void handleAccountHead(
1980 App& app, const crow::Request& req,
1981 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1982 const std::string& /*accountName*/)
Ed Tanous1ef4c342022-05-12 16:12:36 -07001983{
1984 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1985 {
1986 return;
1987 }
Ed Tanous4c7d4d32022-07-07 15:29:35 -07001988 asyncResp->res.addHeader(
1989 boost::beast::http::field::link,
1990 "</redfish/v1/JsonSchemas/ManagerAccount/ManagerAccount.json>; rel=describedby");
1991}
Jiaqing Zhaoafd369c2023-03-07 15:12:22 +08001992
Patrick Williams504af5a2025-02-03 14:29:03 -05001993inline void handleAccountGet(
1994 App& app, const crow::Request& req,
1995 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1996 const std::string& accountName)
Ed Tanous4c7d4d32022-07-07 15:29:35 -07001997{
Jiaqing Zhaoafd369c2023-03-07 15:12:22 +08001998 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1999 {
2000 return;
2001 }
2002 asyncResp->res.addHeader(
2003 boost::beast::http::field::link,
2004 "</redfish/v1/JsonSchemas/ManagerAccount/ManagerAccount.json>; rel=describedby");
2005
Ed Tanous25b54db2024-04-17 15:40:31 -07002006 if constexpr (BMCWEB_INSECURE_DISABLE_AUTH)
2007 {
2008 // If authentication is disabled, there are no user accounts
2009 messages::resourceNotFound(asyncResp->res, "ManagerAccount",
2010 accountName);
2011 return;
2012 }
Jiaqing Zhaoafd369c2023-03-07 15:12:22 +08002013
Ed Tanous1ef4c342022-05-12 16:12:36 -07002014 if (req.session == nullptr)
2015 {
2016 messages::internalError(asyncResp->res);
2017 return;
2018 }
2019 if (req.session->username != accountName)
2020 {
2021 // At this point we've determined that the user is trying to
2022 // modify a user that isn't them. We need to verify that they
2023 // have permissions to modify other users, so re-run the auth
2024 // check with the same permissions, minus ConfigureSelf.
2025 Privileges effectiveUserPrivileges =
Ninad Palsule3e72c202023-03-27 17:19:55 -05002026 redfish::getUserPrivileges(*req.session);
Ed Tanous1ef4c342022-05-12 16:12:36 -07002027 Privileges requiredPermissionsToChangeNonSelf = {"ConfigureUsers",
2028 "ConfigureManager"};
2029 if (!effectiveUserPrivileges.isSupersetOf(
2030 requiredPermissionsToChangeNonSelf))
2031 {
Ed Tanous62598e32023-07-17 17:06:25 -07002032 BMCWEB_LOG_DEBUG("GET Account denied access");
Ed Tanous1ef4c342022-05-12 16:12:36 -07002033 messages::insufficientPrivilege(asyncResp->res);
2034 return;
2035 }
2036 }
2037
George Liu5eb468d2023-06-20 17:03:24 +08002038 sdbusplus::message::object_path path("/xyz/openbmc_project/user");
2039 dbus::utility::getManagedObjects(
2040 "xyz.openbmc_project.User.Manager", path,
Ed Tanous1ef4c342022-05-12 16:12:36 -07002041 [asyncResp,
Ed Tanous5e7e2dc2023-02-16 10:37:01 -08002042 accountName](const boost::system::error_code& ec,
Ed Tanous1ef4c342022-05-12 16:12:36 -07002043 const dbus::utility::ManagedObjectType& users) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002044 if (ec)
Ed Tanous1ef4c342022-05-12 16:12:36 -07002045 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002046 messages::internalError(asyncResp->res);
2047 return;
2048 }
2049 const auto userIt = std::ranges::find_if(
2050 users,
2051 [accountName](
2052 const std::pair<sdbusplus::message::object_path,
2053 dbus::utility::DBusInterfacesMap>& user) {
2054 return accountName == user.first.filename();
2055 });
Ed Tanous1ef4c342022-05-12 16:12:36 -07002056
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002057 if (userIt == users.end())
2058 {
2059 messages::resourceNotFound(asyncResp->res, "ManagerAccount",
2060 accountName);
2061 return;
2062 }
2063
2064 asyncResp->res.jsonValue["@odata.type"] =
2065 "#ManagerAccount.v1_7_0.ManagerAccount";
2066 asyncResp->res.jsonValue["Name"] = "User Account";
2067 asyncResp->res.jsonValue["Description"] = "User Account";
2068 asyncResp->res.jsonValue["Password"] = nullptr;
2069 asyncResp->res.jsonValue["StrictAccountTypes"] = true;
2070
2071 for (const auto& interface : userIt->second)
2072 {
2073 if (interface.first == "xyz.openbmc_project.User.Attributes")
2074 {
Asmitha Karunanithib437a532024-12-20 04:54:25 -06002075 const bool* userEnabled = nullptr;
2076 const bool* userLocked = nullptr;
2077 const std::string* userPrivPtr = nullptr;
2078 const bool* userPasswordExpired = nullptr;
2079 const std::vector<std::string>* userGroups = nullptr;
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002080
Asmitha Karunanithib437a532024-12-20 04:54:25 -06002081 const bool success = sdbusplus::unpackPropertiesNoThrow(
2082 dbus_utils::UnpackErrorPrinter(), interface.second,
2083 "UserEnabled", userEnabled,
2084 "UserLockedForFailedAttempt", userLocked,
2085 "UserPrivilege", userPrivPtr, "UserPasswordExpired",
2086 userPasswordExpired, "UserGroups", userGroups);
2087 if (!success)
2088 {
2089 messages::internalError(asyncResp->res);
2090 return;
2091 }
2092 if (userEnabled == nullptr)
2093 {
2094 BMCWEB_LOG_ERROR("UserEnabled wasn't a bool");
2095 messages::internalError(asyncResp->res);
2096 return;
2097 }
2098 asyncResp->res.jsonValue["Enabled"] = *userEnabled;
2099
2100 if (userLocked == nullptr)
2101 {
2102 BMCWEB_LOG_ERROR("UserLockedForF"
2103 "ailedAttempt "
2104 "wasn't a bool");
2105 messages::internalError(asyncResp->res);
2106 return;
2107 }
2108 asyncResp->res.jsonValue["Locked"] = *userLocked;
2109 nlohmann::json::array_t allowed;
2110 // can only unlock accounts
2111 allowed.emplace_back("false");
2112 asyncResp->res.jsonValue["Locked@Redfish.AllowableValues"] =
2113 std::move(allowed);
2114
2115 if (userPrivPtr == nullptr)
2116 {
2117 BMCWEB_LOG_ERROR("UserPrivilege wasn't a "
2118 "string");
2119 messages::internalError(asyncResp->res);
2120 return;
2121 }
2122 std::string role = getRoleIdFromPrivilege(*userPrivPtr);
2123 if (role.empty())
2124 {
2125 BMCWEB_LOG_ERROR("Invalid user role");
2126 messages::internalError(asyncResp->res);
2127 return;
2128 }
2129 asyncResp->res.jsonValue["RoleId"] = role;
2130
2131 nlohmann::json& roleEntry =
2132 asyncResp->res.jsonValue["Links"]["Role"];
2133 roleEntry["@odata.id"] = boost::urls::format(
2134 "/redfish/v1/AccountService/Roles/{}", role);
2135
2136 if (userPasswordExpired == nullptr)
2137 {
2138 BMCWEB_LOG_ERROR("UserPasswordExpired wasn't a bool");
2139 messages::internalError(asyncResp->res);
2140 return;
2141 }
2142 asyncResp->res.jsonValue["PasswordChangeRequired"] =
2143 *userPasswordExpired;
2144
2145 if (userGroups == nullptr)
2146 {
2147 BMCWEB_LOG_ERROR("userGroups wasn't a string vector");
2148 messages::internalError(asyncResp->res);
2149 return;
2150 }
2151 if (!translateUserGroup(*userGroups, asyncResp->res))
2152 {
2153 BMCWEB_LOG_ERROR("userGroups mapping failed");
2154 messages::internalError(asyncResp->res);
2155 return;
Abhishek Patelc7229812022-02-01 10:07:15 -06002156 }
Ed Tanous1ef4c342022-05-12 16:12:36 -07002157 }
2158 }
Ed Tanous1ef4c342022-05-12 16:12:36 -07002159
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002160 asyncResp->res.jsonValue["@odata.id"] = boost::urls::format(
2161 "/redfish/v1/AccountService/Accounts/{}", accountName);
2162 asyncResp->res.jsonValue["Id"] = accountName;
2163 asyncResp->res.jsonValue["UserName"] = accountName;
2164 });
Ed Tanous1ef4c342022-05-12 16:12:36 -07002165}
2166
Patrick Williams504af5a2025-02-03 14:29:03 -05002167inline void handleAccountDelete(
2168 App& app, const crow::Request& req,
2169 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2170 const std::string& username)
Ed Tanous1ef4c342022-05-12 16:12:36 -07002171{
2172 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2173 {
2174 return;
2175 }
2176
Ed Tanous25b54db2024-04-17 15:40:31 -07002177 if constexpr (BMCWEB_INSECURE_DISABLE_AUTH)
2178 {
2179 // If authentication is disabled, there are no user accounts
2180 messages::resourceNotFound(asyncResp->res, "ManagerAccount", username);
2181 return;
2182 }
Ed Tanous1ef4c342022-05-12 16:12:36 -07002183 sdbusplus::message::object_path tempObjPath(rootUserDbusPath);
2184 tempObjPath /= username;
2185 const std::string userPath(tempObjPath);
2186
2187 crow::connections::systemBus->async_method_call(
Ed Tanous5e7e2dc2023-02-16 10:37:01 -08002188 [asyncResp, username](const boost::system::error_code& ec) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002189 if (ec)
2190 {
2191 messages::resourceNotFound(asyncResp->res, "ManagerAccount",
2192 username);
2193 return;
2194 }
Ed Tanous1ef4c342022-05-12 16:12:36 -07002195
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002196 messages::accountRemoved(asyncResp->res);
2197 },
Ed Tanous1ef4c342022-05-12 16:12:36 -07002198 "xyz.openbmc_project.User.Manager", userPath,
2199 "xyz.openbmc_project.Object.Delete", "Delete");
2200}
2201
Patrick Williams504af5a2025-02-03 14:29:03 -05002202inline void handleAccountPatch(
2203 App& app, const crow::Request& req,
2204 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2205 const std::string& username)
Ed Tanous1ef4c342022-05-12 16:12:36 -07002206{
2207 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2208 {
2209 return;
2210 }
Ed Tanous25b54db2024-04-17 15:40:31 -07002211 if constexpr (BMCWEB_INSECURE_DISABLE_AUTH)
2212 {
2213 // If authentication is disabled, there are no user accounts
2214 messages::resourceNotFound(asyncResp->res, "ManagerAccount", username);
2215 return;
2216 }
Ed Tanous1ef4c342022-05-12 16:12:36 -07002217 std::optional<std::string> newUserName;
2218 std::optional<std::string> password;
2219 std::optional<bool> enabled;
2220 std::optional<std::string> roleId;
2221 std::optional<bool> locked;
Abhishek Patel58345852022-02-02 08:54:25 -06002222 std::optional<std::vector<std::string>> accountTypes;
2223
Ed Tanous1ef4c342022-05-12 16:12:36 -07002224 if (req.session == nullptr)
2225 {
2226 messages::internalError(asyncResp->res);
2227 return;
2228 }
2229
Ed Tanous2b9c1df2024-04-06 13:52:01 -07002230 bool userSelf = (username == req.session->username);
2231
Ed Tanous1ef4c342022-05-12 16:12:36 -07002232 Privileges effectiveUserPrivileges =
Ninad Palsule3e72c202023-03-27 17:19:55 -05002233 redfish::getUserPrivileges(*req.session);
Ed Tanous1ef4c342022-05-12 16:12:36 -07002234 Privileges configureUsers = {"ConfigureUsers"};
2235 bool userHasConfigureUsers =
2236 effectiveUserPrivileges.isSupersetOf(configureUsers);
2237 if (userHasConfigureUsers)
2238 {
2239 // Users with ConfigureUsers can modify for all users
Patrick Williams504af5a2025-02-03 14:29:03 -05002240 if (!json_util::readJsonPatch( //
2241 req, asyncResp->res, //
Myung Baeafc474a2024-10-09 00:53:29 -07002242 "AccountTypes", accountTypes, //
Patrick Williams504af5a2025-02-03 14:29:03 -05002243 "Enabled", enabled, //
2244 "Locked", locked, //
2245 "Password", password, //
2246 "RoleId", roleId, //
2247 "UserName", newUserName //
Myung Baeafc474a2024-10-09 00:53:29 -07002248 ))
Ed Tanous1ef4c342022-05-12 16:12:36 -07002249 {
2250 return;
2251 }
2252 }
2253 else
2254 {
2255 // ConfigureSelf accounts can only modify their own account
Abhishek Patel58345852022-02-02 08:54:25 -06002256 if (!userSelf)
Ed Tanous1ef4c342022-05-12 16:12:36 -07002257 {
2258 messages::insufficientPrivilege(asyncResp->res);
2259 return;
2260 }
2261
2262 // ConfigureSelf accounts can only modify their password
2263 if (!json_util::readJsonPatch(req, asyncResp->res, "Password",
2264 password))
2265 {
2266 return;
2267 }
2268 }
2269
2270 // if user name is not provided in the patch method or if it
2271 // matches the user name in the URI, then we are treating it as
2272 // updating user properties other then username. If username
2273 // provided doesn't match the URI, then we are treating this as
2274 // user rename request.
2275 if (!newUserName || (newUserName.value() == username))
2276 {
2277 updateUserProperties(asyncResp, username, password, enabled, roleId,
Ravi Tejae518ef32024-05-16 10:33:08 -05002278 locked, accountTypes, userSelf, req.session);
Ed Tanous1ef4c342022-05-12 16:12:36 -07002279 return;
2280 }
2281 crow::connections::systemBus->async_method_call(
2282 [asyncResp, username, password(std::move(password)),
2283 roleId(std::move(roleId)), enabled, newUser{std::string(*newUserName)},
Ravi Tejae518ef32024-05-16 10:33:08 -05002284 locked, userSelf, req, accountTypes(std::move(accountTypes))](
Ed Tanouse81de512023-06-27 17:07:00 -07002285 const boost::system::error_code& ec, sdbusplus::message_t& m) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002286 if (ec)
2287 {
2288 userErrorMessageHandler(m.get_error(), asyncResp, newUser,
2289 username);
2290 return;
2291 }
Ed Tanous1ef4c342022-05-12 16:12:36 -07002292
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002293 updateUserProperties(asyncResp, newUser, password, enabled, roleId,
2294 locked, accountTypes, userSelf, req.session);
2295 },
Ed Tanous1ef4c342022-05-12 16:12:36 -07002296 "xyz.openbmc_project.User.Manager", "/xyz/openbmc_project/user",
2297 "xyz.openbmc_project.User.Manager", "RenameUser", username,
2298 *newUserName);
2299}
2300
Ed Tanous6c51eab2021-06-03 12:30:29 -07002301inline void requestAccountServiceRoutes(App& app)
Ed Tanousb9b2e0b2018-09-13 13:47:50 -07002302{
Ed Tanous6c51eab2021-06-03 12:30:29 -07002303 BMCWEB_ROUTE(app, "/redfish/v1/AccountService/")
Ed Tanous4c7d4d32022-07-07 15:29:35 -07002304 .privileges(redfish::privileges::headAccountService)
2305 .methods(boost::beast::http::verb::head)(
2306 std::bind_front(handleAccountServiceHead, std::ref(app)));
2307
2308 BMCWEB_ROUTE(app, "/redfish/v1/AccountService/")
Ed Tanoused398212021-06-09 17:05:54 -07002309 .privileges(redfish::privileges::getAccountService)
Ed Tanous002d39b2022-05-31 08:59:27 -07002310 .methods(boost::beast::http::verb::get)(
Ed Tanous1ef4c342022-05-12 16:12:36 -07002311 std::bind_front(handleAccountServiceGet, std::ref(app)));
Ed Tanous6c51eab2021-06-03 12:30:29 -07002312
Ed Tanousf5ffd802021-07-19 10:55:33 -07002313 BMCWEB_ROUTE(app, "/redfish/v1/AccountService/")
Gunnar Mills1ec43ee2022-01-04 15:39:52 -06002314 .privileges(redfish::privileges::patchAccountService)
Ed Tanousf5ffd802021-07-19 10:55:33 -07002315 .methods(boost::beast::http::verb::patch)(
Ed Tanous1ef4c342022-05-12 16:12:36 -07002316 std::bind_front(handleAccountServicePatch, std::ref(app)));
Ed Tanousf5ffd802021-07-19 10:55:33 -07002317
Ed Tanous1aa375b2024-04-13 11:51:10 -07002318 BMCWEB_ROUTE(
2319 app,
Ed Tanouse9f12012024-10-08 13:37:07 -07002320 "/redfish/v1/AccountService/MultiFactorAuth/ClientCertificate/Certificates/")
Ed Tanous1aa375b2024-04-13 11:51:10 -07002321 .privileges(redfish::privileges::headCertificateCollection)
2322 .methods(boost::beast::http::verb::head)(std::bind_front(
2323 handleAccountServiceClientCertificatesHead, std::ref(app)));
2324
2325 BMCWEB_ROUTE(
2326 app,
Ed Tanouse9f12012024-10-08 13:37:07 -07002327 "/redfish/v1/AccountService/MultiFactorAuth/ClientCertificate/Certificates/")
Ed Tanous1aa375b2024-04-13 11:51:10 -07002328 .privileges(redfish::privileges::getCertificateCollection)
2329 .methods(boost::beast::http::verb::get)(std::bind_front(
2330 handleAccountServiceClientCertificatesGet, std::ref(app)));
2331
2332 BMCWEB_ROUTE(
2333 app,
Ed Tanouse9f12012024-10-08 13:37:07 -07002334 "/redfish/v1/AccountService/MultiFactorAuth/ClientCertificate/Certificates/<str>/")
Ed Tanous1aa375b2024-04-13 11:51:10 -07002335 .privileges(redfish::privileges::headCertificate)
2336 .methods(boost::beast::http::verb::head)(std::bind_front(
2337 handleAccountServiceClientCertificatesInstanceHead, std::ref(app)));
2338
2339 BMCWEB_ROUTE(
2340 app,
2341 "/redfish/v1/AccountService/MultiFactorAuth/ClientCertificate/Certificates/<str>/")
2342 .privileges(redfish::privileges::getCertificate)
2343 .methods(boost::beast::http::verb::get)(std::bind_front(
2344 handleAccountServiceClientCertificatesInstanceGet, std::ref(app)));
2345
Ed Tanous6c51eab2021-06-03 12:30:29 -07002346 BMCWEB_ROUTE(app, "/redfish/v1/AccountService/Accounts/")
Ed Tanous4c7d4d32022-07-07 15:29:35 -07002347 .privileges(redfish::privileges::headManagerAccountCollection)
2348 .methods(boost::beast::http::verb::head)(
2349 std::bind_front(handleAccountCollectionHead, std::ref(app)));
2350
2351 BMCWEB_ROUTE(app, "/redfish/v1/AccountService/Accounts/")
Ed Tanoused398212021-06-09 17:05:54 -07002352 .privileges(redfish::privileges::getManagerAccountCollection)
Ed Tanous6c51eab2021-06-03 12:30:29 -07002353 .methods(boost::beast::http::verb::get)(
Ed Tanous1ef4c342022-05-12 16:12:36 -07002354 std::bind_front(handleAccountCollectionGet, std::ref(app)));
Ed Tanous06e086d2018-09-19 17:19:52 -07002355
Ed Tanous6c51eab2021-06-03 12:30:29 -07002356 BMCWEB_ROUTE(app, "/redfish/v1/AccountService/Accounts/")
Ed Tanoused398212021-06-09 17:05:54 -07002357 .privileges(redfish::privileges::postManagerAccountCollection)
Ed Tanous002d39b2022-05-31 08:59:27 -07002358 .methods(boost::beast::http::verb::post)(
Ed Tanous1ef4c342022-05-12 16:12:36 -07002359 std::bind_front(handleAccountCollectionPost, std::ref(app)));
Ed Tanous002d39b2022-05-31 08:59:27 -07002360
2361 BMCWEB_ROUTE(app, "/redfish/v1/AccountService/Accounts/<str>/")
Ed Tanous4c7d4d32022-07-07 15:29:35 -07002362 .privileges(redfish::privileges::headManagerAccount)
2363 .methods(boost::beast::http::verb::head)(
2364 std::bind_front(handleAccountHead, std::ref(app)));
2365
2366 BMCWEB_ROUTE(app, "/redfish/v1/AccountService/Accounts/<str>/")
Ed Tanous002d39b2022-05-31 08:59:27 -07002367 .privileges(redfish::privileges::getManagerAccount)
2368 .methods(boost::beast::http::verb::get)(
Ed Tanous1ef4c342022-05-12 16:12:36 -07002369 std::bind_front(handleAccountGet, std::ref(app)));
Ed Tanous6c51eab2021-06-03 12:30:29 -07002370
2371 BMCWEB_ROUTE(app, "/redfish/v1/AccountService/Accounts/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07002372 // TODO this privilege should be using the generated endpoints, but
2373 // because of the special handling of ConfigureSelf, it's not able to
2374 // yet
Ed Tanous6c51eab2021-06-03 12:30:29 -07002375 .privileges({{"ConfigureUsers"}, {"ConfigureSelf"}})
2376 .methods(boost::beast::http::verb::patch)(
Ed Tanous1ef4c342022-05-12 16:12:36 -07002377 std::bind_front(handleAccountPatch, std::ref(app)));
Ed Tanous6c51eab2021-06-03 12:30:29 -07002378
2379 BMCWEB_ROUTE(app, "/redfish/v1/AccountService/Accounts/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07002380 .privileges(redfish::privileges::deleteManagerAccount)
Ed Tanous6c51eab2021-06-03 12:30:29 -07002381 .methods(boost::beast::http::verb::delete_)(
Gunnar Mills20fc3072023-01-27 15:13:36 -06002382 std::bind_front(handleAccountDelete, std::ref(app)));
Ed Tanous6c51eab2021-06-03 12:30:29 -07002383}
Lewanczyk, Dawid88d16c92018-02-02 14:51:09 +01002384
Ed Tanous1abe55e2018-09-05 08:30:59 -07002385} // namespace redfish