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