blob: 2cc69760cf38cc986cfd369b508205ede41d53a9 [file] [log] [blame]
Lewanczyk, Dawid88d16c92018-02-02 14:51:09 +01001/*
2// Copyright (c) 2018 Intel Corporation
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15*/
16#pragma once
Lewanczyk, Dawid88d16c92018-02-02 14:51:09 +010017
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080018#include "app.hpp"
Ed Tanous1aa375b2024-04-13 11:51:10 -070019#include "certificate_service.hpp"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080020#include "dbus_utility.hpp"
21#include "error_messages.hpp"
Ed Tanous0ec8b832022-03-14 14:56:47 -070022#include "generated/enums/account_service.hpp"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080023#include "persistent_data.hpp"
24#include "query.hpp"
Ed Tanous0ec8b832022-03-14 14:56:47 -070025#include "registries/privilege_registry.hpp"
Ed Tanous3281bcf2024-06-25 16:02:05 -070026#include "sessions.hpp"
Ed Tanous1aa375b2024-04-13 11:51:10 -070027#include "utils/collection.hpp"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080028#include "utils/dbus_utils.hpp"
29#include "utils/json_utils.hpp"
Ed Tanous0ec8b832022-03-14 14:56:47 -070030
Ed Tanous1aa375b2024-04-13 11:51:10 -070031#include <boost/url/format.hpp>
32#include <boost/url/url.hpp>
Jonathan Doman1e1e5982021-06-11 09:36:17 -070033#include <sdbusplus/asio/property.hpp>
Krzysztof Grobelnyd1bde9e2022-09-07 10:40:51 +020034#include <sdbusplus/unpack_properties.hpp>
Gunnar Mills1214b7e2020-06-04 10:11:30 -050035
George Liu2b731192023-01-11 16:27:13 +080036#include <array>
Ed Tanous1aa375b2024-04-13 11:51:10 -070037#include <memory>
Abhishek Patelc7229812022-02-01 10:07:15 -060038#include <optional>
Ed Tanous3544d2a2023-08-06 18:12:20 -070039#include <ranges>
Abhishek Patelc7229812022-02-01 10:07:15 -060040#include <string>
George Liu2b731192023-01-11 16:27:13 +080041#include <string_view>
Ed Tanous20fa6a22024-05-20 18:02:58 -070042#include <utility>
Abhishek Patelc7229812022-02-01 10:07:15 -060043#include <vector>
44
Ed Tanous1abe55e2018-09-05 08:30:59 -070045namespace redfish
46{
Lewanczyk, Dawid88d16c92018-02-02 14:51:09 +010047
Ed Tanous23a21a12020-07-25 04:45:05 +000048constexpr const char* ldapConfigObjectName =
Ratan Gupta6973a582018-12-13 18:25:44 +053049 "/xyz/openbmc_project/user/ldap/openldap";
Ed Tanous2c70f802020-09-28 14:29:23 -070050constexpr const char* adConfigObject =
Ratan Guptaab828d72019-04-22 14:18:33 +053051 "/xyz/openbmc_project/user/ldap/active_directory";
52
P Dheeraj Srujan Kumarb477fd42021-12-16 07:17:51 +053053constexpr const char* rootUserDbusPath = "/xyz/openbmc_project/user/";
Ratan Gupta6973a582018-12-13 18:25:44 +053054constexpr const char* ldapRootObject = "/xyz/openbmc_project/user/ldap";
55constexpr const char* ldapDbusService = "xyz.openbmc_project.Ldap.Config";
56constexpr const char* ldapConfigInterface =
57 "xyz.openbmc_project.User.Ldap.Config";
58constexpr const char* ldapCreateInterface =
59 "xyz.openbmc_project.User.Ldap.Create";
60constexpr const char* ldapEnableInterface = "xyz.openbmc_project.Object.Enable";
Ratan Gupta06785242019-07-26 22:30:16 +053061constexpr const char* ldapPrivMapperInterface =
62 "xyz.openbmc_project.User.PrivilegeMapper";
Ratan Gupta6973a582018-12-13 18:25:44 +053063
Nagaraju Goruganti54fc5872019-01-30 05:11:00 -060064struct LDAPRoleMapData
65{
66 std::string groupName;
67 std::string privilege;
68};
69
Ratan Gupta6973a582018-12-13 18:25:44 +053070struct LDAPConfigData
71{
Ed Tanous47f29342024-03-19 12:18:06 -070072 std::string uri;
73 std::string bindDN;
74 std::string baseDN;
75 std::string searchScope;
76 std::string serverType;
Ratan Gupta6973a582018-12-13 18:25:44 +053077 bool serviceEnabled = false;
Ed Tanous47f29342024-03-19 12:18:06 -070078 std::string userNameAttribute;
79 std::string groupAttribute;
Nagaraju Goruganti54fc5872019-01-30 05:11:00 -060080 std::vector<std::pair<std::string, LDAPRoleMapData>> groupRoleList;
Ratan Gupta6973a582018-12-13 18:25:44 +053081};
82
Nagaraju Goruganti54fc5872019-01-30 05:11:00 -060083inline std::string getRoleIdFromPrivilege(std::string_view role)
AppaRao Puli84e12cb2018-10-11 01:28:15 +053084{
85 if (role == "priv-admin")
86 {
87 return "Administrator";
88 }
Ed Tanous3174e4d2020-10-07 11:41:22 -070089 if (role == "priv-user")
AppaRao Puli84e12cb2018-10-11 01:28:15 +053090 {
AppaRao Pulic80fee52019-10-16 14:49:36 +053091 return "ReadOnly";
AppaRao Puli84e12cb2018-10-11 01:28:15 +053092 }
Ed Tanous3174e4d2020-10-07 11:41:22 -070093 if (role == "priv-operator")
AppaRao Puli84e12cb2018-10-11 01:28:15 +053094 {
95 return "Operator";
96 }
97 return "";
98}
Nagaraju Goruganti54fc5872019-01-30 05:11:00 -060099inline std::string getPrivilegeFromRoleId(std::string_view role)
AppaRao Puli84e12cb2018-10-11 01:28:15 +0530100{
101 if (role == "Administrator")
102 {
103 return "priv-admin";
104 }
Ed Tanous3174e4d2020-10-07 11:41:22 -0700105 if (role == "ReadOnly")
AppaRao Puli84e12cb2018-10-11 01:28:15 +0530106 {
107 return "priv-user";
108 }
Ed Tanous3174e4d2020-10-07 11:41:22 -0700109 if (role == "Operator")
AppaRao Puli84e12cb2018-10-11 01:28:15 +0530110 {
111 return "priv-operator";
112 }
113 return "";
114}
Ed Tanousb9b2e0b2018-09-13 13:47:50 -0700115
Abhishek Patelc7229812022-02-01 10:07:15 -0600116/**
117 * @brief Maps user group names retrieved from D-Bus object to
118 * Account Types.
119 *
120 * @param[in] userGroups List of User groups
121 * @param[out] res AccountTypes populated
122 *
123 * @return true in case of success, false if UserGroups contains
124 * invalid group name(s).
125 */
126inline bool translateUserGroup(const std::vector<std::string>& userGroups,
127 crow::Response& res)
128{
129 std::vector<std::string> accountTypes;
130 for (const auto& userGroup : userGroups)
131 {
132 if (userGroup == "redfish")
133 {
134 accountTypes.emplace_back("Redfish");
135 accountTypes.emplace_back("WebUI");
136 }
137 else if (userGroup == "ipmi")
138 {
139 accountTypes.emplace_back("IPMI");
140 }
141 else if (userGroup == "ssh")
142 {
Abhishek Patelc7229812022-02-01 10:07:15 -0600143 accountTypes.emplace_back("ManagerConsole");
144 }
Ninad Palsule3e72c202023-03-27 17:19:55 -0500145 else if (userGroup == "hostconsole")
146 {
147 // The hostconsole group controls who can access the host console
148 // port via ssh and websocket.
149 accountTypes.emplace_back("HostConsole");
150 }
Abhishek Patelc7229812022-02-01 10:07:15 -0600151 else if (userGroup == "web")
152 {
153 // 'web' is one of the valid groups in the UserGroups property of
154 // the user account in the D-Bus object. This group is currently not
155 // doing anything, and is considered to be equivalent to 'redfish'.
156 // 'redfish' user group is mapped to 'Redfish'and 'WebUI'
157 // AccountTypes, so do nothing here...
158 }
159 else
160 {
Ed Tanous8ece0e42024-01-02 13:16:50 -0800161 // Invalid user group name. Caller throws an exception.
Abhishek Patelc7229812022-02-01 10:07:15 -0600162 return false;
163 }
164 }
165
166 res.jsonValue["AccountTypes"] = std::move(accountTypes);
167 return true;
168}
169
Abhishek Patel58345852022-02-02 08:54:25 -0600170/**
171 * @brief Builds User Groups from the Account Types
172 *
173 * @param[in] asyncResp Async Response
174 * @param[in] accountTypes List of Account Types
175 * @param[out] userGroups List of User Groups mapped from Account Types
176 *
177 * @return true if Account Types mapped to User Groups, false otherwise.
178 */
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400179inline bool getUserGroupFromAccountType(
180 crow::Response& res, const std::vector<std::string>& accountTypes,
181 std::vector<std::string>& userGroups)
Abhishek Patel58345852022-02-02 08:54:25 -0600182{
183 // Need both Redfish and WebUI Account Types to map to 'redfish' User Group
184 bool redfishType = false;
185 bool webUIType = false;
186
187 for (const auto& accountType : accountTypes)
188 {
189 if (accountType == "Redfish")
190 {
191 redfishType = true;
192 }
193 else if (accountType == "WebUI")
194 {
195 webUIType = true;
196 }
197 else if (accountType == "IPMI")
198 {
199 userGroups.emplace_back("ipmi");
200 }
201 else if (accountType == "HostConsole")
202 {
203 userGroups.emplace_back("hostconsole");
204 }
205 else if (accountType == "ManagerConsole")
206 {
207 userGroups.emplace_back("ssh");
208 }
209 else
210 {
211 // Invalid Account Type
212 messages::propertyValueNotInList(res, "AccountTypes", accountType);
213 return false;
214 }
215 }
216
217 // Both Redfish and WebUI Account Types are needed to PATCH
218 if (redfishType ^ webUIType)
219 {
Ed Tanous62598e32023-07-17 17:06:25 -0700220 BMCWEB_LOG_ERROR(
221 "Missing Redfish or WebUI Account Type to set redfish User Group");
Abhishek Patel58345852022-02-02 08:54:25 -0600222 messages::strictAccountTypes(res, "AccountTypes");
223 return false;
224 }
225
226 if (redfishType && webUIType)
227 {
228 userGroups.emplace_back("redfish");
229 }
230
231 return true;
232}
233
234/**
235 * @brief Sets UserGroups property of the user based on the Account Types
236 *
237 * @param[in] accountTypes List of User Account Types
238 * @param[in] asyncResp Async Response
239 * @param[in] dbusObjectPath D-Bus Object Path
240 * @param[in] userSelf true if User is updating OWN Account Types
241 */
242inline void
243 patchAccountTypes(const std::vector<std::string>& accountTypes,
244 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
245 const std::string& dbusObjectPath, bool userSelf)
246{
247 // Check if User is disabling own Redfish Account Type
248 if (userSelf &&
249 (accountTypes.cend() ==
250 std::find(accountTypes.cbegin(), accountTypes.cend(), "Redfish")))
251 {
Ed Tanous62598e32023-07-17 17:06:25 -0700252 BMCWEB_LOG_ERROR(
253 "User disabling OWN Redfish Account Type is not allowed");
Abhishek Patel58345852022-02-02 08:54:25 -0600254 messages::strictAccountTypes(asyncResp->res, "AccountTypes");
255 return;
256 }
257
258 std::vector<std::string> updatedUserGroups;
259 if (!getUserGroupFromAccountType(asyncResp->res, accountTypes,
260 updatedUserGroups))
261 {
262 // Problem in mapping Account Types to User Groups, Error already
263 // logged.
264 return;
265 }
Ginu Georgee93abac2024-06-14 17:35:27 +0530266 setDbusProperty(asyncResp, "AccountTypes",
267 "xyz.openbmc_project.User.Manager", dbusObjectPath,
268 "xyz.openbmc_project.User.Attributes", "UserGroups",
269 updatedUserGroups);
Abhishek Patel58345852022-02-02 08:54:25 -0600270}
271
zhanghch058d1b46d2021-04-01 11:18:24 +0800272inline void userErrorMessageHandler(
273 const sd_bus_error* e, const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
274 const std::string& newUser, const std::string& username)
jayaprakash Mutyala66b5ca72019-08-07 20:26:37 +0000275{
jayaprakash Mutyala66b5ca72019-08-07 20:26:37 +0000276 if (e == nullptr)
277 {
278 messages::internalError(asyncResp->res);
279 return;
280 }
281
Manojkiran Eda055806b2020-11-03 09:36:28 +0530282 const char* errorMessage = e->name;
jayaprakash Mutyala66b5ca72019-08-07 20:26:37 +0000283 if (strcmp(errorMessage,
284 "xyz.openbmc_project.User.Common.Error.UserNameExists") == 0)
285 {
Jiaqing Zhaod8a5d5d2022-08-05 16:21:51 +0800286 messages::resourceAlreadyExists(asyncResp->res, "ManagerAccount",
jayaprakash Mutyala66b5ca72019-08-07 20:26:37 +0000287 "UserName", newUser);
288 }
289 else if (strcmp(errorMessage, "xyz.openbmc_project.User.Common.Error."
290 "UserNameDoesNotExist") == 0)
291 {
Jiaqing Zhaod8a5d5d2022-08-05 16:21:51 +0800292 messages::resourceNotFound(asyncResp->res, "ManagerAccount", username);
jayaprakash Mutyala66b5ca72019-08-07 20:26:37 +0000293 }
Ed Tanousd4d25792020-09-29 15:15:03 -0700294 else if ((strcmp(errorMessage,
295 "xyz.openbmc_project.Common.Error.InvalidArgument") ==
296 0) ||
George Liu0fda0f12021-11-16 10:06:17 +0800297 (strcmp(
298 errorMessage,
299 "xyz.openbmc_project.User.Common.Error.UserNameGroupFail") ==
300 0))
jayaprakash Mutyala66b5ca72019-08-07 20:26:37 +0000301 {
302 messages::propertyValueFormatError(asyncResp->res, newUser, "UserName");
303 }
304 else if (strcmp(errorMessage,
305 "xyz.openbmc_project.User.Common.Error.NoResource") == 0)
306 {
307 messages::createLimitReachedForResource(asyncResp->res);
308 }
jayaprakash Mutyala66b5ca72019-08-07 20:26:37 +0000309 else
310 {
Gunnar Millsb8ad5832023-10-02 16:26:07 -0500311 BMCWEB_LOG_ERROR("DBUS response error {}", errorMessage);
jayaprakash Mutyala66b5ca72019-08-07 20:26:37 +0000312 messages::internalError(asyncResp->res);
313 }
jayaprakash Mutyala66b5ca72019-08-07 20:26:37 +0000314}
315
Ed Tanous81ce6092020-12-17 16:54:55 +0000316inline void parseLDAPConfigData(nlohmann::json& jsonResponse,
Ed Tanous23a21a12020-07-25 04:45:05 +0000317 const LDAPConfigData& confData,
318 const std::string& ldapType)
Ratan Gupta6973a582018-12-13 18:25:44 +0530319{
Ed Tanous49cc2632024-03-20 12:49:15 -0700320 nlohmann::json::object_t ldap;
Ed Tanous14766872022-03-15 10:44:42 -0700321 ldap["ServiceEnabled"] = confData.serviceEnabled;
Ed Tanous49cc2632024-03-20 12:49:15 -0700322 nlohmann::json::array_t serviceAddresses;
323 serviceAddresses.emplace_back(confData.uri);
324 ldap["ServiceAddresses"] = std::move(serviceAddresses);
325
326 nlohmann::json::object_t authentication;
327 authentication["AuthenticationType"] =
Ed Tanous0ec8b832022-03-14 14:56:47 -0700328 account_service::AuthenticationTypes::UsernameAndPassword;
Ed Tanous49cc2632024-03-20 12:49:15 -0700329 authentication["Username"] = confData.bindDN;
330 authentication["Password"] = nullptr;
331 ldap["Authentication"] = std::move(authentication);
Ed Tanous14766872022-03-15 10:44:42 -0700332
Ed Tanous49cc2632024-03-20 12:49:15 -0700333 nlohmann::json::object_t ldapService;
334 nlohmann::json::object_t searchSettings;
335 nlohmann::json::array_t baseDistinguishedNames;
336 baseDistinguishedNames.emplace_back(confData.baseDN);
Ed Tanous14766872022-03-15 10:44:42 -0700337
Ed Tanous49cc2632024-03-20 12:49:15 -0700338 searchSettings["BaseDistinguishedNames"] =
339 std::move(baseDistinguishedNames);
340 searchSettings["UsernameAttribute"] = confData.userNameAttribute;
341 searchSettings["GroupsAttribute"] = confData.groupAttribute;
342 ldapService["SearchSettings"] = std::move(searchSettings);
343 ldap["LDAPService"] = std::move(ldapService);
344
345 nlohmann::json::array_t roleMapArray;
Ed Tanous9eb808c2022-01-25 10:19:23 -0800346 for (const auto& obj : confData.groupRoleList)
Nagaraju Goruganti54fc5872019-01-30 05:11:00 -0600347 {
Ed Tanous62598e32023-07-17 17:06:25 -0700348 BMCWEB_LOG_DEBUG("Pushing the data groupName={}", obj.second.groupName);
Ed Tanous613dabe2022-07-09 11:17:36 -0700349
Ed Tanous613dabe2022-07-09 11:17:36 -0700350 nlohmann::json::object_t remoteGroup;
351 remoteGroup["RemoteGroup"] = obj.second.groupName;
Jorge Cisneros329f0342022-11-04 16:26:25 +0000352 remoteGroup["LocalRole"] = getRoleIdFromPrivilege(obj.second.privilege);
353 roleMapArray.emplace_back(std::move(remoteGroup));
Nagaraju Goruganti54fc5872019-01-30 05:11:00 -0600354 }
Ed Tanous49cc2632024-03-20 12:49:15 -0700355
356 ldap["RemoteRoleMapping"] = std::move(roleMapArray);
357
358 jsonResponse[ldapType].update(ldap);
Ratan Gupta6973a582018-12-13 18:25:44 +0530359}
360
361/**
Ratan Gupta06785242019-07-26 22:30:16 +0530362 * @brief validates given JSON input and then calls appropriate method to
363 * create, to delete or to set Rolemapping object based on the given input.
364 *
365 */
Ed Tanous23a21a12020-07-25 04:45:05 +0000366inline void handleRoleMapPatch(
zhanghch058d1b46d2021-04-01 11:18:24 +0800367 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ratan Gupta06785242019-07-26 22:30:16 +0530368 const std::vector<std::pair<std::string, LDAPRoleMapData>>& roleMapObjData,
Ed Tanousc1019822024-03-06 12:54:38 -0800369 const std::string& serverType,
370 std::vector<std::variant<nlohmann::json::object_t, std::nullptr_t>>& input)
Ratan Gupta06785242019-07-26 22:30:16 +0530371{
372 for (size_t index = 0; index < input.size(); index++)
373 {
Ed Tanousc1019822024-03-06 12:54:38 -0800374 std::variant<nlohmann::json::object_t, std::nullptr_t>& thisJson =
375 input[index];
376 nlohmann::json::object_t* obj =
377 std::get_if<nlohmann::json::object_t>(&thisJson);
378 if (obj == nullptr)
Ratan Gupta06785242019-07-26 22:30:16 +0530379 {
380 // delete the existing object
381 if (index < roleMapObjData.size())
382 {
383 crow::connections::systemBus->async_method_call(
384 [asyncResp, roleMapObjData, serverType,
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800385 index](const boost::system::error_code& ec) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400386 if (ec)
387 {
388 BMCWEB_LOG_ERROR("DBUS response error: {}", ec);
389 messages::internalError(asyncResp->res);
390 return;
391 }
392 asyncResp->res
393 .jsonValue[serverType]["RemoteRoleMapping"][index] =
394 nullptr;
395 },
Ratan Gupta06785242019-07-26 22:30:16 +0530396 ldapDbusService, roleMapObjData[index].first,
397 "xyz.openbmc_project.Object.Delete", "Delete");
398 }
399 else
400 {
Ed Tanous62598e32023-07-17 17:06:25 -0700401 BMCWEB_LOG_ERROR("Can't delete the object");
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400402 messages::propertyValueTypeError(
403 asyncResp->res, "null",
404 "RemoteRoleMapping/" + std::to_string(index));
Ratan Gupta06785242019-07-26 22:30:16 +0530405 return;
406 }
407 }
Ed Tanousc1019822024-03-06 12:54:38 -0800408 else if (obj->empty())
Ratan Gupta06785242019-07-26 22:30:16 +0530409 {
410 // Don't do anything for the empty objects,parse next json
411 // eg {"RemoteRoleMapping",[{}]}
412 }
413 else
414 {
415 // update/create the object
416 std::optional<std::string> remoteGroup;
417 std::optional<std::string> localRole;
418
Ed Tanousc1019822024-03-06 12:54:38 -0800419 if (!json_util::readJsonObject(*obj, asyncResp->res, "RemoteGroup",
420 remoteGroup, "LocalRole", localRole))
Ratan Gupta06785242019-07-26 22:30:16 +0530421 {
422 continue;
423 }
424
425 // Update existing RoleMapping Object
426 if (index < roleMapObjData.size())
427 {
Ed Tanous62598e32023-07-17 17:06:25 -0700428 BMCWEB_LOG_DEBUG("Update Role Map Object");
Ratan Gupta06785242019-07-26 22:30:16 +0530429 // If "RemoteGroup" info is provided
430 if (remoteGroup)
431 {
Ed Tanousd02aad32024-02-13 14:43:34 -0800432 setDbusProperty(
Ginu Georgee93abac2024-06-14 17:35:27 +0530433 asyncResp,
Ed Tanousd02aad32024-02-13 14:43:34 -0800434 std::format("RemoteRoleMapping/{}/RemoteGroup", index),
Ginu Georgee93abac2024-06-14 17:35:27 +0530435 ldapDbusService, roleMapObjData[index].first,
436 "xyz.openbmc_project.User.PrivilegeMapperEntry",
437 "GroupName", *remoteGroup);
Ratan Gupta06785242019-07-26 22:30:16 +0530438 }
439
440 // If "LocalRole" info is provided
441 if (localRole)
442 {
Ravi Teja6d0b80b2024-07-28 06:09:15 -0500443 std::string priv = getPrivilegeFromRoleId(*localRole);
444 if (priv.empty())
445 {
446 messages::propertyValueNotInList(
447 asyncResp->res, *localRole,
448 std::format("RemoteRoleMapping/{}/LocalRole",
449 index));
450 return;
451 }
Ed Tanousd02aad32024-02-13 14:43:34 -0800452 setDbusProperty(
Ginu Georgee93abac2024-06-14 17:35:27 +0530453 asyncResp,
Ed Tanousd02aad32024-02-13 14:43:34 -0800454 std::format("RemoteRoleMapping/{}/LocalRole", index),
Ginu Georgee93abac2024-06-14 17:35:27 +0530455 ldapDbusService, roleMapObjData[index].first,
456 "xyz.openbmc_project.User.PrivilegeMapperEntry",
Ravi Teja6d0b80b2024-07-28 06:09:15 -0500457 "Privilege", priv);
Ratan Gupta06785242019-07-26 22:30:16 +0530458 }
459 }
460 // Create a new RoleMapping Object.
461 else
462 {
Ed Tanous62598e32023-07-17 17:06:25 -0700463 BMCWEB_LOG_DEBUG(
464 "setRoleMappingProperties: Creating new Object");
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400465 std::string pathString =
466 "RemoteRoleMapping/" + std::to_string(index);
Ratan Gupta06785242019-07-26 22:30:16 +0530467
468 if (!localRole)
469 {
470 messages::propertyMissing(asyncResp->res,
471 pathString + "/LocalRole");
472 continue;
473 }
474 if (!remoteGroup)
475 {
476 messages::propertyMissing(asyncResp->res,
477 pathString + "/RemoteGroup");
478 continue;
479 }
480
481 std::string dbusObjectPath;
482 if (serverType == "ActiveDirectory")
483 {
Ed Tanous2c70f802020-09-28 14:29:23 -0700484 dbusObjectPath = adConfigObject;
Ratan Gupta06785242019-07-26 22:30:16 +0530485 }
486 else if (serverType == "LDAP")
487 {
Ed Tanous23a21a12020-07-25 04:45:05 +0000488 dbusObjectPath = ldapConfigObjectName;
Ratan Gupta06785242019-07-26 22:30:16 +0530489 }
490
Ed Tanous62598e32023-07-17 17:06:25 -0700491 BMCWEB_LOG_DEBUG("Remote Group={},LocalRole={}", *remoteGroup,
492 *localRole);
Ratan Gupta06785242019-07-26 22:30:16 +0530493
494 crow::connections::systemBus->async_method_call(
Ed Tanous271584a2019-07-09 16:24:22 -0700495 [asyncResp, serverType, localRole,
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800496 remoteGroup](const boost::system::error_code& ec) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400497 if (ec)
498 {
499 BMCWEB_LOG_ERROR("DBUS response error: {}", ec);
500 messages::internalError(asyncResp->res);
501 return;
502 }
503 nlohmann::json& remoteRoleJson =
504 asyncResp->res
505 .jsonValue[serverType]["RemoteRoleMapping"];
506 nlohmann::json::object_t roleMapEntry;
507 roleMapEntry["LocalRole"] = *localRole;
508 roleMapEntry["RemoteGroup"] = *remoteGroup;
509 remoteRoleJson.emplace_back(std::move(roleMapEntry));
510 },
Ratan Gupta06785242019-07-26 22:30:16 +0530511 ldapDbusService, dbusObjectPath, ldapPrivMapperInterface,
Ed Tanous3174e4d2020-10-07 11:41:22 -0700512 "Create", *remoteGroup,
Ratan Gupta06785242019-07-26 22:30:16 +0530513 getPrivilegeFromRoleId(std::move(*localRole)));
514 }
515 }
516 }
517}
518
519/**
Ratan Gupta6973a582018-12-13 18:25:44 +0530520 * Function that retrieves all properties for LDAP config object
521 * into JSON
522 */
523template <typename CallbackFunc>
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400524inline void
525 getLDAPConfigData(const std::string& ldapType, CallbackFunc&& callback)
Ratan Gupta6973a582018-12-13 18:25:44 +0530526{
George Liu2b731192023-01-11 16:27:13 +0800527 constexpr std::array<std::string_view, 2> interfaces = {
528 ldapEnableInterface, ldapConfigInterface};
Ratan Gupta6973a582018-12-13 18:25:44 +0530529
George Liu2b731192023-01-11 16:27:13 +0800530 dbus::utility::getDbusObject(
531 ldapConfigObjectName, interfaces,
Ed Tanous8cb2c022024-03-27 16:31:46 -0700532 [callback = std::forward<CallbackFunc>(callback),
Ed Tanousc1019822024-03-06 12:54:38 -0800533 ldapType](const boost::system::error_code& ec,
534 const dbus::utility::MapperGetObject& resp) mutable {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400535 if (ec || resp.empty())
Nagaraju Goruganti54fc5872019-01-30 05:11:00 -0600536 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400537 BMCWEB_LOG_WARNING(
538 "DBUS response error during getting of service name: {}",
539 ec);
540 LDAPConfigData empty{};
541 callback(false, empty, ldapType);
Nagaraju Goruganti54fc5872019-01-30 05:11:00 -0600542 return;
543 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400544 std::string service = resp.begin()->first;
545 sdbusplus::message::object_path path(ldapRootObject);
546 dbus::utility::getManagedObjects(
547 service, path,
548 [callback, ldapType](const boost::system::error_code& ec2,
549 const dbus::utility::ManagedObjectType&
550 ldapObjects) mutable {
551 LDAPConfigData confData{};
552 if (ec2)
Nagaraju Goruganti54fc5872019-01-30 05:11:00 -0600553 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400554 callback(false, confData, ldapType);
555 BMCWEB_LOG_WARNING("D-Bus responses error: {}", ec2);
556 return;
557 }
558
559 std::string ldapDbusType;
560 std::string searchString;
561
562 if (ldapType == "LDAP")
563 {
564 ldapDbusType =
565 "xyz.openbmc_project.User.Ldap.Config.Type.OpenLdap";
566 searchString = "openldap";
567 }
568 else if (ldapType == "ActiveDirectory")
569 {
570 ldapDbusType =
571 "xyz.openbmc_project.User.Ldap.Config.Type.ActiveDirectory";
572 searchString = "active_directory";
573 }
574 else
575 {
576 BMCWEB_LOG_ERROR(
577 "Can't get the DbusType for the given type={}",
578 ldapType);
579 callback(false, confData, ldapType);
580 return;
581 }
582
583 std::string ldapEnableInterfaceStr = ldapEnableInterface;
584 std::string ldapConfigInterfaceStr = ldapConfigInterface;
585
586 for (const auto& object : ldapObjects)
587 {
588 // let's find the object whose ldap type is equal to the
589 // given type
590 if (object.first.str.find(searchString) ==
591 std::string::npos)
Nagaraju Goruganti54fc5872019-01-30 05:11:00 -0600592 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400593 continue;
594 }
595
596 for (const auto& interface : object.second)
597 {
598 if (interface.first == ldapEnableInterfaceStr)
Nagaraju Goruganti54fc5872019-01-30 05:11:00 -0600599 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400600 // rest of the properties are string.
601 for (const auto& property : interface.second)
Nagaraju Goruganti54fc5872019-01-30 05:11:00 -0600602 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400603 if (property.first == "Enabled")
604 {
605 const bool* value =
606 std::get_if<bool>(&property.second);
607 if (value == nullptr)
608 {
609 continue;
610 }
611 confData.serviceEnabled = *value;
612 break;
613 }
Nagaraju Goruganti54fc5872019-01-30 05:11:00 -0600614 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400615 }
616 else if (interface.first == ldapConfigInterfaceStr)
617 {
618 for (const auto& property : interface.second)
619 {
620 const std::string* strValue =
621 std::get_if<std::string>(
622 &property.second);
623 if (strValue == nullptr)
624 {
625 continue;
626 }
627 if (property.first == "LDAPServerURI")
628 {
629 confData.uri = *strValue;
630 }
631 else if (property.first == "LDAPBindDN")
632 {
633 confData.bindDN = *strValue;
634 }
635 else if (property.first == "LDAPBaseDN")
636 {
637 confData.baseDN = *strValue;
638 }
639 else if (property.first ==
640 "LDAPSearchScope")
641 {
642 confData.searchScope = *strValue;
643 }
644 else if (property.first ==
645 "GroupNameAttribute")
646 {
647 confData.groupAttribute = *strValue;
648 }
649 else if (property.first ==
650 "UserNameAttribute")
651 {
652 confData.userNameAttribute = *strValue;
653 }
654 else if (property.first == "LDAPType")
655 {
656 confData.serverType = *strValue;
657 }
658 }
659 }
660 else if (
661 interface.first ==
662 "xyz.openbmc_project.User.PrivilegeMapperEntry")
663 {
664 LDAPRoleMapData roleMapData{};
665 for (const auto& property : interface.second)
666 {
667 const std::string* strValue =
668 std::get_if<std::string>(
669 &property.second);
670
671 if (strValue == nullptr)
672 {
673 continue;
674 }
675
676 if (property.first == "GroupName")
677 {
678 roleMapData.groupName = *strValue;
679 }
680 else if (property.first == "Privilege")
681 {
682 roleMapData.privilege = *strValue;
683 }
684 }
685
686 confData.groupRoleList.emplace_back(
687 object.first.str, roleMapData);
Nagaraju Goruganti54fc5872019-01-30 05:11:00 -0600688 }
689 }
690 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400691 callback(true, confData, ldapType);
692 });
George Liu2b731192023-01-11 16:27:13 +0800693 });
Ratan Gupta6973a582018-12-13 18:25:44 +0530694}
695
Ed Tanous6c51eab2021-06-03 12:30:29 -0700696/**
Ed Tanous6c51eab2021-06-03 12:30:29 -0700697 * @brief updates the LDAP server address and updates the
698 json response with the new value.
699 * @param serviceAddressList address to be updated.
700 * @param asyncResp pointer to the JSON response
701 * @param ldapServerElementName Type of LDAP
702 server(openLDAP/ActiveDirectory)
703 */
Ratan Gupta8a07d282019-03-16 08:33:47 +0530704
Ed Tanous4f48d5f2021-06-21 08:27:45 -0700705inline void handleServiceAddressPatch(
Ed Tanous6c51eab2021-06-03 12:30:29 -0700706 const std::vector<std::string>& serviceAddressList,
707 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
708 const std::string& ldapServerElementName,
709 const std::string& ldapConfigObject)
710{
Ginu Georgee93abac2024-06-14 17:35:27 +0530711 setDbusProperty(asyncResp, ldapServerElementName + "/ServiceAddress",
712 ldapDbusService, ldapConfigObject, ldapConfigInterface,
713 "LDAPServerURI", serviceAddressList.front());
Ed Tanous6c51eab2021-06-03 12:30:29 -0700714}
715/**
716 * @brief updates the LDAP Bind DN and updates the
717 json response with the new value.
718 * @param username name of the user which needs to be updated.
719 * @param asyncResp pointer to the JSON response
720 * @param ldapServerElementName Type of LDAP
721 server(openLDAP/ActiveDirectory)
722 */
Ratan Gupta8a07d282019-03-16 08:33:47 +0530723
Ed Tanous4f48d5f2021-06-21 08:27:45 -0700724inline void
725 handleUserNamePatch(const std::string& username,
726 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
727 const std::string& ldapServerElementName,
728 const std::string& ldapConfigObject)
Ed Tanous6c51eab2021-06-03 12:30:29 -0700729{
Ginu Georgee93abac2024-06-14 17:35:27 +0530730 setDbusProperty(asyncResp,
Ed Tanousd02aad32024-02-13 14:43:34 -0800731 ldapServerElementName + "/Authentication/Username",
Ginu Georgee93abac2024-06-14 17:35:27 +0530732 ldapDbusService, ldapConfigObject, ldapConfigInterface,
733 "LDAPBindDN", username);
Ed Tanous6c51eab2021-06-03 12:30:29 -0700734}
735
736/**
737 * @brief updates the LDAP password
738 * @param password : ldap password which needs to be updated.
739 * @param asyncResp pointer to the JSON response
740 * @param ldapServerElementName Type of LDAP
741 * server(openLDAP/ActiveDirectory)
742 */
743
Ed Tanous4f48d5f2021-06-21 08:27:45 -0700744inline void
745 handlePasswordPatch(const std::string& password,
746 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
747 const std::string& ldapServerElementName,
748 const std::string& ldapConfigObject)
Ed Tanous6c51eab2021-06-03 12:30:29 -0700749{
Ginu Georgee93abac2024-06-14 17:35:27 +0530750 setDbusProperty(asyncResp,
Ed Tanousd02aad32024-02-13 14:43:34 -0800751 ldapServerElementName + "/Authentication/Password",
Ginu Georgee93abac2024-06-14 17:35:27 +0530752 ldapDbusService, ldapConfigObject, ldapConfigInterface,
753 "LDAPBindDNPassword", password);
Ed Tanous6c51eab2021-06-03 12:30:29 -0700754}
755
756/**
757 * @brief updates the LDAP BaseDN and updates the
758 json response with the new value.
759 * @param baseDNList baseDN list which needs to be updated.
760 * @param asyncResp pointer to the JSON response
761 * @param ldapServerElementName Type of LDAP
762 server(openLDAP/ActiveDirectory)
763 */
764
Ed Tanous4f48d5f2021-06-21 08:27:45 -0700765inline void
766 handleBaseDNPatch(const std::vector<std::string>& baseDNList,
767 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
768 const std::string& ldapServerElementName,
769 const std::string& ldapConfigObject)
Ed Tanous6c51eab2021-06-03 12:30:29 -0700770{
Ginu Georgee93abac2024-06-14 17:35:27 +0530771 setDbusProperty(asyncResp,
Ed Tanousd02aad32024-02-13 14:43:34 -0800772 ldapServerElementName +
773 "/LDAPService/SearchSettings/BaseDistinguishedNames",
Ginu Georgee93abac2024-06-14 17:35:27 +0530774 ldapDbusService, ldapConfigObject, ldapConfigInterface,
775 "LDAPBaseDN", baseDNList.front());
Ed Tanous6c51eab2021-06-03 12:30:29 -0700776}
777/**
778 * @brief updates the LDAP user name attribute and updates the
779 json response with the new value.
780 * @param userNameAttribute attribute to be updated.
781 * @param asyncResp pointer to the JSON response
782 * @param ldapServerElementName Type of LDAP
783 server(openLDAP/ActiveDirectory)
784 */
785
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400786inline void handleUserNameAttrPatch(
787 const std::string& userNameAttribute,
788 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
789 const std::string& ldapServerElementName,
790 const std::string& ldapConfigObject)
Ed Tanous6c51eab2021-06-03 12:30:29 -0700791{
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400792 setDbusProperty(
793 asyncResp,
794 ldapServerElementName + "LDAPService/SearchSettings/UsernameAttribute",
795 ldapDbusService, ldapConfigObject, ldapConfigInterface,
796 "UserNameAttribute", userNameAttribute);
Ed Tanous6c51eab2021-06-03 12:30:29 -0700797}
798/**
799 * @brief updates the LDAP group attribute and updates the
800 json response with the new value.
801 * @param groupsAttribute attribute to be updated.
802 * @param asyncResp pointer to the JSON response
803 * @param ldapServerElementName Type of LDAP
804 server(openLDAP/ActiveDirectory)
805 */
806
Ed Tanous4f48d5f2021-06-21 08:27:45 -0700807inline void handleGroupNameAttrPatch(
Ed Tanous6c51eab2021-06-03 12:30:29 -0700808 const std::string& groupsAttribute,
809 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
810 const std::string& ldapServerElementName,
811 const std::string& ldapConfigObject)
812{
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400813 setDbusProperty(
814 asyncResp,
815 ldapServerElementName + "/LDAPService/SearchSettings/GroupsAttribute",
816 ldapDbusService, ldapConfigObject, ldapConfigInterface,
817 "GroupNameAttribute", groupsAttribute);
Ed Tanous6c51eab2021-06-03 12:30:29 -0700818}
819/**
820 * @brief updates the LDAP service enable and updates the
821 json response with the new value.
822 * @param input JSON data.
823 * @param asyncResp pointer to the JSON response
824 * @param ldapServerElementName Type of LDAP
825 server(openLDAP/ActiveDirectory)
826 */
827
Ed Tanous4f48d5f2021-06-21 08:27:45 -0700828inline void handleServiceEnablePatch(
Ed Tanous6c51eab2021-06-03 12:30:29 -0700829 bool serviceEnabled, const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
830 const std::string& ldapServerElementName,
831 const std::string& ldapConfigObject)
832{
Ginu Georgee93abac2024-06-14 17:35:27 +0530833 setDbusProperty(asyncResp, ldapServerElementName + "/ServiceEnabled",
834 ldapDbusService, ldapConfigObject, ldapEnableInterface,
835 "Enabled", serviceEnabled);
Ed Tanous6c51eab2021-06-03 12:30:29 -0700836}
837
Ed Tanousc1019822024-03-06 12:54:38 -0800838struct AuthMethods
Ed Tanous6c51eab2021-06-03 12:30:29 -0700839{
840 std::optional<bool> basicAuth;
841 std::optional<bool> cookie;
842 std::optional<bool> sessionToken;
843 std::optional<bool> xToken;
844 std::optional<bool> tls;
Ed Tanousc1019822024-03-06 12:54:38 -0800845};
Ed Tanous6c51eab2021-06-03 12:30:29 -0700846
Ed Tanousc1019822024-03-06 12:54:38 -0800847inline void
848 handleAuthMethodsPatch(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
849 const AuthMethods& auth)
850{
851 persistent_data::AuthConfigMethods& authMethodsConfig =
Ed Tanous6c51eab2021-06-03 12:30:29 -0700852 persistent_data::SessionStore::getInstance().getAuthMethodsConfig();
853
Ed Tanousc1019822024-03-06 12:54:38 -0800854 if (auth.basicAuth)
Ed Tanous6c51eab2021-06-03 12:30:29 -0700855 {
Ed Tanous25b54db2024-04-17 15:40:31 -0700856 if constexpr (!BMCWEB_BASIC_AUTH)
857 {
858 messages::actionNotSupported(
859 asyncResp->res,
860 "Setting BasicAuth when basic-auth feature is disabled");
861 return;
862 }
863
Ed Tanousc1019822024-03-06 12:54:38 -0800864 authMethodsConfig.basic = *auth.basicAuth;
Ed Tanous6c51eab2021-06-03 12:30:29 -0700865 }
866
Ed Tanousc1019822024-03-06 12:54:38 -0800867 if (auth.cookie)
Ed Tanous6c51eab2021-06-03 12:30:29 -0700868 {
Ed Tanous25b54db2024-04-17 15:40:31 -0700869 if constexpr (!BMCWEB_COOKIE_AUTH)
870 {
871 messages::actionNotSupported(
872 asyncResp->res,
873 "Setting Cookie when cookie-auth feature is disabled");
874 return;
875 }
Ed Tanousc1019822024-03-06 12:54:38 -0800876 authMethodsConfig.cookie = *auth.cookie;
Ed Tanous6c51eab2021-06-03 12:30:29 -0700877 }
878
Ed Tanousc1019822024-03-06 12:54:38 -0800879 if (auth.sessionToken)
Ed Tanous6c51eab2021-06-03 12:30:29 -0700880 {
Ed Tanous25b54db2024-04-17 15:40:31 -0700881 if constexpr (!BMCWEB_SESSION_AUTH)
882 {
883 messages::actionNotSupported(
884 asyncResp->res,
885 "Setting SessionToken when session-auth feature is disabled");
886 return;
887 }
Ed Tanousc1019822024-03-06 12:54:38 -0800888 authMethodsConfig.sessionToken = *auth.sessionToken;
Ed Tanous6c51eab2021-06-03 12:30:29 -0700889 }
890
Ed Tanousc1019822024-03-06 12:54:38 -0800891 if (auth.xToken)
Ed Tanous6c51eab2021-06-03 12:30:29 -0700892 {
Ed Tanous25b54db2024-04-17 15:40:31 -0700893 if constexpr (!BMCWEB_XTOKEN_AUTH)
894 {
895 messages::actionNotSupported(
896 asyncResp->res,
897 "Setting XToken when xtoken-auth feature is disabled");
898 return;
899 }
Ed Tanousc1019822024-03-06 12:54:38 -0800900 authMethodsConfig.xtoken = *auth.xToken;
Ed Tanous6c51eab2021-06-03 12:30:29 -0700901 }
902
Ed Tanousc1019822024-03-06 12:54:38 -0800903 if (auth.tls)
Ed Tanous6c51eab2021-06-03 12:30:29 -0700904 {
Ed Tanous25b54db2024-04-17 15:40:31 -0700905 if constexpr (!BMCWEB_MUTUAL_TLS_AUTH)
906 {
907 messages::actionNotSupported(
908 asyncResp->res,
909 "Setting TLS when mutual-tls-auth feature is disabled");
910 return;
911 }
Ed Tanousc1019822024-03-06 12:54:38 -0800912 authMethodsConfig.tls = *auth.tls;
Ed Tanous6c51eab2021-06-03 12:30:29 -0700913 }
914
915 if (!authMethodsConfig.basic && !authMethodsConfig.cookie &&
916 !authMethodsConfig.sessionToken && !authMethodsConfig.xtoken &&
917 !authMethodsConfig.tls)
918 {
919 // Do not allow user to disable everything
920 messages::actionNotSupported(asyncResp->res,
921 "of disabling all available methods");
922 return;
923 }
924
925 persistent_data::SessionStore::getInstance().updateAuthMethodsConfig(
926 authMethodsConfig);
927 // Save configuration immediately
928 persistent_data::getConfig().writeData();
929
930 messages::success(asyncResp->res);
931}
932
933/**
934 * @brief Get the required values from the given JSON, validates the
935 * value and create the LDAP config object.
936 * @param input JSON data
937 * @param asyncResp pointer to the JSON response
938 * @param serverType Type of LDAP server(openLDAP/ActiveDirectory)
939 */
940
Ed Tanous10cb44f2024-04-11 13:05:20 -0700941struct LdapPatchParams
942{
943 std::optional<std::string> authType;
944 std::optional<std::vector<std::string>> serviceAddressList;
945 std::optional<bool> serviceEnabled;
946 std::optional<std::vector<std::string>> baseDNList;
947 std::optional<std::string> userNameAttribute;
948 std::optional<std::string> groupsAttribute;
949 std::optional<std::string> userName;
950 std::optional<std::string> password;
951 std::optional<
952 std::vector<std::variant<nlohmann::json::object_t, std::nullptr_t>>>
953 remoteRoleMapData;
954};
955
956inline void handleLDAPPatch(LdapPatchParams&& input,
Ed Tanous6c51eab2021-06-03 12:30:29 -0700957 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
958 const std::string& serverType)
959{
960 std::string dbusObjectPath;
961 if (serverType == "ActiveDirectory")
962 {
963 dbusObjectPath = adConfigObject;
964 }
965 else if (serverType == "LDAP")
966 {
967 dbusObjectPath = ldapConfigObjectName;
968 }
969 else
970 {
Ed Tanous10cb44f2024-04-11 13:05:20 -0700971 BMCWEB_LOG_ERROR("serverType wasn't AD or LDAP but was {}????",
972 serverType);
Ed Tanous6c51eab2021-06-03 12:30:29 -0700973 return;
974 }
975
Ed Tanous10cb44f2024-04-11 13:05:20 -0700976 if (input.authType && *input.authType != "UsernameAndPassword")
Ed Tanous6c51eab2021-06-03 12:30:29 -0700977 {
Ed Tanous10cb44f2024-04-11 13:05:20 -0700978 messages::propertyValueNotInList(asyncResp->res, *input.authType,
Ed Tanousc1019822024-03-06 12:54:38 -0800979 "AuthenticationType");
980 return;
Ed Tanous6c51eab2021-06-03 12:30:29 -0700981 }
Ed Tanousc1019822024-03-06 12:54:38 -0800982
Ed Tanous10cb44f2024-04-11 13:05:20 -0700983 if (input.serviceAddressList)
Ed Tanous6c51eab2021-06-03 12:30:29 -0700984 {
Ed Tanous10cb44f2024-04-11 13:05:20 -0700985 if (input.serviceAddressList->empty())
Ratan Guptaeb2bbe52019-04-22 14:27:01 +0530986 {
Ed Tanouse2616cc2022-06-27 12:45:55 -0700987 messages::propertyValueNotInList(
Ed Tanous10cb44f2024-04-11 13:05:20 -0700988 asyncResp->res, *input.serviceAddressList, "ServiceAddress");
Ed Tanouscb13a392020-07-25 19:02:03 +0000989 return;
990 }
Ed Tanous6c51eab2021-06-03 12:30:29 -0700991 }
Ed Tanous10cb44f2024-04-11 13:05:20 -0700992 if (input.baseDNList)
Ed Tanous6c51eab2021-06-03 12:30:29 -0700993 {
Ed Tanous10cb44f2024-04-11 13:05:20 -0700994 if (input.baseDNList->empty())
Ratan Gupta8a07d282019-03-16 08:33:47 +0530995 {
Ed Tanous10cb44f2024-04-11 13:05:20 -0700996 messages::propertyValueNotInList(asyncResp->res, *input.baseDNList,
Ed Tanous6c51eab2021-06-03 12:30:29 -0700997 "BaseDistinguishedNames");
Ratan Gupta8a07d282019-03-16 08:33:47 +0530998 return;
999 }
Ed Tanous6c51eab2021-06-03 12:30:29 -07001000 }
Ratan Gupta8a07d282019-03-16 08:33:47 +05301001
Ed Tanous6c51eab2021-06-03 12:30:29 -07001002 // nothing to update, then return
Ed Tanous10cb44f2024-04-11 13:05:20 -07001003 if (!input.userName && !input.password && !input.serviceAddressList &&
1004 !input.baseDNList && !input.userNameAttribute &&
1005 !input.groupsAttribute && !input.serviceEnabled &&
1006 !input.remoteRoleMapData)
Ed Tanous6c51eab2021-06-03 12:30:29 -07001007 {
1008 return;
1009 }
1010
1011 // Get the existing resource first then keep modifying
1012 // whenever any property gets updated.
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001013 getLDAPConfigData(serverType, [asyncResp, input = std::move(input),
1014 dbusObjectPath = std::move(dbusObjectPath)](
1015 bool success,
1016 const LDAPConfigData& confData,
1017 const std::string& serverT) mutable {
Ed Tanous6c51eab2021-06-03 12:30:29 -07001018 if (!success)
Ratan Gupta8a07d282019-03-16 08:33:47 +05301019 {
Ed Tanous6c51eab2021-06-03 12:30:29 -07001020 messages::internalError(asyncResp->res);
1021 return;
Ratan Gupta8a07d282019-03-16 08:33:47 +05301022 }
Ed Tanous6c51eab2021-06-03 12:30:29 -07001023 parseLDAPConfigData(asyncResp->res.jsonValue, confData, serverT);
1024 if (confData.serviceEnabled)
Ratan Gupta8a07d282019-03-16 08:33:47 +05301025 {
Ed Tanous6c51eab2021-06-03 12:30:29 -07001026 // Disable the service first and update the rest of
1027 // the properties.
1028 handleServiceEnablePatch(false, asyncResp, serverT, dbusObjectPath);
Ratan Gupta8a07d282019-03-16 08:33:47 +05301029 }
Ed Tanous6c51eab2021-06-03 12:30:29 -07001030
Ed Tanous10cb44f2024-04-11 13:05:20 -07001031 if (input.serviceAddressList)
Ratan Gupta8a07d282019-03-16 08:33:47 +05301032 {
Ed Tanous10cb44f2024-04-11 13:05:20 -07001033 handleServiceAddressPatch(*input.serviceAddressList, asyncResp,
1034 serverT, dbusObjectPath);
Ratan Gupta8a07d282019-03-16 08:33:47 +05301035 }
Ed Tanous10cb44f2024-04-11 13:05:20 -07001036 if (input.userName)
Ed Tanous6c51eab2021-06-03 12:30:29 -07001037 {
Ed Tanous10cb44f2024-04-11 13:05:20 -07001038 handleUserNamePatch(*input.userName, asyncResp, serverT,
1039 dbusObjectPath);
Ed Tanous6c51eab2021-06-03 12:30:29 -07001040 }
Ed Tanous10cb44f2024-04-11 13:05:20 -07001041 if (input.password)
Ed Tanous6c51eab2021-06-03 12:30:29 -07001042 {
Ed Tanous10cb44f2024-04-11 13:05:20 -07001043 handlePasswordPatch(*input.password, asyncResp, serverT,
1044 dbusObjectPath);
Ed Tanous6c51eab2021-06-03 12:30:29 -07001045 }
1046
Ed Tanous10cb44f2024-04-11 13:05:20 -07001047 if (input.baseDNList)
Ratan Gupta8a07d282019-03-16 08:33:47 +05301048 {
Ed Tanous10cb44f2024-04-11 13:05:20 -07001049 handleBaseDNPatch(*input.baseDNList, asyncResp, serverT,
1050 dbusObjectPath);
Ed Tanous6c51eab2021-06-03 12:30:29 -07001051 }
Ed Tanous10cb44f2024-04-11 13:05:20 -07001052 if (input.userNameAttribute)
Ed Tanous6c51eab2021-06-03 12:30:29 -07001053 {
Ed Tanous10cb44f2024-04-11 13:05:20 -07001054 handleUserNameAttrPatch(*input.userNameAttribute, asyncResp,
1055 serverT, dbusObjectPath);
Ed Tanous6c51eab2021-06-03 12:30:29 -07001056 }
Ed Tanous10cb44f2024-04-11 13:05:20 -07001057 if (input.groupsAttribute)
Ed Tanous6c51eab2021-06-03 12:30:29 -07001058 {
Ed Tanous10cb44f2024-04-11 13:05:20 -07001059 handleGroupNameAttrPatch(*input.groupsAttribute, asyncResp, serverT,
Ed Tanous6c51eab2021-06-03 12:30:29 -07001060 dbusObjectPath);
1061 }
Ed Tanous10cb44f2024-04-11 13:05:20 -07001062 if (input.serviceEnabled)
Ed Tanous6c51eab2021-06-03 12:30:29 -07001063 {
1064 // if user has given the value as true then enable
1065 // the service. if user has given false then no-op
1066 // as service is already stopped.
Ed Tanous10cb44f2024-04-11 13:05:20 -07001067 if (*input.serviceEnabled)
Ratan Gupta8a07d282019-03-16 08:33:47 +05301068 {
Ed Tanous10cb44f2024-04-11 13:05:20 -07001069 handleServiceEnablePatch(*input.serviceEnabled, asyncResp,
1070 serverT, dbusObjectPath);
Ratan Gupta8a07d282019-03-16 08:33:47 +05301071 }
1072 }
jayaprakash Mutyala96200602020-04-08 11:09:10 +00001073 else
1074 {
Ed Tanous6c51eab2021-06-03 12:30:29 -07001075 // if user has not given the service enabled value
1076 // then revert it to the same state as it was
1077 // before.
1078 handleServiceEnablePatch(confData.serviceEnabled, asyncResp,
1079 serverT, dbusObjectPath);
jayaprakash Mutyala96200602020-04-08 11:09:10 +00001080 }
Ed Tanous04ae99e2018-09-20 15:54:36 -07001081
Ed Tanous10cb44f2024-04-11 13:05:20 -07001082 if (input.remoteRoleMapData)
Ed Tanous6c51eab2021-06-03 12:30:29 -07001083 {
1084 handleRoleMapPatch(asyncResp, confData.groupRoleList, serverT,
Ed Tanous10cb44f2024-04-11 13:05:20 -07001085 *input.remoteRoleMapData);
Ed Tanous6c51eab2021-06-03 12:30:29 -07001086 }
Patrick Williams5a39f772023-10-20 11:20:21 -05001087 });
Ed Tanous6c51eab2021-06-03 12:30:29 -07001088}
1089
Abhishek Patel58345852022-02-02 08:54:25 -06001090inline void updateUserProperties(
1091 std::shared_ptr<bmcweb::AsyncResp> asyncResp, const std::string& username,
1092 const std::optional<std::string>& password,
1093 const std::optional<bool>& enabled,
1094 const std::optional<std::string>& roleId, const std::optional<bool>& locked,
Ravi Tejae518ef32024-05-16 10:33:08 -05001095 std::optional<std::vector<std::string>> accountTypes, bool userSelf,
1096 const std::shared_ptr<persistent_data::UserSession>& session)
Ed Tanous6c51eab2021-06-03 12:30:29 -07001097{
P Dheeraj Srujan Kumarb477fd42021-12-16 07:17:51 +05301098 sdbusplus::message::object_path tempObjPath(rootUserDbusPath);
1099 tempObjPath /= username;
1100 std::string dbusObjectPath(tempObjPath);
Ed Tanous6c51eab2021-06-03 12:30:29 -07001101
1102 dbus::utility::checkDbusPathExists(
Ravi Tejae518ef32024-05-16 10:33:08 -05001103 dbusObjectPath,
1104 [dbusObjectPath, username, password, roleId, enabled, locked,
1105 accountTypes(std::move(accountTypes)), userSelf, session,
1106 asyncResp{std::move(asyncResp)}](int rc) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001107 if (rc <= 0)
Ed Tanous6c51eab2021-06-03 12:30:29 -07001108 {
Jiaqing Zhaod8a5d5d2022-08-05 16:21:51 +08001109 messages::resourceNotFound(asyncResp->res, "ManagerAccount",
1110 username);
Ed Tanous6c51eab2021-06-03 12:30:29 -07001111 return;
1112 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001113
1114 if (password)
Ed Tanous618c14b2022-06-30 17:44:25 -07001115 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001116 int retval = pamUpdatePassword(username, *password);
1117
1118 if (retval == PAM_USER_UNKNOWN)
1119 {
1120 messages::resourceNotFound(asyncResp->res, "ManagerAccount",
1121 username);
1122 }
1123 else if (retval == PAM_AUTHTOK_ERR)
1124 {
1125 // If password is invalid
1126 messages::propertyValueFormatError(asyncResp->res, nullptr,
1127 "Password");
1128 BMCWEB_LOG_ERROR("pamUpdatePassword Failed");
1129 }
1130 else if (retval != PAM_SUCCESS)
1131 {
1132 messages::internalError(asyncResp->res);
1133 return;
1134 }
1135 else
1136 {
1137 // Remove existing sessions of the user when password
1138 // changed
1139 persistent_data::SessionStore::getInstance()
1140 .removeSessionsByUsernameExceptSession(username,
1141 session);
1142 messages::success(asyncResp->res);
1143 }
Ed Tanous618c14b2022-06-30 17:44:25 -07001144 }
1145
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001146 if (enabled)
Patrick Williams5a39f772023-10-20 11:20:21 -05001147 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001148 setDbusProperty(
1149 asyncResp, "Enabled", "xyz.openbmc_project.User.Manager",
1150 dbusObjectPath, "xyz.openbmc_project.User.Attributes",
1151 "UserEnabled", *enabled);
Ed Tanous618c14b2022-06-30 17:44:25 -07001152 }
Patrick Williams5a39f772023-10-20 11:20:21 -05001153
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001154 if (roleId)
Abhishek Patel58345852022-02-02 08:54:25 -06001155 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001156 std::string priv = getPrivilegeFromRoleId(*roleId);
1157 if (priv.empty())
1158 {
1159 messages::propertyValueNotInList(asyncResp->res, true,
1160 "Locked");
1161 return;
1162 }
1163 setDbusProperty(
1164 asyncResp, "RoleId", "xyz.openbmc_project.User.Manager",
1165 dbusObjectPath, "xyz.openbmc_project.User.Attributes",
1166 "UserPrivilege", priv);
Abhishek Patel58345852022-02-02 08:54:25 -06001167 }
Patrick Williams5a39f772023-10-20 11:20:21 -05001168
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001169 if (locked)
1170 {
1171 // admin can unlock the account which is locked by
1172 // successive authentication failures but admin should
1173 // not be allowed to lock an account.
1174 if (*locked)
1175 {
1176 messages::propertyValueNotInList(asyncResp->res, "true",
1177 "Locked");
1178 return;
1179 }
1180 setDbusProperty(
1181 asyncResp, "Locked", "xyz.openbmc_project.User.Manager",
1182 dbusObjectPath, "xyz.openbmc_project.User.Attributes",
1183 "UserLockedForFailedAttempt", *locked);
1184 }
1185
1186 if (accountTypes)
1187 {
1188 patchAccountTypes(*accountTypes, asyncResp, dbusObjectPath,
1189 userSelf);
1190 }
1191 });
Ed Tanous6c51eab2021-06-03 12:30:29 -07001192}
Ed Tanousb9b2e0b2018-09-13 13:47:50 -07001193
Ed Tanous4c7d4d32022-07-07 15:29:35 -07001194inline void handleAccountServiceHead(
1195 App& app, const crow::Request& req,
1196 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
Ed Tanous1ef4c342022-05-12 16:12:36 -07001197{
1198 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1199 {
1200 return;
1201 }
Ed Tanous4c7d4d32022-07-07 15:29:35 -07001202 asyncResp->res.addHeader(
1203 boost::beast::http::field::link,
1204 "</redfish/v1/JsonSchemas/AccountService/AccountService.json>; rel=describedby");
1205}
1206
1207inline void
Ed Tanous1aa375b2024-04-13 11:51:10 -07001208 getClientCertificates(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1209 const nlohmann::json::json_pointer& keyLocation)
1210{
1211 boost::urls::url url(
1212 "/redfish/v1/AccountService/MultiFactorAuth/ClientCertificate/Certificates");
1213 std::array<std::string_view, 1> interfaces = {
1214 "xyz.openbmc_project.Certs.Certificate"};
1215 std::string path = "/xyz/openbmc_project/certs/authority/truststore";
1216
1217 collection_util::getCollectionToKey(asyncResp, url, interfaces, path,
1218 keyLocation);
1219}
1220
1221inline void handleAccountServiceClientCertificatesInstanceHead(
1222 App& app, const crow::Request& req,
1223 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1224 const std::string& /*id*/)
1225{
1226 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1227 {
1228 return;
1229 }
1230
1231 asyncResp->res.addHeader(
1232 boost::beast::http::field::link,
1233 "</redfish/v1/JsonSchemas/Certificate/Certificate.json>; rel=describedby");
1234}
1235
1236inline void handleAccountServiceClientCertificatesInstanceGet(
1237 App& app, const crow::Request& req,
1238 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, const std::string& id)
1239{
1240 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1241 {
1242 return;
1243 }
1244 BMCWEB_LOG_DEBUG("ClientCertificate Certificate ID={}", id);
1245 const boost::urls::url certURL = boost::urls::format(
1246 "/redfish/v1/AccountService/MultiFactorAuth/ClientCertificate/Certificates/{}",
1247 id);
1248 std::string objPath =
1249 sdbusplus::message::object_path(certs::authorityObjectPath) / id;
1250 getCertificateProperties(
1251 asyncResp, objPath,
1252 "xyz.openbmc_project.Certs.Manager.Authority.Truststore", id, certURL,
1253 "Client Certificate");
1254}
1255
1256inline void handleAccountServiceClientCertificatesHead(
1257 App& app, const crow::Request& req,
1258 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1259{
1260 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1261 {
1262 return;
1263 }
1264
1265 asyncResp->res.addHeader(
1266 boost::beast::http::field::link,
1267 "</redfish/v1/JsonSchemas/CertificateCollection/CertificateCollection.json>; rel=describedby");
1268}
1269
1270inline void handleAccountServiceClientCertificatesGet(
1271 App& app, const crow::Request& req,
1272 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1273{
1274 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1275 {
1276 return;
1277 }
1278 getClientCertificates(asyncResp, "/Members"_json_pointer);
1279}
1280
Ed Tanous3ce36882024-06-09 10:58:16 -07001281using account_service::CertificateMappingAttribute;
1282using persistent_data::MTLSCommonNameParseMode;
1283inline CertificateMappingAttribute
1284 getCertificateMapping(MTLSCommonNameParseMode parse)
1285{
1286 switch (parse)
1287 {
1288 case MTLSCommonNameParseMode::CommonName:
1289 {
1290 return CertificateMappingAttribute::CommonName;
1291 }
1292 break;
1293 case MTLSCommonNameParseMode::Whole:
1294 {
1295 return CertificateMappingAttribute::Whole;
1296 }
1297 break;
1298 case MTLSCommonNameParseMode::UserPrincipalName:
1299 {
1300 return CertificateMappingAttribute::UserPrincipalName;
1301 }
1302 break;
1303
1304 case MTLSCommonNameParseMode::Meta:
1305 {
1306 if constexpr (BMCWEB_META_TLS_COMMON_NAME_PARSING)
1307 {
1308 return CertificateMappingAttribute::CommonName;
1309 }
1310 }
1311 break;
1312 default:
1313 {
1314 return CertificateMappingAttribute::Invalid;
1315 }
1316 break;
1317 }
1318}
1319
Ed Tanous1aa375b2024-04-13 11:51:10 -07001320inline void
Ed Tanous4c7d4d32022-07-07 15:29:35 -07001321 handleAccountServiceGet(App& app, const crow::Request& req,
1322 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1323{
Jiaqing Zhaoafd369c2023-03-07 15:12:22 +08001324 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1325 {
1326 return;
1327 }
Ninad Palsule3e72c202023-03-27 17:19:55 -05001328
1329 if (req.session == nullptr)
1330 {
1331 messages::internalError(asyncResp->res);
1332 return;
1333 }
1334
Ed Tanousc1019822024-03-06 12:54:38 -08001335 const persistent_data::AuthConfigMethods& authMethodsConfig =
1336 persistent_data::SessionStore::getInstance().getAuthMethodsConfig();
1337
Jiaqing Zhaoafd369c2023-03-07 15:12:22 +08001338 asyncResp->res.addHeader(
1339 boost::beast::http::field::link,
1340 "</redfish/v1/JsonSchemas/AccountService/AccountService.json>; rel=describedby");
1341
Ed Tanous1ef4c342022-05-12 16:12:36 -07001342 nlohmann::json& json = asyncResp->res.jsonValue;
1343 json["@odata.id"] = "/redfish/v1/AccountService";
Ravi Teja482a69e2024-04-22 06:56:13 -05001344 json["@odata.type"] = "#AccountService.v1_15_0.AccountService";
Ed Tanous1ef4c342022-05-12 16:12:36 -07001345 json["Id"] = "AccountService";
1346 json["Name"] = "Account Service";
1347 json["Description"] = "Account Service";
1348 json["ServiceEnabled"] = true;
1349 json["MaxPasswordLength"] = 20;
1350 json["Accounts"]["@odata.id"] = "/redfish/v1/AccountService/Accounts";
1351 json["Roles"]["@odata.id"] = "/redfish/v1/AccountService/Roles";
Ravi Teja482a69e2024-04-22 06:56:13 -05001352 json["HTTPBasicAuth"] = authMethodsConfig.basic
1353 ? account_service::BasicAuthState::Enabled
1354 : account_service::BasicAuthState::Disabled;
1355
1356 nlohmann::json::array_t allowed;
1357 allowed.emplace_back(account_service::BasicAuthState::Enabled);
1358 allowed.emplace_back(account_service::BasicAuthState::Disabled);
1359 json["HTTPBasicAuth@AllowableValues"] = std::move(allowed);
1360
Ed Tanous1aa375b2024-04-13 11:51:10 -07001361 nlohmann::json::object_t clientCertificate;
1362 clientCertificate["Enabled"] = authMethodsConfig.tls;
Ed Tanous3281bcf2024-06-25 16:02:05 -07001363 clientCertificate["RespondToUnauthenticatedClients"] =
1364 !authMethodsConfig.tlsStrict;
Ed Tanous3ce36882024-06-09 10:58:16 -07001365
1366 using account_service::CertificateMappingAttribute;
1367
1368 CertificateMappingAttribute mapping =
1369 getCertificateMapping(authMethodsConfig.mTLSCommonNameParsingMode);
1370 if (mapping == CertificateMappingAttribute::Invalid)
1371 {
1372 messages::internalError(asyncResp->res);
1373 }
1374 else
1375 {
1376 clientCertificate["CertificateMappingAttribute"] = mapping;
1377 }
Ed Tanous1aa375b2024-04-13 11:51:10 -07001378 nlohmann::json::object_t certificates;
1379 certificates["@odata.id"] =
1380 "/redfish/v1/AccountService/MultiFactorAuth/ClientCertificate/Certificates";
1381 certificates["@odata.type"] =
1382 "#CertificateCollection.CertificateCollection";
1383 clientCertificate["Certificates"] = std::move(certificates);
1384 json["MultiFactorAuth"]["ClientCertificate"] = std::move(clientCertificate);
1385
1386 getClientCertificates(
1387 asyncResp,
1388 "/MultiFactorAuth/ClientCertificate/Certificates/Members"_json_pointer);
1389
Ed Tanous1ef4c342022-05-12 16:12:36 -07001390 json["Oem"]["OpenBMC"]["@odata.type"] =
Ed Tanous5b5574a2022-09-26 19:53:36 -07001391 "#OpenBMCAccountService.v1_0_0.AccountService";
Ed Tanous1ef4c342022-05-12 16:12:36 -07001392 json["Oem"]["OpenBMC"]["@odata.id"] =
1393 "/redfish/v1/AccountService#/Oem/OpenBMC";
1394 json["Oem"]["OpenBMC"]["AuthMethods"]["BasicAuth"] =
1395 authMethodsConfig.basic;
1396 json["Oem"]["OpenBMC"]["AuthMethods"]["SessionToken"] =
1397 authMethodsConfig.sessionToken;
1398 json["Oem"]["OpenBMC"]["AuthMethods"]["XToken"] = authMethodsConfig.xtoken;
1399 json["Oem"]["OpenBMC"]["AuthMethods"]["Cookie"] = authMethodsConfig.cookie;
1400 json["Oem"]["OpenBMC"]["AuthMethods"]["TLS"] = authMethodsConfig.tls;
1401
1402 // /redfish/v1/AccountService/LDAP/Certificates is something only
1403 // ConfigureManager can access then only display when the user has
1404 // permissions ConfigureManager
1405 Privileges effectiveUserPrivileges =
Ninad Palsule3e72c202023-03-27 17:19:55 -05001406 redfish::getUserPrivileges(*req.session);
Ed Tanous1ef4c342022-05-12 16:12:36 -07001407
1408 if (isOperationAllowedWithPrivileges({{"ConfigureManager"}},
1409 effectiveUserPrivileges))
1410 {
1411 asyncResp->res.jsonValue["LDAP"]["Certificates"]["@odata.id"] =
1412 "/redfish/v1/AccountService/LDAP/Certificates";
1413 }
Krzysztof Grobelnyd1bde9e2022-09-07 10:40:51 +02001414 sdbusplus::asio::getAllProperties(
1415 *crow::connections::systemBus, "xyz.openbmc_project.User.Manager",
1416 "/xyz/openbmc_project/user", "xyz.openbmc_project.User.AccountPolicy",
Ed Tanous5e7e2dc2023-02-16 10:37:01 -08001417 [asyncResp](const boost::system::error_code& ec,
Ed Tanous1ef4c342022-05-12 16:12:36 -07001418 const dbus::utility::DBusPropertiesMap& propertiesList) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001419 if (ec)
1420 {
1421 messages::internalError(asyncResp->res);
1422 return;
1423 }
Krzysztof Grobelnyd1bde9e2022-09-07 10:40:51 +02001424
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001425 BMCWEB_LOG_DEBUG("Got {} properties for AccountService",
1426 propertiesList.size());
Krzysztof Grobelnyd1bde9e2022-09-07 10:40:51 +02001427
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001428 const uint8_t* minPasswordLength = nullptr;
1429 const uint32_t* accountUnlockTimeout = nullptr;
1430 const uint16_t* maxLoginAttemptBeforeLockout = nullptr;
Krzysztof Grobelnyd1bde9e2022-09-07 10:40:51 +02001431
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001432 const bool success = sdbusplus::unpackPropertiesNoThrow(
1433 dbus_utils::UnpackErrorPrinter(), propertiesList,
1434 "MinPasswordLength", minPasswordLength, "AccountUnlockTimeout",
1435 accountUnlockTimeout, "MaxLoginAttemptBeforeLockout",
1436 maxLoginAttemptBeforeLockout);
Krzysztof Grobelnyd1bde9e2022-09-07 10:40:51 +02001437
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001438 if (!success)
1439 {
1440 messages::internalError(asyncResp->res);
1441 return;
1442 }
Krzysztof Grobelnyd1bde9e2022-09-07 10:40:51 +02001443
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001444 if (minPasswordLength != nullptr)
1445 {
1446 asyncResp->res.jsonValue["MinPasswordLength"] =
1447 *minPasswordLength;
1448 }
Krzysztof Grobelnyd1bde9e2022-09-07 10:40:51 +02001449
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001450 if (accountUnlockTimeout != nullptr)
1451 {
1452 asyncResp->res.jsonValue["AccountLockoutDuration"] =
1453 *accountUnlockTimeout;
1454 }
Krzysztof Grobelnyd1bde9e2022-09-07 10:40:51 +02001455
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001456 if (maxLoginAttemptBeforeLockout != nullptr)
1457 {
1458 asyncResp->res.jsonValue["AccountLockoutThreshold"] =
1459 *maxLoginAttemptBeforeLockout;
1460 }
1461 });
Ed Tanous1ef4c342022-05-12 16:12:36 -07001462
Ed Tanous02cad962022-06-30 16:50:15 -07001463 auto callback = [asyncResp](bool success, const LDAPConfigData& confData,
Ed Tanous1ef4c342022-05-12 16:12:36 -07001464 const std::string& ldapType) {
1465 if (!success)
1466 {
1467 return;
1468 }
1469 parseLDAPConfigData(asyncResp->res.jsonValue, confData, ldapType);
1470 };
1471
1472 getLDAPConfigData("LDAP", callback);
1473 getLDAPConfigData("ActiveDirectory", callback);
1474}
1475
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001476inline void handleCertificateMappingAttributePatch(
1477 crow::Response& res, const std::string& certMapAttribute)
Ed Tanous3ce36882024-06-09 10:58:16 -07001478{
1479 MTLSCommonNameParseMode parseMode =
1480 persistent_data::getMTLSCommonNameParseMode(certMapAttribute);
1481 if (parseMode == MTLSCommonNameParseMode::Invalid)
1482 {
1483 messages::propertyValueNotInList(res, "CertificateMappingAttribute",
1484 certMapAttribute);
1485 return;
1486 }
1487
1488 persistent_data::AuthConfigMethods& authMethodsConfig =
1489 persistent_data::SessionStore::getInstance().getAuthMethodsConfig();
1490 authMethodsConfig.mTLSCommonNameParsingMode = parseMode;
1491}
1492
Ed Tanous3281bcf2024-06-25 16:02:05 -07001493inline void handleRespondToUnauthenticatedClientsPatch(
1494 App& app, const crow::Request& req, crow::Response& res,
1495 bool respondToUnauthenticatedClients)
1496{
1497 if (req.session != nullptr)
1498 {
1499 // Sanity check. If the user isn't currently authenticated with mutual
1500 // TLS, they very likely are about to permanently lock themselves out.
1501 // Make sure they're using mutual TLS before allowing locking.
1502 if (req.session->sessionType != persistent_data::SessionType::MutualTLS)
1503 {
1504 messages::propertyValueExternalConflict(
1505 res,
1506 "MultiFactorAuth/ClientCertificate/RespondToUnauthenticatedClients",
1507 respondToUnauthenticatedClients);
1508 return;
1509 }
1510 }
1511
1512 persistent_data::AuthConfigMethods& authMethodsConfig =
1513 persistent_data::SessionStore::getInstance().getAuthMethodsConfig();
1514
1515 // Change the settings
1516 authMethodsConfig.tlsStrict = !respondToUnauthenticatedClients;
1517
1518 // Write settings to disk
1519 persistent_data::getConfig().writeData();
1520
1521 // Trigger a reload, to apply the new settings to new connections
1522 app.loadCertificate();
1523}
1524
Ed Tanous1ef4c342022-05-12 16:12:36 -07001525inline void handleAccountServicePatch(
1526 App& app, const crow::Request& req,
1527 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1528{
1529 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1530 {
1531 return;
1532 }
1533 std::optional<uint32_t> unlockTimeout;
1534 std::optional<uint16_t> lockoutThreshold;
1535 std::optional<uint8_t> minPasswordLength;
1536 std::optional<uint16_t> maxPasswordLength;
Ed Tanous10cb44f2024-04-11 13:05:20 -07001537 LdapPatchParams ldapObject;
Ed Tanous3ce36882024-06-09 10:58:16 -07001538 std::optional<std::string> certificateMappingAttribute;
Ed Tanous3281bcf2024-06-25 16:02:05 -07001539 std::optional<bool> respondToUnauthenticatedClients;
Ed Tanous10cb44f2024-04-11 13:05:20 -07001540 LdapPatchParams activeDirectoryObject;
Ed Tanousc1019822024-03-06 12:54:38 -08001541 AuthMethods auth;
Ravi Teja482a69e2024-04-22 06:56:13 -05001542 std::optional<std::string> httpBasicAuth;
Ed Tanous3ce36882024-06-09 10:58:16 -07001543
Ed Tanousc1019822024-03-06 12:54:38 -08001544 // clang-format off
Ed Tanous1ef4c342022-05-12 16:12:36 -07001545 if (!json_util::readJsonPatch(
Ed Tanousc1019822024-03-06 12:54:38 -08001546 req, asyncResp->res,
1547 "AccountLockoutDuration", unlockTimeout,
1548 "AccountLockoutThreshold", lockoutThreshold,
Ed Tanous10cb44f2024-04-11 13:05:20 -07001549 "ActiveDirectory/Authentication/AuthenticationType", activeDirectoryObject.authType,
1550 "ActiveDirectory/Authentication/Password", activeDirectoryObject.password,
1551 "ActiveDirectory/Authentication/Username", activeDirectoryObject.userName,
1552 "ActiveDirectory/LDAPService/SearchSettings/BaseDistinguishedNames", activeDirectoryObject.baseDNList,
1553 "ActiveDirectory/LDAPService/SearchSettings/GroupsAttribute", activeDirectoryObject.groupsAttribute,
1554 "ActiveDirectory/LDAPService/SearchSettings/UsernameAttribute", activeDirectoryObject.userNameAttribute,
1555 "ActiveDirectory/RemoteRoleMapping", activeDirectoryObject.remoteRoleMapData,
1556 "ActiveDirectory/ServiceAddresses", activeDirectoryObject.serviceAddressList,
1557 "ActiveDirectory/ServiceEnabled", activeDirectoryObject.serviceEnabled,
Ed Tanous3ce36882024-06-09 10:58:16 -07001558 "MultiFactorAuth/ClientCertificate/CertificateMappingAttribute", certificateMappingAttribute,
Ed Tanous3281bcf2024-06-25 16:02:05 -07001559 "MultiFactorAuth/ClientCertificate/RespondToUnauthenticatedClients", respondToUnauthenticatedClients,
Ed Tanous10cb44f2024-04-11 13:05:20 -07001560 "LDAP/Authentication/AuthenticationType", ldapObject.authType,
1561 "LDAP/Authentication/Password", ldapObject.password,
1562 "LDAP/Authentication/Username", ldapObject.userName,
1563 "LDAP/LDAPService/SearchSettings/BaseDistinguishedNames", ldapObject.baseDNList,
1564 "LDAP/LDAPService/SearchSettings/GroupsAttribute", ldapObject.groupsAttribute,
1565 "LDAP/LDAPService/SearchSettings/UsernameAttribute", ldapObject.userNameAttribute,
1566 "LDAP/RemoteRoleMapping", ldapObject.remoteRoleMapData,
1567 "LDAP/ServiceAddresses", ldapObject.serviceAddressList,
1568 "LDAP/ServiceEnabled", ldapObject.serviceEnabled,
Ed Tanousc1019822024-03-06 12:54:38 -08001569 "MaxPasswordLength", maxPasswordLength,
1570 "MinPasswordLength", minPasswordLength,
Ed Tanousc1019822024-03-06 12:54:38 -08001571 "Oem/OpenBMC/AuthMethods/BasicAuth", auth.basicAuth,
1572 "Oem/OpenBMC/AuthMethods/Cookie", auth.cookie,
1573 "Oem/OpenBMC/AuthMethods/SessionToken", auth.sessionToken,
Ed Tanous10cb44f2024-04-11 13:05:20 -07001574 "Oem/OpenBMC/AuthMethods/TLS", auth.tls,
Ravi Teja482a69e2024-04-22 06:56:13 -05001575 "Oem/OpenBMC/AuthMethods/XToken", auth.xToken,
1576 "HTTPBasicAuth", httpBasicAuth))
Ed Tanous1ef4c342022-05-12 16:12:36 -07001577 {
1578 return;
1579 }
Ed Tanousc1019822024-03-06 12:54:38 -08001580 // clang-format on
Ed Tanous1ef4c342022-05-12 16:12:36 -07001581
Ravi Teja482a69e2024-04-22 06:56:13 -05001582 if (httpBasicAuth)
1583 {
1584 if (*httpBasicAuth == "Enabled")
1585 {
1586 auth.basicAuth = true;
1587 }
1588 else if (*httpBasicAuth == "Disabled")
1589 {
1590 auth.basicAuth = false;
1591 }
1592 else
1593 {
1594 messages::propertyValueNotInList(asyncResp->res, "HttpBasicAuth",
1595 *httpBasicAuth);
1596 }
1597 }
1598
Ed Tanous3281bcf2024-06-25 16:02:05 -07001599 if (respondToUnauthenticatedClients)
1600 {
1601 handleRespondToUnauthenticatedClientsPatch(
1602 app, req, asyncResp->res, *respondToUnauthenticatedClients);
1603 }
1604
Ed Tanous3ce36882024-06-09 10:58:16 -07001605 if (certificateMappingAttribute)
1606 {
1607 handleCertificateMappingAttributePatch(asyncResp->res,
1608 *certificateMappingAttribute);
1609 }
1610
Ed Tanous1ef4c342022-05-12 16:12:36 -07001611 if (minPasswordLength)
1612 {
Ed Tanousd02aad32024-02-13 14:43:34 -08001613 setDbusProperty(
Ginu Georgee93abac2024-06-14 17:35:27 +05301614 asyncResp, "MinPasswordLength", "xyz.openbmc_project.User.Manager",
Ed Tanousd02aad32024-02-13 14:43:34 -08001615 sdbusplus::message::object_path("/xyz/openbmc_project/user"),
George Liu9ae226f2023-06-21 17:56:46 +08001616 "xyz.openbmc_project.User.AccountPolicy", "MinPasswordLength",
Ginu Georgee93abac2024-06-14 17:35:27 +05301617 *minPasswordLength);
Ed Tanous1ef4c342022-05-12 16:12:36 -07001618 }
1619
1620 if (maxPasswordLength)
1621 {
1622 messages::propertyNotWritable(asyncResp->res, "MaxPasswordLength");
1623 }
1624
Ed Tanous10cb44f2024-04-11 13:05:20 -07001625 handleLDAPPatch(std::move(activeDirectoryObject), asyncResp,
1626 "ActiveDirectory");
1627 handleLDAPPatch(std::move(ldapObject), asyncResp, "LDAP");
Ed Tanous1ef4c342022-05-12 16:12:36 -07001628
Ed Tanousc1019822024-03-06 12:54:38 -08001629 handleAuthMethodsPatch(asyncResp, auth);
Ed Tanous1ef4c342022-05-12 16:12:36 -07001630
Ed Tanous1ef4c342022-05-12 16:12:36 -07001631 if (unlockTimeout)
1632 {
Ed Tanousd02aad32024-02-13 14:43:34 -08001633 setDbusProperty(
Ginu Georgee93abac2024-06-14 17:35:27 +05301634 asyncResp, "AccountLockoutDuration",
1635 "xyz.openbmc_project.User.Manager",
Ed Tanousd02aad32024-02-13 14:43:34 -08001636 sdbusplus::message::object_path("/xyz/openbmc_project/user"),
Ed Tanous1ef4c342022-05-12 16:12:36 -07001637 "xyz.openbmc_project.User.AccountPolicy", "AccountUnlockTimeout",
Ginu Georgee93abac2024-06-14 17:35:27 +05301638 *unlockTimeout);
Ed Tanous1ef4c342022-05-12 16:12:36 -07001639 }
1640 if (lockoutThreshold)
1641 {
Ed Tanousd02aad32024-02-13 14:43:34 -08001642 setDbusProperty(
Ginu Georgee93abac2024-06-14 17:35:27 +05301643 asyncResp, "AccountLockoutThreshold",
1644 "xyz.openbmc_project.User.Manager",
Ed Tanousd02aad32024-02-13 14:43:34 -08001645 sdbusplus::message::object_path("/xyz/openbmc_project/user"),
George Liu9ae226f2023-06-21 17:56:46 +08001646 "xyz.openbmc_project.User.AccountPolicy",
Ginu Georgee93abac2024-06-14 17:35:27 +05301647 "MaxLoginAttemptBeforeLockout", *lockoutThreshold);
Ed Tanous1ef4c342022-05-12 16:12:36 -07001648 }
1649}
1650
Ed Tanous4c7d4d32022-07-07 15:29:35 -07001651inline void handleAccountCollectionHead(
Ed Tanous1ef4c342022-05-12 16:12:36 -07001652 App& app, const crow::Request& req,
1653 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1654{
1655 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1656 {
1657 return;
1658 }
Ed Tanous4c7d4d32022-07-07 15:29:35 -07001659 asyncResp->res.addHeader(
1660 boost::beast::http::field::link,
1661 "</redfish/v1/JsonSchemas/ManagerAccountCollection.json>; rel=describedby");
1662}
1663
1664inline void handleAccountCollectionGet(
1665 App& app, const crow::Request& req,
1666 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1667{
Jiaqing Zhaoafd369c2023-03-07 15:12:22 +08001668 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1669 {
1670 return;
1671 }
Ninad Palsule3e72c202023-03-27 17:19:55 -05001672
1673 if (req.session == nullptr)
1674 {
1675 messages::internalError(asyncResp->res);
1676 return;
1677 }
1678
Jiaqing Zhaoafd369c2023-03-07 15:12:22 +08001679 asyncResp->res.addHeader(
1680 boost::beast::http::field::link,
1681 "</redfish/v1/JsonSchemas/ManagerAccountCollection.json>; rel=describedby");
Ed Tanous1ef4c342022-05-12 16:12:36 -07001682
1683 asyncResp->res.jsonValue["@odata.id"] =
1684 "/redfish/v1/AccountService/Accounts";
1685 asyncResp->res.jsonValue["@odata.type"] = "#ManagerAccountCollection."
1686 "ManagerAccountCollection";
1687 asyncResp->res.jsonValue["Name"] = "Accounts Collection";
1688 asyncResp->res.jsonValue["Description"] = "BMC User Accounts";
1689
1690 Privileges effectiveUserPrivileges =
Ninad Palsule3e72c202023-03-27 17:19:55 -05001691 redfish::getUserPrivileges(*req.session);
Ed Tanous1ef4c342022-05-12 16:12:36 -07001692
1693 std::string thisUser;
1694 if (req.session)
1695 {
1696 thisUser = req.session->username;
1697 }
George Liu5eb468d2023-06-20 17:03:24 +08001698 sdbusplus::message::object_path path("/xyz/openbmc_project/user");
1699 dbus::utility::getManagedObjects(
1700 "xyz.openbmc_project.User.Manager", path,
Ed Tanous1ef4c342022-05-12 16:12:36 -07001701 [asyncResp, thisUser, effectiveUserPrivileges](
Ed Tanous5e7e2dc2023-02-16 10:37:01 -08001702 const boost::system::error_code& ec,
Ed Tanous1ef4c342022-05-12 16:12:36 -07001703 const dbus::utility::ManagedObjectType& users) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001704 if (ec)
Ed Tanous1ef4c342022-05-12 16:12:36 -07001705 {
1706 messages::internalError(asyncResp->res);
Ed Tanous1ef4c342022-05-12 16:12:36 -07001707 return;
1708 }
1709
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001710 bool userCanSeeAllAccounts =
1711 effectiveUserPrivileges.isSupersetOf({"ConfigureUsers"});
1712
1713 bool userCanSeeSelf =
1714 effectiveUserPrivileges.isSupersetOf({"ConfigureSelf"});
1715
1716 nlohmann::json& memberArray = asyncResp->res.jsonValue["Members"];
1717 memberArray = nlohmann::json::array();
1718
1719 for (const auto& userpath : users)
Ed Tanous1ef4c342022-05-12 16:12:36 -07001720 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001721 std::string user = userpath.first.filename();
1722 if (user.empty())
1723 {
1724 messages::internalError(asyncResp->res);
1725 BMCWEB_LOG_ERROR("Invalid firmware ID");
1726
1727 return;
1728 }
1729
1730 // As clarified by Redfish here:
1731 // https://redfishforum.com/thread/281/manageraccountcollection-change-allows-account-enumeration
1732 // Users without ConfigureUsers, only see their own
1733 // account. Users with ConfigureUsers, see all
1734 // accounts.
1735 if (userCanSeeAllAccounts ||
1736 (thisUser == user && userCanSeeSelf))
1737 {
1738 nlohmann::json::object_t member;
1739 member["@odata.id"] = boost::urls::format(
1740 "/redfish/v1/AccountService/Accounts/{}", user);
1741 memberArray.emplace_back(std::move(member));
1742 }
Ed Tanous1ef4c342022-05-12 16:12:36 -07001743 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001744 asyncResp->res.jsonValue["Members@odata.count"] =
1745 memberArray.size();
1746 });
Ed Tanous1ef4c342022-05-12 16:12:36 -07001747}
1748
Ninad Palsule97e90da2023-05-17 14:04:52 -05001749inline void processAfterCreateUser(
1750 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1751 const std::string& username, const std::string& password,
1752 const boost::system::error_code& ec, sdbusplus::message_t& m)
1753{
1754 if (ec)
1755 {
1756 userErrorMessageHandler(m.get_error(), asyncResp, username, "");
1757 return;
1758 }
1759
1760 if (pamUpdatePassword(username, password) != PAM_SUCCESS)
1761 {
1762 // At this point we have a user that's been
1763 // created, but the password set
1764 // failed.Something is wrong, so delete the user
1765 // that we've already created
1766 sdbusplus::message::object_path tempObjPath(rootUserDbusPath);
1767 tempObjPath /= username;
1768 const std::string userPath(tempObjPath);
1769
1770 crow::connections::systemBus->async_method_call(
1771 [asyncResp, password](const boost::system::error_code& ec3) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001772 if (ec3)
1773 {
1774 messages::internalError(asyncResp->res);
1775 return;
1776 }
Ninad Palsule97e90da2023-05-17 14:04:52 -05001777
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001778 // If password is invalid
1779 messages::propertyValueFormatError(asyncResp->res, nullptr,
1780 "Password");
1781 },
Ninad Palsule97e90da2023-05-17 14:04:52 -05001782 "xyz.openbmc_project.User.Manager", userPath,
1783 "xyz.openbmc_project.Object.Delete", "Delete");
1784
Ed Tanous62598e32023-07-17 17:06:25 -07001785 BMCWEB_LOG_ERROR("pamUpdatePassword Failed");
Ninad Palsule97e90da2023-05-17 14:04:52 -05001786 return;
1787 }
1788
1789 messages::created(asyncResp->res);
1790 asyncResp->res.addHeader("Location",
1791 "/redfish/v1/AccountService/Accounts/" + username);
1792}
1793
1794inline void processAfterGetAllGroups(
1795 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1796 const std::string& username, const std::string& password,
Ed Tanouse01d0c32023-06-30 13:21:32 -07001797 const std::string& roleId, bool enabled,
Ninad Palsule9ba73932023-06-01 16:38:57 -05001798 std::optional<std::vector<std::string>> accountTypes,
Ninad Palsule97e90da2023-05-17 14:04:52 -05001799 const std::vector<std::string>& allGroupsList)
Ninad Palsule97e90da2023-05-17 14:04:52 -05001800{
Ninad Palsule3e72c202023-03-27 17:19:55 -05001801 std::vector<std::string> userGroups;
Ninad Palsule9ba73932023-06-01 16:38:57 -05001802 std::vector<std::string> accountTypeUserGroups;
1803
1804 // If user specified account types then convert them to unix user groups
1805 if (accountTypes)
1806 {
1807 if (!getUserGroupFromAccountType(asyncResp->res, *accountTypes,
1808 accountTypeUserGroups))
1809 {
1810 // Problem in mapping Account Types to User Groups, Error already
1811 // logged.
1812 return;
1813 }
1814 }
1815
Ninad Palsule3e72c202023-03-27 17:19:55 -05001816 for (const auto& grp : allGroupsList)
1817 {
Ninad Palsule9ba73932023-06-01 16:38:57 -05001818 // If user specified the account type then only accept groups which are
1819 // in the account types group list.
1820 if (!accountTypeUserGroups.empty())
1821 {
1822 bool found = false;
1823 for (const auto& grp1 : accountTypeUserGroups)
1824 {
1825 if (grp == grp1)
1826 {
1827 found = true;
1828 break;
1829 }
1830 }
1831 if (!found)
1832 {
1833 continue;
1834 }
1835 }
1836
Ninad Palsule3e72c202023-03-27 17:19:55 -05001837 // Console access is provided to the user who is a member of
1838 // hostconsole group and has a administrator role. So, set
1839 // hostconsole group only for the administrator.
Ninad Palsule9ba73932023-06-01 16:38:57 -05001840 if ((grp == "hostconsole") && (roleId != "priv-admin"))
Ninad Palsule3e72c202023-03-27 17:19:55 -05001841 {
Ninad Palsule9ba73932023-06-01 16:38:57 -05001842 if (!accountTypeUserGroups.empty())
1843 {
Ed Tanous62598e32023-07-17 17:06:25 -07001844 BMCWEB_LOG_ERROR(
1845 "Only administrator can get HostConsole access");
Ninad Palsule9ba73932023-06-01 16:38:57 -05001846 asyncResp->res.result(boost::beast::http::status::bad_request);
1847 return;
1848 }
1849 continue;
Ninad Palsule3e72c202023-03-27 17:19:55 -05001850 }
Ninad Palsule9ba73932023-06-01 16:38:57 -05001851 userGroups.emplace_back(grp);
1852 }
1853
1854 // Make sure user specified groups are valid. This is internal error because
1855 // it some inconsistencies between user manager and bmcweb.
1856 if (!accountTypeUserGroups.empty() &&
1857 accountTypeUserGroups.size() != userGroups.size())
1858 {
1859 messages::internalError(asyncResp->res);
1860 return;
Ninad Palsule3e72c202023-03-27 17:19:55 -05001861 }
Ninad Palsule97e90da2023-05-17 14:04:52 -05001862 crow::connections::systemBus->async_method_call(
1863 [asyncResp, username, password](const boost::system::error_code& ec2,
1864 sdbusplus::message_t& m) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001865 processAfterCreateUser(asyncResp, username, password, ec2, m);
1866 },
Ninad Palsule97e90da2023-05-17 14:04:52 -05001867 "xyz.openbmc_project.User.Manager", "/xyz/openbmc_project/user",
Ninad Palsule3e72c202023-03-27 17:19:55 -05001868 "xyz.openbmc_project.User.Manager", "CreateUser", username, userGroups,
Ed Tanouse01d0c32023-06-30 13:21:32 -07001869 roleId, enabled);
Ninad Palsule97e90da2023-05-17 14:04:52 -05001870}
1871
Ed Tanous1ef4c342022-05-12 16:12:36 -07001872inline void handleAccountCollectionPost(
1873 App& app, const crow::Request& req,
1874 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1875{
1876 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1877 {
1878 return;
1879 }
1880 std::string username;
1881 std::string password;
Ed Tanouse01d0c32023-06-30 13:21:32 -07001882 std::optional<std::string> roleIdJson;
1883 std::optional<bool> enabledJson;
Ninad Palsule9ba73932023-06-01 16:38:57 -05001884 std::optional<std::vector<std::string>> accountTypes;
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001885 if (!json_util::readJsonPatch(
1886 req, asyncResp->res, "UserName", username, "Password", password,
1887 "RoleId", roleIdJson, "Enabled", enabledJson, "AccountTypes",
1888 accountTypes))
Ed Tanous1ef4c342022-05-12 16:12:36 -07001889 {
1890 return;
1891 }
1892
Ed Tanouse01d0c32023-06-30 13:21:32 -07001893 std::string roleId = roleIdJson.value_or("User");
1894 std::string priv = getPrivilegeFromRoleId(roleId);
Ed Tanous1ef4c342022-05-12 16:12:36 -07001895 if (priv.empty())
1896 {
Ed Tanouse01d0c32023-06-30 13:21:32 -07001897 messages::propertyValueNotInList(asyncResp->res, roleId, "RoleId");
Ed Tanous1ef4c342022-05-12 16:12:36 -07001898 return;
1899 }
Asmitha Karunanithi239adf82022-03-25 02:59:03 -05001900 roleId = priv;
Ed Tanous1ef4c342022-05-12 16:12:36 -07001901
Ed Tanouse01d0c32023-06-30 13:21:32 -07001902 bool enabled = enabledJson.value_or(true);
1903
Ed Tanous1ef4c342022-05-12 16:12:36 -07001904 // Reading AllGroups property
1905 sdbusplus::asio::getProperty<std::vector<std::string>>(
1906 *crow::connections::systemBus, "xyz.openbmc_project.User.Manager",
1907 "/xyz/openbmc_project/user", "xyz.openbmc_project.User.Manager",
1908 "AllGroups",
Ninad Palsule9ba73932023-06-01 16:38:57 -05001909 [asyncResp, username, password{std::move(password)}, roleId, enabled,
1910 accountTypes](const boost::system::error_code& ec,
1911 const std::vector<std::string>& allGroupsList) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001912 if (ec)
1913 {
1914 BMCWEB_LOG_DEBUG("ERROR with async_method_call");
1915 messages::internalError(asyncResp->res);
1916 return;
1917 }
Ed Tanous1ef4c342022-05-12 16:12:36 -07001918
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001919 if (allGroupsList.empty())
1920 {
1921 messages::internalError(asyncResp->res);
1922 return;
1923 }
Ed Tanous1ef4c342022-05-12 16:12:36 -07001924
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001925 processAfterGetAllGroups(asyncResp, username, password, roleId,
1926 enabled, accountTypes, allGroupsList);
1927 });
Ed Tanous1ef4c342022-05-12 16:12:36 -07001928}
1929
1930inline void
Ed Tanous4c7d4d32022-07-07 15:29:35 -07001931 handleAccountHead(App& app, const crow::Request& req,
1932 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1933 const std::string& /*accountName*/)
Ed Tanous1ef4c342022-05-12 16:12:36 -07001934{
1935 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1936 {
1937 return;
1938 }
Ed Tanous4c7d4d32022-07-07 15:29:35 -07001939 asyncResp->res.addHeader(
1940 boost::beast::http::field::link,
1941 "</redfish/v1/JsonSchemas/ManagerAccount/ManagerAccount.json>; rel=describedby");
1942}
Jiaqing Zhaoafd369c2023-03-07 15:12:22 +08001943
Ed Tanous4c7d4d32022-07-07 15:29:35 -07001944inline void
1945 handleAccountGet(App& app, const crow::Request& req,
1946 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1947 const std::string& accountName)
1948{
Jiaqing Zhaoafd369c2023-03-07 15:12:22 +08001949 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1950 {
1951 return;
1952 }
1953 asyncResp->res.addHeader(
1954 boost::beast::http::field::link,
1955 "</redfish/v1/JsonSchemas/ManagerAccount/ManagerAccount.json>; rel=describedby");
1956
Ed Tanous25b54db2024-04-17 15:40:31 -07001957 if constexpr (BMCWEB_INSECURE_DISABLE_AUTH)
1958 {
1959 // If authentication is disabled, there are no user accounts
1960 messages::resourceNotFound(asyncResp->res, "ManagerAccount",
1961 accountName);
1962 return;
1963 }
Jiaqing Zhaoafd369c2023-03-07 15:12:22 +08001964
Ed Tanous1ef4c342022-05-12 16:12:36 -07001965 if (req.session == nullptr)
1966 {
1967 messages::internalError(asyncResp->res);
1968 return;
1969 }
1970 if (req.session->username != accountName)
1971 {
1972 // At this point we've determined that the user is trying to
1973 // modify a user that isn't them. We need to verify that they
1974 // have permissions to modify other users, so re-run the auth
1975 // check with the same permissions, minus ConfigureSelf.
1976 Privileges effectiveUserPrivileges =
Ninad Palsule3e72c202023-03-27 17:19:55 -05001977 redfish::getUserPrivileges(*req.session);
Ed Tanous1ef4c342022-05-12 16:12:36 -07001978 Privileges requiredPermissionsToChangeNonSelf = {"ConfigureUsers",
1979 "ConfigureManager"};
1980 if (!effectiveUserPrivileges.isSupersetOf(
1981 requiredPermissionsToChangeNonSelf))
1982 {
Ed Tanous62598e32023-07-17 17:06:25 -07001983 BMCWEB_LOG_DEBUG("GET Account denied access");
Ed Tanous1ef4c342022-05-12 16:12:36 -07001984 messages::insufficientPrivilege(asyncResp->res);
1985 return;
1986 }
1987 }
1988
George Liu5eb468d2023-06-20 17:03:24 +08001989 sdbusplus::message::object_path path("/xyz/openbmc_project/user");
1990 dbus::utility::getManagedObjects(
1991 "xyz.openbmc_project.User.Manager", path,
Ed Tanous1ef4c342022-05-12 16:12:36 -07001992 [asyncResp,
Ed Tanous5e7e2dc2023-02-16 10:37:01 -08001993 accountName](const boost::system::error_code& ec,
Ed Tanous1ef4c342022-05-12 16:12:36 -07001994 const dbus::utility::ManagedObjectType& users) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001995 if (ec)
Ed Tanous1ef4c342022-05-12 16:12:36 -07001996 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04001997 messages::internalError(asyncResp->res);
1998 return;
1999 }
2000 const auto userIt = std::ranges::find_if(
2001 users,
2002 [accountName](
2003 const std::pair<sdbusplus::message::object_path,
2004 dbus::utility::DBusInterfacesMap>& user) {
2005 return accountName == user.first.filename();
2006 });
Ed Tanous1ef4c342022-05-12 16:12:36 -07002007
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002008 if (userIt == users.end())
2009 {
2010 messages::resourceNotFound(asyncResp->res, "ManagerAccount",
2011 accountName);
2012 return;
2013 }
2014
2015 asyncResp->res.jsonValue["@odata.type"] =
2016 "#ManagerAccount.v1_7_0.ManagerAccount";
2017 asyncResp->res.jsonValue["Name"] = "User Account";
2018 asyncResp->res.jsonValue["Description"] = "User Account";
2019 asyncResp->res.jsonValue["Password"] = nullptr;
2020 asyncResp->res.jsonValue["StrictAccountTypes"] = true;
2021
2022 for (const auto& interface : userIt->second)
2023 {
2024 if (interface.first == "xyz.openbmc_project.User.Attributes")
2025 {
2026 for (const auto& property : interface.second)
Ed Tanous1ef4c342022-05-12 16:12:36 -07002027 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002028 if (property.first == "UserEnabled")
Ed Tanous1ef4c342022-05-12 16:12:36 -07002029 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002030 const bool* userEnabled =
2031 std::get_if<bool>(&property.second);
2032 if (userEnabled == nullptr)
2033 {
2034 BMCWEB_LOG_ERROR("UserEnabled wasn't a bool");
2035 messages::internalError(asyncResp->res);
2036 return;
2037 }
2038 asyncResp->res.jsonValue["Enabled"] = *userEnabled;
Ed Tanous1ef4c342022-05-12 16:12:36 -07002039 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002040 else if (property.first == "UserLockedForFailedAttempt")
Abhishek Patelc7229812022-02-01 10:07:15 -06002041 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002042 const bool* userLocked =
2043 std::get_if<bool>(&property.second);
2044 if (userLocked == nullptr)
2045 {
2046 BMCWEB_LOG_ERROR("UserLockedForF"
2047 "ailedAttempt "
2048 "wasn't a bool");
2049 messages::internalError(asyncResp->res);
2050 return;
2051 }
2052 asyncResp->res.jsonValue["Locked"] = *userLocked;
2053 nlohmann::json::array_t allowed;
2054 // can only unlock accounts
2055 allowed.emplace_back("false");
2056 asyncResp->res
2057 .jsonValue["Locked@Redfish.AllowableValues"] =
2058 std::move(allowed);
Abhishek Patelc7229812022-02-01 10:07:15 -06002059 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002060 else if (property.first == "UserPrivilege")
Abhishek Patelc7229812022-02-01 10:07:15 -06002061 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002062 const std::string* userPrivPtr =
2063 std::get_if<std::string>(&property.second);
2064 if (userPrivPtr == nullptr)
2065 {
2066 BMCWEB_LOG_ERROR("UserPrivilege wasn't a "
2067 "string");
2068 messages::internalError(asyncResp->res);
2069 return;
2070 }
2071 std::string role =
2072 getRoleIdFromPrivilege(*userPrivPtr);
2073 if (role.empty())
2074 {
2075 BMCWEB_LOG_ERROR("Invalid user role");
2076 messages::internalError(asyncResp->res);
2077 return;
2078 }
2079 asyncResp->res.jsonValue["RoleId"] = role;
2080
2081 nlohmann::json& roleEntry =
2082 asyncResp->res.jsonValue["Links"]["Role"];
2083 roleEntry["@odata.id"] = boost::urls::format(
2084 "/redfish/v1/AccountService/Roles/{}", role);
2085 }
2086 else if (property.first == "UserPasswordExpired")
2087 {
2088 const bool* userPasswordExpired =
2089 std::get_if<bool>(&property.second);
2090 if (userPasswordExpired == nullptr)
2091 {
2092 BMCWEB_LOG_ERROR(
2093 "UserPasswordExpired wasn't a bool");
2094 messages::internalError(asyncResp->res);
2095 return;
2096 }
2097 asyncResp->res.jsonValue["PasswordChangeRequired"] =
2098 *userPasswordExpired;
2099 }
2100 else if (property.first == "UserGroups")
2101 {
2102 const std::vector<std::string>* userGroups =
2103 std::get_if<std::vector<std::string>>(
2104 &property.second);
2105 if (userGroups == nullptr)
2106 {
2107 BMCWEB_LOG_ERROR(
2108 "userGroups wasn't a string vector");
2109 messages::internalError(asyncResp->res);
2110 return;
2111 }
2112 if (!translateUserGroup(*userGroups,
2113 asyncResp->res))
2114 {
2115 BMCWEB_LOG_ERROR("userGroups mapping failed");
2116 messages::internalError(asyncResp->res);
2117 return;
2118 }
Abhishek Patelc7229812022-02-01 10:07:15 -06002119 }
2120 }
Ed Tanous1ef4c342022-05-12 16:12:36 -07002121 }
2122 }
Ed Tanous1ef4c342022-05-12 16:12:36 -07002123
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002124 asyncResp->res.jsonValue["@odata.id"] = boost::urls::format(
2125 "/redfish/v1/AccountService/Accounts/{}", accountName);
2126 asyncResp->res.jsonValue["Id"] = accountName;
2127 asyncResp->res.jsonValue["UserName"] = accountName;
2128 });
Ed Tanous1ef4c342022-05-12 16:12:36 -07002129}
2130
2131inline void
Gunnar Mills20fc3072023-01-27 15:13:36 -06002132 handleAccountDelete(App& app, const crow::Request& req,
2133 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2134 const std::string& username)
Ed Tanous1ef4c342022-05-12 16:12:36 -07002135{
2136 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2137 {
2138 return;
2139 }
2140
Ed Tanous25b54db2024-04-17 15:40:31 -07002141 if constexpr (BMCWEB_INSECURE_DISABLE_AUTH)
2142 {
2143 // If authentication is disabled, there are no user accounts
2144 messages::resourceNotFound(asyncResp->res, "ManagerAccount", username);
2145 return;
2146 }
Ed Tanous1ef4c342022-05-12 16:12:36 -07002147 sdbusplus::message::object_path tempObjPath(rootUserDbusPath);
2148 tempObjPath /= username;
2149 const std::string userPath(tempObjPath);
2150
2151 crow::connections::systemBus->async_method_call(
Ed Tanous5e7e2dc2023-02-16 10:37:01 -08002152 [asyncResp, username](const boost::system::error_code& ec) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002153 if (ec)
2154 {
2155 messages::resourceNotFound(asyncResp->res, "ManagerAccount",
2156 username);
2157 return;
2158 }
Ed Tanous1ef4c342022-05-12 16:12:36 -07002159
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002160 messages::accountRemoved(asyncResp->res);
2161 },
Ed Tanous1ef4c342022-05-12 16:12:36 -07002162 "xyz.openbmc_project.User.Manager", userPath,
2163 "xyz.openbmc_project.Object.Delete", "Delete");
2164}
2165
2166inline void
2167 handleAccountPatch(App& app, const crow::Request& req,
2168 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2169 const std::string& username)
2170{
2171 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2172 {
2173 return;
2174 }
Ed Tanous25b54db2024-04-17 15:40:31 -07002175 if constexpr (BMCWEB_INSECURE_DISABLE_AUTH)
2176 {
2177 // If authentication is disabled, there are no user accounts
2178 messages::resourceNotFound(asyncResp->res, "ManagerAccount", username);
2179 return;
2180 }
Ed Tanous1ef4c342022-05-12 16:12:36 -07002181 std::optional<std::string> newUserName;
2182 std::optional<std::string> password;
2183 std::optional<bool> enabled;
2184 std::optional<std::string> roleId;
2185 std::optional<bool> locked;
Abhishek Patel58345852022-02-02 08:54:25 -06002186 std::optional<std::vector<std::string>> accountTypes;
2187
Ed Tanous1ef4c342022-05-12 16:12:36 -07002188 if (req.session == nullptr)
2189 {
2190 messages::internalError(asyncResp->res);
2191 return;
2192 }
2193
Ed Tanous2b9c1df2024-04-06 13:52:01 -07002194 bool userSelf = (username == req.session->username);
2195
Ed Tanous1ef4c342022-05-12 16:12:36 -07002196 Privileges effectiveUserPrivileges =
Ninad Palsule3e72c202023-03-27 17:19:55 -05002197 redfish::getUserPrivileges(*req.session);
Ed Tanous1ef4c342022-05-12 16:12:36 -07002198 Privileges configureUsers = {"ConfigureUsers"};
2199 bool userHasConfigureUsers =
2200 effectiveUserPrivileges.isSupersetOf(configureUsers);
2201 if (userHasConfigureUsers)
2202 {
2203 // Users with ConfigureUsers can modify for all users
Abhishek Patel58345852022-02-02 08:54:25 -06002204 if (!json_util::readJsonPatch(
2205 req, asyncResp->res, "UserName", newUserName, "Password",
2206 password, "RoleId", roleId, "Enabled", enabled, "Locked",
2207 locked, "AccountTypes", accountTypes))
Ed Tanous1ef4c342022-05-12 16:12:36 -07002208 {
2209 return;
2210 }
2211 }
2212 else
2213 {
2214 // ConfigureSelf accounts can only modify their own account
Abhishek Patel58345852022-02-02 08:54:25 -06002215 if (!userSelf)
Ed Tanous1ef4c342022-05-12 16:12:36 -07002216 {
2217 messages::insufficientPrivilege(asyncResp->res);
2218 return;
2219 }
2220
2221 // ConfigureSelf accounts can only modify their password
2222 if (!json_util::readJsonPatch(req, asyncResp->res, "Password",
2223 password))
2224 {
2225 return;
2226 }
2227 }
2228
2229 // if user name is not provided in the patch method or if it
2230 // matches the user name in the URI, then we are treating it as
2231 // updating user properties other then username. If username
2232 // provided doesn't match the URI, then we are treating this as
2233 // user rename request.
2234 if (!newUserName || (newUserName.value() == username))
2235 {
2236 updateUserProperties(asyncResp, username, password, enabled, roleId,
Ravi Tejae518ef32024-05-16 10:33:08 -05002237 locked, accountTypes, userSelf, req.session);
Ed Tanous1ef4c342022-05-12 16:12:36 -07002238 return;
2239 }
2240 crow::connections::systemBus->async_method_call(
2241 [asyncResp, username, password(std::move(password)),
2242 roleId(std::move(roleId)), enabled, newUser{std::string(*newUserName)},
Ravi Tejae518ef32024-05-16 10:33:08 -05002243 locked, userSelf, req, accountTypes(std::move(accountTypes))](
Ed Tanouse81de512023-06-27 17:07:00 -07002244 const boost::system::error_code& ec, sdbusplus::message_t& m) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002245 if (ec)
2246 {
2247 userErrorMessageHandler(m.get_error(), asyncResp, newUser,
2248 username);
2249 return;
2250 }
Ed Tanous1ef4c342022-05-12 16:12:36 -07002251
Patrick Williamsbd79bce2024-08-16 15:22:20 -04002252 updateUserProperties(asyncResp, newUser, password, enabled, roleId,
2253 locked, accountTypes, userSelf, req.session);
2254 },
Ed Tanous1ef4c342022-05-12 16:12:36 -07002255 "xyz.openbmc_project.User.Manager", "/xyz/openbmc_project/user",
2256 "xyz.openbmc_project.User.Manager", "RenameUser", username,
2257 *newUserName);
2258}
2259
Ed Tanous6c51eab2021-06-03 12:30:29 -07002260inline void requestAccountServiceRoutes(App& app)
Ed Tanousb9b2e0b2018-09-13 13:47:50 -07002261{
Ed Tanous6c51eab2021-06-03 12:30:29 -07002262 BMCWEB_ROUTE(app, "/redfish/v1/AccountService/")
Ed Tanous4c7d4d32022-07-07 15:29:35 -07002263 .privileges(redfish::privileges::headAccountService)
2264 .methods(boost::beast::http::verb::head)(
2265 std::bind_front(handleAccountServiceHead, std::ref(app)));
2266
2267 BMCWEB_ROUTE(app, "/redfish/v1/AccountService/")
Ed Tanoused398212021-06-09 17:05:54 -07002268 .privileges(redfish::privileges::getAccountService)
Ed Tanous002d39b2022-05-31 08:59:27 -07002269 .methods(boost::beast::http::verb::get)(
Ed Tanous1ef4c342022-05-12 16:12:36 -07002270 std::bind_front(handleAccountServiceGet, std::ref(app)));
Ed Tanous6c51eab2021-06-03 12:30:29 -07002271
Ed Tanousf5ffd802021-07-19 10:55:33 -07002272 BMCWEB_ROUTE(app, "/redfish/v1/AccountService/")
Gunnar Mills1ec43ee2022-01-04 15:39:52 -06002273 .privileges(redfish::privileges::patchAccountService)
Ed Tanousf5ffd802021-07-19 10:55:33 -07002274 .methods(boost::beast::http::verb::patch)(
Ed Tanous1ef4c342022-05-12 16:12:36 -07002275 std::bind_front(handleAccountServicePatch, std::ref(app)));
Ed Tanousf5ffd802021-07-19 10:55:33 -07002276
Ed Tanous1aa375b2024-04-13 11:51:10 -07002277 BMCWEB_ROUTE(
2278 app,
2279 "/redfish/v1/AccountService/MultiFactorAuth/ClientCertificate/Certificates")
2280 .privileges(redfish::privileges::headCertificateCollection)
2281 .methods(boost::beast::http::verb::head)(std::bind_front(
2282 handleAccountServiceClientCertificatesHead, std::ref(app)));
2283
2284 BMCWEB_ROUTE(
2285 app,
2286 "/redfish/v1/AccountService/MultiFactorAuth/ClientCertificate/Certificates")
2287 .privileges(redfish::privileges::getCertificateCollection)
2288 .methods(boost::beast::http::verb::get)(std::bind_front(
2289 handleAccountServiceClientCertificatesGet, std::ref(app)));
2290
2291 BMCWEB_ROUTE(
2292 app,
2293 "/redfish/v1/AccountService/MultiFactorAuth/ClientCertificate/Certificates/<str>")
2294 .privileges(redfish::privileges::headCertificate)
2295 .methods(boost::beast::http::verb::head)(std::bind_front(
2296 handleAccountServiceClientCertificatesInstanceHead, std::ref(app)));
2297
2298 BMCWEB_ROUTE(
2299 app,
2300 "/redfish/v1/AccountService/MultiFactorAuth/ClientCertificate/Certificates/<str>/")
2301 .privileges(redfish::privileges::getCertificate)
2302 .methods(boost::beast::http::verb::get)(std::bind_front(
2303 handleAccountServiceClientCertificatesInstanceGet, std::ref(app)));
2304
Ed Tanous6c51eab2021-06-03 12:30:29 -07002305 BMCWEB_ROUTE(app, "/redfish/v1/AccountService/Accounts/")
Ed Tanous4c7d4d32022-07-07 15:29:35 -07002306 .privileges(redfish::privileges::headManagerAccountCollection)
2307 .methods(boost::beast::http::verb::head)(
2308 std::bind_front(handleAccountCollectionHead, std::ref(app)));
2309
2310 BMCWEB_ROUTE(app, "/redfish/v1/AccountService/Accounts/")
Ed Tanoused398212021-06-09 17:05:54 -07002311 .privileges(redfish::privileges::getManagerAccountCollection)
Ed Tanous6c51eab2021-06-03 12:30:29 -07002312 .methods(boost::beast::http::verb::get)(
Ed Tanous1ef4c342022-05-12 16:12:36 -07002313 std::bind_front(handleAccountCollectionGet, std::ref(app)));
Ed Tanous06e086d2018-09-19 17:19:52 -07002314
Ed Tanous6c51eab2021-06-03 12:30:29 -07002315 BMCWEB_ROUTE(app, "/redfish/v1/AccountService/Accounts/")
Ed Tanoused398212021-06-09 17:05:54 -07002316 .privileges(redfish::privileges::postManagerAccountCollection)
Ed Tanous002d39b2022-05-31 08:59:27 -07002317 .methods(boost::beast::http::verb::post)(
Ed Tanous1ef4c342022-05-12 16:12:36 -07002318 std::bind_front(handleAccountCollectionPost, std::ref(app)));
Ed Tanous002d39b2022-05-31 08:59:27 -07002319
2320 BMCWEB_ROUTE(app, "/redfish/v1/AccountService/Accounts/<str>/")
Ed Tanous4c7d4d32022-07-07 15:29:35 -07002321 .privileges(redfish::privileges::headManagerAccount)
2322 .methods(boost::beast::http::verb::head)(
2323 std::bind_front(handleAccountHead, std::ref(app)));
2324
2325 BMCWEB_ROUTE(app, "/redfish/v1/AccountService/Accounts/<str>/")
Ed Tanous002d39b2022-05-31 08:59:27 -07002326 .privileges(redfish::privileges::getManagerAccount)
2327 .methods(boost::beast::http::verb::get)(
Ed Tanous1ef4c342022-05-12 16:12:36 -07002328 std::bind_front(handleAccountGet, std::ref(app)));
Ed Tanous6c51eab2021-06-03 12:30:29 -07002329
2330 BMCWEB_ROUTE(app, "/redfish/v1/AccountService/Accounts/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07002331 // TODO this privilege should be using the generated endpoints, but
2332 // because of the special handling of ConfigureSelf, it's not able to
2333 // yet
Ed Tanous6c51eab2021-06-03 12:30:29 -07002334 .privileges({{"ConfigureUsers"}, {"ConfigureSelf"}})
2335 .methods(boost::beast::http::verb::patch)(
Ed Tanous1ef4c342022-05-12 16:12:36 -07002336 std::bind_front(handleAccountPatch, std::ref(app)));
Ed Tanous6c51eab2021-06-03 12:30:29 -07002337
2338 BMCWEB_ROUTE(app, "/redfish/v1/AccountService/Accounts/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07002339 .privileges(redfish::privileges::deleteManagerAccount)
Ed Tanous6c51eab2021-06-03 12:30:29 -07002340 .methods(boost::beast::http::verb::delete_)(
Gunnar Mills20fc3072023-01-27 15:13:36 -06002341 std::bind_front(handleAccountDelete, std::ref(app)));
Ed Tanous6c51eab2021-06-03 12:30:29 -07002342}
Lewanczyk, Dawid88d16c92018-02-02 14:51:09 +01002343
Ed Tanous1abe55e2018-09-05 08:30:59 -07002344} // namespace redfish