Lewanczyk, Dawid | 88d16c9 | 2018-02-02 14:51:09 +0100 | [diff] [blame] | 1 | /* |
| 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, Dawid | 88d16c9 | 2018-02-02 14:51:09 +0100 | [diff] [blame] | 17 | |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 18 | #include "app.hpp" |
Gunnar Mills | a0735a4 | 2024-09-06 12:51:11 -0500 | [diff] [blame] | 19 | #include "boost_formatters.hpp" |
Ed Tanous | 1aa375b | 2024-04-13 11:51:10 -0700 | [diff] [blame] | 20 | #include "certificate_service.hpp" |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 21 | #include "dbus_utility.hpp" |
| 22 | #include "error_messages.hpp" |
Ed Tanous | 0ec8b83 | 2022-03-14 14:56:47 -0700 | [diff] [blame] | 23 | #include "generated/enums/account_service.hpp" |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 24 | #include "persistent_data.hpp" |
| 25 | #include "query.hpp" |
Ed Tanous | 0ec8b83 | 2022-03-14 14:56:47 -0700 | [diff] [blame] | 26 | #include "registries/privilege_registry.hpp" |
Ed Tanous | 3281bcf | 2024-06-25 16:02:05 -0700 | [diff] [blame] | 27 | #include "sessions.hpp" |
Ed Tanous | 1aa375b | 2024-04-13 11:51:10 -0700 | [diff] [blame] | 28 | #include "utils/collection.hpp" |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 29 | #include "utils/dbus_utils.hpp" |
| 30 | #include "utils/json_utils.hpp" |
Ed Tanous | 0ec8b83 | 2022-03-14 14:56:47 -0700 | [diff] [blame] | 31 | |
Ed Tanous | 1aa375b | 2024-04-13 11:51:10 -0700 | [diff] [blame] | 32 | #include <boost/url/format.hpp> |
| 33 | #include <boost/url/url.hpp> |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 34 | #include <sdbusplus/asio/property.hpp> |
Krzysztof Grobelny | d1bde9e | 2022-09-07 10:40:51 +0200 | [diff] [blame] | 35 | #include <sdbusplus/unpack_properties.hpp> |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 36 | |
George Liu | 2b73119 | 2023-01-11 16:27:13 +0800 | [diff] [blame] | 37 | #include <array> |
Ed Tanous | 1aa375b | 2024-04-13 11:51:10 -0700 | [diff] [blame] | 38 | #include <memory> |
Abhishek Patel | c722981 | 2022-02-01 10:07:15 -0600 | [diff] [blame] | 39 | #include <optional> |
Ed Tanous | 3544d2a | 2023-08-06 18:12:20 -0700 | [diff] [blame] | 40 | #include <ranges> |
Abhishek Patel | c722981 | 2022-02-01 10:07:15 -0600 | [diff] [blame] | 41 | #include <string> |
George Liu | 2b73119 | 2023-01-11 16:27:13 +0800 | [diff] [blame] | 42 | #include <string_view> |
Ed Tanous | 20fa6a2 | 2024-05-20 18:02:58 -0700 | [diff] [blame] | 43 | #include <utility> |
Abhishek Patel | c722981 | 2022-02-01 10:07:15 -0600 | [diff] [blame] | 44 | #include <vector> |
| 45 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 46 | namespace redfish |
| 47 | { |
Lewanczyk, Dawid | 88d16c9 | 2018-02-02 14:51:09 +0100 | [diff] [blame] | 48 | |
Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 49 | constexpr const char* ldapConfigObjectName = |
Ratan Gupta | 6973a58 | 2018-12-13 18:25:44 +0530 | [diff] [blame] | 50 | "/xyz/openbmc_project/user/ldap/openldap"; |
Ed Tanous | 2c70f80 | 2020-09-28 14:29:23 -0700 | [diff] [blame] | 51 | constexpr const char* adConfigObject = |
Ratan Gupta | ab828d7 | 2019-04-22 14:18:33 +0530 | [diff] [blame] | 52 | "/xyz/openbmc_project/user/ldap/active_directory"; |
| 53 | |
P Dheeraj Srujan Kumar | b477fd4 | 2021-12-16 07:17:51 +0530 | [diff] [blame] | 54 | constexpr const char* rootUserDbusPath = "/xyz/openbmc_project/user/"; |
Ratan Gupta | 6973a58 | 2018-12-13 18:25:44 +0530 | [diff] [blame] | 55 | constexpr const char* ldapRootObject = "/xyz/openbmc_project/user/ldap"; |
| 56 | constexpr const char* ldapDbusService = "xyz.openbmc_project.Ldap.Config"; |
| 57 | constexpr const char* ldapConfigInterface = |
| 58 | "xyz.openbmc_project.User.Ldap.Config"; |
| 59 | constexpr const char* ldapCreateInterface = |
| 60 | "xyz.openbmc_project.User.Ldap.Create"; |
| 61 | constexpr const char* ldapEnableInterface = "xyz.openbmc_project.Object.Enable"; |
Ratan Gupta | 0678524 | 2019-07-26 22:30:16 +0530 | [diff] [blame] | 62 | constexpr const char* ldapPrivMapperInterface = |
| 63 | "xyz.openbmc_project.User.PrivilegeMapper"; |
Ratan Gupta | 6973a58 | 2018-12-13 18:25:44 +0530 | [diff] [blame] | 64 | |
Nagaraju Goruganti | 54fc587 | 2019-01-30 05:11:00 -0600 | [diff] [blame] | 65 | struct LDAPRoleMapData |
| 66 | { |
| 67 | std::string groupName; |
| 68 | std::string privilege; |
| 69 | }; |
| 70 | |
Ratan Gupta | 6973a58 | 2018-12-13 18:25:44 +0530 | [diff] [blame] | 71 | struct LDAPConfigData |
| 72 | { |
Ed Tanous | 47f2934 | 2024-03-19 12:18:06 -0700 | [diff] [blame] | 73 | std::string uri; |
| 74 | std::string bindDN; |
| 75 | std::string baseDN; |
| 76 | std::string searchScope; |
| 77 | std::string serverType; |
Ratan Gupta | 6973a58 | 2018-12-13 18:25:44 +0530 | [diff] [blame] | 78 | bool serviceEnabled = false; |
Ed Tanous | 47f2934 | 2024-03-19 12:18:06 -0700 | [diff] [blame] | 79 | std::string userNameAttribute; |
| 80 | std::string groupAttribute; |
Nagaraju Goruganti | 54fc587 | 2019-01-30 05:11:00 -0600 | [diff] [blame] | 81 | std::vector<std::pair<std::string, LDAPRoleMapData>> groupRoleList; |
Ratan Gupta | 6973a58 | 2018-12-13 18:25:44 +0530 | [diff] [blame] | 82 | }; |
| 83 | |
Nagaraju Goruganti | 54fc587 | 2019-01-30 05:11:00 -0600 | [diff] [blame] | 84 | inline std::string getRoleIdFromPrivilege(std::string_view role) |
AppaRao Puli | 84e12cb | 2018-10-11 01:28:15 +0530 | [diff] [blame] | 85 | { |
| 86 | if (role == "priv-admin") |
| 87 | { |
| 88 | return "Administrator"; |
| 89 | } |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 90 | if (role == "priv-user") |
AppaRao Puli | 84e12cb | 2018-10-11 01:28:15 +0530 | [diff] [blame] | 91 | { |
AppaRao Puli | c80fee5 | 2019-10-16 14:49:36 +0530 | [diff] [blame] | 92 | return "ReadOnly"; |
AppaRao Puli | 84e12cb | 2018-10-11 01:28:15 +0530 | [diff] [blame] | 93 | } |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 94 | if (role == "priv-operator") |
AppaRao Puli | 84e12cb | 2018-10-11 01:28:15 +0530 | [diff] [blame] | 95 | { |
| 96 | return "Operator"; |
| 97 | } |
| 98 | return ""; |
| 99 | } |
Nagaraju Goruganti | 54fc587 | 2019-01-30 05:11:00 -0600 | [diff] [blame] | 100 | inline std::string getPrivilegeFromRoleId(std::string_view role) |
AppaRao Puli | 84e12cb | 2018-10-11 01:28:15 +0530 | [diff] [blame] | 101 | { |
| 102 | if (role == "Administrator") |
| 103 | { |
| 104 | return "priv-admin"; |
| 105 | } |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 106 | if (role == "ReadOnly") |
AppaRao Puli | 84e12cb | 2018-10-11 01:28:15 +0530 | [diff] [blame] | 107 | { |
| 108 | return "priv-user"; |
| 109 | } |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 110 | if (role == "Operator") |
AppaRao Puli | 84e12cb | 2018-10-11 01:28:15 +0530 | [diff] [blame] | 111 | { |
| 112 | return "priv-operator"; |
| 113 | } |
| 114 | return ""; |
| 115 | } |
Ed Tanous | b9b2e0b | 2018-09-13 13:47:50 -0700 | [diff] [blame] | 116 | |
Abhishek Patel | c722981 | 2022-02-01 10:07:15 -0600 | [diff] [blame] | 117 | /** |
| 118 | * @brief Maps user group names retrieved from D-Bus object to |
| 119 | * Account Types. |
| 120 | * |
| 121 | * @param[in] userGroups List of User groups |
| 122 | * @param[out] res AccountTypes populated |
| 123 | * |
| 124 | * @return true in case of success, false if UserGroups contains |
| 125 | * invalid group name(s). |
| 126 | */ |
| 127 | inline bool translateUserGroup(const std::vector<std::string>& userGroups, |
| 128 | crow::Response& res) |
| 129 | { |
| 130 | std::vector<std::string> accountTypes; |
| 131 | for (const auto& userGroup : userGroups) |
| 132 | { |
| 133 | if (userGroup == "redfish") |
| 134 | { |
| 135 | accountTypes.emplace_back("Redfish"); |
| 136 | accountTypes.emplace_back("WebUI"); |
| 137 | } |
| 138 | else if (userGroup == "ipmi") |
| 139 | { |
| 140 | accountTypes.emplace_back("IPMI"); |
| 141 | } |
| 142 | else if (userGroup == "ssh") |
| 143 | { |
Abhishek Patel | c722981 | 2022-02-01 10:07:15 -0600 | [diff] [blame] | 144 | accountTypes.emplace_back("ManagerConsole"); |
| 145 | } |
Ninad Palsule | 3e72c20 | 2023-03-27 17:19:55 -0500 | [diff] [blame] | 146 | else if (userGroup == "hostconsole") |
| 147 | { |
| 148 | // The hostconsole group controls who can access the host console |
| 149 | // port via ssh and websocket. |
| 150 | accountTypes.emplace_back("HostConsole"); |
| 151 | } |
Abhishek Patel | c722981 | 2022-02-01 10:07:15 -0600 | [diff] [blame] | 152 | else if (userGroup == "web") |
| 153 | { |
| 154 | // 'web' is one of the valid groups in the UserGroups property of |
| 155 | // the user account in the D-Bus object. This group is currently not |
| 156 | // doing anything, and is considered to be equivalent to 'redfish'. |
| 157 | // 'redfish' user group is mapped to 'Redfish'and 'WebUI' |
| 158 | // AccountTypes, so do nothing here... |
| 159 | } |
| 160 | else |
| 161 | { |
Ed Tanous | 8ece0e4 | 2024-01-02 13:16:50 -0800 | [diff] [blame] | 162 | // Invalid user group name. Caller throws an exception. |
Abhishek Patel | c722981 | 2022-02-01 10:07:15 -0600 | [diff] [blame] | 163 | return false; |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | res.jsonValue["AccountTypes"] = std::move(accountTypes); |
| 168 | return true; |
| 169 | } |
| 170 | |
Abhishek Patel | 5834585 | 2022-02-02 08:54:25 -0600 | [diff] [blame] | 171 | /** |
| 172 | * @brief Builds User Groups from the Account Types |
| 173 | * |
| 174 | * @param[in] asyncResp Async Response |
| 175 | * @param[in] accountTypes List of Account Types |
| 176 | * @param[out] userGroups List of User Groups mapped from Account Types |
| 177 | * |
| 178 | * @return true if Account Types mapped to User Groups, false otherwise. |
| 179 | */ |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 180 | inline bool getUserGroupFromAccountType( |
| 181 | crow::Response& res, const std::vector<std::string>& accountTypes, |
| 182 | std::vector<std::string>& userGroups) |
Abhishek Patel | 5834585 | 2022-02-02 08:54:25 -0600 | [diff] [blame] | 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 Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 221 | BMCWEB_LOG_ERROR( |
| 222 | "Missing Redfish or WebUI Account Type to set redfish User Group"); |
Abhishek Patel | 5834585 | 2022-02-02 08:54:25 -0600 | [diff] [blame] | 223 | 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 | */ |
| 243 | inline 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 Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 253 | BMCWEB_LOG_ERROR( |
| 254 | "User disabling OWN Redfish Account Type is not allowed"); |
Abhishek Patel | 5834585 | 2022-02-02 08:54:25 -0600 | [diff] [blame] | 255 | 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 George | e93abac | 2024-06-14 17:35:27 +0530 | [diff] [blame] | 267 | setDbusProperty(asyncResp, "AccountTypes", |
| 268 | "xyz.openbmc_project.User.Manager", dbusObjectPath, |
| 269 | "xyz.openbmc_project.User.Attributes", "UserGroups", |
| 270 | updatedUserGroups); |
Abhishek Patel | 5834585 | 2022-02-02 08:54:25 -0600 | [diff] [blame] | 271 | } |
| 272 | |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 273 | inline 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 Mutyala | 66b5ca7 | 2019-08-07 20:26:37 +0000 | [diff] [blame] | 276 | { |
jayaprakash Mutyala | 66b5ca7 | 2019-08-07 20:26:37 +0000 | [diff] [blame] | 277 | if (e == nullptr) |
| 278 | { |
| 279 | messages::internalError(asyncResp->res); |
| 280 | return; |
| 281 | } |
| 282 | |
Manojkiran Eda | 055806b | 2020-11-03 09:36:28 +0530 | [diff] [blame] | 283 | const char* errorMessage = e->name; |
jayaprakash Mutyala | 66b5ca7 | 2019-08-07 20:26:37 +0000 | [diff] [blame] | 284 | if (strcmp(errorMessage, |
| 285 | "xyz.openbmc_project.User.Common.Error.UserNameExists") == 0) |
| 286 | { |
Jiaqing Zhao | d8a5d5d | 2022-08-05 16:21:51 +0800 | [diff] [blame] | 287 | messages::resourceAlreadyExists(asyncResp->res, "ManagerAccount", |
jayaprakash Mutyala | 66b5ca7 | 2019-08-07 20:26:37 +0000 | [diff] [blame] | 288 | "UserName", newUser); |
| 289 | } |
| 290 | else if (strcmp(errorMessage, "xyz.openbmc_project.User.Common.Error." |
| 291 | "UserNameDoesNotExist") == 0) |
| 292 | { |
Jiaqing Zhao | d8a5d5d | 2022-08-05 16:21:51 +0800 | [diff] [blame] | 293 | messages::resourceNotFound(asyncResp->res, "ManagerAccount", username); |
jayaprakash Mutyala | 66b5ca7 | 2019-08-07 20:26:37 +0000 | [diff] [blame] | 294 | } |
Ed Tanous | d4d2579 | 2020-09-29 15:15:03 -0700 | [diff] [blame] | 295 | else if ((strcmp(errorMessage, |
| 296 | "xyz.openbmc_project.Common.Error.InvalidArgument") == |
| 297 | 0) || |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 298 | (strcmp( |
| 299 | errorMessage, |
| 300 | "xyz.openbmc_project.User.Common.Error.UserNameGroupFail") == |
| 301 | 0)) |
jayaprakash Mutyala | 66b5ca7 | 2019-08-07 20:26:37 +0000 | [diff] [blame] | 302 | { |
| 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 Mutyala | 66b5ca7 | 2019-08-07 20:26:37 +0000 | [diff] [blame] | 310 | else |
| 311 | { |
Gunnar Mills | b8ad583 | 2023-10-02 16:26:07 -0500 | [diff] [blame] | 312 | BMCWEB_LOG_ERROR("DBUS response error {}", errorMessage); |
jayaprakash Mutyala | 66b5ca7 | 2019-08-07 20:26:37 +0000 | [diff] [blame] | 313 | messages::internalError(asyncResp->res); |
| 314 | } |
jayaprakash Mutyala | 66b5ca7 | 2019-08-07 20:26:37 +0000 | [diff] [blame] | 315 | } |
| 316 | |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 317 | inline void parseLDAPConfigData(nlohmann::json& jsonResponse, |
Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 318 | const LDAPConfigData& confData, |
| 319 | const std::string& ldapType) |
Ratan Gupta | 6973a58 | 2018-12-13 18:25:44 +0530 | [diff] [blame] | 320 | { |
Ed Tanous | 49cc263 | 2024-03-20 12:49:15 -0700 | [diff] [blame] | 321 | nlohmann::json::object_t ldap; |
Ed Tanous | 1476687 | 2022-03-15 10:44:42 -0700 | [diff] [blame] | 322 | ldap["ServiceEnabled"] = confData.serviceEnabled; |
Ed Tanous | 49cc263 | 2024-03-20 12:49:15 -0700 | [diff] [blame] | 323 | 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 Tanous | 0ec8b83 | 2022-03-14 14:56:47 -0700 | [diff] [blame] | 329 | account_service::AuthenticationTypes::UsernameAndPassword; |
Ed Tanous | 49cc263 | 2024-03-20 12:49:15 -0700 | [diff] [blame] | 330 | authentication["Username"] = confData.bindDN; |
| 331 | authentication["Password"] = nullptr; |
| 332 | ldap["Authentication"] = std::move(authentication); |
Ed Tanous | 1476687 | 2022-03-15 10:44:42 -0700 | [diff] [blame] | 333 | |
Ed Tanous | 49cc263 | 2024-03-20 12:49:15 -0700 | [diff] [blame] | 334 | nlohmann::json::object_t ldapService; |
| 335 | nlohmann::json::object_t searchSettings; |
| 336 | nlohmann::json::array_t baseDistinguishedNames; |
| 337 | baseDistinguishedNames.emplace_back(confData.baseDN); |
Ed Tanous | 1476687 | 2022-03-15 10:44:42 -0700 | [diff] [blame] | 338 | |
Ed Tanous | 49cc263 | 2024-03-20 12:49:15 -0700 | [diff] [blame] | 339 | 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 Tanous | 9eb808c | 2022-01-25 10:19:23 -0800 | [diff] [blame] | 347 | for (const auto& obj : confData.groupRoleList) |
Nagaraju Goruganti | 54fc587 | 2019-01-30 05:11:00 -0600 | [diff] [blame] | 348 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 349 | BMCWEB_LOG_DEBUG("Pushing the data groupName={}", obj.second.groupName); |
Ed Tanous | 613dabe | 2022-07-09 11:17:36 -0700 | [diff] [blame] | 350 | |
Ed Tanous | 613dabe | 2022-07-09 11:17:36 -0700 | [diff] [blame] | 351 | nlohmann::json::object_t remoteGroup; |
| 352 | remoteGroup["RemoteGroup"] = obj.second.groupName; |
Jorge Cisneros | 329f034 | 2022-11-04 16:26:25 +0000 | [diff] [blame] | 353 | remoteGroup["LocalRole"] = getRoleIdFromPrivilege(obj.second.privilege); |
| 354 | roleMapArray.emplace_back(std::move(remoteGroup)); |
Nagaraju Goruganti | 54fc587 | 2019-01-30 05:11:00 -0600 | [diff] [blame] | 355 | } |
Ed Tanous | 49cc263 | 2024-03-20 12:49:15 -0700 | [diff] [blame] | 356 | |
| 357 | ldap["RemoteRoleMapping"] = std::move(roleMapArray); |
| 358 | |
| 359 | jsonResponse[ldapType].update(ldap); |
Ratan Gupta | 6973a58 | 2018-12-13 18:25:44 +0530 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | /** |
Ratan Gupta | 0678524 | 2019-07-26 22:30:16 +0530 | [diff] [blame] | 363 | * @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 Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 367 | inline void handleRoleMapPatch( |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 368 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Ratan Gupta | 0678524 | 2019-07-26 22:30:16 +0530 | [diff] [blame] | 369 | const std::vector<std::pair<std::string, LDAPRoleMapData>>& roleMapObjData, |
Ed Tanous | c101982 | 2024-03-06 12:54:38 -0800 | [diff] [blame] | 370 | const std::string& serverType, |
| 371 | std::vector<std::variant<nlohmann::json::object_t, std::nullptr_t>>& input) |
Ratan Gupta | 0678524 | 2019-07-26 22:30:16 +0530 | [diff] [blame] | 372 | { |
| 373 | for (size_t index = 0; index < input.size(); index++) |
| 374 | { |
Ed Tanous | c101982 | 2024-03-06 12:54:38 -0800 | [diff] [blame] | 375 | 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 Gupta | 0678524 | 2019-07-26 22:30:16 +0530 | [diff] [blame] | 380 | { |
| 381 | // delete the existing object |
| 382 | if (index < roleMapObjData.size()) |
| 383 | { |
| 384 | crow::connections::systemBus->async_method_call( |
| 385 | [asyncResp, roleMapObjData, serverType, |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 386 | index](const boost::system::error_code& ec) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 387 | if (ec) |
| 388 | { |
| 389 | BMCWEB_LOG_ERROR("DBUS response error: {}", ec); |
| 390 | messages::internalError(asyncResp->res); |
| 391 | return; |
| 392 | } |
| 393 | asyncResp->res |
| 394 | .jsonValue[serverType]["RemoteRoleMapping"][index] = |
| 395 | nullptr; |
| 396 | }, |
Ratan Gupta | 0678524 | 2019-07-26 22:30:16 +0530 | [diff] [blame] | 397 | ldapDbusService, roleMapObjData[index].first, |
| 398 | "xyz.openbmc_project.Object.Delete", "Delete"); |
| 399 | } |
| 400 | else |
| 401 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 402 | BMCWEB_LOG_ERROR("Can't delete the object"); |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 403 | messages::propertyValueTypeError( |
| 404 | asyncResp->res, "null", |
| 405 | "RemoteRoleMapping/" + std::to_string(index)); |
Ratan Gupta | 0678524 | 2019-07-26 22:30:16 +0530 | [diff] [blame] | 406 | return; |
| 407 | } |
| 408 | } |
Ed Tanous | c101982 | 2024-03-06 12:54:38 -0800 | [diff] [blame] | 409 | else if (obj->empty()) |
Ratan Gupta | 0678524 | 2019-07-26 22:30:16 +0530 | [diff] [blame] | 410 | { |
| 411 | // Don't do anything for the empty objects,parse next json |
| 412 | // eg {"RemoteRoleMapping",[{}]} |
| 413 | } |
| 414 | else |
| 415 | { |
| 416 | // update/create the object |
| 417 | std::optional<std::string> remoteGroup; |
| 418 | std::optional<std::string> localRole; |
| 419 | |
Ed Tanous | c101982 | 2024-03-06 12:54:38 -0800 | [diff] [blame] | 420 | if (!json_util::readJsonObject(*obj, asyncResp->res, "RemoteGroup", |
| 421 | remoteGroup, "LocalRole", localRole)) |
Ratan Gupta | 0678524 | 2019-07-26 22:30:16 +0530 | [diff] [blame] | 422 | { |
| 423 | continue; |
| 424 | } |
| 425 | |
| 426 | // Update existing RoleMapping Object |
| 427 | if (index < roleMapObjData.size()) |
| 428 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 429 | BMCWEB_LOG_DEBUG("Update Role Map Object"); |
Ratan Gupta | 0678524 | 2019-07-26 22:30:16 +0530 | [diff] [blame] | 430 | // If "RemoteGroup" info is provided |
| 431 | if (remoteGroup) |
| 432 | { |
Ed Tanous | d02aad3 | 2024-02-13 14:43:34 -0800 | [diff] [blame] | 433 | setDbusProperty( |
Ginu George | e93abac | 2024-06-14 17:35:27 +0530 | [diff] [blame] | 434 | asyncResp, |
Ed Tanous | d02aad3 | 2024-02-13 14:43:34 -0800 | [diff] [blame] | 435 | std::format("RemoteRoleMapping/{}/RemoteGroup", index), |
Ginu George | e93abac | 2024-06-14 17:35:27 +0530 | [diff] [blame] | 436 | ldapDbusService, roleMapObjData[index].first, |
| 437 | "xyz.openbmc_project.User.PrivilegeMapperEntry", |
| 438 | "GroupName", *remoteGroup); |
Ratan Gupta | 0678524 | 2019-07-26 22:30:16 +0530 | [diff] [blame] | 439 | } |
| 440 | |
| 441 | // If "LocalRole" info is provided |
| 442 | if (localRole) |
| 443 | { |
Ravi Teja | 6d0b80b | 2024-07-28 06:09:15 -0500 | [diff] [blame] | 444 | std::string priv = getPrivilegeFromRoleId(*localRole); |
| 445 | if (priv.empty()) |
| 446 | { |
| 447 | messages::propertyValueNotInList( |
| 448 | asyncResp->res, *localRole, |
| 449 | std::format("RemoteRoleMapping/{}/LocalRole", |
| 450 | index)); |
| 451 | return; |
| 452 | } |
Ed Tanous | d02aad3 | 2024-02-13 14:43:34 -0800 | [diff] [blame] | 453 | setDbusProperty( |
Ginu George | e93abac | 2024-06-14 17:35:27 +0530 | [diff] [blame] | 454 | asyncResp, |
Ed Tanous | d02aad3 | 2024-02-13 14:43:34 -0800 | [diff] [blame] | 455 | std::format("RemoteRoleMapping/{}/LocalRole", index), |
Ginu George | e93abac | 2024-06-14 17:35:27 +0530 | [diff] [blame] | 456 | ldapDbusService, roleMapObjData[index].first, |
| 457 | "xyz.openbmc_project.User.PrivilegeMapperEntry", |
Ravi Teja | 6d0b80b | 2024-07-28 06:09:15 -0500 | [diff] [blame] | 458 | "Privilege", priv); |
Ratan Gupta | 0678524 | 2019-07-26 22:30:16 +0530 | [diff] [blame] | 459 | } |
| 460 | } |
| 461 | // Create a new RoleMapping Object. |
| 462 | else |
| 463 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 464 | BMCWEB_LOG_DEBUG( |
| 465 | "setRoleMappingProperties: Creating new Object"); |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 466 | std::string pathString = |
| 467 | "RemoteRoleMapping/" + std::to_string(index); |
Ratan Gupta | 0678524 | 2019-07-26 22:30:16 +0530 | [diff] [blame] | 468 | |
| 469 | if (!localRole) |
| 470 | { |
| 471 | messages::propertyMissing(asyncResp->res, |
| 472 | pathString + "/LocalRole"); |
| 473 | continue; |
| 474 | } |
| 475 | if (!remoteGroup) |
| 476 | { |
| 477 | messages::propertyMissing(asyncResp->res, |
| 478 | pathString + "/RemoteGroup"); |
| 479 | continue; |
| 480 | } |
| 481 | |
| 482 | std::string dbusObjectPath; |
| 483 | if (serverType == "ActiveDirectory") |
| 484 | { |
Ed Tanous | 2c70f80 | 2020-09-28 14:29:23 -0700 | [diff] [blame] | 485 | dbusObjectPath = adConfigObject; |
Ratan Gupta | 0678524 | 2019-07-26 22:30:16 +0530 | [diff] [blame] | 486 | } |
| 487 | else if (serverType == "LDAP") |
| 488 | { |
Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 489 | dbusObjectPath = ldapConfigObjectName; |
Ratan Gupta | 0678524 | 2019-07-26 22:30:16 +0530 | [diff] [blame] | 490 | } |
| 491 | |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 492 | BMCWEB_LOG_DEBUG("Remote Group={},LocalRole={}", *remoteGroup, |
| 493 | *localRole); |
Ratan Gupta | 0678524 | 2019-07-26 22:30:16 +0530 | [diff] [blame] | 494 | |
| 495 | crow::connections::systemBus->async_method_call( |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 496 | [asyncResp, serverType, localRole, |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 497 | remoteGroup](const boost::system::error_code& ec) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 498 | if (ec) |
| 499 | { |
| 500 | BMCWEB_LOG_ERROR("DBUS response error: {}", ec); |
| 501 | messages::internalError(asyncResp->res); |
| 502 | return; |
| 503 | } |
| 504 | nlohmann::json& remoteRoleJson = |
| 505 | asyncResp->res |
| 506 | .jsonValue[serverType]["RemoteRoleMapping"]; |
| 507 | nlohmann::json::object_t roleMapEntry; |
| 508 | roleMapEntry["LocalRole"] = *localRole; |
| 509 | roleMapEntry["RemoteGroup"] = *remoteGroup; |
| 510 | remoteRoleJson.emplace_back(std::move(roleMapEntry)); |
| 511 | }, |
Ratan Gupta | 0678524 | 2019-07-26 22:30:16 +0530 | [diff] [blame] | 512 | ldapDbusService, dbusObjectPath, ldapPrivMapperInterface, |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 513 | "Create", *remoteGroup, |
Ratan Gupta | 0678524 | 2019-07-26 22:30:16 +0530 | [diff] [blame] | 514 | getPrivilegeFromRoleId(std::move(*localRole))); |
| 515 | } |
| 516 | } |
| 517 | } |
| 518 | } |
| 519 | |
| 520 | /** |
Ratan Gupta | 6973a58 | 2018-12-13 18:25:44 +0530 | [diff] [blame] | 521 | * Function that retrieves all properties for LDAP config object |
| 522 | * into JSON |
| 523 | */ |
| 524 | template <typename CallbackFunc> |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 525 | inline void |
| 526 | getLDAPConfigData(const std::string& ldapType, CallbackFunc&& callback) |
Ratan Gupta | 6973a58 | 2018-12-13 18:25:44 +0530 | [diff] [blame] | 527 | { |
George Liu | 2b73119 | 2023-01-11 16:27:13 +0800 | [diff] [blame] | 528 | constexpr std::array<std::string_view, 2> interfaces = { |
| 529 | ldapEnableInterface, ldapConfigInterface}; |
Ratan Gupta | 6973a58 | 2018-12-13 18:25:44 +0530 | [diff] [blame] | 530 | |
George Liu | 2b73119 | 2023-01-11 16:27:13 +0800 | [diff] [blame] | 531 | dbus::utility::getDbusObject( |
| 532 | ldapConfigObjectName, interfaces, |
Ed Tanous | 8cb2c02 | 2024-03-27 16:31:46 -0700 | [diff] [blame] | 533 | [callback = std::forward<CallbackFunc>(callback), |
Ed Tanous | c101982 | 2024-03-06 12:54:38 -0800 | [diff] [blame] | 534 | ldapType](const boost::system::error_code& ec, |
| 535 | const dbus::utility::MapperGetObject& resp) mutable { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 536 | if (ec || resp.empty()) |
Nagaraju Goruganti | 54fc587 | 2019-01-30 05:11:00 -0600 | [diff] [blame] | 537 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 538 | BMCWEB_LOG_WARNING( |
| 539 | "DBUS response error during getting of service name: {}", |
| 540 | ec); |
| 541 | LDAPConfigData empty{}; |
| 542 | callback(false, empty, ldapType); |
Nagaraju Goruganti | 54fc587 | 2019-01-30 05:11:00 -0600 | [diff] [blame] | 543 | return; |
| 544 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 545 | std::string service = resp.begin()->first; |
| 546 | sdbusplus::message::object_path path(ldapRootObject); |
| 547 | dbus::utility::getManagedObjects( |
| 548 | service, path, |
| 549 | [callback, ldapType](const boost::system::error_code& ec2, |
| 550 | const dbus::utility::ManagedObjectType& |
| 551 | ldapObjects) mutable { |
| 552 | LDAPConfigData confData{}; |
| 553 | if (ec2) |
Nagaraju Goruganti | 54fc587 | 2019-01-30 05:11:00 -0600 | [diff] [blame] | 554 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 555 | callback(false, confData, ldapType); |
| 556 | BMCWEB_LOG_WARNING("D-Bus responses error: {}", ec2); |
| 557 | return; |
| 558 | } |
| 559 | |
| 560 | std::string ldapDbusType; |
| 561 | std::string searchString; |
| 562 | |
| 563 | if (ldapType == "LDAP") |
| 564 | { |
| 565 | ldapDbusType = |
| 566 | "xyz.openbmc_project.User.Ldap.Config.Type.OpenLdap"; |
| 567 | searchString = "openldap"; |
| 568 | } |
| 569 | else if (ldapType == "ActiveDirectory") |
| 570 | { |
| 571 | ldapDbusType = |
| 572 | "xyz.openbmc_project.User.Ldap.Config.Type.ActiveDirectory"; |
| 573 | searchString = "active_directory"; |
| 574 | } |
| 575 | else |
| 576 | { |
| 577 | BMCWEB_LOG_ERROR( |
| 578 | "Can't get the DbusType for the given type={}", |
| 579 | ldapType); |
| 580 | callback(false, confData, ldapType); |
| 581 | return; |
| 582 | } |
| 583 | |
| 584 | std::string ldapEnableInterfaceStr = ldapEnableInterface; |
| 585 | std::string ldapConfigInterfaceStr = ldapConfigInterface; |
| 586 | |
| 587 | for (const auto& object : ldapObjects) |
| 588 | { |
| 589 | // let's find the object whose ldap type is equal to the |
| 590 | // given type |
| 591 | if (object.first.str.find(searchString) == |
| 592 | std::string::npos) |
Nagaraju Goruganti | 54fc587 | 2019-01-30 05:11:00 -0600 | [diff] [blame] | 593 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 594 | continue; |
| 595 | } |
| 596 | |
| 597 | for (const auto& interface : object.second) |
| 598 | { |
| 599 | if (interface.first == ldapEnableInterfaceStr) |
Nagaraju Goruganti | 54fc587 | 2019-01-30 05:11:00 -0600 | [diff] [blame] | 600 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 601 | // rest of the properties are string. |
| 602 | for (const auto& property : interface.second) |
Nagaraju Goruganti | 54fc587 | 2019-01-30 05:11:00 -0600 | [diff] [blame] | 603 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 604 | if (property.first == "Enabled") |
| 605 | { |
| 606 | const bool* value = |
| 607 | std::get_if<bool>(&property.second); |
| 608 | if (value == nullptr) |
| 609 | { |
| 610 | continue; |
| 611 | } |
| 612 | confData.serviceEnabled = *value; |
| 613 | break; |
| 614 | } |
Nagaraju Goruganti | 54fc587 | 2019-01-30 05:11:00 -0600 | [diff] [blame] | 615 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 616 | } |
| 617 | else if (interface.first == ldapConfigInterfaceStr) |
| 618 | { |
| 619 | for (const auto& property : interface.second) |
| 620 | { |
| 621 | const std::string* strValue = |
| 622 | std::get_if<std::string>( |
| 623 | &property.second); |
| 624 | if (strValue == nullptr) |
| 625 | { |
| 626 | continue; |
| 627 | } |
| 628 | if (property.first == "LDAPServerURI") |
| 629 | { |
| 630 | confData.uri = *strValue; |
| 631 | } |
| 632 | else if (property.first == "LDAPBindDN") |
| 633 | { |
| 634 | confData.bindDN = *strValue; |
| 635 | } |
| 636 | else if (property.first == "LDAPBaseDN") |
| 637 | { |
| 638 | confData.baseDN = *strValue; |
| 639 | } |
| 640 | else if (property.first == |
| 641 | "LDAPSearchScope") |
| 642 | { |
| 643 | confData.searchScope = *strValue; |
| 644 | } |
| 645 | else if (property.first == |
| 646 | "GroupNameAttribute") |
| 647 | { |
| 648 | confData.groupAttribute = *strValue; |
| 649 | } |
| 650 | else if (property.first == |
| 651 | "UserNameAttribute") |
| 652 | { |
| 653 | confData.userNameAttribute = *strValue; |
| 654 | } |
| 655 | else if (property.first == "LDAPType") |
| 656 | { |
| 657 | confData.serverType = *strValue; |
| 658 | } |
| 659 | } |
| 660 | } |
| 661 | else if ( |
| 662 | interface.first == |
| 663 | "xyz.openbmc_project.User.PrivilegeMapperEntry") |
| 664 | { |
| 665 | LDAPRoleMapData roleMapData{}; |
| 666 | for (const auto& property : interface.second) |
| 667 | { |
| 668 | const std::string* strValue = |
| 669 | std::get_if<std::string>( |
| 670 | &property.second); |
| 671 | |
| 672 | if (strValue == nullptr) |
| 673 | { |
| 674 | continue; |
| 675 | } |
| 676 | |
| 677 | if (property.first == "GroupName") |
| 678 | { |
| 679 | roleMapData.groupName = *strValue; |
| 680 | } |
| 681 | else if (property.first == "Privilege") |
| 682 | { |
| 683 | roleMapData.privilege = *strValue; |
| 684 | } |
| 685 | } |
| 686 | |
| 687 | confData.groupRoleList.emplace_back( |
| 688 | object.first.str, roleMapData); |
Nagaraju Goruganti | 54fc587 | 2019-01-30 05:11:00 -0600 | [diff] [blame] | 689 | } |
| 690 | } |
| 691 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 692 | callback(true, confData, ldapType); |
| 693 | }); |
George Liu | 2b73119 | 2023-01-11 16:27:13 +0800 | [diff] [blame] | 694 | }); |
Ratan Gupta | 6973a58 | 2018-12-13 18:25:44 +0530 | [diff] [blame] | 695 | } |
| 696 | |
Ed Tanous | 6c51eab | 2021-06-03 12:30:29 -0700 | [diff] [blame] | 697 | /** |
Ed Tanous | 6c51eab | 2021-06-03 12:30:29 -0700 | [diff] [blame] | 698 | * @brief updates the LDAP server address and updates the |
| 699 | json response with the new value. |
| 700 | * @param serviceAddressList address to be updated. |
| 701 | * @param asyncResp pointer to the JSON response |
| 702 | * @param ldapServerElementName Type of LDAP |
| 703 | server(openLDAP/ActiveDirectory) |
| 704 | */ |
Ratan Gupta | 8a07d28 | 2019-03-16 08:33:47 +0530 | [diff] [blame] | 705 | |
Ed Tanous | 4f48d5f | 2021-06-21 08:27:45 -0700 | [diff] [blame] | 706 | inline void handleServiceAddressPatch( |
Ed Tanous | 6c51eab | 2021-06-03 12:30:29 -0700 | [diff] [blame] | 707 | const std::vector<std::string>& serviceAddressList, |
| 708 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 709 | const std::string& ldapServerElementName, |
| 710 | const std::string& ldapConfigObject) |
| 711 | { |
Ginu George | e93abac | 2024-06-14 17:35:27 +0530 | [diff] [blame] | 712 | setDbusProperty(asyncResp, ldapServerElementName + "/ServiceAddress", |
| 713 | ldapDbusService, ldapConfigObject, ldapConfigInterface, |
| 714 | "LDAPServerURI", serviceAddressList.front()); |
Ed Tanous | 6c51eab | 2021-06-03 12:30:29 -0700 | [diff] [blame] | 715 | } |
| 716 | /** |
| 717 | * @brief updates the LDAP Bind DN and updates the |
| 718 | json response with the new value. |
| 719 | * @param username name of the user which needs to be updated. |
| 720 | * @param asyncResp pointer to the JSON response |
| 721 | * @param ldapServerElementName Type of LDAP |
| 722 | server(openLDAP/ActiveDirectory) |
| 723 | */ |
Ratan Gupta | 8a07d28 | 2019-03-16 08:33:47 +0530 | [diff] [blame] | 724 | |
Ed Tanous | 4f48d5f | 2021-06-21 08:27:45 -0700 | [diff] [blame] | 725 | inline void |
| 726 | handleUserNamePatch(const std::string& username, |
| 727 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 728 | const std::string& ldapServerElementName, |
| 729 | const std::string& ldapConfigObject) |
Ed Tanous | 6c51eab | 2021-06-03 12:30:29 -0700 | [diff] [blame] | 730 | { |
Ginu George | e93abac | 2024-06-14 17:35:27 +0530 | [diff] [blame] | 731 | setDbusProperty(asyncResp, |
Ed Tanous | d02aad3 | 2024-02-13 14:43:34 -0800 | [diff] [blame] | 732 | ldapServerElementName + "/Authentication/Username", |
Ginu George | e93abac | 2024-06-14 17:35:27 +0530 | [diff] [blame] | 733 | ldapDbusService, ldapConfigObject, ldapConfigInterface, |
| 734 | "LDAPBindDN", username); |
Ed Tanous | 6c51eab | 2021-06-03 12:30:29 -0700 | [diff] [blame] | 735 | } |
| 736 | |
| 737 | /** |
| 738 | * @brief updates the LDAP password |
| 739 | * @param password : ldap password which needs to be updated. |
| 740 | * @param asyncResp pointer to the JSON response |
| 741 | * @param ldapServerElementName Type of LDAP |
| 742 | * server(openLDAP/ActiveDirectory) |
| 743 | */ |
| 744 | |
Ed Tanous | 4f48d5f | 2021-06-21 08:27:45 -0700 | [diff] [blame] | 745 | inline void |
| 746 | handlePasswordPatch(const std::string& password, |
| 747 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 748 | const std::string& ldapServerElementName, |
| 749 | const std::string& ldapConfigObject) |
Ed Tanous | 6c51eab | 2021-06-03 12:30:29 -0700 | [diff] [blame] | 750 | { |
Ginu George | e93abac | 2024-06-14 17:35:27 +0530 | [diff] [blame] | 751 | setDbusProperty(asyncResp, |
Ed Tanous | d02aad3 | 2024-02-13 14:43:34 -0800 | [diff] [blame] | 752 | ldapServerElementName + "/Authentication/Password", |
Ginu George | e93abac | 2024-06-14 17:35:27 +0530 | [diff] [blame] | 753 | ldapDbusService, ldapConfigObject, ldapConfigInterface, |
| 754 | "LDAPBindDNPassword", password); |
Ed Tanous | 6c51eab | 2021-06-03 12:30:29 -0700 | [diff] [blame] | 755 | } |
| 756 | |
| 757 | /** |
| 758 | * @brief updates the LDAP BaseDN and updates the |
| 759 | json response with the new value. |
| 760 | * @param baseDNList baseDN list which needs to be updated. |
| 761 | * @param asyncResp pointer to the JSON response |
| 762 | * @param ldapServerElementName Type of LDAP |
| 763 | server(openLDAP/ActiveDirectory) |
| 764 | */ |
| 765 | |
Ed Tanous | 4f48d5f | 2021-06-21 08:27:45 -0700 | [diff] [blame] | 766 | inline void |
| 767 | handleBaseDNPatch(const std::vector<std::string>& baseDNList, |
| 768 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 769 | const std::string& ldapServerElementName, |
| 770 | const std::string& ldapConfigObject) |
Ed Tanous | 6c51eab | 2021-06-03 12:30:29 -0700 | [diff] [blame] | 771 | { |
Ginu George | e93abac | 2024-06-14 17:35:27 +0530 | [diff] [blame] | 772 | setDbusProperty(asyncResp, |
Ed Tanous | d02aad3 | 2024-02-13 14:43:34 -0800 | [diff] [blame] | 773 | ldapServerElementName + |
| 774 | "/LDAPService/SearchSettings/BaseDistinguishedNames", |
Ginu George | e93abac | 2024-06-14 17:35:27 +0530 | [diff] [blame] | 775 | ldapDbusService, ldapConfigObject, ldapConfigInterface, |
| 776 | "LDAPBaseDN", baseDNList.front()); |
Ed Tanous | 6c51eab | 2021-06-03 12:30:29 -0700 | [diff] [blame] | 777 | } |
| 778 | /** |
| 779 | * @brief updates the LDAP user name attribute and updates the |
| 780 | json response with the new value. |
| 781 | * @param userNameAttribute attribute to be updated. |
| 782 | * @param asyncResp pointer to the JSON response |
| 783 | * @param ldapServerElementName Type of LDAP |
| 784 | server(openLDAP/ActiveDirectory) |
| 785 | */ |
| 786 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 787 | inline void handleUserNameAttrPatch( |
| 788 | const std::string& userNameAttribute, |
| 789 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 790 | const std::string& ldapServerElementName, |
| 791 | const std::string& ldapConfigObject) |
Ed Tanous | 6c51eab | 2021-06-03 12:30:29 -0700 | [diff] [blame] | 792 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 793 | setDbusProperty( |
| 794 | asyncResp, |
| 795 | ldapServerElementName + "LDAPService/SearchSettings/UsernameAttribute", |
| 796 | ldapDbusService, ldapConfigObject, ldapConfigInterface, |
| 797 | "UserNameAttribute", userNameAttribute); |
Ed Tanous | 6c51eab | 2021-06-03 12:30:29 -0700 | [diff] [blame] | 798 | } |
| 799 | /** |
| 800 | * @brief updates the LDAP group attribute and updates the |
| 801 | json response with the new value. |
| 802 | * @param groupsAttribute attribute to be updated. |
| 803 | * @param asyncResp pointer to the JSON response |
| 804 | * @param ldapServerElementName Type of LDAP |
| 805 | server(openLDAP/ActiveDirectory) |
| 806 | */ |
| 807 | |
Ed Tanous | 4f48d5f | 2021-06-21 08:27:45 -0700 | [diff] [blame] | 808 | inline void handleGroupNameAttrPatch( |
Ed Tanous | 6c51eab | 2021-06-03 12:30:29 -0700 | [diff] [blame] | 809 | const std::string& groupsAttribute, |
| 810 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 811 | const std::string& ldapServerElementName, |
| 812 | const std::string& ldapConfigObject) |
| 813 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 814 | setDbusProperty( |
| 815 | asyncResp, |
| 816 | ldapServerElementName + "/LDAPService/SearchSettings/GroupsAttribute", |
| 817 | ldapDbusService, ldapConfigObject, ldapConfigInterface, |
| 818 | "GroupNameAttribute", groupsAttribute); |
Ed Tanous | 6c51eab | 2021-06-03 12:30:29 -0700 | [diff] [blame] | 819 | } |
| 820 | /** |
| 821 | * @brief updates the LDAP service enable and updates the |
| 822 | json response with the new value. |
| 823 | * @param input JSON data. |
| 824 | * @param asyncResp pointer to the JSON response |
| 825 | * @param ldapServerElementName Type of LDAP |
| 826 | server(openLDAP/ActiveDirectory) |
| 827 | */ |
| 828 | |
Ed Tanous | 4f48d5f | 2021-06-21 08:27:45 -0700 | [diff] [blame] | 829 | inline void handleServiceEnablePatch( |
Ed Tanous | 6c51eab | 2021-06-03 12:30:29 -0700 | [diff] [blame] | 830 | bool serviceEnabled, const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 831 | const std::string& ldapServerElementName, |
| 832 | const std::string& ldapConfigObject) |
| 833 | { |
Ginu George | e93abac | 2024-06-14 17:35:27 +0530 | [diff] [blame] | 834 | setDbusProperty(asyncResp, ldapServerElementName + "/ServiceEnabled", |
| 835 | ldapDbusService, ldapConfigObject, ldapEnableInterface, |
| 836 | "Enabled", serviceEnabled); |
Ed Tanous | 6c51eab | 2021-06-03 12:30:29 -0700 | [diff] [blame] | 837 | } |
| 838 | |
Ed Tanous | c101982 | 2024-03-06 12:54:38 -0800 | [diff] [blame] | 839 | struct AuthMethods |
Ed Tanous | 6c51eab | 2021-06-03 12:30:29 -0700 | [diff] [blame] | 840 | { |
| 841 | std::optional<bool> basicAuth; |
| 842 | std::optional<bool> cookie; |
| 843 | std::optional<bool> sessionToken; |
| 844 | std::optional<bool> xToken; |
| 845 | std::optional<bool> tls; |
Ed Tanous | c101982 | 2024-03-06 12:54:38 -0800 | [diff] [blame] | 846 | }; |
Ed Tanous | 6c51eab | 2021-06-03 12:30:29 -0700 | [diff] [blame] | 847 | |
Ed Tanous | c101982 | 2024-03-06 12:54:38 -0800 | [diff] [blame] | 848 | inline void |
| 849 | handleAuthMethodsPatch(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 850 | const AuthMethods& auth) |
| 851 | { |
| 852 | persistent_data::AuthConfigMethods& authMethodsConfig = |
Ed Tanous | 6c51eab | 2021-06-03 12:30:29 -0700 | [diff] [blame] | 853 | persistent_data::SessionStore::getInstance().getAuthMethodsConfig(); |
| 854 | |
Ed Tanous | c101982 | 2024-03-06 12:54:38 -0800 | [diff] [blame] | 855 | if (auth.basicAuth) |
Ed Tanous | 6c51eab | 2021-06-03 12:30:29 -0700 | [diff] [blame] | 856 | { |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 857 | if constexpr (!BMCWEB_BASIC_AUTH) |
| 858 | { |
| 859 | messages::actionNotSupported( |
| 860 | asyncResp->res, |
| 861 | "Setting BasicAuth when basic-auth feature is disabled"); |
| 862 | return; |
| 863 | } |
| 864 | |
Ed Tanous | c101982 | 2024-03-06 12:54:38 -0800 | [diff] [blame] | 865 | authMethodsConfig.basic = *auth.basicAuth; |
Ed Tanous | 6c51eab | 2021-06-03 12:30:29 -0700 | [diff] [blame] | 866 | } |
| 867 | |
Ed Tanous | c101982 | 2024-03-06 12:54:38 -0800 | [diff] [blame] | 868 | if (auth.cookie) |
Ed Tanous | 6c51eab | 2021-06-03 12:30:29 -0700 | [diff] [blame] | 869 | { |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 870 | if constexpr (!BMCWEB_COOKIE_AUTH) |
| 871 | { |
| 872 | messages::actionNotSupported( |
| 873 | asyncResp->res, |
| 874 | "Setting Cookie when cookie-auth feature is disabled"); |
| 875 | return; |
| 876 | } |
Ed Tanous | c101982 | 2024-03-06 12:54:38 -0800 | [diff] [blame] | 877 | authMethodsConfig.cookie = *auth.cookie; |
Ed Tanous | 6c51eab | 2021-06-03 12:30:29 -0700 | [diff] [blame] | 878 | } |
| 879 | |
Ed Tanous | c101982 | 2024-03-06 12:54:38 -0800 | [diff] [blame] | 880 | if (auth.sessionToken) |
Ed Tanous | 6c51eab | 2021-06-03 12:30:29 -0700 | [diff] [blame] | 881 | { |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 882 | if constexpr (!BMCWEB_SESSION_AUTH) |
| 883 | { |
| 884 | messages::actionNotSupported( |
| 885 | asyncResp->res, |
| 886 | "Setting SessionToken when session-auth feature is disabled"); |
| 887 | return; |
| 888 | } |
Ed Tanous | c101982 | 2024-03-06 12:54:38 -0800 | [diff] [blame] | 889 | authMethodsConfig.sessionToken = *auth.sessionToken; |
Ed Tanous | 6c51eab | 2021-06-03 12:30:29 -0700 | [diff] [blame] | 890 | } |
| 891 | |
Ed Tanous | c101982 | 2024-03-06 12:54:38 -0800 | [diff] [blame] | 892 | if (auth.xToken) |
Ed Tanous | 6c51eab | 2021-06-03 12:30:29 -0700 | [diff] [blame] | 893 | { |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 894 | if constexpr (!BMCWEB_XTOKEN_AUTH) |
| 895 | { |
| 896 | messages::actionNotSupported( |
| 897 | asyncResp->res, |
| 898 | "Setting XToken when xtoken-auth feature is disabled"); |
| 899 | return; |
| 900 | } |
Ed Tanous | c101982 | 2024-03-06 12:54:38 -0800 | [diff] [blame] | 901 | authMethodsConfig.xtoken = *auth.xToken; |
Ed Tanous | 6c51eab | 2021-06-03 12:30:29 -0700 | [diff] [blame] | 902 | } |
| 903 | |
Ed Tanous | c101982 | 2024-03-06 12:54:38 -0800 | [diff] [blame] | 904 | if (auth.tls) |
Ed Tanous | 6c51eab | 2021-06-03 12:30:29 -0700 | [diff] [blame] | 905 | { |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 906 | if constexpr (!BMCWEB_MUTUAL_TLS_AUTH) |
| 907 | { |
| 908 | messages::actionNotSupported( |
| 909 | asyncResp->res, |
| 910 | "Setting TLS when mutual-tls-auth feature is disabled"); |
| 911 | return; |
| 912 | } |
Ed Tanous | c101982 | 2024-03-06 12:54:38 -0800 | [diff] [blame] | 913 | authMethodsConfig.tls = *auth.tls; |
Ed Tanous | 6c51eab | 2021-06-03 12:30:29 -0700 | [diff] [blame] | 914 | } |
| 915 | |
| 916 | if (!authMethodsConfig.basic && !authMethodsConfig.cookie && |
| 917 | !authMethodsConfig.sessionToken && !authMethodsConfig.xtoken && |
| 918 | !authMethodsConfig.tls) |
| 919 | { |
| 920 | // Do not allow user to disable everything |
| 921 | messages::actionNotSupported(asyncResp->res, |
| 922 | "of disabling all available methods"); |
| 923 | return; |
| 924 | } |
| 925 | |
| 926 | persistent_data::SessionStore::getInstance().updateAuthMethodsConfig( |
| 927 | authMethodsConfig); |
| 928 | // Save configuration immediately |
| 929 | persistent_data::getConfig().writeData(); |
| 930 | |
| 931 | messages::success(asyncResp->res); |
| 932 | } |
| 933 | |
| 934 | /** |
| 935 | * @brief Get the required values from the given JSON, validates the |
| 936 | * value and create the LDAP config object. |
| 937 | * @param input JSON data |
| 938 | * @param asyncResp pointer to the JSON response |
| 939 | * @param serverType Type of LDAP server(openLDAP/ActiveDirectory) |
| 940 | */ |
| 941 | |
Ed Tanous | 10cb44f | 2024-04-11 13:05:20 -0700 | [diff] [blame] | 942 | struct LdapPatchParams |
| 943 | { |
| 944 | std::optional<std::string> authType; |
| 945 | std::optional<std::vector<std::string>> serviceAddressList; |
| 946 | std::optional<bool> serviceEnabled; |
| 947 | std::optional<std::vector<std::string>> baseDNList; |
| 948 | std::optional<std::string> userNameAttribute; |
| 949 | std::optional<std::string> groupsAttribute; |
| 950 | std::optional<std::string> userName; |
| 951 | std::optional<std::string> password; |
| 952 | std::optional< |
| 953 | std::vector<std::variant<nlohmann::json::object_t, std::nullptr_t>>> |
| 954 | remoteRoleMapData; |
| 955 | }; |
| 956 | |
| 957 | inline void handleLDAPPatch(LdapPatchParams&& input, |
Ed Tanous | 6c51eab | 2021-06-03 12:30:29 -0700 | [diff] [blame] | 958 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 959 | const std::string& serverType) |
| 960 | { |
| 961 | std::string dbusObjectPath; |
| 962 | if (serverType == "ActiveDirectory") |
| 963 | { |
| 964 | dbusObjectPath = adConfigObject; |
| 965 | } |
| 966 | else if (serverType == "LDAP") |
| 967 | { |
| 968 | dbusObjectPath = ldapConfigObjectName; |
| 969 | } |
| 970 | else |
| 971 | { |
Ed Tanous | 10cb44f | 2024-04-11 13:05:20 -0700 | [diff] [blame] | 972 | BMCWEB_LOG_ERROR("serverType wasn't AD or LDAP but was {}????", |
| 973 | serverType); |
Ed Tanous | 6c51eab | 2021-06-03 12:30:29 -0700 | [diff] [blame] | 974 | return; |
| 975 | } |
| 976 | |
Ed Tanous | 10cb44f | 2024-04-11 13:05:20 -0700 | [diff] [blame] | 977 | if (input.authType && *input.authType != "UsernameAndPassword") |
Ed Tanous | 6c51eab | 2021-06-03 12:30:29 -0700 | [diff] [blame] | 978 | { |
Ed Tanous | 10cb44f | 2024-04-11 13:05:20 -0700 | [diff] [blame] | 979 | messages::propertyValueNotInList(asyncResp->res, *input.authType, |
Ed Tanous | c101982 | 2024-03-06 12:54:38 -0800 | [diff] [blame] | 980 | "AuthenticationType"); |
| 981 | return; |
Ed Tanous | 6c51eab | 2021-06-03 12:30:29 -0700 | [diff] [blame] | 982 | } |
Ed Tanous | c101982 | 2024-03-06 12:54:38 -0800 | [diff] [blame] | 983 | |
Ed Tanous | 10cb44f | 2024-04-11 13:05:20 -0700 | [diff] [blame] | 984 | if (input.serviceAddressList) |
Ed Tanous | 6c51eab | 2021-06-03 12:30:29 -0700 | [diff] [blame] | 985 | { |
Ed Tanous | 10cb44f | 2024-04-11 13:05:20 -0700 | [diff] [blame] | 986 | if (input.serviceAddressList->empty()) |
Ratan Gupta | eb2bbe5 | 2019-04-22 14:27:01 +0530 | [diff] [blame] | 987 | { |
Ed Tanous | e2616cc | 2022-06-27 12:45:55 -0700 | [diff] [blame] | 988 | messages::propertyValueNotInList( |
Ed Tanous | 10cb44f | 2024-04-11 13:05:20 -0700 | [diff] [blame] | 989 | asyncResp->res, *input.serviceAddressList, "ServiceAddress"); |
Ed Tanous | cb13a39 | 2020-07-25 19:02:03 +0000 | [diff] [blame] | 990 | return; |
| 991 | } |
Ed Tanous | 6c51eab | 2021-06-03 12:30:29 -0700 | [diff] [blame] | 992 | } |
Ed Tanous | 10cb44f | 2024-04-11 13:05:20 -0700 | [diff] [blame] | 993 | if (input.baseDNList) |
Ed Tanous | 6c51eab | 2021-06-03 12:30:29 -0700 | [diff] [blame] | 994 | { |
Ed Tanous | 10cb44f | 2024-04-11 13:05:20 -0700 | [diff] [blame] | 995 | if (input.baseDNList->empty()) |
Ratan Gupta | 8a07d28 | 2019-03-16 08:33:47 +0530 | [diff] [blame] | 996 | { |
Ed Tanous | 10cb44f | 2024-04-11 13:05:20 -0700 | [diff] [blame] | 997 | messages::propertyValueNotInList(asyncResp->res, *input.baseDNList, |
Ed Tanous | 6c51eab | 2021-06-03 12:30:29 -0700 | [diff] [blame] | 998 | "BaseDistinguishedNames"); |
Ratan Gupta | 8a07d28 | 2019-03-16 08:33:47 +0530 | [diff] [blame] | 999 | return; |
| 1000 | } |
Ed Tanous | 6c51eab | 2021-06-03 12:30:29 -0700 | [diff] [blame] | 1001 | } |
Ratan Gupta | 8a07d28 | 2019-03-16 08:33:47 +0530 | [diff] [blame] | 1002 | |
Ed Tanous | 6c51eab | 2021-06-03 12:30:29 -0700 | [diff] [blame] | 1003 | // nothing to update, then return |
Ed Tanous | 10cb44f | 2024-04-11 13:05:20 -0700 | [diff] [blame] | 1004 | if (!input.userName && !input.password && !input.serviceAddressList && |
| 1005 | !input.baseDNList && !input.userNameAttribute && |
| 1006 | !input.groupsAttribute && !input.serviceEnabled && |
| 1007 | !input.remoteRoleMapData) |
Ed Tanous | 6c51eab | 2021-06-03 12:30:29 -0700 | [diff] [blame] | 1008 | { |
| 1009 | return; |
| 1010 | } |
| 1011 | |
| 1012 | // Get the existing resource first then keep modifying |
| 1013 | // whenever any property gets updated. |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1014 | getLDAPConfigData(serverType, [asyncResp, input = std::move(input), |
| 1015 | dbusObjectPath = std::move(dbusObjectPath)]( |
| 1016 | bool success, |
| 1017 | const LDAPConfigData& confData, |
| 1018 | const std::string& serverT) mutable { |
Ed Tanous | 6c51eab | 2021-06-03 12:30:29 -0700 | [diff] [blame] | 1019 | if (!success) |
Ratan Gupta | 8a07d28 | 2019-03-16 08:33:47 +0530 | [diff] [blame] | 1020 | { |
Ed Tanous | 6c51eab | 2021-06-03 12:30:29 -0700 | [diff] [blame] | 1021 | messages::internalError(asyncResp->res); |
| 1022 | return; |
Ratan Gupta | 8a07d28 | 2019-03-16 08:33:47 +0530 | [diff] [blame] | 1023 | } |
Ed Tanous | 6c51eab | 2021-06-03 12:30:29 -0700 | [diff] [blame] | 1024 | parseLDAPConfigData(asyncResp->res.jsonValue, confData, serverT); |
| 1025 | if (confData.serviceEnabled) |
Ratan Gupta | 8a07d28 | 2019-03-16 08:33:47 +0530 | [diff] [blame] | 1026 | { |
Ed Tanous | 6c51eab | 2021-06-03 12:30:29 -0700 | [diff] [blame] | 1027 | // Disable the service first and update the rest of |
| 1028 | // the properties. |
| 1029 | handleServiceEnablePatch(false, asyncResp, serverT, dbusObjectPath); |
Ratan Gupta | 8a07d28 | 2019-03-16 08:33:47 +0530 | [diff] [blame] | 1030 | } |
Ed Tanous | 6c51eab | 2021-06-03 12:30:29 -0700 | [diff] [blame] | 1031 | |
Ed Tanous | 10cb44f | 2024-04-11 13:05:20 -0700 | [diff] [blame] | 1032 | if (input.serviceAddressList) |
Ratan Gupta | 8a07d28 | 2019-03-16 08:33:47 +0530 | [diff] [blame] | 1033 | { |
Ed Tanous | 10cb44f | 2024-04-11 13:05:20 -0700 | [diff] [blame] | 1034 | handleServiceAddressPatch(*input.serviceAddressList, asyncResp, |
| 1035 | serverT, dbusObjectPath); |
Ratan Gupta | 8a07d28 | 2019-03-16 08:33:47 +0530 | [diff] [blame] | 1036 | } |
Ed Tanous | 10cb44f | 2024-04-11 13:05:20 -0700 | [diff] [blame] | 1037 | if (input.userName) |
Ed Tanous | 6c51eab | 2021-06-03 12:30:29 -0700 | [diff] [blame] | 1038 | { |
Ed Tanous | 10cb44f | 2024-04-11 13:05:20 -0700 | [diff] [blame] | 1039 | handleUserNamePatch(*input.userName, asyncResp, serverT, |
| 1040 | dbusObjectPath); |
Ed Tanous | 6c51eab | 2021-06-03 12:30:29 -0700 | [diff] [blame] | 1041 | } |
Ed Tanous | 10cb44f | 2024-04-11 13:05:20 -0700 | [diff] [blame] | 1042 | if (input.password) |
Ed Tanous | 6c51eab | 2021-06-03 12:30:29 -0700 | [diff] [blame] | 1043 | { |
Ed Tanous | 10cb44f | 2024-04-11 13:05:20 -0700 | [diff] [blame] | 1044 | handlePasswordPatch(*input.password, asyncResp, serverT, |
| 1045 | dbusObjectPath); |
Ed Tanous | 6c51eab | 2021-06-03 12:30:29 -0700 | [diff] [blame] | 1046 | } |
| 1047 | |
Ed Tanous | 10cb44f | 2024-04-11 13:05:20 -0700 | [diff] [blame] | 1048 | if (input.baseDNList) |
Ratan Gupta | 8a07d28 | 2019-03-16 08:33:47 +0530 | [diff] [blame] | 1049 | { |
Ed Tanous | 10cb44f | 2024-04-11 13:05:20 -0700 | [diff] [blame] | 1050 | handleBaseDNPatch(*input.baseDNList, asyncResp, serverT, |
| 1051 | dbusObjectPath); |
Ed Tanous | 6c51eab | 2021-06-03 12:30:29 -0700 | [diff] [blame] | 1052 | } |
Ed Tanous | 10cb44f | 2024-04-11 13:05:20 -0700 | [diff] [blame] | 1053 | if (input.userNameAttribute) |
Ed Tanous | 6c51eab | 2021-06-03 12:30:29 -0700 | [diff] [blame] | 1054 | { |
Ed Tanous | 10cb44f | 2024-04-11 13:05:20 -0700 | [diff] [blame] | 1055 | handleUserNameAttrPatch(*input.userNameAttribute, asyncResp, |
| 1056 | serverT, dbusObjectPath); |
Ed Tanous | 6c51eab | 2021-06-03 12:30:29 -0700 | [diff] [blame] | 1057 | } |
Ed Tanous | 10cb44f | 2024-04-11 13:05:20 -0700 | [diff] [blame] | 1058 | if (input.groupsAttribute) |
Ed Tanous | 6c51eab | 2021-06-03 12:30:29 -0700 | [diff] [blame] | 1059 | { |
Ed Tanous | 10cb44f | 2024-04-11 13:05:20 -0700 | [diff] [blame] | 1060 | handleGroupNameAttrPatch(*input.groupsAttribute, asyncResp, serverT, |
Ed Tanous | 6c51eab | 2021-06-03 12:30:29 -0700 | [diff] [blame] | 1061 | dbusObjectPath); |
| 1062 | } |
Ed Tanous | 10cb44f | 2024-04-11 13:05:20 -0700 | [diff] [blame] | 1063 | if (input.serviceEnabled) |
Ed Tanous | 6c51eab | 2021-06-03 12:30:29 -0700 | [diff] [blame] | 1064 | { |
| 1065 | // if user has given the value as true then enable |
| 1066 | // the service. if user has given false then no-op |
| 1067 | // as service is already stopped. |
Ed Tanous | 10cb44f | 2024-04-11 13:05:20 -0700 | [diff] [blame] | 1068 | if (*input.serviceEnabled) |
Ratan Gupta | 8a07d28 | 2019-03-16 08:33:47 +0530 | [diff] [blame] | 1069 | { |
Ed Tanous | 10cb44f | 2024-04-11 13:05:20 -0700 | [diff] [blame] | 1070 | handleServiceEnablePatch(*input.serviceEnabled, asyncResp, |
| 1071 | serverT, dbusObjectPath); |
Ratan Gupta | 8a07d28 | 2019-03-16 08:33:47 +0530 | [diff] [blame] | 1072 | } |
| 1073 | } |
jayaprakash Mutyala | 9620060 | 2020-04-08 11:09:10 +0000 | [diff] [blame] | 1074 | else |
| 1075 | { |
Ed Tanous | 6c51eab | 2021-06-03 12:30:29 -0700 | [diff] [blame] | 1076 | // if user has not given the service enabled value |
| 1077 | // then revert it to the same state as it was |
| 1078 | // before. |
| 1079 | handleServiceEnablePatch(confData.serviceEnabled, asyncResp, |
| 1080 | serverT, dbusObjectPath); |
jayaprakash Mutyala | 9620060 | 2020-04-08 11:09:10 +0000 | [diff] [blame] | 1081 | } |
Ed Tanous | 04ae99e | 2018-09-20 15:54:36 -0700 | [diff] [blame] | 1082 | |
Ed Tanous | 10cb44f | 2024-04-11 13:05:20 -0700 | [diff] [blame] | 1083 | if (input.remoteRoleMapData) |
Ed Tanous | 6c51eab | 2021-06-03 12:30:29 -0700 | [diff] [blame] | 1084 | { |
| 1085 | handleRoleMapPatch(asyncResp, confData.groupRoleList, serverT, |
Ed Tanous | 10cb44f | 2024-04-11 13:05:20 -0700 | [diff] [blame] | 1086 | *input.remoteRoleMapData); |
Ed Tanous | 6c51eab | 2021-06-03 12:30:29 -0700 | [diff] [blame] | 1087 | } |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 1088 | }); |
Ed Tanous | 6c51eab | 2021-06-03 12:30:29 -0700 | [diff] [blame] | 1089 | } |
| 1090 | |
Abhishek Patel | 5834585 | 2022-02-02 08:54:25 -0600 | [diff] [blame] | 1091 | inline void updateUserProperties( |
| 1092 | std::shared_ptr<bmcweb::AsyncResp> asyncResp, const std::string& username, |
| 1093 | const std::optional<std::string>& password, |
| 1094 | const std::optional<bool>& enabled, |
| 1095 | const std::optional<std::string>& roleId, const std::optional<bool>& locked, |
Ravi Teja | e518ef3 | 2024-05-16 10:33:08 -0500 | [diff] [blame] | 1096 | std::optional<std::vector<std::string>> accountTypes, bool userSelf, |
| 1097 | const std::shared_ptr<persistent_data::UserSession>& session) |
Ed Tanous | 6c51eab | 2021-06-03 12:30:29 -0700 | [diff] [blame] | 1098 | { |
P Dheeraj Srujan Kumar | b477fd4 | 2021-12-16 07:17:51 +0530 | [diff] [blame] | 1099 | sdbusplus::message::object_path tempObjPath(rootUserDbusPath); |
| 1100 | tempObjPath /= username; |
| 1101 | std::string dbusObjectPath(tempObjPath); |
Ed Tanous | 6c51eab | 2021-06-03 12:30:29 -0700 | [diff] [blame] | 1102 | |
| 1103 | dbus::utility::checkDbusPathExists( |
Ravi Teja | e518ef3 | 2024-05-16 10:33:08 -0500 | [diff] [blame] | 1104 | dbusObjectPath, |
| 1105 | [dbusObjectPath, username, password, roleId, enabled, locked, |
| 1106 | accountTypes(std::move(accountTypes)), userSelf, session, |
| 1107 | asyncResp{std::move(asyncResp)}](int rc) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1108 | if (rc <= 0) |
Ed Tanous | 6c51eab | 2021-06-03 12:30:29 -0700 | [diff] [blame] | 1109 | { |
Jiaqing Zhao | d8a5d5d | 2022-08-05 16:21:51 +0800 | [diff] [blame] | 1110 | messages::resourceNotFound(asyncResp->res, "ManagerAccount", |
| 1111 | username); |
Ed Tanous | 6c51eab | 2021-06-03 12:30:29 -0700 | [diff] [blame] | 1112 | return; |
| 1113 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1114 | |
| 1115 | if (password) |
Ed Tanous | 618c14b | 2022-06-30 17:44:25 -0700 | [diff] [blame] | 1116 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1117 | int retval = pamUpdatePassword(username, *password); |
| 1118 | |
| 1119 | if (retval == PAM_USER_UNKNOWN) |
| 1120 | { |
| 1121 | messages::resourceNotFound(asyncResp->res, "ManagerAccount", |
| 1122 | username); |
| 1123 | } |
| 1124 | else if (retval == PAM_AUTHTOK_ERR) |
| 1125 | { |
| 1126 | // If password is invalid |
| 1127 | messages::propertyValueFormatError(asyncResp->res, nullptr, |
| 1128 | "Password"); |
| 1129 | BMCWEB_LOG_ERROR("pamUpdatePassword Failed"); |
| 1130 | } |
| 1131 | else if (retval != PAM_SUCCESS) |
| 1132 | { |
| 1133 | messages::internalError(asyncResp->res); |
| 1134 | return; |
| 1135 | } |
| 1136 | else |
| 1137 | { |
| 1138 | // Remove existing sessions of the user when password |
| 1139 | // changed |
| 1140 | persistent_data::SessionStore::getInstance() |
| 1141 | .removeSessionsByUsernameExceptSession(username, |
| 1142 | session); |
| 1143 | messages::success(asyncResp->res); |
| 1144 | } |
Ed Tanous | 618c14b | 2022-06-30 17:44:25 -0700 | [diff] [blame] | 1145 | } |
| 1146 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1147 | if (enabled) |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 1148 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1149 | setDbusProperty( |
| 1150 | asyncResp, "Enabled", "xyz.openbmc_project.User.Manager", |
| 1151 | dbusObjectPath, "xyz.openbmc_project.User.Attributes", |
| 1152 | "UserEnabled", *enabled); |
Ed Tanous | 618c14b | 2022-06-30 17:44:25 -0700 | [diff] [blame] | 1153 | } |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 1154 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1155 | if (roleId) |
Abhishek Patel | 5834585 | 2022-02-02 08:54:25 -0600 | [diff] [blame] | 1156 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1157 | std::string priv = getPrivilegeFromRoleId(*roleId); |
| 1158 | if (priv.empty()) |
| 1159 | { |
| 1160 | messages::propertyValueNotInList(asyncResp->res, true, |
| 1161 | "Locked"); |
| 1162 | return; |
| 1163 | } |
| 1164 | setDbusProperty( |
| 1165 | asyncResp, "RoleId", "xyz.openbmc_project.User.Manager", |
| 1166 | dbusObjectPath, "xyz.openbmc_project.User.Attributes", |
| 1167 | "UserPrivilege", priv); |
Abhishek Patel | 5834585 | 2022-02-02 08:54:25 -0600 | [diff] [blame] | 1168 | } |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 1169 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1170 | if (locked) |
| 1171 | { |
| 1172 | // admin can unlock the account which is locked by |
| 1173 | // successive authentication failures but admin should |
| 1174 | // not be allowed to lock an account. |
| 1175 | if (*locked) |
| 1176 | { |
| 1177 | messages::propertyValueNotInList(asyncResp->res, "true", |
| 1178 | "Locked"); |
| 1179 | return; |
| 1180 | } |
| 1181 | setDbusProperty( |
| 1182 | asyncResp, "Locked", "xyz.openbmc_project.User.Manager", |
| 1183 | dbusObjectPath, "xyz.openbmc_project.User.Attributes", |
| 1184 | "UserLockedForFailedAttempt", *locked); |
| 1185 | } |
| 1186 | |
| 1187 | if (accountTypes) |
| 1188 | { |
| 1189 | patchAccountTypes(*accountTypes, asyncResp, dbusObjectPath, |
| 1190 | userSelf); |
| 1191 | } |
| 1192 | }); |
Ed Tanous | 6c51eab | 2021-06-03 12:30:29 -0700 | [diff] [blame] | 1193 | } |
Ed Tanous | b9b2e0b | 2018-09-13 13:47:50 -0700 | [diff] [blame] | 1194 | |
Ed Tanous | 4c7d4d3 | 2022-07-07 15:29:35 -0700 | [diff] [blame] | 1195 | inline void handleAccountServiceHead( |
| 1196 | App& app, const crow::Request& req, |
| 1197 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
Ed Tanous | 1ef4c34 | 2022-05-12 16:12:36 -0700 | [diff] [blame] | 1198 | { |
| 1199 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 1200 | { |
| 1201 | return; |
| 1202 | } |
Ed Tanous | 4c7d4d3 | 2022-07-07 15:29:35 -0700 | [diff] [blame] | 1203 | asyncResp->res.addHeader( |
| 1204 | boost::beast::http::field::link, |
| 1205 | "</redfish/v1/JsonSchemas/AccountService/AccountService.json>; rel=describedby"); |
| 1206 | } |
| 1207 | |
| 1208 | inline void |
Ed Tanous | 1aa375b | 2024-04-13 11:51:10 -0700 | [diff] [blame] | 1209 | getClientCertificates(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1210 | const nlohmann::json::json_pointer& keyLocation) |
| 1211 | { |
| 1212 | boost::urls::url url( |
| 1213 | "/redfish/v1/AccountService/MultiFactorAuth/ClientCertificate/Certificates"); |
| 1214 | std::array<std::string_view, 1> interfaces = { |
| 1215 | "xyz.openbmc_project.Certs.Certificate"}; |
| 1216 | std::string path = "/xyz/openbmc_project/certs/authority/truststore"; |
| 1217 | |
| 1218 | collection_util::getCollectionToKey(asyncResp, url, interfaces, path, |
| 1219 | keyLocation); |
| 1220 | } |
| 1221 | |
| 1222 | inline void handleAccountServiceClientCertificatesInstanceHead( |
| 1223 | App& app, const crow::Request& req, |
| 1224 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1225 | const std::string& /*id*/) |
| 1226 | { |
| 1227 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 1228 | { |
| 1229 | return; |
| 1230 | } |
| 1231 | |
| 1232 | asyncResp->res.addHeader( |
| 1233 | boost::beast::http::field::link, |
| 1234 | "</redfish/v1/JsonSchemas/Certificate/Certificate.json>; rel=describedby"); |
| 1235 | } |
| 1236 | |
| 1237 | inline void handleAccountServiceClientCertificatesInstanceGet( |
| 1238 | App& app, const crow::Request& req, |
| 1239 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, const std::string& id) |
| 1240 | { |
| 1241 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 1242 | { |
| 1243 | return; |
| 1244 | } |
| 1245 | BMCWEB_LOG_DEBUG("ClientCertificate Certificate ID={}", id); |
| 1246 | const boost::urls::url certURL = boost::urls::format( |
| 1247 | "/redfish/v1/AccountService/MultiFactorAuth/ClientCertificate/Certificates/{}", |
| 1248 | id); |
| 1249 | std::string objPath = |
| 1250 | sdbusplus::message::object_path(certs::authorityObjectPath) / id; |
| 1251 | getCertificateProperties( |
| 1252 | asyncResp, objPath, |
| 1253 | "xyz.openbmc_project.Certs.Manager.Authority.Truststore", id, certURL, |
| 1254 | "Client Certificate"); |
| 1255 | } |
| 1256 | |
| 1257 | inline void handleAccountServiceClientCertificatesHead( |
| 1258 | App& app, const crow::Request& req, |
| 1259 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
| 1260 | { |
| 1261 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 1262 | { |
| 1263 | return; |
| 1264 | } |
| 1265 | |
| 1266 | asyncResp->res.addHeader( |
| 1267 | boost::beast::http::field::link, |
| 1268 | "</redfish/v1/JsonSchemas/CertificateCollection/CertificateCollection.json>; rel=describedby"); |
| 1269 | } |
| 1270 | |
| 1271 | inline void handleAccountServiceClientCertificatesGet( |
| 1272 | App& app, const crow::Request& req, |
| 1273 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
| 1274 | { |
| 1275 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 1276 | { |
| 1277 | return; |
| 1278 | } |
| 1279 | getClientCertificates(asyncResp, "/Members"_json_pointer); |
| 1280 | } |
| 1281 | |
Ed Tanous | 3ce3688 | 2024-06-09 10:58:16 -0700 | [diff] [blame] | 1282 | using account_service::CertificateMappingAttribute; |
| 1283 | using persistent_data::MTLSCommonNameParseMode; |
| 1284 | inline CertificateMappingAttribute |
| 1285 | getCertificateMapping(MTLSCommonNameParseMode parse) |
| 1286 | { |
| 1287 | switch (parse) |
| 1288 | { |
| 1289 | case MTLSCommonNameParseMode::CommonName: |
| 1290 | { |
| 1291 | return CertificateMappingAttribute::CommonName; |
| 1292 | } |
| 1293 | break; |
| 1294 | case MTLSCommonNameParseMode::Whole: |
| 1295 | { |
| 1296 | return CertificateMappingAttribute::Whole; |
| 1297 | } |
| 1298 | break; |
| 1299 | case MTLSCommonNameParseMode::UserPrincipalName: |
| 1300 | { |
| 1301 | return CertificateMappingAttribute::UserPrincipalName; |
| 1302 | } |
| 1303 | break; |
| 1304 | |
| 1305 | case MTLSCommonNameParseMode::Meta: |
| 1306 | { |
| 1307 | if constexpr (BMCWEB_META_TLS_COMMON_NAME_PARSING) |
| 1308 | { |
| 1309 | return CertificateMappingAttribute::CommonName; |
| 1310 | } |
| 1311 | } |
| 1312 | break; |
| 1313 | default: |
| 1314 | { |
| 1315 | return CertificateMappingAttribute::Invalid; |
| 1316 | } |
| 1317 | break; |
| 1318 | } |
| 1319 | } |
| 1320 | |
Ed Tanous | 1aa375b | 2024-04-13 11:51:10 -0700 | [diff] [blame] | 1321 | inline void |
Ed Tanous | 4c7d4d3 | 2022-07-07 15:29:35 -0700 | [diff] [blame] | 1322 | handleAccountServiceGet(App& app, const crow::Request& req, |
| 1323 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
| 1324 | { |
Jiaqing Zhao | afd369c | 2023-03-07 15:12:22 +0800 | [diff] [blame] | 1325 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 1326 | { |
| 1327 | return; |
| 1328 | } |
Ninad Palsule | 3e72c20 | 2023-03-27 17:19:55 -0500 | [diff] [blame] | 1329 | |
| 1330 | if (req.session == nullptr) |
| 1331 | { |
| 1332 | messages::internalError(asyncResp->res); |
| 1333 | return; |
| 1334 | } |
| 1335 | |
Ed Tanous | c101982 | 2024-03-06 12:54:38 -0800 | [diff] [blame] | 1336 | const persistent_data::AuthConfigMethods& authMethodsConfig = |
| 1337 | persistent_data::SessionStore::getInstance().getAuthMethodsConfig(); |
| 1338 | |
Jiaqing Zhao | afd369c | 2023-03-07 15:12:22 +0800 | [diff] [blame] | 1339 | asyncResp->res.addHeader( |
| 1340 | boost::beast::http::field::link, |
| 1341 | "</redfish/v1/JsonSchemas/AccountService/AccountService.json>; rel=describedby"); |
| 1342 | |
Ed Tanous | 1ef4c34 | 2022-05-12 16:12:36 -0700 | [diff] [blame] | 1343 | nlohmann::json& json = asyncResp->res.jsonValue; |
| 1344 | json["@odata.id"] = "/redfish/v1/AccountService"; |
Ravi Teja | 482a69e | 2024-04-22 06:56:13 -0500 | [diff] [blame] | 1345 | json["@odata.type"] = "#AccountService.v1_15_0.AccountService"; |
Ed Tanous | 1ef4c34 | 2022-05-12 16:12:36 -0700 | [diff] [blame] | 1346 | json["Id"] = "AccountService"; |
| 1347 | json["Name"] = "Account Service"; |
| 1348 | json["Description"] = "Account Service"; |
| 1349 | json["ServiceEnabled"] = true; |
| 1350 | json["MaxPasswordLength"] = 20; |
| 1351 | json["Accounts"]["@odata.id"] = "/redfish/v1/AccountService/Accounts"; |
| 1352 | json["Roles"]["@odata.id"] = "/redfish/v1/AccountService/Roles"; |
Ravi Teja | 482a69e | 2024-04-22 06:56:13 -0500 | [diff] [blame] | 1353 | json["HTTPBasicAuth"] = authMethodsConfig.basic |
| 1354 | ? account_service::BasicAuthState::Enabled |
| 1355 | : account_service::BasicAuthState::Disabled; |
| 1356 | |
| 1357 | nlohmann::json::array_t allowed; |
| 1358 | allowed.emplace_back(account_service::BasicAuthState::Enabled); |
| 1359 | allowed.emplace_back(account_service::BasicAuthState::Disabled); |
| 1360 | json["HTTPBasicAuth@AllowableValues"] = std::move(allowed); |
| 1361 | |
Ed Tanous | 1aa375b | 2024-04-13 11:51:10 -0700 | [diff] [blame] | 1362 | nlohmann::json::object_t clientCertificate; |
| 1363 | clientCertificate["Enabled"] = authMethodsConfig.tls; |
Ed Tanous | 3281bcf | 2024-06-25 16:02:05 -0700 | [diff] [blame] | 1364 | clientCertificate["RespondToUnauthenticatedClients"] = |
| 1365 | !authMethodsConfig.tlsStrict; |
Ed Tanous | 3ce3688 | 2024-06-09 10:58:16 -0700 | [diff] [blame] | 1366 | |
| 1367 | using account_service::CertificateMappingAttribute; |
| 1368 | |
| 1369 | CertificateMappingAttribute mapping = |
| 1370 | getCertificateMapping(authMethodsConfig.mTLSCommonNameParsingMode); |
| 1371 | if (mapping == CertificateMappingAttribute::Invalid) |
| 1372 | { |
| 1373 | messages::internalError(asyncResp->res); |
| 1374 | } |
| 1375 | else |
| 1376 | { |
| 1377 | clientCertificate["CertificateMappingAttribute"] = mapping; |
| 1378 | } |
Ed Tanous | 1aa375b | 2024-04-13 11:51:10 -0700 | [diff] [blame] | 1379 | nlohmann::json::object_t certificates; |
| 1380 | certificates["@odata.id"] = |
| 1381 | "/redfish/v1/AccountService/MultiFactorAuth/ClientCertificate/Certificates"; |
| 1382 | certificates["@odata.type"] = |
| 1383 | "#CertificateCollection.CertificateCollection"; |
| 1384 | clientCertificate["Certificates"] = std::move(certificates); |
| 1385 | json["MultiFactorAuth"]["ClientCertificate"] = std::move(clientCertificate); |
| 1386 | |
| 1387 | getClientCertificates( |
| 1388 | asyncResp, |
| 1389 | "/MultiFactorAuth/ClientCertificate/Certificates/Members"_json_pointer); |
| 1390 | |
Ed Tanous | 1ef4c34 | 2022-05-12 16:12:36 -0700 | [diff] [blame] | 1391 | json["Oem"]["OpenBMC"]["@odata.type"] = |
Ed Tanous | 5b5574a | 2022-09-26 19:53:36 -0700 | [diff] [blame] | 1392 | "#OpenBMCAccountService.v1_0_0.AccountService"; |
Ed Tanous | 1ef4c34 | 2022-05-12 16:12:36 -0700 | [diff] [blame] | 1393 | json["Oem"]["OpenBMC"]["@odata.id"] = |
| 1394 | "/redfish/v1/AccountService#/Oem/OpenBMC"; |
| 1395 | json["Oem"]["OpenBMC"]["AuthMethods"]["BasicAuth"] = |
| 1396 | authMethodsConfig.basic; |
| 1397 | json["Oem"]["OpenBMC"]["AuthMethods"]["SessionToken"] = |
| 1398 | authMethodsConfig.sessionToken; |
| 1399 | json["Oem"]["OpenBMC"]["AuthMethods"]["XToken"] = authMethodsConfig.xtoken; |
| 1400 | json["Oem"]["OpenBMC"]["AuthMethods"]["Cookie"] = authMethodsConfig.cookie; |
| 1401 | json["Oem"]["OpenBMC"]["AuthMethods"]["TLS"] = authMethodsConfig.tls; |
| 1402 | |
| 1403 | // /redfish/v1/AccountService/LDAP/Certificates is something only |
| 1404 | // ConfigureManager can access then only display when the user has |
| 1405 | // permissions ConfigureManager |
| 1406 | Privileges effectiveUserPrivileges = |
Ninad Palsule | 3e72c20 | 2023-03-27 17:19:55 -0500 | [diff] [blame] | 1407 | redfish::getUserPrivileges(*req.session); |
Ed Tanous | 1ef4c34 | 2022-05-12 16:12:36 -0700 | [diff] [blame] | 1408 | |
| 1409 | if (isOperationAllowedWithPrivileges({{"ConfigureManager"}}, |
| 1410 | effectiveUserPrivileges)) |
| 1411 | { |
| 1412 | asyncResp->res.jsonValue["LDAP"]["Certificates"]["@odata.id"] = |
| 1413 | "/redfish/v1/AccountService/LDAP/Certificates"; |
| 1414 | } |
Krzysztof Grobelny | d1bde9e | 2022-09-07 10:40:51 +0200 | [diff] [blame] | 1415 | sdbusplus::asio::getAllProperties( |
| 1416 | *crow::connections::systemBus, "xyz.openbmc_project.User.Manager", |
| 1417 | "/xyz/openbmc_project/user", "xyz.openbmc_project.User.AccountPolicy", |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 1418 | [asyncResp](const boost::system::error_code& ec, |
Ed Tanous | 1ef4c34 | 2022-05-12 16:12:36 -0700 | [diff] [blame] | 1419 | const dbus::utility::DBusPropertiesMap& propertiesList) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1420 | if (ec) |
| 1421 | { |
| 1422 | messages::internalError(asyncResp->res); |
| 1423 | return; |
| 1424 | } |
Krzysztof Grobelny | d1bde9e | 2022-09-07 10:40:51 +0200 | [diff] [blame] | 1425 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1426 | BMCWEB_LOG_DEBUG("Got {} properties for AccountService", |
| 1427 | propertiesList.size()); |
Krzysztof Grobelny | d1bde9e | 2022-09-07 10:40:51 +0200 | [diff] [blame] | 1428 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1429 | const uint8_t* minPasswordLength = nullptr; |
| 1430 | const uint32_t* accountUnlockTimeout = nullptr; |
| 1431 | const uint16_t* maxLoginAttemptBeforeLockout = nullptr; |
Krzysztof Grobelny | d1bde9e | 2022-09-07 10:40:51 +0200 | [diff] [blame] | 1432 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1433 | const bool success = sdbusplus::unpackPropertiesNoThrow( |
| 1434 | dbus_utils::UnpackErrorPrinter(), propertiesList, |
| 1435 | "MinPasswordLength", minPasswordLength, "AccountUnlockTimeout", |
| 1436 | accountUnlockTimeout, "MaxLoginAttemptBeforeLockout", |
| 1437 | maxLoginAttemptBeforeLockout); |
Krzysztof Grobelny | d1bde9e | 2022-09-07 10:40:51 +0200 | [diff] [blame] | 1438 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1439 | if (!success) |
| 1440 | { |
| 1441 | messages::internalError(asyncResp->res); |
| 1442 | return; |
| 1443 | } |
Krzysztof Grobelny | d1bde9e | 2022-09-07 10:40:51 +0200 | [diff] [blame] | 1444 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1445 | if (minPasswordLength != nullptr) |
| 1446 | { |
| 1447 | asyncResp->res.jsonValue["MinPasswordLength"] = |
| 1448 | *minPasswordLength; |
| 1449 | } |
Krzysztof Grobelny | d1bde9e | 2022-09-07 10:40:51 +0200 | [diff] [blame] | 1450 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1451 | if (accountUnlockTimeout != nullptr) |
| 1452 | { |
| 1453 | asyncResp->res.jsonValue["AccountLockoutDuration"] = |
| 1454 | *accountUnlockTimeout; |
| 1455 | } |
Krzysztof Grobelny | d1bde9e | 2022-09-07 10:40:51 +0200 | [diff] [blame] | 1456 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1457 | if (maxLoginAttemptBeforeLockout != nullptr) |
| 1458 | { |
| 1459 | asyncResp->res.jsonValue["AccountLockoutThreshold"] = |
| 1460 | *maxLoginAttemptBeforeLockout; |
| 1461 | } |
| 1462 | }); |
Ed Tanous | 1ef4c34 | 2022-05-12 16:12:36 -0700 | [diff] [blame] | 1463 | |
Ed Tanous | 02cad96 | 2022-06-30 16:50:15 -0700 | [diff] [blame] | 1464 | auto callback = [asyncResp](bool success, const LDAPConfigData& confData, |
Ed Tanous | 1ef4c34 | 2022-05-12 16:12:36 -0700 | [diff] [blame] | 1465 | const std::string& ldapType) { |
| 1466 | if (!success) |
| 1467 | { |
| 1468 | return; |
| 1469 | } |
| 1470 | parseLDAPConfigData(asyncResp->res.jsonValue, confData, ldapType); |
| 1471 | }; |
| 1472 | |
| 1473 | getLDAPConfigData("LDAP", callback); |
| 1474 | getLDAPConfigData("ActiveDirectory", callback); |
| 1475 | } |
| 1476 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1477 | inline void handleCertificateMappingAttributePatch( |
| 1478 | crow::Response& res, const std::string& certMapAttribute) |
Ed Tanous | 3ce3688 | 2024-06-09 10:58:16 -0700 | [diff] [blame] | 1479 | { |
| 1480 | MTLSCommonNameParseMode parseMode = |
| 1481 | persistent_data::getMTLSCommonNameParseMode(certMapAttribute); |
| 1482 | if (parseMode == MTLSCommonNameParseMode::Invalid) |
| 1483 | { |
| 1484 | messages::propertyValueNotInList(res, "CertificateMappingAttribute", |
| 1485 | certMapAttribute); |
| 1486 | return; |
| 1487 | } |
| 1488 | |
| 1489 | persistent_data::AuthConfigMethods& authMethodsConfig = |
| 1490 | persistent_data::SessionStore::getInstance().getAuthMethodsConfig(); |
| 1491 | authMethodsConfig.mTLSCommonNameParsingMode = parseMode; |
| 1492 | } |
| 1493 | |
Ed Tanous | 3281bcf | 2024-06-25 16:02:05 -0700 | [diff] [blame] | 1494 | inline void handleRespondToUnauthenticatedClientsPatch( |
| 1495 | App& app, const crow::Request& req, crow::Response& res, |
| 1496 | bool respondToUnauthenticatedClients) |
| 1497 | { |
| 1498 | if (req.session != nullptr) |
| 1499 | { |
| 1500 | // Sanity check. If the user isn't currently authenticated with mutual |
| 1501 | // TLS, they very likely are about to permanently lock themselves out. |
| 1502 | // Make sure they're using mutual TLS before allowing locking. |
| 1503 | if (req.session->sessionType != persistent_data::SessionType::MutualTLS) |
| 1504 | { |
| 1505 | messages::propertyValueExternalConflict( |
| 1506 | res, |
| 1507 | "MultiFactorAuth/ClientCertificate/RespondToUnauthenticatedClients", |
| 1508 | respondToUnauthenticatedClients); |
| 1509 | return; |
| 1510 | } |
| 1511 | } |
| 1512 | |
| 1513 | persistent_data::AuthConfigMethods& authMethodsConfig = |
| 1514 | persistent_data::SessionStore::getInstance().getAuthMethodsConfig(); |
| 1515 | |
| 1516 | // Change the settings |
| 1517 | authMethodsConfig.tlsStrict = !respondToUnauthenticatedClients; |
| 1518 | |
| 1519 | // Write settings to disk |
| 1520 | persistent_data::getConfig().writeData(); |
| 1521 | |
| 1522 | // Trigger a reload, to apply the new settings to new connections |
| 1523 | app.loadCertificate(); |
| 1524 | } |
| 1525 | |
Ed Tanous | 1ef4c34 | 2022-05-12 16:12:36 -0700 | [diff] [blame] | 1526 | inline void handleAccountServicePatch( |
| 1527 | App& app, const crow::Request& req, |
| 1528 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
| 1529 | { |
| 1530 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 1531 | { |
| 1532 | return; |
| 1533 | } |
| 1534 | std::optional<uint32_t> unlockTimeout; |
| 1535 | std::optional<uint16_t> lockoutThreshold; |
| 1536 | std::optional<uint8_t> minPasswordLength; |
| 1537 | std::optional<uint16_t> maxPasswordLength; |
Ed Tanous | 10cb44f | 2024-04-11 13:05:20 -0700 | [diff] [blame] | 1538 | LdapPatchParams ldapObject; |
Ed Tanous | 3ce3688 | 2024-06-09 10:58:16 -0700 | [diff] [blame] | 1539 | std::optional<std::string> certificateMappingAttribute; |
Ed Tanous | 3281bcf | 2024-06-25 16:02:05 -0700 | [diff] [blame] | 1540 | std::optional<bool> respondToUnauthenticatedClients; |
Ed Tanous | 10cb44f | 2024-04-11 13:05:20 -0700 | [diff] [blame] | 1541 | LdapPatchParams activeDirectoryObject; |
Ed Tanous | c101982 | 2024-03-06 12:54:38 -0800 | [diff] [blame] | 1542 | AuthMethods auth; |
Ravi Teja | 482a69e | 2024-04-22 06:56:13 -0500 | [diff] [blame] | 1543 | std::optional<std::string> httpBasicAuth; |
Ed Tanous | 3ce3688 | 2024-06-09 10:58:16 -0700 | [diff] [blame] | 1544 | |
Ed Tanous | c101982 | 2024-03-06 12:54:38 -0800 | [diff] [blame] | 1545 | // clang-format off |
Ed Tanous | 1ef4c34 | 2022-05-12 16:12:36 -0700 | [diff] [blame] | 1546 | if (!json_util::readJsonPatch( |
Ed Tanous | c101982 | 2024-03-06 12:54:38 -0800 | [diff] [blame] | 1547 | req, asyncResp->res, |
| 1548 | "AccountLockoutDuration", unlockTimeout, |
| 1549 | "AccountLockoutThreshold", lockoutThreshold, |
Ed Tanous | 10cb44f | 2024-04-11 13:05:20 -0700 | [diff] [blame] | 1550 | "ActiveDirectory/Authentication/AuthenticationType", activeDirectoryObject.authType, |
| 1551 | "ActiveDirectory/Authentication/Password", activeDirectoryObject.password, |
| 1552 | "ActiveDirectory/Authentication/Username", activeDirectoryObject.userName, |
| 1553 | "ActiveDirectory/LDAPService/SearchSettings/BaseDistinguishedNames", activeDirectoryObject.baseDNList, |
| 1554 | "ActiveDirectory/LDAPService/SearchSettings/GroupsAttribute", activeDirectoryObject.groupsAttribute, |
| 1555 | "ActiveDirectory/LDAPService/SearchSettings/UsernameAttribute", activeDirectoryObject.userNameAttribute, |
| 1556 | "ActiveDirectory/RemoteRoleMapping", activeDirectoryObject.remoteRoleMapData, |
| 1557 | "ActiveDirectory/ServiceAddresses", activeDirectoryObject.serviceAddressList, |
| 1558 | "ActiveDirectory/ServiceEnabled", activeDirectoryObject.serviceEnabled, |
Ed Tanous | 3ce3688 | 2024-06-09 10:58:16 -0700 | [diff] [blame] | 1559 | "MultiFactorAuth/ClientCertificate/CertificateMappingAttribute", certificateMappingAttribute, |
Ed Tanous | 3281bcf | 2024-06-25 16:02:05 -0700 | [diff] [blame] | 1560 | "MultiFactorAuth/ClientCertificate/RespondToUnauthenticatedClients", respondToUnauthenticatedClients, |
Ed Tanous | 10cb44f | 2024-04-11 13:05:20 -0700 | [diff] [blame] | 1561 | "LDAP/Authentication/AuthenticationType", ldapObject.authType, |
| 1562 | "LDAP/Authentication/Password", ldapObject.password, |
| 1563 | "LDAP/Authentication/Username", ldapObject.userName, |
| 1564 | "LDAP/LDAPService/SearchSettings/BaseDistinguishedNames", ldapObject.baseDNList, |
| 1565 | "LDAP/LDAPService/SearchSettings/GroupsAttribute", ldapObject.groupsAttribute, |
| 1566 | "LDAP/LDAPService/SearchSettings/UsernameAttribute", ldapObject.userNameAttribute, |
| 1567 | "LDAP/RemoteRoleMapping", ldapObject.remoteRoleMapData, |
| 1568 | "LDAP/ServiceAddresses", ldapObject.serviceAddressList, |
| 1569 | "LDAP/ServiceEnabled", ldapObject.serviceEnabled, |
Ed Tanous | c101982 | 2024-03-06 12:54:38 -0800 | [diff] [blame] | 1570 | "MaxPasswordLength", maxPasswordLength, |
| 1571 | "MinPasswordLength", minPasswordLength, |
Ed Tanous | c101982 | 2024-03-06 12:54:38 -0800 | [diff] [blame] | 1572 | "Oem/OpenBMC/AuthMethods/BasicAuth", auth.basicAuth, |
| 1573 | "Oem/OpenBMC/AuthMethods/Cookie", auth.cookie, |
| 1574 | "Oem/OpenBMC/AuthMethods/SessionToken", auth.sessionToken, |
Ed Tanous | 10cb44f | 2024-04-11 13:05:20 -0700 | [diff] [blame] | 1575 | "Oem/OpenBMC/AuthMethods/TLS", auth.tls, |
Ravi Teja | 482a69e | 2024-04-22 06:56:13 -0500 | [diff] [blame] | 1576 | "Oem/OpenBMC/AuthMethods/XToken", auth.xToken, |
| 1577 | "HTTPBasicAuth", httpBasicAuth)) |
Ed Tanous | 1ef4c34 | 2022-05-12 16:12:36 -0700 | [diff] [blame] | 1578 | { |
| 1579 | return; |
| 1580 | } |
Ed Tanous | c101982 | 2024-03-06 12:54:38 -0800 | [diff] [blame] | 1581 | // clang-format on |
Ed Tanous | 1ef4c34 | 2022-05-12 16:12:36 -0700 | [diff] [blame] | 1582 | |
Ravi Teja | 482a69e | 2024-04-22 06:56:13 -0500 | [diff] [blame] | 1583 | if (httpBasicAuth) |
| 1584 | { |
| 1585 | if (*httpBasicAuth == "Enabled") |
| 1586 | { |
| 1587 | auth.basicAuth = true; |
| 1588 | } |
| 1589 | else if (*httpBasicAuth == "Disabled") |
| 1590 | { |
| 1591 | auth.basicAuth = false; |
| 1592 | } |
| 1593 | else |
| 1594 | { |
| 1595 | messages::propertyValueNotInList(asyncResp->res, "HttpBasicAuth", |
| 1596 | *httpBasicAuth); |
| 1597 | } |
| 1598 | } |
| 1599 | |
Ed Tanous | 3281bcf | 2024-06-25 16:02:05 -0700 | [diff] [blame] | 1600 | if (respondToUnauthenticatedClients) |
| 1601 | { |
| 1602 | handleRespondToUnauthenticatedClientsPatch( |
| 1603 | app, req, asyncResp->res, *respondToUnauthenticatedClients); |
| 1604 | } |
| 1605 | |
Ed Tanous | 3ce3688 | 2024-06-09 10:58:16 -0700 | [diff] [blame] | 1606 | if (certificateMappingAttribute) |
| 1607 | { |
| 1608 | handleCertificateMappingAttributePatch(asyncResp->res, |
| 1609 | *certificateMappingAttribute); |
| 1610 | } |
| 1611 | |
Ed Tanous | 1ef4c34 | 2022-05-12 16:12:36 -0700 | [diff] [blame] | 1612 | if (minPasswordLength) |
| 1613 | { |
Ed Tanous | d02aad3 | 2024-02-13 14:43:34 -0800 | [diff] [blame] | 1614 | setDbusProperty( |
Ginu George | e93abac | 2024-06-14 17:35:27 +0530 | [diff] [blame] | 1615 | asyncResp, "MinPasswordLength", "xyz.openbmc_project.User.Manager", |
Ed Tanous | d02aad3 | 2024-02-13 14:43:34 -0800 | [diff] [blame] | 1616 | sdbusplus::message::object_path("/xyz/openbmc_project/user"), |
George Liu | 9ae226f | 2023-06-21 17:56:46 +0800 | [diff] [blame] | 1617 | "xyz.openbmc_project.User.AccountPolicy", "MinPasswordLength", |
Ginu George | e93abac | 2024-06-14 17:35:27 +0530 | [diff] [blame] | 1618 | *minPasswordLength); |
Ed Tanous | 1ef4c34 | 2022-05-12 16:12:36 -0700 | [diff] [blame] | 1619 | } |
| 1620 | |
| 1621 | if (maxPasswordLength) |
| 1622 | { |
| 1623 | messages::propertyNotWritable(asyncResp->res, "MaxPasswordLength"); |
| 1624 | } |
| 1625 | |
Ed Tanous | 10cb44f | 2024-04-11 13:05:20 -0700 | [diff] [blame] | 1626 | handleLDAPPatch(std::move(activeDirectoryObject), asyncResp, |
| 1627 | "ActiveDirectory"); |
| 1628 | handleLDAPPatch(std::move(ldapObject), asyncResp, "LDAP"); |
Ed Tanous | 1ef4c34 | 2022-05-12 16:12:36 -0700 | [diff] [blame] | 1629 | |
Ed Tanous | c101982 | 2024-03-06 12:54:38 -0800 | [diff] [blame] | 1630 | handleAuthMethodsPatch(asyncResp, auth); |
Ed Tanous | 1ef4c34 | 2022-05-12 16:12:36 -0700 | [diff] [blame] | 1631 | |
Ed Tanous | 1ef4c34 | 2022-05-12 16:12:36 -0700 | [diff] [blame] | 1632 | if (unlockTimeout) |
| 1633 | { |
Ed Tanous | d02aad3 | 2024-02-13 14:43:34 -0800 | [diff] [blame] | 1634 | setDbusProperty( |
Ginu George | e93abac | 2024-06-14 17:35:27 +0530 | [diff] [blame] | 1635 | asyncResp, "AccountLockoutDuration", |
| 1636 | "xyz.openbmc_project.User.Manager", |
Ed Tanous | d02aad3 | 2024-02-13 14:43:34 -0800 | [diff] [blame] | 1637 | sdbusplus::message::object_path("/xyz/openbmc_project/user"), |
Ed Tanous | 1ef4c34 | 2022-05-12 16:12:36 -0700 | [diff] [blame] | 1638 | "xyz.openbmc_project.User.AccountPolicy", "AccountUnlockTimeout", |
Ginu George | e93abac | 2024-06-14 17:35:27 +0530 | [diff] [blame] | 1639 | *unlockTimeout); |
Ed Tanous | 1ef4c34 | 2022-05-12 16:12:36 -0700 | [diff] [blame] | 1640 | } |
| 1641 | if (lockoutThreshold) |
| 1642 | { |
Ed Tanous | d02aad3 | 2024-02-13 14:43:34 -0800 | [diff] [blame] | 1643 | setDbusProperty( |
Ginu George | e93abac | 2024-06-14 17:35:27 +0530 | [diff] [blame] | 1644 | asyncResp, "AccountLockoutThreshold", |
| 1645 | "xyz.openbmc_project.User.Manager", |
Ed Tanous | d02aad3 | 2024-02-13 14:43:34 -0800 | [diff] [blame] | 1646 | sdbusplus::message::object_path("/xyz/openbmc_project/user"), |
George Liu | 9ae226f | 2023-06-21 17:56:46 +0800 | [diff] [blame] | 1647 | "xyz.openbmc_project.User.AccountPolicy", |
Ginu George | e93abac | 2024-06-14 17:35:27 +0530 | [diff] [blame] | 1648 | "MaxLoginAttemptBeforeLockout", *lockoutThreshold); |
Ed Tanous | 1ef4c34 | 2022-05-12 16:12:36 -0700 | [diff] [blame] | 1649 | } |
| 1650 | } |
| 1651 | |
Ed Tanous | 4c7d4d3 | 2022-07-07 15:29:35 -0700 | [diff] [blame] | 1652 | inline void handleAccountCollectionHead( |
Ed Tanous | 1ef4c34 | 2022-05-12 16:12:36 -0700 | [diff] [blame] | 1653 | App& app, const crow::Request& req, |
| 1654 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
| 1655 | { |
| 1656 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 1657 | { |
| 1658 | return; |
| 1659 | } |
Ed Tanous | 4c7d4d3 | 2022-07-07 15:29:35 -0700 | [diff] [blame] | 1660 | asyncResp->res.addHeader( |
| 1661 | boost::beast::http::field::link, |
| 1662 | "</redfish/v1/JsonSchemas/ManagerAccountCollection.json>; rel=describedby"); |
| 1663 | } |
| 1664 | |
| 1665 | inline void handleAccountCollectionGet( |
| 1666 | App& app, const crow::Request& req, |
| 1667 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
| 1668 | { |
Jiaqing Zhao | afd369c | 2023-03-07 15:12:22 +0800 | [diff] [blame] | 1669 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 1670 | { |
| 1671 | return; |
| 1672 | } |
Ninad Palsule | 3e72c20 | 2023-03-27 17:19:55 -0500 | [diff] [blame] | 1673 | |
| 1674 | if (req.session == nullptr) |
| 1675 | { |
| 1676 | messages::internalError(asyncResp->res); |
| 1677 | return; |
| 1678 | } |
| 1679 | |
Jiaqing Zhao | afd369c | 2023-03-07 15:12:22 +0800 | [diff] [blame] | 1680 | asyncResp->res.addHeader( |
| 1681 | boost::beast::http::field::link, |
| 1682 | "</redfish/v1/JsonSchemas/ManagerAccountCollection.json>; rel=describedby"); |
Ed Tanous | 1ef4c34 | 2022-05-12 16:12:36 -0700 | [diff] [blame] | 1683 | |
| 1684 | asyncResp->res.jsonValue["@odata.id"] = |
| 1685 | "/redfish/v1/AccountService/Accounts"; |
| 1686 | asyncResp->res.jsonValue["@odata.type"] = "#ManagerAccountCollection." |
| 1687 | "ManagerAccountCollection"; |
| 1688 | asyncResp->res.jsonValue["Name"] = "Accounts Collection"; |
| 1689 | asyncResp->res.jsonValue["Description"] = "BMC User Accounts"; |
| 1690 | |
| 1691 | Privileges effectiveUserPrivileges = |
Ninad Palsule | 3e72c20 | 2023-03-27 17:19:55 -0500 | [diff] [blame] | 1692 | redfish::getUserPrivileges(*req.session); |
Ed Tanous | 1ef4c34 | 2022-05-12 16:12:36 -0700 | [diff] [blame] | 1693 | |
| 1694 | std::string thisUser; |
| 1695 | if (req.session) |
| 1696 | { |
| 1697 | thisUser = req.session->username; |
| 1698 | } |
George Liu | 5eb468d | 2023-06-20 17:03:24 +0800 | [diff] [blame] | 1699 | sdbusplus::message::object_path path("/xyz/openbmc_project/user"); |
| 1700 | dbus::utility::getManagedObjects( |
| 1701 | "xyz.openbmc_project.User.Manager", path, |
Ed Tanous | 1ef4c34 | 2022-05-12 16:12:36 -0700 | [diff] [blame] | 1702 | [asyncResp, thisUser, effectiveUserPrivileges]( |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 1703 | const boost::system::error_code& ec, |
Ed Tanous | 1ef4c34 | 2022-05-12 16:12:36 -0700 | [diff] [blame] | 1704 | const dbus::utility::ManagedObjectType& users) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1705 | if (ec) |
Ed Tanous | 1ef4c34 | 2022-05-12 16:12:36 -0700 | [diff] [blame] | 1706 | { |
| 1707 | messages::internalError(asyncResp->res); |
Ed Tanous | 1ef4c34 | 2022-05-12 16:12:36 -0700 | [diff] [blame] | 1708 | return; |
| 1709 | } |
| 1710 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1711 | bool userCanSeeAllAccounts = |
| 1712 | effectiveUserPrivileges.isSupersetOf({"ConfigureUsers"}); |
| 1713 | |
| 1714 | bool userCanSeeSelf = |
| 1715 | effectiveUserPrivileges.isSupersetOf({"ConfigureSelf"}); |
| 1716 | |
| 1717 | nlohmann::json& memberArray = asyncResp->res.jsonValue["Members"]; |
| 1718 | memberArray = nlohmann::json::array(); |
| 1719 | |
| 1720 | for (const auto& userpath : users) |
Ed Tanous | 1ef4c34 | 2022-05-12 16:12:36 -0700 | [diff] [blame] | 1721 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1722 | std::string user = userpath.first.filename(); |
| 1723 | if (user.empty()) |
| 1724 | { |
| 1725 | messages::internalError(asyncResp->res); |
| 1726 | BMCWEB_LOG_ERROR("Invalid firmware ID"); |
| 1727 | |
| 1728 | return; |
| 1729 | } |
| 1730 | |
| 1731 | // As clarified by Redfish here: |
| 1732 | // https://redfishforum.com/thread/281/manageraccountcollection-change-allows-account-enumeration |
| 1733 | // Users without ConfigureUsers, only see their own |
| 1734 | // account. Users with ConfigureUsers, see all |
| 1735 | // accounts. |
| 1736 | if (userCanSeeAllAccounts || |
| 1737 | (thisUser == user && userCanSeeSelf)) |
| 1738 | { |
| 1739 | nlohmann::json::object_t member; |
| 1740 | member["@odata.id"] = boost::urls::format( |
| 1741 | "/redfish/v1/AccountService/Accounts/{}", user); |
| 1742 | memberArray.emplace_back(std::move(member)); |
| 1743 | } |
Ed Tanous | 1ef4c34 | 2022-05-12 16:12:36 -0700 | [diff] [blame] | 1744 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1745 | asyncResp->res.jsonValue["Members@odata.count"] = |
| 1746 | memberArray.size(); |
| 1747 | }); |
Ed Tanous | 1ef4c34 | 2022-05-12 16:12:36 -0700 | [diff] [blame] | 1748 | } |
| 1749 | |
Ninad Palsule | 97e90da | 2023-05-17 14:04:52 -0500 | [diff] [blame] | 1750 | inline void processAfterCreateUser( |
| 1751 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1752 | const std::string& username, const std::string& password, |
| 1753 | const boost::system::error_code& ec, sdbusplus::message_t& m) |
| 1754 | { |
| 1755 | if (ec) |
| 1756 | { |
| 1757 | userErrorMessageHandler(m.get_error(), asyncResp, username, ""); |
| 1758 | return; |
| 1759 | } |
| 1760 | |
| 1761 | if (pamUpdatePassword(username, password) != PAM_SUCCESS) |
| 1762 | { |
| 1763 | // At this point we have a user that's been |
| 1764 | // created, but the password set |
| 1765 | // failed.Something is wrong, so delete the user |
| 1766 | // that we've already created |
| 1767 | sdbusplus::message::object_path tempObjPath(rootUserDbusPath); |
| 1768 | tempObjPath /= username; |
| 1769 | const std::string userPath(tempObjPath); |
| 1770 | |
| 1771 | crow::connections::systemBus->async_method_call( |
| 1772 | [asyncResp, password](const boost::system::error_code& ec3) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1773 | if (ec3) |
| 1774 | { |
| 1775 | messages::internalError(asyncResp->res); |
| 1776 | return; |
| 1777 | } |
Ninad Palsule | 97e90da | 2023-05-17 14:04:52 -0500 | [diff] [blame] | 1778 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1779 | // If password is invalid |
| 1780 | messages::propertyValueFormatError(asyncResp->res, nullptr, |
| 1781 | "Password"); |
| 1782 | }, |
Ninad Palsule | 97e90da | 2023-05-17 14:04:52 -0500 | [diff] [blame] | 1783 | "xyz.openbmc_project.User.Manager", userPath, |
| 1784 | "xyz.openbmc_project.Object.Delete", "Delete"); |
| 1785 | |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 1786 | BMCWEB_LOG_ERROR("pamUpdatePassword Failed"); |
Ninad Palsule | 97e90da | 2023-05-17 14:04:52 -0500 | [diff] [blame] | 1787 | return; |
| 1788 | } |
| 1789 | |
| 1790 | messages::created(asyncResp->res); |
| 1791 | asyncResp->res.addHeader("Location", |
| 1792 | "/redfish/v1/AccountService/Accounts/" + username); |
| 1793 | } |
| 1794 | |
| 1795 | inline void processAfterGetAllGroups( |
| 1796 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1797 | const std::string& username, const std::string& password, |
Ed Tanous | e01d0c3 | 2023-06-30 13:21:32 -0700 | [diff] [blame] | 1798 | const std::string& roleId, bool enabled, |
Ninad Palsule | 9ba7393 | 2023-06-01 16:38:57 -0500 | [diff] [blame] | 1799 | std::optional<std::vector<std::string>> accountTypes, |
Ninad Palsule | 97e90da | 2023-05-17 14:04:52 -0500 | [diff] [blame] | 1800 | const std::vector<std::string>& allGroupsList) |
Ninad Palsule | 97e90da | 2023-05-17 14:04:52 -0500 | [diff] [blame] | 1801 | { |
Ninad Palsule | 3e72c20 | 2023-03-27 17:19:55 -0500 | [diff] [blame] | 1802 | std::vector<std::string> userGroups; |
Ninad Palsule | 9ba7393 | 2023-06-01 16:38:57 -0500 | [diff] [blame] | 1803 | std::vector<std::string> accountTypeUserGroups; |
| 1804 | |
| 1805 | // If user specified account types then convert them to unix user groups |
| 1806 | if (accountTypes) |
| 1807 | { |
| 1808 | if (!getUserGroupFromAccountType(asyncResp->res, *accountTypes, |
| 1809 | accountTypeUserGroups)) |
| 1810 | { |
| 1811 | // Problem in mapping Account Types to User Groups, Error already |
| 1812 | // logged. |
| 1813 | return; |
| 1814 | } |
| 1815 | } |
| 1816 | |
Ninad Palsule | 3e72c20 | 2023-03-27 17:19:55 -0500 | [diff] [blame] | 1817 | for (const auto& grp : allGroupsList) |
| 1818 | { |
Ninad Palsule | 9ba7393 | 2023-06-01 16:38:57 -0500 | [diff] [blame] | 1819 | // If user specified the account type then only accept groups which are |
| 1820 | // in the account types group list. |
| 1821 | if (!accountTypeUserGroups.empty()) |
| 1822 | { |
| 1823 | bool found = false; |
| 1824 | for (const auto& grp1 : accountTypeUserGroups) |
| 1825 | { |
| 1826 | if (grp == grp1) |
| 1827 | { |
| 1828 | found = true; |
| 1829 | break; |
| 1830 | } |
| 1831 | } |
| 1832 | if (!found) |
| 1833 | { |
| 1834 | continue; |
| 1835 | } |
| 1836 | } |
| 1837 | |
Ninad Palsule | 3e72c20 | 2023-03-27 17:19:55 -0500 | [diff] [blame] | 1838 | // Console access is provided to the user who is a member of |
| 1839 | // hostconsole group and has a administrator role. So, set |
| 1840 | // hostconsole group only for the administrator. |
Ninad Palsule | 9ba7393 | 2023-06-01 16:38:57 -0500 | [diff] [blame] | 1841 | if ((grp == "hostconsole") && (roleId != "priv-admin")) |
Ninad Palsule | 3e72c20 | 2023-03-27 17:19:55 -0500 | [diff] [blame] | 1842 | { |
Ninad Palsule | 9ba7393 | 2023-06-01 16:38:57 -0500 | [diff] [blame] | 1843 | if (!accountTypeUserGroups.empty()) |
| 1844 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 1845 | BMCWEB_LOG_ERROR( |
| 1846 | "Only administrator can get HostConsole access"); |
Ninad Palsule | 9ba7393 | 2023-06-01 16:38:57 -0500 | [diff] [blame] | 1847 | asyncResp->res.result(boost::beast::http::status::bad_request); |
| 1848 | return; |
| 1849 | } |
| 1850 | continue; |
Ninad Palsule | 3e72c20 | 2023-03-27 17:19:55 -0500 | [diff] [blame] | 1851 | } |
Ninad Palsule | 9ba7393 | 2023-06-01 16:38:57 -0500 | [diff] [blame] | 1852 | userGroups.emplace_back(grp); |
| 1853 | } |
| 1854 | |
| 1855 | // Make sure user specified groups are valid. This is internal error because |
| 1856 | // it some inconsistencies between user manager and bmcweb. |
| 1857 | if (!accountTypeUserGroups.empty() && |
| 1858 | accountTypeUserGroups.size() != userGroups.size()) |
| 1859 | { |
| 1860 | messages::internalError(asyncResp->res); |
| 1861 | return; |
Ninad Palsule | 3e72c20 | 2023-03-27 17:19:55 -0500 | [diff] [blame] | 1862 | } |
Ninad Palsule | 97e90da | 2023-05-17 14:04:52 -0500 | [diff] [blame] | 1863 | crow::connections::systemBus->async_method_call( |
| 1864 | [asyncResp, username, password](const boost::system::error_code& ec2, |
| 1865 | sdbusplus::message_t& m) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1866 | processAfterCreateUser(asyncResp, username, password, ec2, m); |
| 1867 | }, |
Ninad Palsule | 97e90da | 2023-05-17 14:04:52 -0500 | [diff] [blame] | 1868 | "xyz.openbmc_project.User.Manager", "/xyz/openbmc_project/user", |
Ninad Palsule | 3e72c20 | 2023-03-27 17:19:55 -0500 | [diff] [blame] | 1869 | "xyz.openbmc_project.User.Manager", "CreateUser", username, userGroups, |
Ed Tanous | e01d0c3 | 2023-06-30 13:21:32 -0700 | [diff] [blame] | 1870 | roleId, enabled); |
Ninad Palsule | 97e90da | 2023-05-17 14:04:52 -0500 | [diff] [blame] | 1871 | } |
| 1872 | |
Ed Tanous | 1ef4c34 | 2022-05-12 16:12:36 -0700 | [diff] [blame] | 1873 | inline void handleAccountCollectionPost( |
| 1874 | App& app, const crow::Request& req, |
| 1875 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
| 1876 | { |
| 1877 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 1878 | { |
| 1879 | return; |
| 1880 | } |
| 1881 | std::string username; |
| 1882 | std::string password; |
Ed Tanous | e01d0c3 | 2023-06-30 13:21:32 -0700 | [diff] [blame] | 1883 | std::optional<std::string> roleIdJson; |
| 1884 | std::optional<bool> enabledJson; |
Ninad Palsule | 9ba7393 | 2023-06-01 16:38:57 -0500 | [diff] [blame] | 1885 | std::optional<std::vector<std::string>> accountTypes; |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1886 | if (!json_util::readJsonPatch( |
| 1887 | req, asyncResp->res, "UserName", username, "Password", password, |
| 1888 | "RoleId", roleIdJson, "Enabled", enabledJson, "AccountTypes", |
| 1889 | accountTypes)) |
Ed Tanous | 1ef4c34 | 2022-05-12 16:12:36 -0700 | [diff] [blame] | 1890 | { |
| 1891 | return; |
| 1892 | } |
| 1893 | |
Ed Tanous | e01d0c3 | 2023-06-30 13:21:32 -0700 | [diff] [blame] | 1894 | std::string roleId = roleIdJson.value_or("User"); |
| 1895 | std::string priv = getPrivilegeFromRoleId(roleId); |
Ed Tanous | 1ef4c34 | 2022-05-12 16:12:36 -0700 | [diff] [blame] | 1896 | if (priv.empty()) |
| 1897 | { |
Ed Tanous | e01d0c3 | 2023-06-30 13:21:32 -0700 | [diff] [blame] | 1898 | messages::propertyValueNotInList(asyncResp->res, roleId, "RoleId"); |
Ed Tanous | 1ef4c34 | 2022-05-12 16:12:36 -0700 | [diff] [blame] | 1899 | return; |
| 1900 | } |
Asmitha Karunanithi | 239adf8 | 2022-03-25 02:59:03 -0500 | [diff] [blame] | 1901 | roleId = priv; |
Ed Tanous | 1ef4c34 | 2022-05-12 16:12:36 -0700 | [diff] [blame] | 1902 | |
Ed Tanous | e01d0c3 | 2023-06-30 13:21:32 -0700 | [diff] [blame] | 1903 | bool enabled = enabledJson.value_or(true); |
| 1904 | |
Ed Tanous | 1ef4c34 | 2022-05-12 16:12:36 -0700 | [diff] [blame] | 1905 | // Reading AllGroups property |
| 1906 | sdbusplus::asio::getProperty<std::vector<std::string>>( |
| 1907 | *crow::connections::systemBus, "xyz.openbmc_project.User.Manager", |
| 1908 | "/xyz/openbmc_project/user", "xyz.openbmc_project.User.Manager", |
| 1909 | "AllGroups", |
Ninad Palsule | 9ba7393 | 2023-06-01 16:38:57 -0500 | [diff] [blame] | 1910 | [asyncResp, username, password{std::move(password)}, roleId, enabled, |
| 1911 | accountTypes](const boost::system::error_code& ec, |
| 1912 | const std::vector<std::string>& allGroupsList) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1913 | if (ec) |
| 1914 | { |
Gunnar Mills | a0735a4 | 2024-09-06 12:51:11 -0500 | [diff] [blame] | 1915 | BMCWEB_LOG_ERROR("D-Bus response error {}", ec); |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1916 | messages::internalError(asyncResp->res); |
| 1917 | return; |
| 1918 | } |
Ed Tanous | 1ef4c34 | 2022-05-12 16:12:36 -0700 | [diff] [blame] | 1919 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1920 | if (allGroupsList.empty()) |
| 1921 | { |
| 1922 | messages::internalError(asyncResp->res); |
| 1923 | return; |
| 1924 | } |
Ed Tanous | 1ef4c34 | 2022-05-12 16:12:36 -0700 | [diff] [blame] | 1925 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1926 | processAfterGetAllGroups(asyncResp, username, password, roleId, |
| 1927 | enabled, accountTypes, allGroupsList); |
| 1928 | }); |
Ed Tanous | 1ef4c34 | 2022-05-12 16:12:36 -0700 | [diff] [blame] | 1929 | } |
| 1930 | |
| 1931 | inline void |
Ed Tanous | 4c7d4d3 | 2022-07-07 15:29:35 -0700 | [diff] [blame] | 1932 | handleAccountHead(App& app, const crow::Request& req, |
| 1933 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1934 | const std::string& /*accountName*/) |
Ed Tanous | 1ef4c34 | 2022-05-12 16:12:36 -0700 | [diff] [blame] | 1935 | { |
| 1936 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 1937 | { |
| 1938 | return; |
| 1939 | } |
Ed Tanous | 4c7d4d3 | 2022-07-07 15:29:35 -0700 | [diff] [blame] | 1940 | asyncResp->res.addHeader( |
| 1941 | boost::beast::http::field::link, |
| 1942 | "</redfish/v1/JsonSchemas/ManagerAccount/ManagerAccount.json>; rel=describedby"); |
| 1943 | } |
Jiaqing Zhao | afd369c | 2023-03-07 15:12:22 +0800 | [diff] [blame] | 1944 | |
Ed Tanous | 4c7d4d3 | 2022-07-07 15:29:35 -0700 | [diff] [blame] | 1945 | inline void |
| 1946 | handleAccountGet(App& app, const crow::Request& req, |
| 1947 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1948 | const std::string& accountName) |
| 1949 | { |
Jiaqing Zhao | afd369c | 2023-03-07 15:12:22 +0800 | [diff] [blame] | 1950 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 1951 | { |
| 1952 | return; |
| 1953 | } |
| 1954 | asyncResp->res.addHeader( |
| 1955 | boost::beast::http::field::link, |
| 1956 | "</redfish/v1/JsonSchemas/ManagerAccount/ManagerAccount.json>; rel=describedby"); |
| 1957 | |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 1958 | if constexpr (BMCWEB_INSECURE_DISABLE_AUTH) |
| 1959 | { |
| 1960 | // If authentication is disabled, there are no user accounts |
| 1961 | messages::resourceNotFound(asyncResp->res, "ManagerAccount", |
| 1962 | accountName); |
| 1963 | return; |
| 1964 | } |
Jiaqing Zhao | afd369c | 2023-03-07 15:12:22 +0800 | [diff] [blame] | 1965 | |
Ed Tanous | 1ef4c34 | 2022-05-12 16:12:36 -0700 | [diff] [blame] | 1966 | if (req.session == nullptr) |
| 1967 | { |
| 1968 | messages::internalError(asyncResp->res); |
| 1969 | return; |
| 1970 | } |
| 1971 | if (req.session->username != accountName) |
| 1972 | { |
| 1973 | // At this point we've determined that the user is trying to |
| 1974 | // modify a user that isn't them. We need to verify that they |
| 1975 | // have permissions to modify other users, so re-run the auth |
| 1976 | // check with the same permissions, minus ConfigureSelf. |
| 1977 | Privileges effectiveUserPrivileges = |
Ninad Palsule | 3e72c20 | 2023-03-27 17:19:55 -0500 | [diff] [blame] | 1978 | redfish::getUserPrivileges(*req.session); |
Ed Tanous | 1ef4c34 | 2022-05-12 16:12:36 -0700 | [diff] [blame] | 1979 | Privileges requiredPermissionsToChangeNonSelf = {"ConfigureUsers", |
| 1980 | "ConfigureManager"}; |
| 1981 | if (!effectiveUserPrivileges.isSupersetOf( |
| 1982 | requiredPermissionsToChangeNonSelf)) |
| 1983 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 1984 | BMCWEB_LOG_DEBUG("GET Account denied access"); |
Ed Tanous | 1ef4c34 | 2022-05-12 16:12:36 -0700 | [diff] [blame] | 1985 | messages::insufficientPrivilege(asyncResp->res); |
| 1986 | return; |
| 1987 | } |
| 1988 | } |
| 1989 | |
George Liu | 5eb468d | 2023-06-20 17:03:24 +0800 | [diff] [blame] | 1990 | sdbusplus::message::object_path path("/xyz/openbmc_project/user"); |
| 1991 | dbus::utility::getManagedObjects( |
| 1992 | "xyz.openbmc_project.User.Manager", path, |
Ed Tanous | 1ef4c34 | 2022-05-12 16:12:36 -0700 | [diff] [blame] | 1993 | [asyncResp, |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 1994 | accountName](const boost::system::error_code& ec, |
Ed Tanous | 1ef4c34 | 2022-05-12 16:12:36 -0700 | [diff] [blame] | 1995 | const dbus::utility::ManagedObjectType& users) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1996 | if (ec) |
Ed Tanous | 1ef4c34 | 2022-05-12 16:12:36 -0700 | [diff] [blame] | 1997 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1998 | messages::internalError(asyncResp->res); |
| 1999 | return; |
| 2000 | } |
| 2001 | const auto userIt = std::ranges::find_if( |
| 2002 | users, |
| 2003 | [accountName]( |
| 2004 | const std::pair<sdbusplus::message::object_path, |
| 2005 | dbus::utility::DBusInterfacesMap>& user) { |
| 2006 | return accountName == user.first.filename(); |
| 2007 | }); |
Ed Tanous | 1ef4c34 | 2022-05-12 16:12:36 -0700 | [diff] [blame] | 2008 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2009 | if (userIt == users.end()) |
| 2010 | { |
| 2011 | messages::resourceNotFound(asyncResp->res, "ManagerAccount", |
| 2012 | accountName); |
| 2013 | return; |
| 2014 | } |
| 2015 | |
| 2016 | asyncResp->res.jsonValue["@odata.type"] = |
| 2017 | "#ManagerAccount.v1_7_0.ManagerAccount"; |
| 2018 | asyncResp->res.jsonValue["Name"] = "User Account"; |
| 2019 | asyncResp->res.jsonValue["Description"] = "User Account"; |
| 2020 | asyncResp->res.jsonValue["Password"] = nullptr; |
| 2021 | asyncResp->res.jsonValue["StrictAccountTypes"] = true; |
| 2022 | |
| 2023 | for (const auto& interface : userIt->second) |
| 2024 | { |
| 2025 | if (interface.first == "xyz.openbmc_project.User.Attributes") |
| 2026 | { |
| 2027 | for (const auto& property : interface.second) |
Ed Tanous | 1ef4c34 | 2022-05-12 16:12:36 -0700 | [diff] [blame] | 2028 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2029 | if (property.first == "UserEnabled") |
Ed Tanous | 1ef4c34 | 2022-05-12 16:12:36 -0700 | [diff] [blame] | 2030 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2031 | const bool* userEnabled = |
| 2032 | std::get_if<bool>(&property.second); |
| 2033 | if (userEnabled == nullptr) |
| 2034 | { |
| 2035 | BMCWEB_LOG_ERROR("UserEnabled wasn't a bool"); |
| 2036 | messages::internalError(asyncResp->res); |
| 2037 | return; |
| 2038 | } |
| 2039 | asyncResp->res.jsonValue["Enabled"] = *userEnabled; |
Ed Tanous | 1ef4c34 | 2022-05-12 16:12:36 -0700 | [diff] [blame] | 2040 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2041 | else if (property.first == "UserLockedForFailedAttempt") |
Abhishek Patel | c722981 | 2022-02-01 10:07:15 -0600 | [diff] [blame] | 2042 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2043 | const bool* userLocked = |
| 2044 | std::get_if<bool>(&property.second); |
| 2045 | if (userLocked == nullptr) |
| 2046 | { |
| 2047 | BMCWEB_LOG_ERROR("UserLockedForF" |
| 2048 | "ailedAttempt " |
| 2049 | "wasn't a bool"); |
| 2050 | messages::internalError(asyncResp->res); |
| 2051 | return; |
| 2052 | } |
| 2053 | asyncResp->res.jsonValue["Locked"] = *userLocked; |
| 2054 | nlohmann::json::array_t allowed; |
| 2055 | // can only unlock accounts |
| 2056 | allowed.emplace_back("false"); |
| 2057 | asyncResp->res |
| 2058 | .jsonValue["Locked@Redfish.AllowableValues"] = |
| 2059 | std::move(allowed); |
Abhishek Patel | c722981 | 2022-02-01 10:07:15 -0600 | [diff] [blame] | 2060 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2061 | else if (property.first == "UserPrivilege") |
Abhishek Patel | c722981 | 2022-02-01 10:07:15 -0600 | [diff] [blame] | 2062 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2063 | const std::string* userPrivPtr = |
| 2064 | std::get_if<std::string>(&property.second); |
| 2065 | if (userPrivPtr == nullptr) |
| 2066 | { |
| 2067 | BMCWEB_LOG_ERROR("UserPrivilege wasn't a " |
| 2068 | "string"); |
| 2069 | messages::internalError(asyncResp->res); |
| 2070 | return; |
| 2071 | } |
| 2072 | std::string role = |
| 2073 | getRoleIdFromPrivilege(*userPrivPtr); |
| 2074 | if (role.empty()) |
| 2075 | { |
| 2076 | BMCWEB_LOG_ERROR("Invalid user role"); |
| 2077 | messages::internalError(asyncResp->res); |
| 2078 | return; |
| 2079 | } |
| 2080 | asyncResp->res.jsonValue["RoleId"] = role; |
| 2081 | |
| 2082 | nlohmann::json& roleEntry = |
| 2083 | asyncResp->res.jsonValue["Links"]["Role"]; |
| 2084 | roleEntry["@odata.id"] = boost::urls::format( |
| 2085 | "/redfish/v1/AccountService/Roles/{}", role); |
| 2086 | } |
| 2087 | else if (property.first == "UserPasswordExpired") |
| 2088 | { |
| 2089 | const bool* userPasswordExpired = |
| 2090 | std::get_if<bool>(&property.second); |
| 2091 | if (userPasswordExpired == nullptr) |
| 2092 | { |
| 2093 | BMCWEB_LOG_ERROR( |
| 2094 | "UserPasswordExpired wasn't a bool"); |
| 2095 | messages::internalError(asyncResp->res); |
| 2096 | return; |
| 2097 | } |
| 2098 | asyncResp->res.jsonValue["PasswordChangeRequired"] = |
| 2099 | *userPasswordExpired; |
| 2100 | } |
| 2101 | else if (property.first == "UserGroups") |
| 2102 | { |
| 2103 | const std::vector<std::string>* userGroups = |
| 2104 | std::get_if<std::vector<std::string>>( |
| 2105 | &property.second); |
| 2106 | if (userGroups == nullptr) |
| 2107 | { |
| 2108 | BMCWEB_LOG_ERROR( |
| 2109 | "userGroups wasn't a string vector"); |
| 2110 | messages::internalError(asyncResp->res); |
| 2111 | return; |
| 2112 | } |
| 2113 | if (!translateUserGroup(*userGroups, |
| 2114 | asyncResp->res)) |
| 2115 | { |
| 2116 | BMCWEB_LOG_ERROR("userGroups mapping failed"); |
| 2117 | messages::internalError(asyncResp->res); |
| 2118 | return; |
| 2119 | } |
Abhishek Patel | c722981 | 2022-02-01 10:07:15 -0600 | [diff] [blame] | 2120 | } |
| 2121 | } |
Ed Tanous | 1ef4c34 | 2022-05-12 16:12:36 -0700 | [diff] [blame] | 2122 | } |
| 2123 | } |
Ed Tanous | 1ef4c34 | 2022-05-12 16:12:36 -0700 | [diff] [blame] | 2124 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2125 | asyncResp->res.jsonValue["@odata.id"] = boost::urls::format( |
| 2126 | "/redfish/v1/AccountService/Accounts/{}", accountName); |
| 2127 | asyncResp->res.jsonValue["Id"] = accountName; |
| 2128 | asyncResp->res.jsonValue["UserName"] = accountName; |
| 2129 | }); |
Ed Tanous | 1ef4c34 | 2022-05-12 16:12:36 -0700 | [diff] [blame] | 2130 | } |
| 2131 | |
| 2132 | inline void |
Gunnar Mills | 20fc307 | 2023-01-27 15:13:36 -0600 | [diff] [blame] | 2133 | handleAccountDelete(App& app, const crow::Request& req, |
| 2134 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 2135 | const std::string& username) |
Ed Tanous | 1ef4c34 | 2022-05-12 16:12:36 -0700 | [diff] [blame] | 2136 | { |
| 2137 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 2138 | { |
| 2139 | return; |
| 2140 | } |
| 2141 | |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 2142 | if constexpr (BMCWEB_INSECURE_DISABLE_AUTH) |
| 2143 | { |
| 2144 | // If authentication is disabled, there are no user accounts |
| 2145 | messages::resourceNotFound(asyncResp->res, "ManagerAccount", username); |
| 2146 | return; |
| 2147 | } |
Ed Tanous | 1ef4c34 | 2022-05-12 16:12:36 -0700 | [diff] [blame] | 2148 | sdbusplus::message::object_path tempObjPath(rootUserDbusPath); |
| 2149 | tempObjPath /= username; |
| 2150 | const std::string userPath(tempObjPath); |
| 2151 | |
| 2152 | crow::connections::systemBus->async_method_call( |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 2153 | [asyncResp, username](const boost::system::error_code& ec) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2154 | if (ec) |
| 2155 | { |
| 2156 | messages::resourceNotFound(asyncResp->res, "ManagerAccount", |
| 2157 | username); |
| 2158 | return; |
| 2159 | } |
Ed Tanous | 1ef4c34 | 2022-05-12 16:12:36 -0700 | [diff] [blame] | 2160 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2161 | messages::accountRemoved(asyncResp->res); |
| 2162 | }, |
Ed Tanous | 1ef4c34 | 2022-05-12 16:12:36 -0700 | [diff] [blame] | 2163 | "xyz.openbmc_project.User.Manager", userPath, |
| 2164 | "xyz.openbmc_project.Object.Delete", "Delete"); |
| 2165 | } |
| 2166 | |
| 2167 | inline void |
| 2168 | handleAccountPatch(App& app, const crow::Request& req, |
| 2169 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 2170 | const std::string& username) |
| 2171 | { |
| 2172 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 2173 | { |
| 2174 | return; |
| 2175 | } |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 2176 | if constexpr (BMCWEB_INSECURE_DISABLE_AUTH) |
| 2177 | { |
| 2178 | // If authentication is disabled, there are no user accounts |
| 2179 | messages::resourceNotFound(asyncResp->res, "ManagerAccount", username); |
| 2180 | return; |
| 2181 | } |
Ed Tanous | 1ef4c34 | 2022-05-12 16:12:36 -0700 | [diff] [blame] | 2182 | std::optional<std::string> newUserName; |
| 2183 | std::optional<std::string> password; |
| 2184 | std::optional<bool> enabled; |
| 2185 | std::optional<std::string> roleId; |
| 2186 | std::optional<bool> locked; |
Abhishek Patel | 5834585 | 2022-02-02 08:54:25 -0600 | [diff] [blame] | 2187 | std::optional<std::vector<std::string>> accountTypes; |
| 2188 | |
Ed Tanous | 1ef4c34 | 2022-05-12 16:12:36 -0700 | [diff] [blame] | 2189 | if (req.session == nullptr) |
| 2190 | { |
| 2191 | messages::internalError(asyncResp->res); |
| 2192 | return; |
| 2193 | } |
| 2194 | |
Ed Tanous | 2b9c1df | 2024-04-06 13:52:01 -0700 | [diff] [blame] | 2195 | bool userSelf = (username == req.session->username); |
| 2196 | |
Ed Tanous | 1ef4c34 | 2022-05-12 16:12:36 -0700 | [diff] [blame] | 2197 | Privileges effectiveUserPrivileges = |
Ninad Palsule | 3e72c20 | 2023-03-27 17:19:55 -0500 | [diff] [blame] | 2198 | redfish::getUserPrivileges(*req.session); |
Ed Tanous | 1ef4c34 | 2022-05-12 16:12:36 -0700 | [diff] [blame] | 2199 | Privileges configureUsers = {"ConfigureUsers"}; |
| 2200 | bool userHasConfigureUsers = |
| 2201 | effectiveUserPrivileges.isSupersetOf(configureUsers); |
| 2202 | if (userHasConfigureUsers) |
| 2203 | { |
| 2204 | // Users with ConfigureUsers can modify for all users |
Abhishek Patel | 5834585 | 2022-02-02 08:54:25 -0600 | [diff] [blame] | 2205 | if (!json_util::readJsonPatch( |
| 2206 | req, asyncResp->res, "UserName", newUserName, "Password", |
| 2207 | password, "RoleId", roleId, "Enabled", enabled, "Locked", |
| 2208 | locked, "AccountTypes", accountTypes)) |
Ed Tanous | 1ef4c34 | 2022-05-12 16:12:36 -0700 | [diff] [blame] | 2209 | { |
| 2210 | return; |
| 2211 | } |
| 2212 | } |
| 2213 | else |
| 2214 | { |
| 2215 | // ConfigureSelf accounts can only modify their own account |
Abhishek Patel | 5834585 | 2022-02-02 08:54:25 -0600 | [diff] [blame] | 2216 | if (!userSelf) |
Ed Tanous | 1ef4c34 | 2022-05-12 16:12:36 -0700 | [diff] [blame] | 2217 | { |
| 2218 | messages::insufficientPrivilege(asyncResp->res); |
| 2219 | return; |
| 2220 | } |
| 2221 | |
| 2222 | // ConfigureSelf accounts can only modify their password |
| 2223 | if (!json_util::readJsonPatch(req, asyncResp->res, "Password", |
| 2224 | password)) |
| 2225 | { |
| 2226 | return; |
| 2227 | } |
| 2228 | } |
| 2229 | |
| 2230 | // if user name is not provided in the patch method or if it |
| 2231 | // matches the user name in the URI, then we are treating it as |
| 2232 | // updating user properties other then username. If username |
| 2233 | // provided doesn't match the URI, then we are treating this as |
| 2234 | // user rename request. |
| 2235 | if (!newUserName || (newUserName.value() == username)) |
| 2236 | { |
| 2237 | updateUserProperties(asyncResp, username, password, enabled, roleId, |
Ravi Teja | e518ef3 | 2024-05-16 10:33:08 -0500 | [diff] [blame] | 2238 | locked, accountTypes, userSelf, req.session); |
Ed Tanous | 1ef4c34 | 2022-05-12 16:12:36 -0700 | [diff] [blame] | 2239 | return; |
| 2240 | } |
| 2241 | crow::connections::systemBus->async_method_call( |
| 2242 | [asyncResp, username, password(std::move(password)), |
| 2243 | roleId(std::move(roleId)), enabled, newUser{std::string(*newUserName)}, |
Ravi Teja | e518ef3 | 2024-05-16 10:33:08 -0500 | [diff] [blame] | 2244 | locked, userSelf, req, accountTypes(std::move(accountTypes))]( |
Ed Tanous | e81de51 | 2023-06-27 17:07:00 -0700 | [diff] [blame] | 2245 | const boost::system::error_code& ec, sdbusplus::message_t& m) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2246 | if (ec) |
| 2247 | { |
| 2248 | userErrorMessageHandler(m.get_error(), asyncResp, newUser, |
| 2249 | username); |
| 2250 | return; |
| 2251 | } |
Ed Tanous | 1ef4c34 | 2022-05-12 16:12:36 -0700 | [diff] [blame] | 2252 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2253 | updateUserProperties(asyncResp, newUser, password, enabled, roleId, |
| 2254 | locked, accountTypes, userSelf, req.session); |
| 2255 | }, |
Ed Tanous | 1ef4c34 | 2022-05-12 16:12:36 -0700 | [diff] [blame] | 2256 | "xyz.openbmc_project.User.Manager", "/xyz/openbmc_project/user", |
| 2257 | "xyz.openbmc_project.User.Manager", "RenameUser", username, |
| 2258 | *newUserName); |
| 2259 | } |
| 2260 | |
Ed Tanous | 6c51eab | 2021-06-03 12:30:29 -0700 | [diff] [blame] | 2261 | inline void requestAccountServiceRoutes(App& app) |
Ed Tanous | b9b2e0b | 2018-09-13 13:47:50 -0700 | [diff] [blame] | 2262 | { |
Ed Tanous | 6c51eab | 2021-06-03 12:30:29 -0700 | [diff] [blame] | 2263 | BMCWEB_ROUTE(app, "/redfish/v1/AccountService/") |
Ed Tanous | 4c7d4d3 | 2022-07-07 15:29:35 -0700 | [diff] [blame] | 2264 | .privileges(redfish::privileges::headAccountService) |
| 2265 | .methods(boost::beast::http::verb::head)( |
| 2266 | std::bind_front(handleAccountServiceHead, std::ref(app))); |
| 2267 | |
| 2268 | BMCWEB_ROUTE(app, "/redfish/v1/AccountService/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 2269 | .privileges(redfish::privileges::getAccountService) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2270 | .methods(boost::beast::http::verb::get)( |
Ed Tanous | 1ef4c34 | 2022-05-12 16:12:36 -0700 | [diff] [blame] | 2271 | std::bind_front(handleAccountServiceGet, std::ref(app))); |
Ed Tanous | 6c51eab | 2021-06-03 12:30:29 -0700 | [diff] [blame] | 2272 | |
Ed Tanous | f5ffd80 | 2021-07-19 10:55:33 -0700 | [diff] [blame] | 2273 | BMCWEB_ROUTE(app, "/redfish/v1/AccountService/") |
Gunnar Mills | 1ec43ee | 2022-01-04 15:39:52 -0600 | [diff] [blame] | 2274 | .privileges(redfish::privileges::patchAccountService) |
Ed Tanous | f5ffd80 | 2021-07-19 10:55:33 -0700 | [diff] [blame] | 2275 | .methods(boost::beast::http::verb::patch)( |
Ed Tanous | 1ef4c34 | 2022-05-12 16:12:36 -0700 | [diff] [blame] | 2276 | std::bind_front(handleAccountServicePatch, std::ref(app))); |
Ed Tanous | f5ffd80 | 2021-07-19 10:55:33 -0700 | [diff] [blame] | 2277 | |
Ed Tanous | 1aa375b | 2024-04-13 11:51:10 -0700 | [diff] [blame] | 2278 | BMCWEB_ROUTE( |
| 2279 | app, |
| 2280 | "/redfish/v1/AccountService/MultiFactorAuth/ClientCertificate/Certificates") |
| 2281 | .privileges(redfish::privileges::headCertificateCollection) |
| 2282 | .methods(boost::beast::http::verb::head)(std::bind_front( |
| 2283 | handleAccountServiceClientCertificatesHead, std::ref(app))); |
| 2284 | |
| 2285 | BMCWEB_ROUTE( |
| 2286 | app, |
| 2287 | "/redfish/v1/AccountService/MultiFactorAuth/ClientCertificate/Certificates") |
| 2288 | .privileges(redfish::privileges::getCertificateCollection) |
| 2289 | .methods(boost::beast::http::verb::get)(std::bind_front( |
| 2290 | handleAccountServiceClientCertificatesGet, std::ref(app))); |
| 2291 | |
| 2292 | BMCWEB_ROUTE( |
| 2293 | app, |
| 2294 | "/redfish/v1/AccountService/MultiFactorAuth/ClientCertificate/Certificates/<str>") |
| 2295 | .privileges(redfish::privileges::headCertificate) |
| 2296 | .methods(boost::beast::http::verb::head)(std::bind_front( |
| 2297 | handleAccountServiceClientCertificatesInstanceHead, std::ref(app))); |
| 2298 | |
| 2299 | BMCWEB_ROUTE( |
| 2300 | app, |
| 2301 | "/redfish/v1/AccountService/MultiFactorAuth/ClientCertificate/Certificates/<str>/") |
| 2302 | .privileges(redfish::privileges::getCertificate) |
| 2303 | .methods(boost::beast::http::verb::get)(std::bind_front( |
| 2304 | handleAccountServiceClientCertificatesInstanceGet, std::ref(app))); |
| 2305 | |
Ed Tanous | 6c51eab | 2021-06-03 12:30:29 -0700 | [diff] [blame] | 2306 | BMCWEB_ROUTE(app, "/redfish/v1/AccountService/Accounts/") |
Ed Tanous | 4c7d4d3 | 2022-07-07 15:29:35 -0700 | [diff] [blame] | 2307 | .privileges(redfish::privileges::headManagerAccountCollection) |
| 2308 | .methods(boost::beast::http::verb::head)( |
| 2309 | std::bind_front(handleAccountCollectionHead, std::ref(app))); |
| 2310 | |
| 2311 | BMCWEB_ROUTE(app, "/redfish/v1/AccountService/Accounts/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 2312 | .privileges(redfish::privileges::getManagerAccountCollection) |
Ed Tanous | 6c51eab | 2021-06-03 12:30:29 -0700 | [diff] [blame] | 2313 | .methods(boost::beast::http::verb::get)( |
Ed Tanous | 1ef4c34 | 2022-05-12 16:12:36 -0700 | [diff] [blame] | 2314 | std::bind_front(handleAccountCollectionGet, std::ref(app))); |
Ed Tanous | 06e086d | 2018-09-19 17:19:52 -0700 | [diff] [blame] | 2315 | |
Ed Tanous | 6c51eab | 2021-06-03 12:30:29 -0700 | [diff] [blame] | 2316 | BMCWEB_ROUTE(app, "/redfish/v1/AccountService/Accounts/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 2317 | .privileges(redfish::privileges::postManagerAccountCollection) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2318 | .methods(boost::beast::http::verb::post)( |
Ed Tanous | 1ef4c34 | 2022-05-12 16:12:36 -0700 | [diff] [blame] | 2319 | std::bind_front(handleAccountCollectionPost, std::ref(app))); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2320 | |
| 2321 | BMCWEB_ROUTE(app, "/redfish/v1/AccountService/Accounts/<str>/") |
Ed Tanous | 4c7d4d3 | 2022-07-07 15:29:35 -0700 | [diff] [blame] | 2322 | .privileges(redfish::privileges::headManagerAccount) |
| 2323 | .methods(boost::beast::http::verb::head)( |
| 2324 | std::bind_front(handleAccountHead, std::ref(app))); |
| 2325 | |
| 2326 | BMCWEB_ROUTE(app, "/redfish/v1/AccountService/Accounts/<str>/") |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2327 | .privileges(redfish::privileges::getManagerAccount) |
| 2328 | .methods(boost::beast::http::verb::get)( |
Ed Tanous | 1ef4c34 | 2022-05-12 16:12:36 -0700 | [diff] [blame] | 2329 | std::bind_front(handleAccountGet, std::ref(app))); |
Ed Tanous | 6c51eab | 2021-06-03 12:30:29 -0700 | [diff] [blame] | 2330 | |
| 2331 | BMCWEB_ROUTE(app, "/redfish/v1/AccountService/Accounts/<str>/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 2332 | // TODO this privilege should be using the generated endpoints, but |
| 2333 | // because of the special handling of ConfigureSelf, it's not able to |
| 2334 | // yet |
Ed Tanous | 6c51eab | 2021-06-03 12:30:29 -0700 | [diff] [blame] | 2335 | .privileges({{"ConfigureUsers"}, {"ConfigureSelf"}}) |
| 2336 | .methods(boost::beast::http::verb::patch)( |
Ed Tanous | 1ef4c34 | 2022-05-12 16:12:36 -0700 | [diff] [blame] | 2337 | std::bind_front(handleAccountPatch, std::ref(app))); |
Ed Tanous | 6c51eab | 2021-06-03 12:30:29 -0700 | [diff] [blame] | 2338 | |
| 2339 | BMCWEB_ROUTE(app, "/redfish/v1/AccountService/Accounts/<str>/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 2340 | .privileges(redfish::privileges::deleteManagerAccount) |
Ed Tanous | 6c51eab | 2021-06-03 12:30:29 -0700 | [diff] [blame] | 2341 | .methods(boost::beast::http::verb::delete_)( |
Gunnar Mills | 20fc307 | 2023-01-27 15:13:36 -0600 | [diff] [blame] | 2342 | std::bind_front(handleAccountDelete, std::ref(app))); |
Ed Tanous | 6c51eab | 2021-06-03 12:30:29 -0700 | [diff] [blame] | 2343 | } |
Lewanczyk, Dawid | 88d16c9 | 2018-02-02 14:51:09 +0100 | [diff] [blame] | 2344 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 2345 | } // namespace redfish |