blob: a0725e6f7e5173a24c5f6eab9f2481b9ab339bdf [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 */
179inline bool
180 getUserGroupFromAccountType(crow::Response& res,
181 const std::vector<std::string>& accountTypes,
182 std::vector<std::string>& userGroups)
183{
184 // Need both Redfish and WebUI Account Types to map to 'redfish' User Group
185 bool redfishType = false;
186 bool webUIType = false;
187
188 for (const auto& accountType : accountTypes)
189 {
190 if (accountType == "Redfish")
191 {
192 redfishType = true;
193 }
194 else if (accountType == "WebUI")
195 {
196 webUIType = true;
197 }
198 else if (accountType == "IPMI")
199 {
200 userGroups.emplace_back("ipmi");
201 }
202 else if (accountType == "HostConsole")
203 {
204 userGroups.emplace_back("hostconsole");
205 }
206 else if (accountType == "ManagerConsole")
207 {
208 userGroups.emplace_back("ssh");
209 }
210 else
211 {
212 // Invalid Account Type
213 messages::propertyValueNotInList(res, "AccountTypes", accountType);
214 return false;
215 }
216 }
217
218 // Both Redfish and WebUI Account Types are needed to PATCH
219 if (redfishType ^ webUIType)
220 {
Ed Tanous62598e32023-07-17 17:06:25 -0700221 BMCWEB_LOG_ERROR(
222 "Missing Redfish or WebUI Account Type to set redfish User Group");
Abhishek Patel58345852022-02-02 08:54:25 -0600223 messages::strictAccountTypes(res, "AccountTypes");
224 return false;
225 }
226
227 if (redfishType && webUIType)
228 {
229 userGroups.emplace_back("redfish");
230 }
231
232 return true;
233}
234
235/**
236 * @brief Sets UserGroups property of the user based on the Account Types
237 *
238 * @param[in] accountTypes List of User Account Types
239 * @param[in] asyncResp Async Response
240 * @param[in] dbusObjectPath D-Bus Object Path
241 * @param[in] userSelf true if User is updating OWN Account Types
242 */
243inline void
244 patchAccountTypes(const std::vector<std::string>& accountTypes,
245 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
246 const std::string& dbusObjectPath, bool userSelf)
247{
248 // Check if User is disabling own Redfish Account Type
249 if (userSelf &&
250 (accountTypes.cend() ==
251 std::find(accountTypes.cbegin(), accountTypes.cend(), "Redfish")))
252 {
Ed Tanous62598e32023-07-17 17:06:25 -0700253 BMCWEB_LOG_ERROR(
254 "User disabling OWN Redfish Account Type is not allowed");
Abhishek Patel58345852022-02-02 08:54:25 -0600255 messages::strictAccountTypes(asyncResp->res, "AccountTypes");
256 return;
257 }
258
259 std::vector<std::string> updatedUserGroups;
260 if (!getUserGroupFromAccountType(asyncResp->res, accountTypes,
261 updatedUserGroups))
262 {
263 // Problem in mapping Account Types to User Groups, Error already
264 // logged.
265 return;
266 }
Ginu Georgee93abac2024-06-14 17:35:27 +0530267 setDbusProperty(asyncResp, "AccountTypes",
268 "xyz.openbmc_project.User.Manager", dbusObjectPath,
269 "xyz.openbmc_project.User.Attributes", "UserGroups",
270 updatedUserGroups);
Abhishek Patel58345852022-02-02 08:54:25 -0600271}
272
zhanghch058d1b46d2021-04-01 11:18:24 +0800273inline void userErrorMessageHandler(
274 const sd_bus_error* e, const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
275 const std::string& newUser, const std::string& username)
jayaprakash Mutyala66b5ca72019-08-07 20:26:37 +0000276{
jayaprakash Mutyala66b5ca72019-08-07 20:26:37 +0000277 if (e == nullptr)
278 {
279 messages::internalError(asyncResp->res);
280 return;
281 }
282
Manojkiran Eda055806b2020-11-03 09:36:28 +0530283 const char* errorMessage = e->name;
jayaprakash Mutyala66b5ca72019-08-07 20:26:37 +0000284 if (strcmp(errorMessage,
285 "xyz.openbmc_project.User.Common.Error.UserNameExists") == 0)
286 {
Jiaqing Zhaod8a5d5d2022-08-05 16:21:51 +0800287 messages::resourceAlreadyExists(asyncResp->res, "ManagerAccount",
jayaprakash Mutyala66b5ca72019-08-07 20:26:37 +0000288 "UserName", newUser);
289 }
290 else if (strcmp(errorMessage, "xyz.openbmc_project.User.Common.Error."
291 "UserNameDoesNotExist") == 0)
292 {
Jiaqing Zhaod8a5d5d2022-08-05 16:21:51 +0800293 messages::resourceNotFound(asyncResp->res, "ManagerAccount", username);
jayaprakash Mutyala66b5ca72019-08-07 20:26:37 +0000294 }
Ed Tanousd4d25792020-09-29 15:15:03 -0700295 else if ((strcmp(errorMessage,
296 "xyz.openbmc_project.Common.Error.InvalidArgument") ==
297 0) ||
George Liu0fda0f12021-11-16 10:06:17 +0800298 (strcmp(
299 errorMessage,
300 "xyz.openbmc_project.User.Common.Error.UserNameGroupFail") ==
301 0))
jayaprakash Mutyala66b5ca72019-08-07 20:26:37 +0000302 {
303 messages::propertyValueFormatError(asyncResp->res, newUser, "UserName");
304 }
305 else if (strcmp(errorMessage,
306 "xyz.openbmc_project.User.Common.Error.NoResource") == 0)
307 {
308 messages::createLimitReachedForResource(asyncResp->res);
309 }
jayaprakash Mutyala66b5ca72019-08-07 20:26:37 +0000310 else
311 {
Gunnar Millsb8ad5832023-10-02 16:26:07 -0500312 BMCWEB_LOG_ERROR("DBUS response error {}", errorMessage);
jayaprakash Mutyala66b5ca72019-08-07 20:26:37 +0000313 messages::internalError(asyncResp->res);
314 }
jayaprakash Mutyala66b5ca72019-08-07 20:26:37 +0000315}
316
Ed Tanous81ce6092020-12-17 16:54:55 +0000317inline void parseLDAPConfigData(nlohmann::json& jsonResponse,
Ed Tanous23a21a12020-07-25 04:45:05 +0000318 const LDAPConfigData& confData,
319 const std::string& ldapType)
Ratan Gupta6973a582018-12-13 18:25:44 +0530320{
Ed Tanous49cc2632024-03-20 12:49:15 -0700321 nlohmann::json::object_t ldap;
Ed Tanous14766872022-03-15 10:44:42 -0700322 ldap["ServiceEnabled"] = confData.serviceEnabled;
Ed Tanous49cc2632024-03-20 12:49:15 -0700323 nlohmann::json::array_t serviceAddresses;
324 serviceAddresses.emplace_back(confData.uri);
325 ldap["ServiceAddresses"] = std::move(serviceAddresses);
326
327 nlohmann::json::object_t authentication;
328 authentication["AuthenticationType"] =
Ed Tanous0ec8b832022-03-14 14:56:47 -0700329 account_service::AuthenticationTypes::UsernameAndPassword;
Ed Tanous49cc2632024-03-20 12:49:15 -0700330 authentication["Username"] = confData.bindDN;
331 authentication["Password"] = nullptr;
332 ldap["Authentication"] = std::move(authentication);
Ed Tanous14766872022-03-15 10:44:42 -0700333
Ed Tanous49cc2632024-03-20 12:49:15 -0700334 nlohmann::json::object_t ldapService;
335 nlohmann::json::object_t searchSettings;
336 nlohmann::json::array_t baseDistinguishedNames;
337 baseDistinguishedNames.emplace_back(confData.baseDN);
Ed Tanous14766872022-03-15 10:44:42 -0700338
Ed Tanous49cc2632024-03-20 12:49:15 -0700339 searchSettings["BaseDistinguishedNames"] =
340 std::move(baseDistinguishedNames);
341 searchSettings["UsernameAttribute"] = confData.userNameAttribute;
342 searchSettings["GroupsAttribute"] = confData.groupAttribute;
343 ldapService["SearchSettings"] = std::move(searchSettings);
344 ldap["LDAPService"] = std::move(ldapService);
345
346 nlohmann::json::array_t roleMapArray;
Ed Tanous9eb808c2022-01-25 10:19:23 -0800347 for (const auto& obj : confData.groupRoleList)
Nagaraju Goruganti54fc5872019-01-30 05:11:00 -0600348 {
Ed Tanous62598e32023-07-17 17:06:25 -0700349 BMCWEB_LOG_DEBUG("Pushing the data groupName={}", obj.second.groupName);
Ed Tanous613dabe2022-07-09 11:17:36 -0700350
Ed Tanous613dabe2022-07-09 11:17:36 -0700351 nlohmann::json::object_t remoteGroup;
352 remoteGroup["RemoteGroup"] = obj.second.groupName;
Jorge Cisneros329f0342022-11-04 16:26:25 +0000353 remoteGroup["LocalRole"] = getRoleIdFromPrivilege(obj.second.privilege);
354 roleMapArray.emplace_back(std::move(remoteGroup));
Nagaraju Goruganti54fc5872019-01-30 05:11:00 -0600355 }
Ed Tanous49cc2632024-03-20 12:49:15 -0700356
357 ldap["RemoteRoleMapping"] = std::move(roleMapArray);
358
359 jsonResponse[ldapType].update(ldap);
Ratan Gupta6973a582018-12-13 18:25:44 +0530360}
361
362/**
Ratan Gupta06785242019-07-26 22:30:16 +0530363 * @brief validates given JSON input and then calls appropriate method to
364 * create, to delete or to set Rolemapping object based on the given input.
365 *
366 */
Ed Tanous23a21a12020-07-25 04:45:05 +0000367inline void handleRoleMapPatch(
zhanghch058d1b46d2021-04-01 11:18:24 +0800368 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ratan Gupta06785242019-07-26 22:30:16 +0530369 const std::vector<std::pair<std::string, LDAPRoleMapData>>& roleMapObjData,
Ed Tanousc1019822024-03-06 12:54:38 -0800370 const std::string& serverType,
371 std::vector<std::variant<nlohmann::json::object_t, std::nullptr_t>>& input)
Ratan Gupta06785242019-07-26 22:30:16 +0530372{
373 for (size_t index = 0; index < input.size(); index++)
374 {
Ed Tanousc1019822024-03-06 12:54:38 -0800375 std::variant<nlohmann::json::object_t, std::nullptr_t>& thisJson =
376 input[index];
377 nlohmann::json::object_t* obj =
378 std::get_if<nlohmann::json::object_t>(&thisJson);
379 if (obj == nullptr)
Ratan Gupta06785242019-07-26 22:30:16 +0530380 {
381 // delete the existing object
382 if (index < roleMapObjData.size())
383 {
384 crow::connections::systemBus->async_method_call(
385 [asyncResp, roleMapObjData, serverType,
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800386 index](const boost::system::error_code& ec) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700387 if (ec)
388 {
Ed Tanous62598e32023-07-17 17:06:25 -0700389 BMCWEB_LOG_ERROR("DBUS response error: {}", ec);
Ed Tanous002d39b2022-05-31 08:59:27 -0700390 messages::internalError(asyncResp->res);
391 return;
392 }
Patrick Williams89492a12023-05-10 07:51:34 -0500393 asyncResp->res.jsonValue[serverType]["RemoteRoleMapping"]
394 [index] = nullptr;
Patrick Williams5a39f772023-10-20 11:20:21 -0500395 },
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");
Ed Tanousc1019822024-03-06 12:54:38 -0800402 messages::propertyValueTypeError(asyncResp->res, "null",
Ed Tanous2e8c4bd2022-06-27 12:59:12 -0700403 "RemoteRoleMapping/" +
404 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 {
Ed Tanousd02aad32024-02-13 14:43:34 -0800443 setDbusProperty(
Ginu Georgee93abac2024-06-14 17:35:27 +0530444 asyncResp,
Ed Tanousd02aad32024-02-13 14:43:34 -0800445 std::format("RemoteRoleMapping/{}/LocalRole", index),
Ginu Georgee93abac2024-06-14 17:35:27 +0530446 ldapDbusService, roleMapObjData[index].first,
447 "xyz.openbmc_project.User.PrivilegeMapperEntry",
448 "Privilege", *localRole);
Ratan Gupta06785242019-07-26 22:30:16 +0530449 }
450 }
451 // Create a new RoleMapping Object.
452 else
453 {
Ed Tanous62598e32023-07-17 17:06:25 -0700454 BMCWEB_LOG_DEBUG(
455 "setRoleMappingProperties: Creating new Object");
Patrick Williams89492a12023-05-10 07:51:34 -0500456 std::string pathString = "RemoteRoleMapping/" +
457 std::to_string(index);
Ratan Gupta06785242019-07-26 22:30:16 +0530458
459 if (!localRole)
460 {
461 messages::propertyMissing(asyncResp->res,
462 pathString + "/LocalRole");
463 continue;
464 }
465 if (!remoteGroup)
466 {
467 messages::propertyMissing(asyncResp->res,
468 pathString + "/RemoteGroup");
469 continue;
470 }
471
472 std::string dbusObjectPath;
473 if (serverType == "ActiveDirectory")
474 {
Ed Tanous2c70f802020-09-28 14:29:23 -0700475 dbusObjectPath = adConfigObject;
Ratan Gupta06785242019-07-26 22:30:16 +0530476 }
477 else if (serverType == "LDAP")
478 {
Ed Tanous23a21a12020-07-25 04:45:05 +0000479 dbusObjectPath = ldapConfigObjectName;
Ratan Gupta06785242019-07-26 22:30:16 +0530480 }
481
Ed Tanous62598e32023-07-17 17:06:25 -0700482 BMCWEB_LOG_DEBUG("Remote Group={},LocalRole={}", *remoteGroup,
483 *localRole);
Ratan Gupta06785242019-07-26 22:30:16 +0530484
485 crow::connections::systemBus->async_method_call(
Ed Tanous271584a2019-07-09 16:24:22 -0700486 [asyncResp, serverType, localRole,
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800487 remoteGroup](const boost::system::error_code& ec) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700488 if (ec)
489 {
Ed Tanous62598e32023-07-17 17:06:25 -0700490 BMCWEB_LOG_ERROR("DBUS response error: {}", ec);
Ed Tanous002d39b2022-05-31 08:59:27 -0700491 messages::internalError(asyncResp->res);
492 return;
493 }
494 nlohmann::json& remoteRoleJson =
495 asyncResp->res
496 .jsonValue[serverType]["RemoteRoleMapping"];
497 nlohmann::json::object_t roleMapEntry;
498 roleMapEntry["LocalRole"] = *localRole;
499 roleMapEntry["RemoteGroup"] = *remoteGroup;
Patrick Williamsb2ba3072023-05-12 10:27:39 -0500500 remoteRoleJson.emplace_back(std::move(roleMapEntry));
Patrick Williams5a39f772023-10-20 11:20:21 -0500501 },
Ratan Gupta06785242019-07-26 22:30:16 +0530502 ldapDbusService, dbusObjectPath, ldapPrivMapperInterface,
Ed Tanous3174e4d2020-10-07 11:41:22 -0700503 "Create", *remoteGroup,
Ratan Gupta06785242019-07-26 22:30:16 +0530504 getPrivilegeFromRoleId(std::move(*localRole)));
505 }
506 }
507 }
508}
509
510/**
Ratan Gupta6973a582018-12-13 18:25:44 +0530511 * Function that retrieves all properties for LDAP config object
512 * into JSON
513 */
514template <typename CallbackFunc>
515inline void getLDAPConfigData(const std::string& ldapType,
516 CallbackFunc&& callback)
517{
George Liu2b731192023-01-11 16:27:13 +0800518 constexpr std::array<std::string_view, 2> interfaces = {
519 ldapEnableInterface, ldapConfigInterface};
Ratan Gupta6973a582018-12-13 18:25:44 +0530520
George Liu2b731192023-01-11 16:27:13 +0800521 dbus::utility::getDbusObject(
522 ldapConfigObjectName, interfaces,
Ed Tanous8cb2c022024-03-27 16:31:46 -0700523 [callback = std::forward<CallbackFunc>(callback),
Ed Tanousc1019822024-03-06 12:54:38 -0800524 ldapType](const boost::system::error_code& ec,
525 const dbus::utility::MapperGetObject& resp) mutable {
Ed Tanous002d39b2022-05-31 08:59:27 -0700526 if (ec || resp.empty())
527 {
Carson Labradobf2dded2023-08-10 00:37:06 +0000528 BMCWEB_LOG_WARNING(
Ed Tanous62598e32023-07-17 17:06:25 -0700529 "DBUS response error during getting of service name: {}", ec);
Ed Tanous002d39b2022-05-31 08:59:27 -0700530 LDAPConfigData empty{};
531 callback(false, empty, ldapType);
532 return;
533 }
534 std::string service = resp.begin()->first;
George Liu5eb468d2023-06-20 17:03:24 +0800535 sdbusplus::message::object_path path(ldapRootObject);
536 dbus::utility::getManagedObjects(
537 service, path,
Ed Tanousc1019822024-03-06 12:54:38 -0800538 [callback, ldapType](
539 const boost::system::error_code& ec2,
540 const dbus::utility::ManagedObjectType& ldapObjects) mutable {
Ed Tanous002d39b2022-05-31 08:59:27 -0700541 LDAPConfigData confData{};
Ed Tanous8b242752023-06-27 17:17:13 -0700542 if (ec2)
Nagaraju Goruganti54fc5872019-01-30 05:11:00 -0600543 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700544 callback(false, confData, ldapType);
Carson Labradobf2dded2023-08-10 00:37:06 +0000545 BMCWEB_LOG_WARNING("D-Bus responses error: {}", ec2);
Nagaraju Goruganti54fc5872019-01-30 05:11:00 -0600546 return;
547 }
Nagaraju Goruganti54fc5872019-01-30 05:11:00 -0600548
Ed Tanous002d39b2022-05-31 08:59:27 -0700549 std::string ldapDbusType;
550 std::string searchString;
Nagaraju Goruganti54fc5872019-01-30 05:11:00 -0600551
Ed Tanous002d39b2022-05-31 08:59:27 -0700552 if (ldapType == "LDAP")
553 {
554 ldapDbusType =
555 "xyz.openbmc_project.User.Ldap.Config.Type.OpenLdap";
556 searchString = "openldap";
557 }
558 else if (ldapType == "ActiveDirectory")
559 {
560 ldapDbusType =
561 "xyz.openbmc_project.User.Ldap.Config.Type.ActiveDirectory";
562 searchString = "active_directory";
563 }
564 else
565 {
Ed Tanous62598e32023-07-17 17:06:25 -0700566 BMCWEB_LOG_ERROR("Can't get the DbusType for the given type={}",
567 ldapType);
Ed Tanous002d39b2022-05-31 08:59:27 -0700568 callback(false, confData, ldapType);
569 return;
570 }
Nagaraju Goruganti54fc5872019-01-30 05:11:00 -0600571
Ed Tanous002d39b2022-05-31 08:59:27 -0700572 std::string ldapEnableInterfaceStr = ldapEnableInterface;
573 std::string ldapConfigInterfaceStr = ldapConfigInterface;
Nagaraju Goruganti54fc5872019-01-30 05:11:00 -0600574
Ed Tanous002d39b2022-05-31 08:59:27 -0700575 for (const auto& object : ldapObjects)
576 {
577 // let's find the object whose ldap type is equal to the
578 // given type
579 if (object.first.str.find(searchString) == std::string::npos)
580 {
581 continue;
582 }
583
584 for (const auto& interface : object.second)
585 {
586 if (interface.first == ldapEnableInterfaceStr)
Nagaraju Goruganti54fc5872019-01-30 05:11:00 -0600587 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700588 // rest of the properties are string.
589 for (const auto& property : interface.second)
Nagaraju Goruganti54fc5872019-01-30 05:11:00 -0600590 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700591 if (property.first == "Enabled")
Nagaraju Goruganti54fc5872019-01-30 05:11:00 -0600592 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700593 const bool* value =
594 std::get_if<bool>(&property.second);
595 if (value == nullptr)
Nagaraju Goruganti54fc5872019-01-30 05:11:00 -0600596 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700597 continue;
Nagaraju Goruganti54fc5872019-01-30 05:11:00 -0600598 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700599 confData.serviceEnabled = *value;
600 break;
Nagaraju Goruganti54fc5872019-01-30 05:11:00 -0600601 }
602 }
603 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700604 else if (interface.first == ldapConfigInterfaceStr)
605 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700606 for (const auto& property : interface.second)
607 {
608 const std::string* strValue =
609 std::get_if<std::string>(&property.second);
610 if (strValue == nullptr)
611 {
612 continue;
613 }
614 if (property.first == "LDAPServerURI")
615 {
616 confData.uri = *strValue;
617 }
618 else if (property.first == "LDAPBindDN")
619 {
620 confData.bindDN = *strValue;
621 }
622 else if (property.first == "LDAPBaseDN")
623 {
624 confData.baseDN = *strValue;
625 }
626 else if (property.first == "LDAPSearchScope")
627 {
628 confData.searchScope = *strValue;
629 }
630 else if (property.first == "GroupNameAttribute")
631 {
632 confData.groupAttribute = *strValue;
633 }
634 else if (property.first == "UserNameAttribute")
635 {
636 confData.userNameAttribute = *strValue;
637 }
638 else if (property.first == "LDAPType")
639 {
640 confData.serverType = *strValue;
641 }
642 }
643 }
644 else if (interface.first ==
645 "xyz.openbmc_project.User.PrivilegeMapperEntry")
646 {
647 LDAPRoleMapData roleMapData{};
648 for (const auto& property : interface.second)
649 {
650 const std::string* strValue =
651 std::get_if<std::string>(&property.second);
652
653 if (strValue == nullptr)
654 {
655 continue;
656 }
657
658 if (property.first == "GroupName")
659 {
660 roleMapData.groupName = *strValue;
661 }
662 else if (property.first == "Privilege")
663 {
664 roleMapData.privilege = *strValue;
665 }
666 }
667
668 confData.groupRoleList.emplace_back(object.first.str,
669 roleMapData);
670 }
671 }
672 }
673 callback(true, confData, ldapType);
George Liu2b731192023-01-11 16:27:13 +0800674 });
Patrick Williams5a39f772023-10-20 11:20:21 -0500675 });
Ratan Gupta6973a582018-12-13 18:25:44 +0530676}
677
Ed Tanous6c51eab2021-06-03 12:30:29 -0700678/**
Ed Tanous6c51eab2021-06-03 12:30:29 -0700679 * @brief updates the LDAP server address and updates the
680 json response with the new value.
681 * @param serviceAddressList address to be updated.
682 * @param asyncResp pointer to the JSON response
683 * @param ldapServerElementName Type of LDAP
684 server(openLDAP/ActiveDirectory)
685 */
Ratan Gupta8a07d282019-03-16 08:33:47 +0530686
Ed Tanous4f48d5f2021-06-21 08:27:45 -0700687inline void handleServiceAddressPatch(
Ed Tanous6c51eab2021-06-03 12:30:29 -0700688 const std::vector<std::string>& serviceAddressList,
689 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
690 const std::string& ldapServerElementName,
691 const std::string& ldapConfigObject)
692{
Ginu Georgee93abac2024-06-14 17:35:27 +0530693 setDbusProperty(asyncResp, ldapServerElementName + "/ServiceAddress",
694 ldapDbusService, ldapConfigObject, ldapConfigInterface,
695 "LDAPServerURI", serviceAddressList.front());
Ed Tanous6c51eab2021-06-03 12:30:29 -0700696}
697/**
698 * @brief updates the LDAP Bind DN and updates the
699 json response with the new value.
700 * @param username name of the user which needs to be updated.
701 * @param asyncResp pointer to the JSON response
702 * @param ldapServerElementName Type of LDAP
703 server(openLDAP/ActiveDirectory)
704 */
Ratan Gupta8a07d282019-03-16 08:33:47 +0530705
Ed Tanous4f48d5f2021-06-21 08:27:45 -0700706inline void
707 handleUserNamePatch(const std::string& username,
708 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
709 const std::string& ldapServerElementName,
710 const std::string& ldapConfigObject)
Ed Tanous6c51eab2021-06-03 12:30:29 -0700711{
Ginu Georgee93abac2024-06-14 17:35:27 +0530712 setDbusProperty(asyncResp,
Ed Tanousd02aad32024-02-13 14:43:34 -0800713 ldapServerElementName + "/Authentication/Username",
Ginu Georgee93abac2024-06-14 17:35:27 +0530714 ldapDbusService, ldapConfigObject, ldapConfigInterface,
715 "LDAPBindDN", username);
Ed Tanous6c51eab2021-06-03 12:30:29 -0700716}
717
718/**
719 * @brief updates the LDAP password
720 * @param password : ldap password which needs to be updated.
721 * @param asyncResp pointer to the JSON response
722 * @param ldapServerElementName Type of LDAP
723 * server(openLDAP/ActiveDirectory)
724 */
725
Ed Tanous4f48d5f2021-06-21 08:27:45 -0700726inline void
727 handlePasswordPatch(const std::string& password,
728 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
729 const std::string& ldapServerElementName,
730 const std::string& ldapConfigObject)
Ed Tanous6c51eab2021-06-03 12:30:29 -0700731{
Ginu Georgee93abac2024-06-14 17:35:27 +0530732 setDbusProperty(asyncResp,
Ed Tanousd02aad32024-02-13 14:43:34 -0800733 ldapServerElementName + "/Authentication/Password",
Ginu Georgee93abac2024-06-14 17:35:27 +0530734 ldapDbusService, ldapConfigObject, ldapConfigInterface,
735 "LDAPBindDNPassword", password);
Ed Tanous6c51eab2021-06-03 12:30:29 -0700736}
737
738/**
739 * @brief updates the LDAP BaseDN and updates the
740 json response with the new value.
741 * @param baseDNList baseDN list which needs to be updated.
742 * @param asyncResp pointer to the JSON response
743 * @param ldapServerElementName Type of LDAP
744 server(openLDAP/ActiveDirectory)
745 */
746
Ed Tanous4f48d5f2021-06-21 08:27:45 -0700747inline void
748 handleBaseDNPatch(const std::vector<std::string>& baseDNList,
749 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
750 const std::string& ldapServerElementName,
751 const std::string& ldapConfigObject)
Ed Tanous6c51eab2021-06-03 12:30:29 -0700752{
Ginu Georgee93abac2024-06-14 17:35:27 +0530753 setDbusProperty(asyncResp,
Ed Tanousd02aad32024-02-13 14:43:34 -0800754 ldapServerElementName +
755 "/LDAPService/SearchSettings/BaseDistinguishedNames",
Ginu Georgee93abac2024-06-14 17:35:27 +0530756 ldapDbusService, ldapConfigObject, ldapConfigInterface,
757 "LDAPBaseDN", baseDNList.front());
Ed Tanous6c51eab2021-06-03 12:30:29 -0700758}
759/**
760 * @brief updates the LDAP user name attribute and updates the
761 json response with the new value.
762 * @param userNameAttribute attribute to be updated.
763 * @param asyncResp pointer to the JSON response
764 * @param ldapServerElementName Type of LDAP
765 server(openLDAP/ActiveDirectory)
766 */
767
Ed Tanous4f48d5f2021-06-21 08:27:45 -0700768inline void
769 handleUserNameAttrPatch(const std::string& userNameAttribute,
770 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
771 const std::string& ldapServerElementName,
772 const std::string& ldapConfigObject)
Ed Tanous6c51eab2021-06-03 12:30:29 -0700773{
Ginu Georgee93abac2024-06-14 17:35:27 +0530774 setDbusProperty(asyncResp,
Ed Tanousd02aad32024-02-13 14:43:34 -0800775 ldapServerElementName +
776 "LDAPService/SearchSettings/UsernameAttribute",
Ginu Georgee93abac2024-06-14 17:35:27 +0530777 ldapDbusService, ldapConfigObject, ldapConfigInterface,
778 "UserNameAttribute", userNameAttribute);
Ed Tanous6c51eab2021-06-03 12:30:29 -0700779}
780/**
781 * @brief updates the LDAP group attribute and updates the
782 json response with the new value.
783 * @param groupsAttribute attribute to be updated.
784 * @param asyncResp pointer to the JSON response
785 * @param ldapServerElementName Type of LDAP
786 server(openLDAP/ActiveDirectory)
787 */
788
Ed Tanous4f48d5f2021-06-21 08:27:45 -0700789inline void handleGroupNameAttrPatch(
Ed Tanous6c51eab2021-06-03 12:30:29 -0700790 const std::string& groupsAttribute,
791 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
792 const std::string& ldapServerElementName,
793 const std::string& ldapConfigObject)
794{
Ginu Georgee93abac2024-06-14 17:35:27 +0530795 setDbusProperty(asyncResp,
Ed Tanousd02aad32024-02-13 14:43:34 -0800796 ldapServerElementName +
797 "/LDAPService/SearchSettings/GroupsAttribute",
Ginu Georgee93abac2024-06-14 17:35:27 +0530798 ldapDbusService, ldapConfigObject, ldapConfigInterface,
799 "GroupNameAttribute", groupsAttribute);
Ed Tanous6c51eab2021-06-03 12:30:29 -0700800}
801/**
802 * @brief updates the LDAP service enable and updates the
803 json response with the new value.
804 * @param input JSON data.
805 * @param asyncResp pointer to the JSON response
806 * @param ldapServerElementName Type of LDAP
807 server(openLDAP/ActiveDirectory)
808 */
809
Ed Tanous4f48d5f2021-06-21 08:27:45 -0700810inline void handleServiceEnablePatch(
Ed Tanous6c51eab2021-06-03 12:30:29 -0700811 bool serviceEnabled, const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
812 const std::string& ldapServerElementName,
813 const std::string& ldapConfigObject)
814{
Ginu Georgee93abac2024-06-14 17:35:27 +0530815 setDbusProperty(asyncResp, ldapServerElementName + "/ServiceEnabled",
816 ldapDbusService, ldapConfigObject, ldapEnableInterface,
817 "Enabled", serviceEnabled);
Ed Tanous6c51eab2021-06-03 12:30:29 -0700818}
819
Ed Tanousc1019822024-03-06 12:54:38 -0800820struct AuthMethods
Ed Tanous6c51eab2021-06-03 12:30:29 -0700821{
822 std::optional<bool> basicAuth;
823 std::optional<bool> cookie;
824 std::optional<bool> sessionToken;
825 std::optional<bool> xToken;
826 std::optional<bool> tls;
Ed Tanousc1019822024-03-06 12:54:38 -0800827};
Ed Tanous6c51eab2021-06-03 12:30:29 -0700828
Ed Tanousc1019822024-03-06 12:54:38 -0800829inline void
830 handleAuthMethodsPatch(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
831 const AuthMethods& auth)
832{
833 persistent_data::AuthConfigMethods& authMethodsConfig =
Ed Tanous6c51eab2021-06-03 12:30:29 -0700834 persistent_data::SessionStore::getInstance().getAuthMethodsConfig();
835
Ed Tanousc1019822024-03-06 12:54:38 -0800836 if (auth.basicAuth)
Ed Tanous6c51eab2021-06-03 12:30:29 -0700837 {
Ed Tanous25b54db2024-04-17 15:40:31 -0700838 if constexpr (!BMCWEB_BASIC_AUTH)
839 {
840 messages::actionNotSupported(
841 asyncResp->res,
842 "Setting BasicAuth when basic-auth feature is disabled");
843 return;
844 }
845
Ed Tanousc1019822024-03-06 12:54:38 -0800846 authMethodsConfig.basic = *auth.basicAuth;
Ed Tanous6c51eab2021-06-03 12:30:29 -0700847 }
848
Ed Tanousc1019822024-03-06 12:54:38 -0800849 if (auth.cookie)
Ed Tanous6c51eab2021-06-03 12:30:29 -0700850 {
Ed Tanous25b54db2024-04-17 15:40:31 -0700851 if constexpr (!BMCWEB_COOKIE_AUTH)
852 {
853 messages::actionNotSupported(
854 asyncResp->res,
855 "Setting Cookie when cookie-auth feature is disabled");
856 return;
857 }
Ed Tanousc1019822024-03-06 12:54:38 -0800858 authMethodsConfig.cookie = *auth.cookie;
Ed Tanous6c51eab2021-06-03 12:30:29 -0700859 }
860
Ed Tanousc1019822024-03-06 12:54:38 -0800861 if (auth.sessionToken)
Ed Tanous6c51eab2021-06-03 12:30:29 -0700862 {
Ed Tanous25b54db2024-04-17 15:40:31 -0700863 if constexpr (!BMCWEB_SESSION_AUTH)
864 {
865 messages::actionNotSupported(
866 asyncResp->res,
867 "Setting SessionToken when session-auth feature is disabled");
868 return;
869 }
Ed Tanousc1019822024-03-06 12:54:38 -0800870 authMethodsConfig.sessionToken = *auth.sessionToken;
Ed Tanous6c51eab2021-06-03 12:30:29 -0700871 }
872
Ed Tanousc1019822024-03-06 12:54:38 -0800873 if (auth.xToken)
Ed Tanous6c51eab2021-06-03 12:30:29 -0700874 {
Ed Tanous25b54db2024-04-17 15:40:31 -0700875 if constexpr (!BMCWEB_XTOKEN_AUTH)
876 {
877 messages::actionNotSupported(
878 asyncResp->res,
879 "Setting XToken when xtoken-auth feature is disabled");
880 return;
881 }
Ed Tanousc1019822024-03-06 12:54:38 -0800882 authMethodsConfig.xtoken = *auth.xToken;
Ed Tanous6c51eab2021-06-03 12:30:29 -0700883 }
884
Ed Tanousc1019822024-03-06 12:54:38 -0800885 if (auth.tls)
Ed Tanous6c51eab2021-06-03 12:30:29 -0700886 {
Ed Tanous25b54db2024-04-17 15:40:31 -0700887 if constexpr (!BMCWEB_MUTUAL_TLS_AUTH)
888 {
889 messages::actionNotSupported(
890 asyncResp->res,
891 "Setting TLS when mutual-tls-auth feature is disabled");
892 return;
893 }
Ed Tanousc1019822024-03-06 12:54:38 -0800894 authMethodsConfig.tls = *auth.tls;
Ed Tanous6c51eab2021-06-03 12:30:29 -0700895 }
896
897 if (!authMethodsConfig.basic && !authMethodsConfig.cookie &&
898 !authMethodsConfig.sessionToken && !authMethodsConfig.xtoken &&
899 !authMethodsConfig.tls)
900 {
901 // Do not allow user to disable everything
902 messages::actionNotSupported(asyncResp->res,
903 "of disabling all available methods");
904 return;
905 }
906
907 persistent_data::SessionStore::getInstance().updateAuthMethodsConfig(
908 authMethodsConfig);
909 // Save configuration immediately
910 persistent_data::getConfig().writeData();
911
912 messages::success(asyncResp->res);
913}
914
915/**
916 * @brief Get the required values from the given JSON, validates the
917 * value and create the LDAP config object.
918 * @param input JSON data
919 * @param asyncResp pointer to the JSON response
920 * @param serverType Type of LDAP server(openLDAP/ActiveDirectory)
921 */
922
Ed Tanous10cb44f2024-04-11 13:05:20 -0700923struct LdapPatchParams
924{
925 std::optional<std::string> authType;
926 std::optional<std::vector<std::string>> serviceAddressList;
927 std::optional<bool> serviceEnabled;
928 std::optional<std::vector<std::string>> baseDNList;
929 std::optional<std::string> userNameAttribute;
930 std::optional<std::string> groupsAttribute;
931 std::optional<std::string> userName;
932 std::optional<std::string> password;
933 std::optional<
934 std::vector<std::variant<nlohmann::json::object_t, std::nullptr_t>>>
935 remoteRoleMapData;
936};
937
938inline void handleLDAPPatch(LdapPatchParams&& input,
Ed Tanous6c51eab2021-06-03 12:30:29 -0700939 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
940 const std::string& serverType)
941{
942 std::string dbusObjectPath;
943 if (serverType == "ActiveDirectory")
944 {
945 dbusObjectPath = adConfigObject;
946 }
947 else if (serverType == "LDAP")
948 {
949 dbusObjectPath = ldapConfigObjectName;
950 }
951 else
952 {
Ed Tanous10cb44f2024-04-11 13:05:20 -0700953 BMCWEB_LOG_ERROR("serverType wasn't AD or LDAP but was {}????",
954 serverType);
Ed Tanous6c51eab2021-06-03 12:30:29 -0700955 return;
956 }
957
Ed Tanous10cb44f2024-04-11 13:05:20 -0700958 if (input.authType && *input.authType != "UsernameAndPassword")
Ed Tanous6c51eab2021-06-03 12:30:29 -0700959 {
Ed Tanous10cb44f2024-04-11 13:05:20 -0700960 messages::propertyValueNotInList(asyncResp->res, *input.authType,
Ed Tanousc1019822024-03-06 12:54:38 -0800961 "AuthenticationType");
962 return;
Ed Tanous6c51eab2021-06-03 12:30:29 -0700963 }
Ed Tanousc1019822024-03-06 12:54:38 -0800964
Ed Tanous10cb44f2024-04-11 13:05:20 -0700965 if (input.serviceAddressList)
Ed Tanous6c51eab2021-06-03 12:30:29 -0700966 {
Ed Tanous10cb44f2024-04-11 13:05:20 -0700967 if (input.serviceAddressList->empty())
Ratan Guptaeb2bbe52019-04-22 14:27:01 +0530968 {
Ed Tanouse2616cc2022-06-27 12:45:55 -0700969 messages::propertyValueNotInList(
Ed Tanous10cb44f2024-04-11 13:05:20 -0700970 asyncResp->res, *input.serviceAddressList, "ServiceAddress");
Ed Tanouscb13a392020-07-25 19:02:03 +0000971 return;
972 }
Ed Tanous6c51eab2021-06-03 12:30:29 -0700973 }
Ed Tanous10cb44f2024-04-11 13:05:20 -0700974 if (input.baseDNList)
Ed Tanous6c51eab2021-06-03 12:30:29 -0700975 {
Ed Tanous10cb44f2024-04-11 13:05:20 -0700976 if (input.baseDNList->empty())
Ratan Gupta8a07d282019-03-16 08:33:47 +0530977 {
Ed Tanous10cb44f2024-04-11 13:05:20 -0700978 messages::propertyValueNotInList(asyncResp->res, *input.baseDNList,
Ed Tanous6c51eab2021-06-03 12:30:29 -0700979 "BaseDistinguishedNames");
Ratan Gupta8a07d282019-03-16 08:33:47 +0530980 return;
981 }
Ed Tanous6c51eab2021-06-03 12:30:29 -0700982 }
Ratan Gupta8a07d282019-03-16 08:33:47 +0530983
Ed Tanous6c51eab2021-06-03 12:30:29 -0700984 // nothing to update, then return
Ed Tanous10cb44f2024-04-11 13:05:20 -0700985 if (!input.userName && !input.password && !input.serviceAddressList &&
986 !input.baseDNList && !input.userNameAttribute &&
987 !input.groupsAttribute && !input.serviceEnabled &&
988 !input.remoteRoleMapData)
Ed Tanous6c51eab2021-06-03 12:30:29 -0700989 {
990 return;
991 }
992
993 // Get the existing resource first then keep modifying
994 // whenever any property gets updated.
Ed Tanous10cb44f2024-04-11 13:05:20 -0700995 getLDAPConfigData(serverType,
996 [asyncResp, input = std::move(input),
997 dbusObjectPath = std::move(dbusObjectPath)](
998 bool success, const LDAPConfigData& confData,
999 const std::string& serverT) mutable {
Ed Tanous6c51eab2021-06-03 12:30:29 -07001000 if (!success)
Ratan Gupta8a07d282019-03-16 08:33:47 +05301001 {
Ed Tanous6c51eab2021-06-03 12:30:29 -07001002 messages::internalError(asyncResp->res);
1003 return;
Ratan Gupta8a07d282019-03-16 08:33:47 +05301004 }
Ed Tanous6c51eab2021-06-03 12:30:29 -07001005 parseLDAPConfigData(asyncResp->res.jsonValue, confData, serverT);
1006 if (confData.serviceEnabled)
Ratan Gupta8a07d282019-03-16 08:33:47 +05301007 {
Ed Tanous6c51eab2021-06-03 12:30:29 -07001008 // Disable the service first and update the rest of
1009 // the properties.
1010 handleServiceEnablePatch(false, asyncResp, serverT, dbusObjectPath);
Ratan Gupta8a07d282019-03-16 08:33:47 +05301011 }
Ed Tanous6c51eab2021-06-03 12:30:29 -07001012
Ed Tanous10cb44f2024-04-11 13:05:20 -07001013 if (input.serviceAddressList)
Ratan Gupta8a07d282019-03-16 08:33:47 +05301014 {
Ed Tanous10cb44f2024-04-11 13:05:20 -07001015 handleServiceAddressPatch(*input.serviceAddressList, asyncResp,
1016 serverT, dbusObjectPath);
Ratan Gupta8a07d282019-03-16 08:33:47 +05301017 }
Ed Tanous10cb44f2024-04-11 13:05:20 -07001018 if (input.userName)
Ed Tanous6c51eab2021-06-03 12:30:29 -07001019 {
Ed Tanous10cb44f2024-04-11 13:05:20 -07001020 handleUserNamePatch(*input.userName, asyncResp, serverT,
1021 dbusObjectPath);
Ed Tanous6c51eab2021-06-03 12:30:29 -07001022 }
Ed Tanous10cb44f2024-04-11 13:05:20 -07001023 if (input.password)
Ed Tanous6c51eab2021-06-03 12:30:29 -07001024 {
Ed Tanous10cb44f2024-04-11 13:05:20 -07001025 handlePasswordPatch(*input.password, asyncResp, serverT,
1026 dbusObjectPath);
Ed Tanous6c51eab2021-06-03 12:30:29 -07001027 }
1028
Ed Tanous10cb44f2024-04-11 13:05:20 -07001029 if (input.baseDNList)
Ratan Gupta8a07d282019-03-16 08:33:47 +05301030 {
Ed Tanous10cb44f2024-04-11 13:05:20 -07001031 handleBaseDNPatch(*input.baseDNList, asyncResp, serverT,
1032 dbusObjectPath);
Ed Tanous6c51eab2021-06-03 12:30:29 -07001033 }
Ed Tanous10cb44f2024-04-11 13:05:20 -07001034 if (input.userNameAttribute)
Ed Tanous6c51eab2021-06-03 12:30:29 -07001035 {
Ed Tanous10cb44f2024-04-11 13:05:20 -07001036 handleUserNameAttrPatch(*input.userNameAttribute, asyncResp,
1037 serverT, dbusObjectPath);
Ed Tanous6c51eab2021-06-03 12:30:29 -07001038 }
Ed Tanous10cb44f2024-04-11 13:05:20 -07001039 if (input.groupsAttribute)
Ed Tanous6c51eab2021-06-03 12:30:29 -07001040 {
Ed Tanous10cb44f2024-04-11 13:05:20 -07001041 handleGroupNameAttrPatch(*input.groupsAttribute, asyncResp, serverT,
Ed Tanous6c51eab2021-06-03 12:30:29 -07001042 dbusObjectPath);
1043 }
Ed Tanous10cb44f2024-04-11 13:05:20 -07001044 if (input.serviceEnabled)
Ed Tanous6c51eab2021-06-03 12:30:29 -07001045 {
1046 // if user has given the value as true then enable
1047 // the service. if user has given false then no-op
1048 // as service is already stopped.
Ed Tanous10cb44f2024-04-11 13:05:20 -07001049 if (*input.serviceEnabled)
Ratan Gupta8a07d282019-03-16 08:33:47 +05301050 {
Ed Tanous10cb44f2024-04-11 13:05:20 -07001051 handleServiceEnablePatch(*input.serviceEnabled, asyncResp,
1052 serverT, dbusObjectPath);
Ratan Gupta8a07d282019-03-16 08:33:47 +05301053 }
1054 }
jayaprakash Mutyala96200602020-04-08 11:09:10 +00001055 else
1056 {
Ed Tanous6c51eab2021-06-03 12:30:29 -07001057 // if user has not given the service enabled value
1058 // then revert it to the same state as it was
1059 // before.
1060 handleServiceEnablePatch(confData.serviceEnabled, asyncResp,
1061 serverT, dbusObjectPath);
jayaprakash Mutyala96200602020-04-08 11:09:10 +00001062 }
Ed Tanous04ae99e2018-09-20 15:54:36 -07001063
Ed Tanous10cb44f2024-04-11 13:05:20 -07001064 if (input.remoteRoleMapData)
Ed Tanous6c51eab2021-06-03 12:30:29 -07001065 {
1066 handleRoleMapPatch(asyncResp, confData.groupRoleList, serverT,
Ed Tanous10cb44f2024-04-11 13:05:20 -07001067 *input.remoteRoleMapData);
Ed Tanous6c51eab2021-06-03 12:30:29 -07001068 }
Patrick Williams5a39f772023-10-20 11:20:21 -05001069 });
Ed Tanous6c51eab2021-06-03 12:30:29 -07001070}
1071
Abhishek Patel58345852022-02-02 08:54:25 -06001072inline void updateUserProperties(
1073 std::shared_ptr<bmcweb::AsyncResp> asyncResp, const std::string& username,
1074 const std::optional<std::string>& password,
1075 const std::optional<bool>& enabled,
1076 const std::optional<std::string>& roleId, const std::optional<bool>& locked,
Ravi Tejae518ef32024-05-16 10:33:08 -05001077 std::optional<std::vector<std::string>> accountTypes, bool userSelf,
1078 const std::shared_ptr<persistent_data::UserSession>& session)
Ed Tanous6c51eab2021-06-03 12:30:29 -07001079{
P Dheeraj Srujan Kumarb477fd42021-12-16 07:17:51 +05301080 sdbusplus::message::object_path tempObjPath(rootUserDbusPath);
1081 tempObjPath /= username;
1082 std::string dbusObjectPath(tempObjPath);
Ed Tanous6c51eab2021-06-03 12:30:29 -07001083
1084 dbus::utility::checkDbusPathExists(
Ravi Tejae518ef32024-05-16 10:33:08 -05001085 dbusObjectPath,
1086 [dbusObjectPath, username, password, roleId, enabled, locked,
1087 accountTypes(std::move(accountTypes)), userSelf, session,
1088 asyncResp{std::move(asyncResp)}](int rc) {
Patrick Williams5a39f772023-10-20 11:20:21 -05001089 if (rc <= 0)
1090 {
1091 messages::resourceNotFound(asyncResp->res, "ManagerAccount",
1092 username);
1093 return;
1094 }
1095
1096 if (password)
1097 {
1098 int retval = pamUpdatePassword(username, *password);
1099
1100 if (retval == PAM_USER_UNKNOWN)
Ed Tanous6c51eab2021-06-03 12:30:29 -07001101 {
Jiaqing Zhaod8a5d5d2022-08-05 16:21:51 +08001102 messages::resourceNotFound(asyncResp->res, "ManagerAccount",
1103 username);
Patrick Williams5a39f772023-10-20 11:20:21 -05001104 }
1105 else if (retval == PAM_AUTHTOK_ERR)
1106 {
1107 // If password is invalid
1108 messages::propertyValueFormatError(asyncResp->res, nullptr,
1109 "Password");
1110 BMCWEB_LOG_ERROR("pamUpdatePassword Failed");
1111 }
1112 else if (retval != PAM_SUCCESS)
1113 {
1114 messages::internalError(asyncResp->res);
Ed Tanous6c51eab2021-06-03 12:30:29 -07001115 return;
1116 }
Patrick Williams5a39f772023-10-20 11:20:21 -05001117 else
Ed Tanous618c14b2022-06-30 17:44:25 -07001118 {
Ravi Tejae518ef32024-05-16 10:33:08 -05001119 // Remove existing sessions of the user when password changed
1120 persistent_data::SessionStore::getInstance()
1121 .removeSessionsByUsernameExceptSession(username, session);
Patrick Williams5a39f772023-10-20 11:20:21 -05001122 messages::success(asyncResp->res);
Ed Tanous618c14b2022-06-30 17:44:25 -07001123 }
Patrick Williams5a39f772023-10-20 11:20:21 -05001124 }
Ed Tanous618c14b2022-06-30 17:44:25 -07001125
Patrick Williams5a39f772023-10-20 11:20:21 -05001126 if (enabled)
1127 {
Ginu Georgee93abac2024-06-14 17:35:27 +05301128 setDbusProperty(asyncResp, "Enabled",
1129 "xyz.openbmc_project.User.Manager", dbusObjectPath,
Ed Tanousd02aad32024-02-13 14:43:34 -08001130 "xyz.openbmc_project.User.Attributes",
Ginu Georgee93abac2024-06-14 17:35:27 +05301131 "UserEnabled", *enabled);
Patrick Williams5a39f772023-10-20 11:20:21 -05001132 }
1133
1134 if (roleId)
1135 {
1136 std::string priv = getPrivilegeFromRoleId(*roleId);
1137 if (priv.empty())
1138 {
1139 messages::propertyValueNotInList(asyncResp->res, true,
1140 "Locked");
1141 return;
Ed Tanous618c14b2022-06-30 17:44:25 -07001142 }
Ginu Georgee93abac2024-06-14 17:35:27 +05301143 setDbusProperty(asyncResp, "RoleId",
1144 "xyz.openbmc_project.User.Manager", dbusObjectPath,
Ed Tanousd02aad32024-02-13 14:43:34 -08001145 "xyz.openbmc_project.User.Attributes",
Ginu Georgee93abac2024-06-14 17:35:27 +05301146 "UserPrivilege", priv);
Patrick Williams5a39f772023-10-20 11:20:21 -05001147 }
1148
1149 if (locked)
1150 {
1151 // admin can unlock the account which is locked by
1152 // successive authentication failures but admin should
1153 // not be allowed to lock an account.
1154 if (*locked)
Abhishek Patel58345852022-02-02 08:54:25 -06001155 {
Patrick Williams5a39f772023-10-20 11:20:21 -05001156 messages::propertyValueNotInList(asyncResp->res, "true",
1157 "Locked");
1158 return;
Abhishek Patel58345852022-02-02 08:54:25 -06001159 }
Ginu Georgee93abac2024-06-14 17:35:27 +05301160 setDbusProperty(asyncResp, "Locked",
1161 "xyz.openbmc_project.User.Manager", dbusObjectPath,
Ed Tanousd02aad32024-02-13 14:43:34 -08001162 "xyz.openbmc_project.User.Attributes",
Ginu Georgee93abac2024-06-14 17:35:27 +05301163 "UserLockedForFailedAttempt", *locked);
Patrick Williams5a39f772023-10-20 11:20:21 -05001164 }
1165
1166 if (accountTypes)
1167 {
1168 patchAccountTypes(*accountTypes, asyncResp, dbusObjectPath,
1169 userSelf);
1170 }
1171 });
Ed Tanous6c51eab2021-06-03 12:30:29 -07001172}
Ed Tanousb9b2e0b2018-09-13 13:47:50 -07001173
Ed Tanous4c7d4d32022-07-07 15:29:35 -07001174inline void handleAccountServiceHead(
1175 App& app, const crow::Request& req,
1176 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
Ed Tanous1ef4c342022-05-12 16:12:36 -07001177{
1178 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1179 {
1180 return;
1181 }
Ed Tanous4c7d4d32022-07-07 15:29:35 -07001182 asyncResp->res.addHeader(
1183 boost::beast::http::field::link,
1184 "</redfish/v1/JsonSchemas/AccountService/AccountService.json>; rel=describedby");
1185}
1186
1187inline void
Ed Tanous1aa375b2024-04-13 11:51:10 -07001188 getClientCertificates(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1189 const nlohmann::json::json_pointer& keyLocation)
1190{
1191 boost::urls::url url(
1192 "/redfish/v1/AccountService/MultiFactorAuth/ClientCertificate/Certificates");
1193 std::array<std::string_view, 1> interfaces = {
1194 "xyz.openbmc_project.Certs.Certificate"};
1195 std::string path = "/xyz/openbmc_project/certs/authority/truststore";
1196
1197 collection_util::getCollectionToKey(asyncResp, url, interfaces, path,
1198 keyLocation);
1199}
1200
1201inline void handleAccountServiceClientCertificatesInstanceHead(
1202 App& app, const crow::Request& req,
1203 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1204 const std::string& /*id*/)
1205{
1206 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1207 {
1208 return;
1209 }
1210
1211 asyncResp->res.addHeader(
1212 boost::beast::http::field::link,
1213 "</redfish/v1/JsonSchemas/Certificate/Certificate.json>; rel=describedby");
1214}
1215
1216inline void handleAccountServiceClientCertificatesInstanceGet(
1217 App& app, const crow::Request& req,
1218 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, const std::string& id)
1219{
1220 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1221 {
1222 return;
1223 }
1224 BMCWEB_LOG_DEBUG("ClientCertificate Certificate ID={}", id);
1225 const boost::urls::url certURL = boost::urls::format(
1226 "/redfish/v1/AccountService/MultiFactorAuth/ClientCertificate/Certificates/{}",
1227 id);
1228 std::string objPath =
1229 sdbusplus::message::object_path(certs::authorityObjectPath) / id;
1230 getCertificateProperties(
1231 asyncResp, objPath,
1232 "xyz.openbmc_project.Certs.Manager.Authority.Truststore", id, certURL,
1233 "Client Certificate");
1234}
1235
1236inline void handleAccountServiceClientCertificatesHead(
1237 App& app, const crow::Request& req,
1238 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1239{
1240 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1241 {
1242 return;
1243 }
1244
1245 asyncResp->res.addHeader(
1246 boost::beast::http::field::link,
1247 "</redfish/v1/JsonSchemas/CertificateCollection/CertificateCollection.json>; rel=describedby");
1248}
1249
1250inline void handleAccountServiceClientCertificatesGet(
1251 App& app, const crow::Request& req,
1252 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1253{
1254 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1255 {
1256 return;
1257 }
1258 getClientCertificates(asyncResp, "/Members"_json_pointer);
1259}
1260
Ed Tanous3ce36882024-06-09 10:58:16 -07001261using account_service::CertificateMappingAttribute;
1262using persistent_data::MTLSCommonNameParseMode;
1263inline CertificateMappingAttribute
1264 getCertificateMapping(MTLSCommonNameParseMode parse)
1265{
1266 switch (parse)
1267 {
1268 case MTLSCommonNameParseMode::CommonName:
1269 {
1270 return CertificateMappingAttribute::CommonName;
1271 }
1272 break;
1273 case MTLSCommonNameParseMode::Whole:
1274 {
1275 return CertificateMappingAttribute::Whole;
1276 }
1277 break;
1278 case MTLSCommonNameParseMode::UserPrincipalName:
1279 {
1280 return CertificateMappingAttribute::UserPrincipalName;
1281 }
1282 break;
1283
1284 case MTLSCommonNameParseMode::Meta:
1285 {
1286 if constexpr (BMCWEB_META_TLS_COMMON_NAME_PARSING)
1287 {
1288 return CertificateMappingAttribute::CommonName;
1289 }
1290 }
1291 break;
1292 default:
1293 {
1294 return CertificateMappingAttribute::Invalid;
1295 }
1296 break;
1297 }
1298}
1299
Ed Tanous1aa375b2024-04-13 11:51:10 -07001300inline void
Ed Tanous4c7d4d32022-07-07 15:29:35 -07001301 handleAccountServiceGet(App& app, const crow::Request& req,
1302 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1303{
Jiaqing Zhaoafd369c2023-03-07 15:12:22 +08001304 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1305 {
1306 return;
1307 }
Ninad Palsule3e72c202023-03-27 17:19:55 -05001308
1309 if (req.session == nullptr)
1310 {
1311 messages::internalError(asyncResp->res);
1312 return;
1313 }
1314
Ed Tanousc1019822024-03-06 12:54:38 -08001315 const persistent_data::AuthConfigMethods& authMethodsConfig =
1316 persistent_data::SessionStore::getInstance().getAuthMethodsConfig();
1317
Jiaqing Zhaoafd369c2023-03-07 15:12:22 +08001318 asyncResp->res.addHeader(
1319 boost::beast::http::field::link,
1320 "</redfish/v1/JsonSchemas/AccountService/AccountService.json>; rel=describedby");
1321
Ed Tanous1ef4c342022-05-12 16:12:36 -07001322 nlohmann::json& json = asyncResp->res.jsonValue;
1323 json["@odata.id"] = "/redfish/v1/AccountService";
Ravi Teja482a69e2024-04-22 06:56:13 -05001324 json["@odata.type"] = "#AccountService.v1_15_0.AccountService";
Ed Tanous1ef4c342022-05-12 16:12:36 -07001325 json["Id"] = "AccountService";
1326 json["Name"] = "Account Service";
1327 json["Description"] = "Account Service";
1328 json["ServiceEnabled"] = true;
1329 json["MaxPasswordLength"] = 20;
1330 json["Accounts"]["@odata.id"] = "/redfish/v1/AccountService/Accounts";
1331 json["Roles"]["@odata.id"] = "/redfish/v1/AccountService/Roles";
Ravi Teja482a69e2024-04-22 06:56:13 -05001332 json["HTTPBasicAuth"] = authMethodsConfig.basic
1333 ? account_service::BasicAuthState::Enabled
1334 : account_service::BasicAuthState::Disabled;
1335
1336 nlohmann::json::array_t allowed;
1337 allowed.emplace_back(account_service::BasicAuthState::Enabled);
1338 allowed.emplace_back(account_service::BasicAuthState::Disabled);
1339 json["HTTPBasicAuth@AllowableValues"] = std::move(allowed);
1340
Ed Tanous1aa375b2024-04-13 11:51:10 -07001341 nlohmann::json::object_t clientCertificate;
1342 clientCertificate["Enabled"] = authMethodsConfig.tls;
Ed Tanous3281bcf2024-06-25 16:02:05 -07001343 clientCertificate["RespondToUnauthenticatedClients"] =
1344 !authMethodsConfig.tlsStrict;
Ed Tanous3ce36882024-06-09 10:58:16 -07001345
1346 using account_service::CertificateMappingAttribute;
1347
1348 CertificateMappingAttribute mapping =
1349 getCertificateMapping(authMethodsConfig.mTLSCommonNameParsingMode);
1350 if (mapping == CertificateMappingAttribute::Invalid)
1351 {
1352 messages::internalError(asyncResp->res);
1353 }
1354 else
1355 {
1356 clientCertificate["CertificateMappingAttribute"] = mapping;
1357 }
Ed Tanous1aa375b2024-04-13 11:51:10 -07001358 nlohmann::json::object_t certificates;
1359 certificates["@odata.id"] =
1360 "/redfish/v1/AccountService/MultiFactorAuth/ClientCertificate/Certificates";
1361 certificates["@odata.type"] =
1362 "#CertificateCollection.CertificateCollection";
1363 clientCertificate["Certificates"] = std::move(certificates);
1364 json["MultiFactorAuth"]["ClientCertificate"] = std::move(clientCertificate);
1365
1366 getClientCertificates(
1367 asyncResp,
1368 "/MultiFactorAuth/ClientCertificate/Certificates/Members"_json_pointer);
1369
Ed Tanous1ef4c342022-05-12 16:12:36 -07001370 json["Oem"]["OpenBMC"]["@odata.type"] =
Ed Tanous5b5574a2022-09-26 19:53:36 -07001371 "#OpenBMCAccountService.v1_0_0.AccountService";
Ed Tanous1ef4c342022-05-12 16:12:36 -07001372 json["Oem"]["OpenBMC"]["@odata.id"] =
1373 "/redfish/v1/AccountService#/Oem/OpenBMC";
1374 json["Oem"]["OpenBMC"]["AuthMethods"]["BasicAuth"] =
1375 authMethodsConfig.basic;
1376 json["Oem"]["OpenBMC"]["AuthMethods"]["SessionToken"] =
1377 authMethodsConfig.sessionToken;
1378 json["Oem"]["OpenBMC"]["AuthMethods"]["XToken"] = authMethodsConfig.xtoken;
1379 json["Oem"]["OpenBMC"]["AuthMethods"]["Cookie"] = authMethodsConfig.cookie;
1380 json["Oem"]["OpenBMC"]["AuthMethods"]["TLS"] = authMethodsConfig.tls;
1381
1382 // /redfish/v1/AccountService/LDAP/Certificates is something only
1383 // ConfigureManager can access then only display when the user has
1384 // permissions ConfigureManager
1385 Privileges effectiveUserPrivileges =
Ninad Palsule3e72c202023-03-27 17:19:55 -05001386 redfish::getUserPrivileges(*req.session);
Ed Tanous1ef4c342022-05-12 16:12:36 -07001387
1388 if (isOperationAllowedWithPrivileges({{"ConfigureManager"}},
1389 effectiveUserPrivileges))
1390 {
1391 asyncResp->res.jsonValue["LDAP"]["Certificates"]["@odata.id"] =
1392 "/redfish/v1/AccountService/LDAP/Certificates";
1393 }
Krzysztof Grobelnyd1bde9e2022-09-07 10:40:51 +02001394 sdbusplus::asio::getAllProperties(
1395 *crow::connections::systemBus, "xyz.openbmc_project.User.Manager",
1396 "/xyz/openbmc_project/user", "xyz.openbmc_project.User.AccountPolicy",
Ed Tanous5e7e2dc2023-02-16 10:37:01 -08001397 [asyncResp](const boost::system::error_code& ec,
Ed Tanous1ef4c342022-05-12 16:12:36 -07001398 const dbus::utility::DBusPropertiesMap& propertiesList) {
1399 if (ec)
1400 {
1401 messages::internalError(asyncResp->res);
1402 return;
1403 }
Krzysztof Grobelnyd1bde9e2022-09-07 10:40:51 +02001404
Ed Tanous1aa375b2024-04-13 11:51:10 -07001405 BMCWEB_LOG_DEBUG("Got {} properties for AccountService",
Ed Tanous62598e32023-07-17 17:06:25 -07001406 propertiesList.size());
Krzysztof Grobelnyd1bde9e2022-09-07 10:40:51 +02001407
1408 const uint8_t* minPasswordLength = nullptr;
1409 const uint32_t* accountUnlockTimeout = nullptr;
1410 const uint16_t* maxLoginAttemptBeforeLockout = nullptr;
1411
1412 const bool success = sdbusplus::unpackPropertiesNoThrow(
1413 dbus_utils::UnpackErrorPrinter(), propertiesList,
1414 "MinPasswordLength", minPasswordLength, "AccountUnlockTimeout",
1415 accountUnlockTimeout, "MaxLoginAttemptBeforeLockout",
1416 maxLoginAttemptBeforeLockout);
1417
1418 if (!success)
Ed Tanous1ef4c342022-05-12 16:12:36 -07001419 {
Krzysztof Grobelnyd1bde9e2022-09-07 10:40:51 +02001420 messages::internalError(asyncResp->res);
1421 return;
Ed Tanous1ef4c342022-05-12 16:12:36 -07001422 }
Krzysztof Grobelnyd1bde9e2022-09-07 10:40:51 +02001423
1424 if (minPasswordLength != nullptr)
1425 {
1426 asyncResp->res.jsonValue["MinPasswordLength"] = *minPasswordLength;
1427 }
1428
1429 if (accountUnlockTimeout != nullptr)
1430 {
1431 asyncResp->res.jsonValue["AccountLockoutDuration"] =
1432 *accountUnlockTimeout;
1433 }
1434
1435 if (maxLoginAttemptBeforeLockout != nullptr)
1436 {
1437 asyncResp->res.jsonValue["AccountLockoutThreshold"] =
1438 *maxLoginAttemptBeforeLockout;
1439 }
Patrick Williams5a39f772023-10-20 11:20:21 -05001440 });
Ed Tanous1ef4c342022-05-12 16:12:36 -07001441
Ed Tanous02cad962022-06-30 16:50:15 -07001442 auto callback = [asyncResp](bool success, const LDAPConfigData& confData,
Ed Tanous1ef4c342022-05-12 16:12:36 -07001443 const std::string& ldapType) {
1444 if (!success)
1445 {
1446 return;
1447 }
1448 parseLDAPConfigData(asyncResp->res.jsonValue, confData, ldapType);
1449 };
1450
1451 getLDAPConfigData("LDAP", callback);
1452 getLDAPConfigData("ActiveDirectory", callback);
1453}
1454
Ed Tanous3ce36882024-06-09 10:58:16 -07001455inline void
1456 handleCertificateMappingAttributePatch(crow::Response& res,
1457 const std::string& certMapAttribute)
1458{
1459 MTLSCommonNameParseMode parseMode =
1460 persistent_data::getMTLSCommonNameParseMode(certMapAttribute);
1461 if (parseMode == MTLSCommonNameParseMode::Invalid)
1462 {
1463 messages::propertyValueNotInList(res, "CertificateMappingAttribute",
1464 certMapAttribute);
1465 return;
1466 }
1467
1468 persistent_data::AuthConfigMethods& authMethodsConfig =
1469 persistent_data::SessionStore::getInstance().getAuthMethodsConfig();
1470 authMethodsConfig.mTLSCommonNameParsingMode = parseMode;
1471}
1472
Ed Tanous3281bcf2024-06-25 16:02:05 -07001473inline void handleRespondToUnauthenticatedClientsPatch(
1474 App& app, const crow::Request& req, crow::Response& res,
1475 bool respondToUnauthenticatedClients)
1476{
1477 if (req.session != nullptr)
1478 {
1479 // Sanity check. If the user isn't currently authenticated with mutual
1480 // TLS, they very likely are about to permanently lock themselves out.
1481 // Make sure they're using mutual TLS before allowing locking.
1482 if (req.session->sessionType != persistent_data::SessionType::MutualTLS)
1483 {
1484 messages::propertyValueExternalConflict(
1485 res,
1486 "MultiFactorAuth/ClientCertificate/RespondToUnauthenticatedClients",
1487 respondToUnauthenticatedClients);
1488 return;
1489 }
1490 }
1491
1492 persistent_data::AuthConfigMethods& authMethodsConfig =
1493 persistent_data::SessionStore::getInstance().getAuthMethodsConfig();
1494
1495 // Change the settings
1496 authMethodsConfig.tlsStrict = !respondToUnauthenticatedClients;
1497
1498 // Write settings to disk
1499 persistent_data::getConfig().writeData();
1500
1501 // Trigger a reload, to apply the new settings to new connections
1502 app.loadCertificate();
1503}
1504
Ed Tanous1ef4c342022-05-12 16:12:36 -07001505inline void handleAccountServicePatch(
1506 App& app, const crow::Request& req,
1507 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1508{
1509 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1510 {
1511 return;
1512 }
1513 std::optional<uint32_t> unlockTimeout;
1514 std::optional<uint16_t> lockoutThreshold;
1515 std::optional<uint8_t> minPasswordLength;
1516 std::optional<uint16_t> maxPasswordLength;
Ed Tanous10cb44f2024-04-11 13:05:20 -07001517 LdapPatchParams ldapObject;
Ed Tanous3ce36882024-06-09 10:58:16 -07001518 std::optional<std::string> certificateMappingAttribute;
Ed Tanous3281bcf2024-06-25 16:02:05 -07001519 std::optional<bool> respondToUnauthenticatedClients;
Ed Tanous10cb44f2024-04-11 13:05:20 -07001520 LdapPatchParams activeDirectoryObject;
Ed Tanousc1019822024-03-06 12:54:38 -08001521 AuthMethods auth;
Ravi Teja482a69e2024-04-22 06:56:13 -05001522 std::optional<std::string> httpBasicAuth;
Ed Tanous3ce36882024-06-09 10:58:16 -07001523
Ed Tanousc1019822024-03-06 12:54:38 -08001524 // clang-format off
Ed Tanous1ef4c342022-05-12 16:12:36 -07001525 if (!json_util::readJsonPatch(
Ed Tanousc1019822024-03-06 12:54:38 -08001526 req, asyncResp->res,
1527 "AccountLockoutDuration", unlockTimeout,
1528 "AccountLockoutThreshold", lockoutThreshold,
Ed Tanous10cb44f2024-04-11 13:05:20 -07001529 "ActiveDirectory/Authentication/AuthenticationType", activeDirectoryObject.authType,
1530 "ActiveDirectory/Authentication/Password", activeDirectoryObject.password,
1531 "ActiveDirectory/Authentication/Username", activeDirectoryObject.userName,
1532 "ActiveDirectory/LDAPService/SearchSettings/BaseDistinguishedNames", activeDirectoryObject.baseDNList,
1533 "ActiveDirectory/LDAPService/SearchSettings/GroupsAttribute", activeDirectoryObject.groupsAttribute,
1534 "ActiveDirectory/LDAPService/SearchSettings/UsernameAttribute", activeDirectoryObject.userNameAttribute,
1535 "ActiveDirectory/RemoteRoleMapping", activeDirectoryObject.remoteRoleMapData,
1536 "ActiveDirectory/ServiceAddresses", activeDirectoryObject.serviceAddressList,
1537 "ActiveDirectory/ServiceEnabled", activeDirectoryObject.serviceEnabled,
Ed Tanous3ce36882024-06-09 10:58:16 -07001538 "MultiFactorAuth/ClientCertificate/CertificateMappingAttribute", certificateMappingAttribute,
Ed Tanous3281bcf2024-06-25 16:02:05 -07001539 "MultiFactorAuth/ClientCertificate/RespondToUnauthenticatedClients", respondToUnauthenticatedClients,
Ed Tanous10cb44f2024-04-11 13:05:20 -07001540 "LDAP/Authentication/AuthenticationType", ldapObject.authType,
1541 "LDAP/Authentication/Password", ldapObject.password,
1542 "LDAP/Authentication/Username", ldapObject.userName,
1543 "LDAP/LDAPService/SearchSettings/BaseDistinguishedNames", ldapObject.baseDNList,
1544 "LDAP/LDAPService/SearchSettings/GroupsAttribute", ldapObject.groupsAttribute,
1545 "LDAP/LDAPService/SearchSettings/UsernameAttribute", ldapObject.userNameAttribute,
1546 "LDAP/RemoteRoleMapping", ldapObject.remoteRoleMapData,
1547 "LDAP/ServiceAddresses", ldapObject.serviceAddressList,
1548 "LDAP/ServiceEnabled", ldapObject.serviceEnabled,
Ed Tanousc1019822024-03-06 12:54:38 -08001549 "MaxPasswordLength", maxPasswordLength,
1550 "MinPasswordLength", minPasswordLength,
Ed Tanousc1019822024-03-06 12:54:38 -08001551 "Oem/OpenBMC/AuthMethods/BasicAuth", auth.basicAuth,
1552 "Oem/OpenBMC/AuthMethods/Cookie", auth.cookie,
1553 "Oem/OpenBMC/AuthMethods/SessionToken", auth.sessionToken,
Ed Tanous10cb44f2024-04-11 13:05:20 -07001554 "Oem/OpenBMC/AuthMethods/TLS", auth.tls,
Ravi Teja482a69e2024-04-22 06:56:13 -05001555 "Oem/OpenBMC/AuthMethods/XToken", auth.xToken,
1556 "HTTPBasicAuth", httpBasicAuth))
Ed Tanous1ef4c342022-05-12 16:12:36 -07001557 {
1558 return;
1559 }
Ed Tanousc1019822024-03-06 12:54:38 -08001560 // clang-format on
Ed Tanous1ef4c342022-05-12 16:12:36 -07001561
Ravi Teja482a69e2024-04-22 06:56:13 -05001562 if (httpBasicAuth)
1563 {
1564 if (*httpBasicAuth == "Enabled")
1565 {
1566 auth.basicAuth = true;
1567 }
1568 else if (*httpBasicAuth == "Disabled")
1569 {
1570 auth.basicAuth = false;
1571 }
1572 else
1573 {
1574 messages::propertyValueNotInList(asyncResp->res, "HttpBasicAuth",
1575 *httpBasicAuth);
1576 }
1577 }
1578
Ed Tanous3281bcf2024-06-25 16:02:05 -07001579 if (respondToUnauthenticatedClients)
1580 {
1581 handleRespondToUnauthenticatedClientsPatch(
1582 app, req, asyncResp->res, *respondToUnauthenticatedClients);
1583 }
1584
Ed Tanous3ce36882024-06-09 10:58:16 -07001585 if (certificateMappingAttribute)
1586 {
1587 handleCertificateMappingAttributePatch(asyncResp->res,
1588 *certificateMappingAttribute);
1589 }
1590
Ed Tanous1ef4c342022-05-12 16:12:36 -07001591 if (minPasswordLength)
1592 {
Ed Tanousd02aad32024-02-13 14:43:34 -08001593 setDbusProperty(
Ginu Georgee93abac2024-06-14 17:35:27 +05301594 asyncResp, "MinPasswordLength", "xyz.openbmc_project.User.Manager",
Ed Tanousd02aad32024-02-13 14:43:34 -08001595 sdbusplus::message::object_path("/xyz/openbmc_project/user"),
George Liu9ae226f2023-06-21 17:56:46 +08001596 "xyz.openbmc_project.User.AccountPolicy", "MinPasswordLength",
Ginu Georgee93abac2024-06-14 17:35:27 +05301597 *minPasswordLength);
Ed Tanous1ef4c342022-05-12 16:12:36 -07001598 }
1599
1600 if (maxPasswordLength)
1601 {
1602 messages::propertyNotWritable(asyncResp->res, "MaxPasswordLength");
1603 }
1604
Ed Tanous10cb44f2024-04-11 13:05:20 -07001605 handleLDAPPatch(std::move(activeDirectoryObject), asyncResp,
1606 "ActiveDirectory");
1607 handleLDAPPatch(std::move(ldapObject), asyncResp, "LDAP");
Ed Tanous1ef4c342022-05-12 16:12:36 -07001608
Ed Tanousc1019822024-03-06 12:54:38 -08001609 handleAuthMethodsPatch(asyncResp, auth);
Ed Tanous1ef4c342022-05-12 16:12:36 -07001610
Ed Tanous1ef4c342022-05-12 16:12:36 -07001611 if (unlockTimeout)
1612 {
Ed Tanousd02aad32024-02-13 14:43:34 -08001613 setDbusProperty(
Ginu Georgee93abac2024-06-14 17:35:27 +05301614 asyncResp, "AccountLockoutDuration",
1615 "xyz.openbmc_project.User.Manager",
Ed Tanousd02aad32024-02-13 14:43:34 -08001616 sdbusplus::message::object_path("/xyz/openbmc_project/user"),
Ed Tanous1ef4c342022-05-12 16:12:36 -07001617 "xyz.openbmc_project.User.AccountPolicy", "AccountUnlockTimeout",
Ginu Georgee93abac2024-06-14 17:35:27 +05301618 *unlockTimeout);
Ed Tanous1ef4c342022-05-12 16:12:36 -07001619 }
1620 if (lockoutThreshold)
1621 {
Ed Tanousd02aad32024-02-13 14:43:34 -08001622 setDbusProperty(
Ginu Georgee93abac2024-06-14 17:35:27 +05301623 asyncResp, "AccountLockoutThreshold",
1624 "xyz.openbmc_project.User.Manager",
Ed Tanousd02aad32024-02-13 14:43:34 -08001625 sdbusplus::message::object_path("/xyz/openbmc_project/user"),
George Liu9ae226f2023-06-21 17:56:46 +08001626 "xyz.openbmc_project.User.AccountPolicy",
Ginu Georgee93abac2024-06-14 17:35:27 +05301627 "MaxLoginAttemptBeforeLockout", *lockoutThreshold);
Ed Tanous1ef4c342022-05-12 16:12:36 -07001628 }
1629}
1630
Ed Tanous4c7d4d32022-07-07 15:29:35 -07001631inline void handleAccountCollectionHead(
Ed Tanous1ef4c342022-05-12 16:12:36 -07001632 App& app, const crow::Request& req,
1633 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1634{
1635 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1636 {
1637 return;
1638 }
Ed Tanous4c7d4d32022-07-07 15:29:35 -07001639 asyncResp->res.addHeader(
1640 boost::beast::http::field::link,
1641 "</redfish/v1/JsonSchemas/ManagerAccountCollection.json>; rel=describedby");
1642}
1643
1644inline void handleAccountCollectionGet(
1645 App& app, const crow::Request& req,
1646 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1647{
Jiaqing Zhaoafd369c2023-03-07 15:12:22 +08001648 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1649 {
1650 return;
1651 }
Ninad Palsule3e72c202023-03-27 17:19:55 -05001652
1653 if (req.session == nullptr)
1654 {
1655 messages::internalError(asyncResp->res);
1656 return;
1657 }
1658
Jiaqing Zhaoafd369c2023-03-07 15:12:22 +08001659 asyncResp->res.addHeader(
1660 boost::beast::http::field::link,
1661 "</redfish/v1/JsonSchemas/ManagerAccountCollection.json>; rel=describedby");
Ed Tanous1ef4c342022-05-12 16:12:36 -07001662
1663 asyncResp->res.jsonValue["@odata.id"] =
1664 "/redfish/v1/AccountService/Accounts";
1665 asyncResp->res.jsonValue["@odata.type"] = "#ManagerAccountCollection."
1666 "ManagerAccountCollection";
1667 asyncResp->res.jsonValue["Name"] = "Accounts Collection";
1668 asyncResp->res.jsonValue["Description"] = "BMC User Accounts";
1669
1670 Privileges effectiveUserPrivileges =
Ninad Palsule3e72c202023-03-27 17:19:55 -05001671 redfish::getUserPrivileges(*req.session);
Ed Tanous1ef4c342022-05-12 16:12:36 -07001672
1673 std::string thisUser;
1674 if (req.session)
1675 {
1676 thisUser = req.session->username;
1677 }
George Liu5eb468d2023-06-20 17:03:24 +08001678 sdbusplus::message::object_path path("/xyz/openbmc_project/user");
1679 dbus::utility::getManagedObjects(
1680 "xyz.openbmc_project.User.Manager", path,
Ed Tanous1ef4c342022-05-12 16:12:36 -07001681 [asyncResp, thisUser, effectiveUserPrivileges](
Ed Tanous5e7e2dc2023-02-16 10:37:01 -08001682 const boost::system::error_code& ec,
Ed Tanous1ef4c342022-05-12 16:12:36 -07001683 const dbus::utility::ManagedObjectType& users) {
1684 if (ec)
1685 {
1686 messages::internalError(asyncResp->res);
1687 return;
1688 }
1689
1690 bool userCanSeeAllAccounts =
1691 effectiveUserPrivileges.isSupersetOf({"ConfigureUsers"});
1692
1693 bool userCanSeeSelf =
1694 effectiveUserPrivileges.isSupersetOf({"ConfigureSelf"});
1695
1696 nlohmann::json& memberArray = asyncResp->res.jsonValue["Members"];
1697 memberArray = nlohmann::json::array();
1698
1699 for (const auto& userpath : users)
1700 {
1701 std::string user = userpath.first.filename();
1702 if (user.empty())
1703 {
1704 messages::internalError(asyncResp->res);
Ed Tanous62598e32023-07-17 17:06:25 -07001705 BMCWEB_LOG_ERROR("Invalid firmware ID");
Ed Tanous1ef4c342022-05-12 16:12:36 -07001706
1707 return;
1708 }
1709
1710 // As clarified by Redfish here:
1711 // https://redfishforum.com/thread/281/manageraccountcollection-change-allows-account-enumeration
1712 // Users without ConfigureUsers, only see their own
1713 // account. Users with ConfigureUsers, see all
1714 // accounts.
1715 if (userCanSeeAllAccounts || (thisUser == user && userCanSeeSelf))
1716 {
1717 nlohmann::json::object_t member;
Ed Tanous3b327802023-08-14 09:23:43 -07001718 member["@odata.id"] = boost::urls::format(
1719 "/redfish/v1/AccountService/Accounts/{}", user);
Patrick Williamsb2ba3072023-05-12 10:27:39 -05001720 memberArray.emplace_back(std::move(member));
Ed Tanous1ef4c342022-05-12 16:12:36 -07001721 }
1722 }
1723 asyncResp->res.jsonValue["Members@odata.count"] = memberArray.size();
Patrick Williams5a39f772023-10-20 11:20:21 -05001724 });
Ed Tanous1ef4c342022-05-12 16:12:36 -07001725}
1726
Ninad Palsule97e90da2023-05-17 14:04:52 -05001727inline void processAfterCreateUser(
1728 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1729 const std::string& username, const std::string& password,
1730 const boost::system::error_code& ec, sdbusplus::message_t& m)
1731{
1732 if (ec)
1733 {
1734 userErrorMessageHandler(m.get_error(), asyncResp, username, "");
1735 return;
1736 }
1737
1738 if (pamUpdatePassword(username, password) != PAM_SUCCESS)
1739 {
1740 // At this point we have a user that's been
1741 // created, but the password set
1742 // failed.Something is wrong, so delete the user
1743 // that we've already created
1744 sdbusplus::message::object_path tempObjPath(rootUserDbusPath);
1745 tempObjPath /= username;
1746 const std::string userPath(tempObjPath);
1747
1748 crow::connections::systemBus->async_method_call(
1749 [asyncResp, password](const boost::system::error_code& ec3) {
1750 if (ec3)
1751 {
1752 messages::internalError(asyncResp->res);
1753 return;
1754 }
1755
1756 // If password is invalid
Jason M. Bills9bd80832023-08-30 15:19:41 -07001757 messages::propertyValueFormatError(asyncResp->res, nullptr,
Ninad Palsule97e90da2023-05-17 14:04:52 -05001758 "Password");
Patrick Williams5a39f772023-10-20 11:20:21 -05001759 },
Ninad Palsule97e90da2023-05-17 14:04:52 -05001760 "xyz.openbmc_project.User.Manager", userPath,
1761 "xyz.openbmc_project.Object.Delete", "Delete");
1762
Ed Tanous62598e32023-07-17 17:06:25 -07001763 BMCWEB_LOG_ERROR("pamUpdatePassword Failed");
Ninad Palsule97e90da2023-05-17 14:04:52 -05001764 return;
1765 }
1766
1767 messages::created(asyncResp->res);
1768 asyncResp->res.addHeader("Location",
1769 "/redfish/v1/AccountService/Accounts/" + username);
1770}
1771
1772inline void processAfterGetAllGroups(
1773 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1774 const std::string& username, const std::string& password,
Ed Tanouse01d0c32023-06-30 13:21:32 -07001775 const std::string& roleId, bool enabled,
Ninad Palsule9ba73932023-06-01 16:38:57 -05001776 std::optional<std::vector<std::string>> accountTypes,
Ninad Palsule97e90da2023-05-17 14:04:52 -05001777 const std::vector<std::string>& allGroupsList)
Ninad Palsule97e90da2023-05-17 14:04:52 -05001778{
Ninad Palsule3e72c202023-03-27 17:19:55 -05001779 std::vector<std::string> userGroups;
Ninad Palsule9ba73932023-06-01 16:38:57 -05001780 std::vector<std::string> accountTypeUserGroups;
1781
1782 // If user specified account types then convert them to unix user groups
1783 if (accountTypes)
1784 {
1785 if (!getUserGroupFromAccountType(asyncResp->res, *accountTypes,
1786 accountTypeUserGroups))
1787 {
1788 // Problem in mapping Account Types to User Groups, Error already
1789 // logged.
1790 return;
1791 }
1792 }
1793
Ninad Palsule3e72c202023-03-27 17:19:55 -05001794 for (const auto& grp : allGroupsList)
1795 {
Ninad Palsule9ba73932023-06-01 16:38:57 -05001796 // If user specified the account type then only accept groups which are
1797 // in the account types group list.
1798 if (!accountTypeUserGroups.empty())
1799 {
1800 bool found = false;
1801 for (const auto& grp1 : accountTypeUserGroups)
1802 {
1803 if (grp == grp1)
1804 {
1805 found = true;
1806 break;
1807 }
1808 }
1809 if (!found)
1810 {
1811 continue;
1812 }
1813 }
1814
Ninad Palsule3e72c202023-03-27 17:19:55 -05001815 // Console access is provided to the user who is a member of
1816 // hostconsole group and has a administrator role. So, set
1817 // hostconsole group only for the administrator.
Ninad Palsule9ba73932023-06-01 16:38:57 -05001818 if ((grp == "hostconsole") && (roleId != "priv-admin"))
Ninad Palsule3e72c202023-03-27 17:19:55 -05001819 {
Ninad Palsule9ba73932023-06-01 16:38:57 -05001820 if (!accountTypeUserGroups.empty())
1821 {
Ed Tanous62598e32023-07-17 17:06:25 -07001822 BMCWEB_LOG_ERROR(
1823 "Only administrator can get HostConsole access");
Ninad Palsule9ba73932023-06-01 16:38:57 -05001824 asyncResp->res.result(boost::beast::http::status::bad_request);
1825 return;
1826 }
1827 continue;
Ninad Palsule3e72c202023-03-27 17:19:55 -05001828 }
Ninad Palsule9ba73932023-06-01 16:38:57 -05001829 userGroups.emplace_back(grp);
1830 }
1831
1832 // Make sure user specified groups are valid. This is internal error because
1833 // it some inconsistencies between user manager and bmcweb.
1834 if (!accountTypeUserGroups.empty() &&
1835 accountTypeUserGroups.size() != userGroups.size())
1836 {
1837 messages::internalError(asyncResp->res);
1838 return;
Ninad Palsule3e72c202023-03-27 17:19:55 -05001839 }
Ninad Palsule97e90da2023-05-17 14:04:52 -05001840 crow::connections::systemBus->async_method_call(
1841 [asyncResp, username, password](const boost::system::error_code& ec2,
1842 sdbusplus::message_t& m) {
1843 processAfterCreateUser(asyncResp, username, password, ec2, m);
Patrick Williams5a39f772023-10-20 11:20:21 -05001844 },
Ninad Palsule97e90da2023-05-17 14:04:52 -05001845 "xyz.openbmc_project.User.Manager", "/xyz/openbmc_project/user",
Ninad Palsule3e72c202023-03-27 17:19:55 -05001846 "xyz.openbmc_project.User.Manager", "CreateUser", username, userGroups,
Ed Tanouse01d0c32023-06-30 13:21:32 -07001847 roleId, enabled);
Ninad Palsule97e90da2023-05-17 14:04:52 -05001848}
1849
Ed Tanous1ef4c342022-05-12 16:12:36 -07001850inline void handleAccountCollectionPost(
1851 App& app, const crow::Request& req,
1852 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1853{
1854 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1855 {
1856 return;
1857 }
1858 std::string username;
1859 std::string password;
Ed Tanouse01d0c32023-06-30 13:21:32 -07001860 std::optional<std::string> roleIdJson;
1861 std::optional<bool> enabledJson;
Ninad Palsule9ba73932023-06-01 16:38:57 -05001862 std::optional<std::vector<std::string>> accountTypes;
Ed Tanouse01d0c32023-06-30 13:21:32 -07001863 if (!json_util::readJsonPatch(req, asyncResp->res, "UserName", username,
1864 "Password", password, "RoleId", roleIdJson,
1865 "Enabled", enabledJson, "AccountTypes",
1866 accountTypes))
Ed Tanous1ef4c342022-05-12 16:12:36 -07001867 {
1868 return;
1869 }
1870
Ed Tanouse01d0c32023-06-30 13:21:32 -07001871 std::string roleId = roleIdJson.value_or("User");
1872 std::string priv = getPrivilegeFromRoleId(roleId);
Ed Tanous1ef4c342022-05-12 16:12:36 -07001873 if (priv.empty())
1874 {
Ed Tanouse01d0c32023-06-30 13:21:32 -07001875 messages::propertyValueNotInList(asyncResp->res, roleId, "RoleId");
Ed Tanous1ef4c342022-05-12 16:12:36 -07001876 return;
1877 }
Asmitha Karunanithi239adf82022-03-25 02:59:03 -05001878 roleId = priv;
Ed Tanous1ef4c342022-05-12 16:12:36 -07001879
Ed Tanouse01d0c32023-06-30 13:21:32 -07001880 bool enabled = enabledJson.value_or(true);
1881
Ed Tanous1ef4c342022-05-12 16:12:36 -07001882 // Reading AllGroups property
1883 sdbusplus::asio::getProperty<std::vector<std::string>>(
1884 *crow::connections::systemBus, "xyz.openbmc_project.User.Manager",
1885 "/xyz/openbmc_project/user", "xyz.openbmc_project.User.Manager",
1886 "AllGroups",
Ninad Palsule9ba73932023-06-01 16:38:57 -05001887 [asyncResp, username, password{std::move(password)}, roleId, enabled,
1888 accountTypes](const boost::system::error_code& ec,
1889 const std::vector<std::string>& allGroupsList) {
Ed Tanous1ef4c342022-05-12 16:12:36 -07001890 if (ec)
1891 {
Ed Tanous62598e32023-07-17 17:06:25 -07001892 BMCWEB_LOG_DEBUG("ERROR with async_method_call");
Ed Tanous1ef4c342022-05-12 16:12:36 -07001893 messages::internalError(asyncResp->res);
1894 return;
1895 }
1896
1897 if (allGroupsList.empty())
1898 {
1899 messages::internalError(asyncResp->res);
1900 return;
1901 }
1902
Ninad Palsule97e90da2023-05-17 14:04:52 -05001903 processAfterGetAllGroups(asyncResp, username, password, roleId, enabled,
Ninad Palsule9ba73932023-06-01 16:38:57 -05001904 accountTypes, allGroupsList);
Patrick Williams5a39f772023-10-20 11:20:21 -05001905 });
Ed Tanous1ef4c342022-05-12 16:12:36 -07001906}
1907
1908inline void
Ed Tanous4c7d4d32022-07-07 15:29:35 -07001909 handleAccountHead(App& app, const crow::Request& req,
1910 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1911 const std::string& /*accountName*/)
Ed Tanous1ef4c342022-05-12 16:12:36 -07001912{
1913 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1914 {
1915 return;
1916 }
Ed Tanous4c7d4d32022-07-07 15:29:35 -07001917 asyncResp->res.addHeader(
1918 boost::beast::http::field::link,
1919 "</redfish/v1/JsonSchemas/ManagerAccount/ManagerAccount.json>; rel=describedby");
1920}
Jiaqing Zhaoafd369c2023-03-07 15:12:22 +08001921
Ed Tanous4c7d4d32022-07-07 15:29:35 -07001922inline void
1923 handleAccountGet(App& app, const crow::Request& req,
1924 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1925 const std::string& accountName)
1926{
Jiaqing Zhaoafd369c2023-03-07 15:12:22 +08001927 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1928 {
1929 return;
1930 }
1931 asyncResp->res.addHeader(
1932 boost::beast::http::field::link,
1933 "</redfish/v1/JsonSchemas/ManagerAccount/ManagerAccount.json>; rel=describedby");
1934
Ed Tanous25b54db2024-04-17 15:40:31 -07001935 if constexpr (BMCWEB_INSECURE_DISABLE_AUTH)
1936 {
1937 // If authentication is disabled, there are no user accounts
1938 messages::resourceNotFound(asyncResp->res, "ManagerAccount",
1939 accountName);
1940 return;
1941 }
Jiaqing Zhaoafd369c2023-03-07 15:12:22 +08001942
Ed Tanous1ef4c342022-05-12 16:12:36 -07001943 if (req.session == nullptr)
1944 {
1945 messages::internalError(asyncResp->res);
1946 return;
1947 }
1948 if (req.session->username != accountName)
1949 {
1950 // At this point we've determined that the user is trying to
1951 // modify a user that isn't them. We need to verify that they
1952 // have permissions to modify other users, so re-run the auth
1953 // check with the same permissions, minus ConfigureSelf.
1954 Privileges effectiveUserPrivileges =
Ninad Palsule3e72c202023-03-27 17:19:55 -05001955 redfish::getUserPrivileges(*req.session);
Ed Tanous1ef4c342022-05-12 16:12:36 -07001956 Privileges requiredPermissionsToChangeNonSelf = {"ConfigureUsers",
1957 "ConfigureManager"};
1958 if (!effectiveUserPrivileges.isSupersetOf(
1959 requiredPermissionsToChangeNonSelf))
1960 {
Ed Tanous62598e32023-07-17 17:06:25 -07001961 BMCWEB_LOG_DEBUG("GET Account denied access");
Ed Tanous1ef4c342022-05-12 16:12:36 -07001962 messages::insufficientPrivilege(asyncResp->res);
1963 return;
1964 }
1965 }
1966
George Liu5eb468d2023-06-20 17:03:24 +08001967 sdbusplus::message::object_path path("/xyz/openbmc_project/user");
1968 dbus::utility::getManagedObjects(
1969 "xyz.openbmc_project.User.Manager", path,
Ed Tanous1ef4c342022-05-12 16:12:36 -07001970 [asyncResp,
Ed Tanous5e7e2dc2023-02-16 10:37:01 -08001971 accountName](const boost::system::error_code& ec,
Ed Tanous1ef4c342022-05-12 16:12:36 -07001972 const dbus::utility::ManagedObjectType& users) {
1973 if (ec)
1974 {
1975 messages::internalError(asyncResp->res);
1976 return;
1977 }
Ed Tanous3544d2a2023-08-06 18:12:20 -07001978 const auto userIt = std::ranges::find_if(
Michael Shen80f79a42023-08-24 13:41:53 +00001979 users,
1980 [accountName](
1981 const std::pair<sdbusplus::message::object_path,
1982 dbus::utility::DBusInterfacesMap>& user) {
1983 return accountName == user.first.filename();
Patrick Williams5a39f772023-10-20 11:20:21 -05001984 });
Ed Tanous1ef4c342022-05-12 16:12:36 -07001985
1986 if (userIt == users.end())
1987 {
1988 messages::resourceNotFound(asyncResp->res, "ManagerAccount",
1989 accountName);
1990 return;
1991 }
1992
1993 asyncResp->res.jsonValue["@odata.type"] =
Abhishek Patel58345852022-02-02 08:54:25 -06001994 "#ManagerAccount.v1_7_0.ManagerAccount";
Ed Tanous1ef4c342022-05-12 16:12:36 -07001995 asyncResp->res.jsonValue["Name"] = "User Account";
1996 asyncResp->res.jsonValue["Description"] = "User Account";
1997 asyncResp->res.jsonValue["Password"] = nullptr;
Abhishek Patel58345852022-02-02 08:54:25 -06001998 asyncResp->res.jsonValue["StrictAccountTypes"] = true;
Ed Tanous1ef4c342022-05-12 16:12:36 -07001999
2000 for (const auto& interface : userIt->second)
2001 {
2002 if (interface.first == "xyz.openbmc_project.User.Attributes")
2003 {
2004 for (const auto& property : interface.second)
2005 {
2006 if (property.first == "UserEnabled")
2007 {
2008 const bool* userEnabled =
2009 std::get_if<bool>(&property.second);
2010 if (userEnabled == nullptr)
2011 {
Ed Tanous62598e32023-07-17 17:06:25 -07002012 BMCWEB_LOG_ERROR("UserEnabled wasn't a bool");
Ed Tanous1ef4c342022-05-12 16:12:36 -07002013 messages::internalError(asyncResp->res);
2014 return;
2015 }
2016 asyncResp->res.jsonValue["Enabled"] = *userEnabled;
2017 }
2018 else if (property.first == "UserLockedForFailedAttempt")
2019 {
2020 const bool* userLocked =
2021 std::get_if<bool>(&property.second);
2022 if (userLocked == nullptr)
2023 {
Ed Tanous62598e32023-07-17 17:06:25 -07002024 BMCWEB_LOG_ERROR("UserLockedForF"
2025 "ailedAttempt "
2026 "wasn't a bool");
Ed Tanous1ef4c342022-05-12 16:12:36 -07002027 messages::internalError(asyncResp->res);
2028 return;
2029 }
2030 asyncResp->res.jsonValue["Locked"] = *userLocked;
Ed Tanous20fa6a22024-05-20 18:02:58 -07002031 nlohmann::json::array_t allowed;
2032 // can only unlock accounts
2033 allowed.emplace_back("false");
Ed Tanous1ef4c342022-05-12 16:12:36 -07002034 asyncResp->res
Ed Tanous20fa6a22024-05-20 18:02:58 -07002035 .jsonValue["Locked@Redfish.AllowableValues"] =
2036 std::move(allowed);
Ed Tanous1ef4c342022-05-12 16:12:36 -07002037 }
2038 else if (property.first == "UserPrivilege")
2039 {
2040 const std::string* userPrivPtr =
2041 std::get_if<std::string>(&property.second);
2042 if (userPrivPtr == nullptr)
2043 {
Ed Tanous62598e32023-07-17 17:06:25 -07002044 BMCWEB_LOG_ERROR("UserPrivilege wasn't a "
2045 "string");
Ed Tanous1ef4c342022-05-12 16:12:36 -07002046 messages::internalError(asyncResp->res);
2047 return;
2048 }
2049 std::string role = getRoleIdFromPrivilege(*userPrivPtr);
2050 if (role.empty())
2051 {
Ed Tanous62598e32023-07-17 17:06:25 -07002052 BMCWEB_LOG_ERROR("Invalid user role");
Ed Tanous1ef4c342022-05-12 16:12:36 -07002053 messages::internalError(asyncResp->res);
2054 return;
2055 }
2056 asyncResp->res.jsonValue["RoleId"] = role;
2057
2058 nlohmann::json& roleEntry =
2059 asyncResp->res.jsonValue["Links"]["Role"];
Ed Tanous3b327802023-08-14 09:23:43 -07002060 roleEntry["@odata.id"] = boost::urls::format(
2061 "/redfish/v1/AccountService/Roles/{}", role);
Ed Tanous1ef4c342022-05-12 16:12:36 -07002062 }
2063 else if (property.first == "UserPasswordExpired")
2064 {
2065 const bool* userPasswordExpired =
2066 std::get_if<bool>(&property.second);
2067 if (userPasswordExpired == nullptr)
2068 {
Ed Tanous62598e32023-07-17 17:06:25 -07002069 BMCWEB_LOG_ERROR(
2070 "UserPasswordExpired wasn't a bool");
Ed Tanous1ef4c342022-05-12 16:12:36 -07002071 messages::internalError(asyncResp->res);
2072 return;
2073 }
2074 asyncResp->res.jsonValue["PasswordChangeRequired"] =
2075 *userPasswordExpired;
2076 }
Abhishek Patelc7229812022-02-01 10:07:15 -06002077 else if (property.first == "UserGroups")
2078 {
2079 const std::vector<std::string>* userGroups =
2080 std::get_if<std::vector<std::string>>(
2081 &property.second);
2082 if (userGroups == nullptr)
2083 {
Ed Tanous62598e32023-07-17 17:06:25 -07002084 BMCWEB_LOG_ERROR(
2085 "userGroups wasn't a string vector");
Abhishek Patelc7229812022-02-01 10:07:15 -06002086 messages::internalError(asyncResp->res);
2087 return;
2088 }
2089 if (!translateUserGroup(*userGroups, asyncResp->res))
2090 {
Ed Tanous62598e32023-07-17 17:06:25 -07002091 BMCWEB_LOG_ERROR("userGroups mapping failed");
Abhishek Patelc7229812022-02-01 10:07:15 -06002092 messages::internalError(asyncResp->res);
2093 return;
2094 }
2095 }
Ed Tanous1ef4c342022-05-12 16:12:36 -07002096 }
2097 }
2098 }
2099
Ed Tanous3b327802023-08-14 09:23:43 -07002100 asyncResp->res.jsonValue["@odata.id"] = boost::urls::format(
2101 "/redfish/v1/AccountService/Accounts/{}", accountName);
Ed Tanous1ef4c342022-05-12 16:12:36 -07002102 asyncResp->res.jsonValue["Id"] = accountName;
2103 asyncResp->res.jsonValue["UserName"] = accountName;
Patrick Williams5a39f772023-10-20 11:20:21 -05002104 });
Ed Tanous1ef4c342022-05-12 16:12:36 -07002105}
2106
2107inline void
Gunnar Mills20fc3072023-01-27 15:13:36 -06002108 handleAccountDelete(App& app, const crow::Request& req,
2109 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2110 const std::string& username)
Ed Tanous1ef4c342022-05-12 16:12:36 -07002111{
2112 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2113 {
2114 return;
2115 }
2116
Ed Tanous25b54db2024-04-17 15:40:31 -07002117 if constexpr (BMCWEB_INSECURE_DISABLE_AUTH)
2118 {
2119 // If authentication is disabled, there are no user accounts
2120 messages::resourceNotFound(asyncResp->res, "ManagerAccount", username);
2121 return;
2122 }
Ed Tanous1ef4c342022-05-12 16:12:36 -07002123 sdbusplus::message::object_path tempObjPath(rootUserDbusPath);
2124 tempObjPath /= username;
2125 const std::string userPath(tempObjPath);
2126
2127 crow::connections::systemBus->async_method_call(
Ed Tanous5e7e2dc2023-02-16 10:37:01 -08002128 [asyncResp, username](const boost::system::error_code& ec) {
Ed Tanous1ef4c342022-05-12 16:12:36 -07002129 if (ec)
2130 {
Jiaqing Zhaod8a5d5d2022-08-05 16:21:51 +08002131 messages::resourceNotFound(asyncResp->res, "ManagerAccount",
Ed Tanous1ef4c342022-05-12 16:12:36 -07002132 username);
2133 return;
2134 }
2135
2136 messages::accountRemoved(asyncResp->res);
Patrick Williams5a39f772023-10-20 11:20:21 -05002137 },
Ed Tanous1ef4c342022-05-12 16:12:36 -07002138 "xyz.openbmc_project.User.Manager", userPath,
2139 "xyz.openbmc_project.Object.Delete", "Delete");
2140}
2141
2142inline void
2143 handleAccountPatch(App& app, const crow::Request& req,
2144 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2145 const std::string& username)
2146{
2147 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2148 {
2149 return;
2150 }
Ed Tanous25b54db2024-04-17 15:40:31 -07002151 if constexpr (BMCWEB_INSECURE_DISABLE_AUTH)
2152 {
2153 // If authentication is disabled, there are no user accounts
2154 messages::resourceNotFound(asyncResp->res, "ManagerAccount", username);
2155 return;
2156 }
Ed Tanous1ef4c342022-05-12 16:12:36 -07002157 std::optional<std::string> newUserName;
2158 std::optional<std::string> password;
2159 std::optional<bool> enabled;
2160 std::optional<std::string> roleId;
2161 std::optional<bool> locked;
Abhishek Patel58345852022-02-02 08:54:25 -06002162 std::optional<std::vector<std::string>> accountTypes;
2163
Ed Tanous1ef4c342022-05-12 16:12:36 -07002164 if (req.session == nullptr)
2165 {
2166 messages::internalError(asyncResp->res);
2167 return;
2168 }
2169
Ed Tanous2b9c1df2024-04-06 13:52:01 -07002170 bool userSelf = (username == req.session->username);
2171
Ed Tanous1ef4c342022-05-12 16:12:36 -07002172 Privileges effectiveUserPrivileges =
Ninad Palsule3e72c202023-03-27 17:19:55 -05002173 redfish::getUserPrivileges(*req.session);
Ed Tanous1ef4c342022-05-12 16:12:36 -07002174 Privileges configureUsers = {"ConfigureUsers"};
2175 bool userHasConfigureUsers =
2176 effectiveUserPrivileges.isSupersetOf(configureUsers);
2177 if (userHasConfigureUsers)
2178 {
2179 // Users with ConfigureUsers can modify for all users
Abhishek Patel58345852022-02-02 08:54:25 -06002180 if (!json_util::readJsonPatch(
2181 req, asyncResp->res, "UserName", newUserName, "Password",
2182 password, "RoleId", roleId, "Enabled", enabled, "Locked",
2183 locked, "AccountTypes", accountTypes))
Ed Tanous1ef4c342022-05-12 16:12:36 -07002184 {
2185 return;
2186 }
2187 }
2188 else
2189 {
2190 // ConfigureSelf accounts can only modify their own account
Abhishek Patel58345852022-02-02 08:54:25 -06002191 if (!userSelf)
Ed Tanous1ef4c342022-05-12 16:12:36 -07002192 {
2193 messages::insufficientPrivilege(asyncResp->res);
2194 return;
2195 }
2196
2197 // ConfigureSelf accounts can only modify their password
2198 if (!json_util::readJsonPatch(req, asyncResp->res, "Password",
2199 password))
2200 {
2201 return;
2202 }
2203 }
2204
2205 // if user name is not provided in the patch method or if it
2206 // matches the user name in the URI, then we are treating it as
2207 // updating user properties other then username. If username
2208 // provided doesn't match the URI, then we are treating this as
2209 // user rename request.
2210 if (!newUserName || (newUserName.value() == username))
2211 {
2212 updateUserProperties(asyncResp, username, password, enabled, roleId,
Ravi Tejae518ef32024-05-16 10:33:08 -05002213 locked, accountTypes, userSelf, req.session);
Ed Tanous1ef4c342022-05-12 16:12:36 -07002214 return;
2215 }
2216 crow::connections::systemBus->async_method_call(
2217 [asyncResp, username, password(std::move(password)),
2218 roleId(std::move(roleId)), enabled, newUser{std::string(*newUserName)},
Ravi Tejae518ef32024-05-16 10:33:08 -05002219 locked, userSelf, req, accountTypes(std::move(accountTypes))](
Ed Tanouse81de512023-06-27 17:07:00 -07002220 const boost::system::error_code& ec, sdbusplus::message_t& m) {
Ed Tanous1ef4c342022-05-12 16:12:36 -07002221 if (ec)
2222 {
2223 userErrorMessageHandler(m.get_error(), asyncResp, newUser,
2224 username);
2225 return;
2226 }
2227
2228 updateUserProperties(asyncResp, newUser, password, enabled, roleId,
Ravi Tejae518ef32024-05-16 10:33:08 -05002229 locked, accountTypes, userSelf, req.session);
Patrick Williams5a39f772023-10-20 11:20:21 -05002230 },
Ed Tanous1ef4c342022-05-12 16:12:36 -07002231 "xyz.openbmc_project.User.Manager", "/xyz/openbmc_project/user",
2232 "xyz.openbmc_project.User.Manager", "RenameUser", username,
2233 *newUserName);
2234}
2235
Ed Tanous6c51eab2021-06-03 12:30:29 -07002236inline void requestAccountServiceRoutes(App& app)
Ed Tanousb9b2e0b2018-09-13 13:47:50 -07002237{
Ed Tanous6c51eab2021-06-03 12:30:29 -07002238 BMCWEB_ROUTE(app, "/redfish/v1/AccountService/")
Ed Tanous4c7d4d32022-07-07 15:29:35 -07002239 .privileges(redfish::privileges::headAccountService)
2240 .methods(boost::beast::http::verb::head)(
2241 std::bind_front(handleAccountServiceHead, std::ref(app)));
2242
2243 BMCWEB_ROUTE(app, "/redfish/v1/AccountService/")
Ed Tanoused398212021-06-09 17:05:54 -07002244 .privileges(redfish::privileges::getAccountService)
Ed Tanous002d39b2022-05-31 08:59:27 -07002245 .methods(boost::beast::http::verb::get)(
Ed Tanous1ef4c342022-05-12 16:12:36 -07002246 std::bind_front(handleAccountServiceGet, std::ref(app)));
Ed Tanous6c51eab2021-06-03 12:30:29 -07002247
Ed Tanousf5ffd802021-07-19 10:55:33 -07002248 BMCWEB_ROUTE(app, "/redfish/v1/AccountService/")
Gunnar Mills1ec43ee2022-01-04 15:39:52 -06002249 .privileges(redfish::privileges::patchAccountService)
Ed Tanousf5ffd802021-07-19 10:55:33 -07002250 .methods(boost::beast::http::verb::patch)(
Ed Tanous1ef4c342022-05-12 16:12:36 -07002251 std::bind_front(handleAccountServicePatch, std::ref(app)));
Ed Tanousf5ffd802021-07-19 10:55:33 -07002252
Ed Tanous1aa375b2024-04-13 11:51:10 -07002253 BMCWEB_ROUTE(
2254 app,
2255 "/redfish/v1/AccountService/MultiFactorAuth/ClientCertificate/Certificates")
2256 .privileges(redfish::privileges::headCertificateCollection)
2257 .methods(boost::beast::http::verb::head)(std::bind_front(
2258 handleAccountServiceClientCertificatesHead, std::ref(app)));
2259
2260 BMCWEB_ROUTE(
2261 app,
2262 "/redfish/v1/AccountService/MultiFactorAuth/ClientCertificate/Certificates")
2263 .privileges(redfish::privileges::getCertificateCollection)
2264 .methods(boost::beast::http::verb::get)(std::bind_front(
2265 handleAccountServiceClientCertificatesGet, std::ref(app)));
2266
2267 BMCWEB_ROUTE(
2268 app,
2269 "/redfish/v1/AccountService/MultiFactorAuth/ClientCertificate/Certificates/<str>")
2270 .privileges(redfish::privileges::headCertificate)
2271 .methods(boost::beast::http::verb::head)(std::bind_front(
2272 handleAccountServiceClientCertificatesInstanceHead, std::ref(app)));
2273
2274 BMCWEB_ROUTE(
2275 app,
2276 "/redfish/v1/AccountService/MultiFactorAuth/ClientCertificate/Certificates/<str>/")
2277 .privileges(redfish::privileges::getCertificate)
2278 .methods(boost::beast::http::verb::get)(std::bind_front(
2279 handleAccountServiceClientCertificatesInstanceGet, std::ref(app)));
2280
Ed Tanous6c51eab2021-06-03 12:30:29 -07002281 BMCWEB_ROUTE(app, "/redfish/v1/AccountService/Accounts/")
Ed Tanous4c7d4d32022-07-07 15:29:35 -07002282 .privileges(redfish::privileges::headManagerAccountCollection)
2283 .methods(boost::beast::http::verb::head)(
2284 std::bind_front(handleAccountCollectionHead, std::ref(app)));
2285
2286 BMCWEB_ROUTE(app, "/redfish/v1/AccountService/Accounts/")
Ed Tanoused398212021-06-09 17:05:54 -07002287 .privileges(redfish::privileges::getManagerAccountCollection)
Ed Tanous6c51eab2021-06-03 12:30:29 -07002288 .methods(boost::beast::http::verb::get)(
Ed Tanous1ef4c342022-05-12 16:12:36 -07002289 std::bind_front(handleAccountCollectionGet, std::ref(app)));
Ed Tanous06e086d2018-09-19 17:19:52 -07002290
Ed Tanous6c51eab2021-06-03 12:30:29 -07002291 BMCWEB_ROUTE(app, "/redfish/v1/AccountService/Accounts/")
Ed Tanoused398212021-06-09 17:05:54 -07002292 .privileges(redfish::privileges::postManagerAccountCollection)
Ed Tanous002d39b2022-05-31 08:59:27 -07002293 .methods(boost::beast::http::verb::post)(
Ed Tanous1ef4c342022-05-12 16:12:36 -07002294 std::bind_front(handleAccountCollectionPost, std::ref(app)));
Ed Tanous002d39b2022-05-31 08:59:27 -07002295
2296 BMCWEB_ROUTE(app, "/redfish/v1/AccountService/Accounts/<str>/")
Ed Tanous4c7d4d32022-07-07 15:29:35 -07002297 .privileges(redfish::privileges::headManagerAccount)
2298 .methods(boost::beast::http::verb::head)(
2299 std::bind_front(handleAccountHead, std::ref(app)));
2300
2301 BMCWEB_ROUTE(app, "/redfish/v1/AccountService/Accounts/<str>/")
Ed Tanous002d39b2022-05-31 08:59:27 -07002302 .privileges(redfish::privileges::getManagerAccount)
2303 .methods(boost::beast::http::verb::get)(
Ed Tanous1ef4c342022-05-12 16:12:36 -07002304 std::bind_front(handleAccountGet, std::ref(app)));
Ed Tanous6c51eab2021-06-03 12:30:29 -07002305
2306 BMCWEB_ROUTE(app, "/redfish/v1/AccountService/Accounts/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07002307 // TODO this privilege should be using the generated endpoints, but
2308 // because of the special handling of ConfigureSelf, it's not able to
2309 // yet
Ed Tanous6c51eab2021-06-03 12:30:29 -07002310 .privileges({{"ConfigureUsers"}, {"ConfigureSelf"}})
2311 .methods(boost::beast::http::verb::patch)(
Ed Tanous1ef4c342022-05-12 16:12:36 -07002312 std::bind_front(handleAccountPatch, std::ref(app)));
Ed Tanous6c51eab2021-06-03 12:30:29 -07002313
2314 BMCWEB_ROUTE(app, "/redfish/v1/AccountService/Accounts/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -07002315 .privileges(redfish::privileges::deleteManagerAccount)
Ed Tanous6c51eab2021-06-03 12:30:29 -07002316 .methods(boost::beast::http::verb::delete_)(
Gunnar Mills20fc3072023-01-27 15:13:36 -06002317 std::bind_front(handleAccountDelete, std::ref(app)));
Ed Tanous6c51eab2021-06-03 12:30:29 -07002318}
Lewanczyk, Dawid88d16c92018-02-02 14:51:09 +01002319
Ed Tanous1abe55e2018-09-05 08:30:59 -07002320} // namespace redfish