Kowalski, Kamil | 2b7981f | 2018-01-31 13:24:59 +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 |
Borawski.Lukasz | 43a095a | 2018-02-19 15:39:01 +0100 | [diff] [blame] | 17 | |
Kowalski, Kamil | f4c4dcf | 2018-01-29 14:55:35 +0100 | [diff] [blame] | 18 | #include "error_messages.hpp" |
Ed Tanous | 52cc112 | 2020-07-18 13:51:21 -0700 | [diff] [blame] | 19 | #include "persistent_data.hpp" |
Kowalski, Kamil | 2b7981f | 2018-01-31 13:24:59 +0100 | [diff] [blame] | 20 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 21 | #include <app.hpp> |
Ed Tanous | ace85d6 | 2021-10-26 12:45:59 -0700 | [diff] [blame] | 22 | #include <http/utility.hpp> |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 23 | #include <query.hpp> |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 24 | #include <registries/privilege_registry.hpp> |
Ed Tanous | 840098b | 2022-06-28 12:06:17 -0700 | [diff] [blame] | 25 | #include <utils/json_utils.hpp> |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 26 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 27 | namespace redfish |
| 28 | { |
Kowalski, Kamil | 2b7981f | 2018-01-31 13:24:59 +0100 | [diff] [blame] | 29 | |
Ed Tanous | 4f48d5f | 2021-06-21 08:27:45 -0700 | [diff] [blame] | 30 | inline void fillSessionObject(crow::Response& res, |
| 31 | const persistent_data::UserSession& session) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 32 | { |
Ed Tanous | faa34cc | 2021-06-03 13:27:02 -0700 | [diff] [blame] | 33 | res.jsonValue["Id"] = session.uniqueId; |
| 34 | res.jsonValue["UserName"] = session.username; |
| 35 | res.jsonValue["@odata.id"] = |
| 36 | "/redfish/v1/SessionService/Sessions/" + session.uniqueId; |
Ed Tanous | bb759e3 | 2022-08-02 17:07:54 -0700 | [diff] [blame] | 37 | res.jsonValue["@odata.type"] = "#Session.v1_5_0.Session"; |
Ed Tanous | faa34cc | 2021-06-03 13:27:02 -0700 | [diff] [blame] | 38 | res.jsonValue["Name"] = "User Session"; |
| 39 | res.jsonValue["Description"] = "Manager User Session"; |
| 40 | res.jsonValue["ClientOriginIPAddress"] = session.clientIp; |
Ed Tanous | bb759e3 | 2022-08-02 17:07:54 -0700 | [diff] [blame] | 41 | if (session.clientId) |
| 42 | { |
| 43 | res.jsonValue["Context"] = *session.clientId; |
| 44 | } |
| 45 | // The below implementation is deprecated in leiu of Session.Context |
Sunitha Harish | c0ea7ae | 2020-10-30 02:37:30 -0500 | [diff] [blame] | 46 | #ifdef BMCWEB_ENABLE_IBM_MANAGEMENT_CONSOLE |
Ed Tanous | faa34cc | 2021-06-03 13:27:02 -0700 | [diff] [blame] | 47 | res.jsonValue["Oem"]["OpenBMC"]["@odata.type"] = |
| 48 | "#OemSession.v1_0_0.Session"; |
Ed Tanous | bb759e3 | 2022-08-02 17:07:54 -0700 | [diff] [blame] | 49 | res.jsonValue["Oem"]["OpenBMC"]["ClientID"] = session.clientId.value_or(""); |
Sunitha Harish | 08bdcc7 | 2020-05-12 05:17:57 -0500 | [diff] [blame] | 50 | #endif |
Ed Tanous | faa34cc | 2021-06-03 13:27:02 -0700 | [diff] [blame] | 51 | } |
Kowalski, Kamil | 2b7981f | 2018-01-31 13:24:59 +0100 | [diff] [blame] | 52 | |
Ed Tanous | 724340d | 2022-03-14 09:10:07 -0700 | [diff] [blame] | 53 | inline void |
Ed Tanous | a1e0871 | 2022-07-07 16:10:39 -0700 | [diff] [blame] | 54 | handleSessionHead(crow::App& app, const crow::Request& req, |
| 55 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 56 | const std::string& /*sessionId*/) |
Ed Tanous | 724340d | 2022-03-14 09:10:07 -0700 | [diff] [blame] | 57 | { |
Ed Tanous | a1e0871 | 2022-07-07 16:10:39 -0700 | [diff] [blame] | 58 | |
Carson Labrado | 3ba0007 | 2022-06-06 19:40:56 +0000 | [diff] [blame] | 59 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 60 | { |
| 61 | return; |
| 62 | } |
Ed Tanous | a1e0871 | 2022-07-07 16:10:39 -0700 | [diff] [blame] | 63 | asyncResp->res.addHeader( |
| 64 | boost::beast::http::field::link, |
| 65 | "</redfish/v1/JsonSchemas/Session/Session.json>; rel=describedby"); |
| 66 | } |
| 67 | |
| 68 | inline void |
| 69 | handleSessionGet(crow::App& app, const crow::Request& req, |
| 70 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 71 | const std::string& sessionId) |
| 72 | { |
| 73 | handleSessionHead(app, req, asyncResp, sessionId); |
| 74 | |
Ed Tanous | 724340d | 2022-03-14 09:10:07 -0700 | [diff] [blame] | 75 | // Note that control also reaches here via doPost and doDelete. |
| 76 | auto session = |
| 77 | persistent_data::SessionStore::getInstance().getSessionByUid(sessionId); |
| 78 | |
| 79 | if (session == nullptr) |
| 80 | { |
| 81 | messages::resourceNotFound(asyncResp->res, "Session", sessionId); |
| 82 | return; |
| 83 | } |
| 84 | |
| 85 | fillSessionObject(asyncResp->res, *session); |
| 86 | } |
| 87 | |
| 88 | inline void |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 89 | handleSessionDelete(crow::App& app, const crow::Request& req, |
Ed Tanous | 724340d | 2022-03-14 09:10:07 -0700 | [diff] [blame] | 90 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 91 | const std::string& sessionId) |
| 92 | { |
Carson Labrado | 3ba0007 | 2022-06-06 19:40:56 +0000 | [diff] [blame] | 93 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 94 | { |
| 95 | return; |
| 96 | } |
Ed Tanous | 724340d | 2022-03-14 09:10:07 -0700 | [diff] [blame] | 97 | auto session = |
| 98 | persistent_data::SessionStore::getInstance().getSessionByUid(sessionId); |
| 99 | |
| 100 | if (session == nullptr) |
| 101 | { |
| 102 | messages::resourceNotFound(asyncResp->res, "Session", sessionId); |
| 103 | return; |
| 104 | } |
| 105 | |
| 106 | // Perform a proper ConfigureSelf authority check. If a |
| 107 | // session is being used to DELETE some other user's session, |
| 108 | // then the ConfigureSelf privilege does not apply. In that |
| 109 | // case, perform the authority check again without the user's |
| 110 | // ConfigureSelf privilege. |
wukaihua-fii-na | 0fd2986 | 2022-05-18 09:19:16 +0800 | [diff] [blame] | 111 | if (req.session != nullptr && !session->username.empty() && |
| 112 | session->username != req.session->username) |
Ed Tanous | 724340d | 2022-03-14 09:10:07 -0700 | [diff] [blame] | 113 | { |
| 114 | Privileges effectiveUserPrivileges = |
| 115 | redfish::getUserPrivileges(req.userRole); |
| 116 | |
| 117 | if (!effectiveUserPrivileges.isSupersetOf({"ConfigureUsers"})) |
| 118 | { |
| 119 | messages::insufficientPrivilege(asyncResp->res); |
| 120 | return; |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | persistent_data::SessionStore::getInstance().removeSession(session); |
| 125 | messages::success(asyncResp->res); |
| 126 | } |
| 127 | |
| 128 | inline nlohmann::json getSessionCollectionMembers() |
| 129 | { |
| 130 | std::vector<const std::string*> sessionIds = |
| 131 | persistent_data::SessionStore::getInstance().getUniqueIds( |
| 132 | false, persistent_data::PersistenceType::TIMEOUT); |
| 133 | nlohmann::json ret = nlohmann::json::array(); |
| 134 | for (const std::string* uid : sessionIds) |
| 135 | { |
Ed Tanous | 1476687 | 2022-03-15 10:44:42 -0700 | [diff] [blame] | 136 | nlohmann::json::object_t session; |
| 137 | session["@odata.id"] = "/redfish/v1/SessionService/Sessions/" + *uid; |
| 138 | ret.push_back(std::move(session)); |
Ed Tanous | 724340d | 2022-03-14 09:10:07 -0700 | [diff] [blame] | 139 | } |
| 140 | return ret; |
| 141 | } |
| 142 | |
Ed Tanous | a1e0871 | 2022-07-07 16:10:39 -0700 | [diff] [blame] | 143 | inline void handleSessionCollectionHead( |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 144 | crow::App& app, const crow::Request& req, |
Ed Tanous | 724340d | 2022-03-14 09:10:07 -0700 | [diff] [blame] | 145 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
| 146 | { |
Ed Tanous | a1e0871 | 2022-07-07 16:10:39 -0700 | [diff] [blame] | 147 | |
Carson Labrado | 3ba0007 | 2022-06-06 19:40:56 +0000 | [diff] [blame] | 148 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 149 | { |
| 150 | return; |
| 151 | } |
Ed Tanous | a1e0871 | 2022-07-07 16:10:39 -0700 | [diff] [blame] | 152 | asyncResp->res.addHeader( |
| 153 | boost::beast::http::field::link, |
| 154 | "</redfish/v1/JsonSchemas/SessionCollection.json>; rel=describedby"); |
| 155 | } |
| 156 | |
| 157 | inline void handleSessionCollectionGet( |
| 158 | crow::App& app, const crow::Request& req, |
| 159 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
| 160 | { |
| 161 | handleSessionCollectionHead(app, req, asyncResp); |
Ed Tanous | 724340d | 2022-03-14 09:10:07 -0700 | [diff] [blame] | 162 | asyncResp->res.jsonValue["Members"] = getSessionCollectionMembers(); |
| 163 | asyncResp->res.jsonValue["Members@odata.count"] = |
| 164 | asyncResp->res.jsonValue["Members"].size(); |
| 165 | asyncResp->res.jsonValue["@odata.type"] = |
| 166 | "#SessionCollection.SessionCollection"; |
| 167 | asyncResp->res.jsonValue["@odata.id"] = |
| 168 | "/redfish/v1/SessionService/Sessions/"; |
| 169 | asyncResp->res.jsonValue["Name"] = "Session Collection"; |
| 170 | asyncResp->res.jsonValue["Description"] = "Session Collection"; |
| 171 | } |
| 172 | |
| 173 | inline void handleSessionCollectionMembersGet( |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 174 | crow::App& app, const crow::Request& req, |
Ed Tanous | 724340d | 2022-03-14 09:10:07 -0700 | [diff] [blame] | 175 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
| 176 | { |
Carson Labrado | 3ba0007 | 2022-06-06 19:40:56 +0000 | [diff] [blame] | 177 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 178 | { |
| 179 | return; |
| 180 | } |
Ed Tanous | 724340d | 2022-03-14 09:10:07 -0700 | [diff] [blame] | 181 | asyncResp->res.jsonValue = getSessionCollectionMembers(); |
| 182 | } |
| 183 | |
Ed Tanous | 4ee8e21 | 2022-05-28 09:42:51 -0700 | [diff] [blame] | 184 | inline void handleSessionCollectionPost( |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 185 | crow::App& app, const crow::Request& req, |
Ed Tanous | 724340d | 2022-03-14 09:10:07 -0700 | [diff] [blame] | 186 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
| 187 | { |
Carson Labrado | 3ba0007 | 2022-06-06 19:40:56 +0000 | [diff] [blame] | 188 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 189 | { |
| 190 | return; |
| 191 | } |
Ed Tanous | 724340d | 2022-03-14 09:10:07 -0700 | [diff] [blame] | 192 | std::string username; |
| 193 | std::string password; |
| 194 | std::optional<nlohmann::json> oemObject; |
Ed Tanous | bb759e3 | 2022-08-02 17:07:54 -0700 | [diff] [blame] | 195 | std::optional<std::string> clientId; |
Ed Tanous | 724340d | 2022-03-14 09:10:07 -0700 | [diff] [blame] | 196 | if (!json_util::readJsonPatch(req, asyncResp->res, "UserName", username, |
Ed Tanous | bb759e3 | 2022-08-02 17:07:54 -0700 | [diff] [blame] | 197 | "Password", password, "Context", clientId, |
| 198 | "Oem", oemObject)) |
Ed Tanous | 724340d | 2022-03-14 09:10:07 -0700 | [diff] [blame] | 199 | { |
| 200 | return; |
| 201 | } |
| 202 | |
| 203 | if (password.empty() || username.empty() || |
| 204 | asyncResp->res.result() != boost::beast::http::status::ok) |
| 205 | { |
| 206 | if (username.empty()) |
| 207 | { |
| 208 | messages::propertyMissing(asyncResp->res, "UserName"); |
| 209 | } |
| 210 | |
| 211 | if (password.empty()) |
| 212 | { |
| 213 | messages::propertyMissing(asyncResp->res, "Password"); |
| 214 | } |
| 215 | |
| 216 | return; |
| 217 | } |
| 218 | |
| 219 | int pamrc = pamAuthenticateUser(username, password); |
| 220 | bool isConfigureSelfOnly = pamrc == PAM_NEW_AUTHTOK_REQD; |
| 221 | if ((pamrc != PAM_SUCCESS) && !isConfigureSelfOnly) |
| 222 | { |
| 223 | messages::resourceAtUriUnauthorized(asyncResp->res, req.urlView, |
| 224 | "Invalid username or password"); |
| 225 | return; |
| 226 | } |
| 227 | #ifdef BMCWEB_ENABLE_IBM_MANAGEMENT_CONSOLE |
| 228 | if (oemObject) |
| 229 | { |
| 230 | std::optional<nlohmann::json> bmcOem; |
| 231 | if (!json_util::readJson(*oemObject, asyncResp->res, "OpenBMC", bmcOem)) |
| 232 | { |
| 233 | return; |
| 234 | } |
Ed Tanous | bb759e3 | 2022-08-02 17:07:54 -0700 | [diff] [blame] | 235 | |
| 236 | std::optional<std::string> oemClientId; |
| 237 | if (!json_util::readJson(*bmcOem, asyncResp->res, "ClientID", |
| 238 | oemClientId)) |
Ed Tanous | 724340d | 2022-03-14 09:10:07 -0700 | [diff] [blame] | 239 | { |
| 240 | BMCWEB_LOG_ERROR << "Could not read ClientId"; |
| 241 | return; |
| 242 | } |
Ed Tanous | bb759e3 | 2022-08-02 17:07:54 -0700 | [diff] [blame] | 243 | if (oemClientId) |
| 244 | { |
| 245 | if (clientId) |
| 246 | { |
| 247 | messages::propertyValueConflict(*oemClientId, *clientId); |
| 248 | return; |
| 249 | } |
| 250 | clientId = *oemClientId; |
| 251 | } |
Ed Tanous | 724340d | 2022-03-14 09:10:07 -0700 | [diff] [blame] | 252 | } |
| 253 | #endif |
| 254 | |
| 255 | // User is authenticated - create session |
| 256 | std::shared_ptr<persistent_data::UserSession> session = |
| 257 | persistent_data::SessionStore::getInstance().generateUserSession( |
| 258 | username, req.ipAddress, clientId, |
| 259 | persistent_data::PersistenceType::TIMEOUT, isConfigureSelfOnly); |
Brad Bishop | 02e53ae | 2022-07-29 14:38:40 -0400 | [diff] [blame] | 260 | if (session == nullptr) |
| 261 | { |
| 262 | messages::internalError(asyncResp->res); |
| 263 | return; |
| 264 | } |
| 265 | |
Ed Tanous | 724340d | 2022-03-14 09:10:07 -0700 | [diff] [blame] | 266 | asyncResp->res.addHeader("X-Auth-Token", session->sessionToken); |
| 267 | asyncResp->res.addHeader( |
| 268 | "Location", "/redfish/v1/SessionService/Sessions/" + session->uniqueId); |
| 269 | asyncResp->res.result(boost::beast::http::status::created); |
| 270 | if (session->isConfigureSelfOnly) |
| 271 | { |
| 272 | messages::passwordChangeRequired( |
| 273 | asyncResp->res, |
| 274 | crow::utility::urlFromPieces("redfish", "v1", "AccountService", |
Brad Bishop | 85e6471 | 2022-07-29 12:59:07 -0400 | [diff] [blame] | 275 | "Accounts", session->username)); |
Ed Tanous | 724340d | 2022-03-14 09:10:07 -0700 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | fillSessionObject(asyncResp->res, *session); |
| 279 | } |
Ed Tanous | a1e0871 | 2022-07-07 16:10:39 -0700 | [diff] [blame] | 280 | inline void handleSessionServiceHead( |
| 281 | crow::App& app, const crow::Request& req, |
| 282 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
| 283 | { |
| 284 | |
| 285 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 286 | { |
| 287 | return; |
| 288 | } |
| 289 | asyncResp->res.addHeader( |
| 290 | boost::beast::http::field::link, |
| 291 | "</redfish/v1/JsonSchemas/SessionService/SessionService.json>; rel=describedby"); |
| 292 | } |
Ed Tanous | 724340d | 2022-03-14 09:10:07 -0700 | [diff] [blame] | 293 | inline void |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 294 | handleSessionServiceGet(crow::App& app, const crow::Request& req, |
Ed Tanous | 724340d | 2022-03-14 09:10:07 -0700 | [diff] [blame] | 295 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
| 296 | |
| 297 | { |
Ed Tanous | a1e0871 | 2022-07-07 16:10:39 -0700 | [diff] [blame] | 298 | handleSessionServiceHead(app, req, asyncResp); |
Ed Tanous | 724340d | 2022-03-14 09:10:07 -0700 | [diff] [blame] | 299 | asyncResp->res.jsonValue["@odata.type"] = |
| 300 | "#SessionService.v1_0_2.SessionService"; |
| 301 | asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/SessionService/"; |
| 302 | asyncResp->res.jsonValue["Name"] = "Session Service"; |
| 303 | asyncResp->res.jsonValue["Id"] = "SessionService"; |
| 304 | asyncResp->res.jsonValue["Description"] = "Session Service"; |
| 305 | asyncResp->res.jsonValue["SessionTimeout"] = |
| 306 | persistent_data::SessionStore::getInstance().getTimeoutInSeconds(); |
| 307 | asyncResp->res.jsonValue["ServiceEnabled"] = true; |
| 308 | |
Ed Tanous | 1476687 | 2022-03-15 10:44:42 -0700 | [diff] [blame] | 309 | asyncResp->res.jsonValue["Sessions"]["@odata.id"] = |
| 310 | "/redfish/v1/SessionService/Sessions"; |
Ed Tanous | 724340d | 2022-03-14 09:10:07 -0700 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | inline void handleSessionServicePatch( |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 314 | crow::App& app, const crow::Request& req, |
Ed Tanous | 724340d | 2022-03-14 09:10:07 -0700 | [diff] [blame] | 315 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
| 316 | { |
Carson Labrado | 3ba0007 | 2022-06-06 19:40:56 +0000 | [diff] [blame] | 317 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 318 | { |
| 319 | return; |
| 320 | } |
Ed Tanous | 724340d | 2022-03-14 09:10:07 -0700 | [diff] [blame] | 321 | std::optional<int64_t> sessionTimeout; |
| 322 | if (!json_util::readJsonPatch(req, asyncResp->res, "SessionTimeout", |
| 323 | sessionTimeout)) |
| 324 | { |
| 325 | return; |
| 326 | } |
| 327 | |
| 328 | if (sessionTimeout) |
| 329 | { |
| 330 | // The mininum & maximum allowed values for session timeout |
| 331 | // are 30 seconds and 86400 seconds respectively as per the |
| 332 | // session service schema mentioned at |
| 333 | // https://redfish.dmtf.org/schemas/v1/SessionService.v1_1_7.json |
| 334 | |
| 335 | if (*sessionTimeout <= 86400 && *sessionTimeout >= 30) |
| 336 | { |
| 337 | std::chrono::seconds sessionTimeoutInseconds(*sessionTimeout); |
| 338 | persistent_data::SessionStore::getInstance().updateSessionTimeout( |
| 339 | sessionTimeoutInseconds); |
| 340 | messages::propertyValueModified(asyncResp->res, "SessionTimeOut", |
| 341 | std::to_string(*sessionTimeout)); |
| 342 | } |
| 343 | else |
| 344 | { |
| 345 | messages::propertyValueNotInList(asyncResp->res, |
| 346 | std::to_string(*sessionTimeout), |
| 347 | "SessionTimeOut"); |
| 348 | } |
| 349 | } |
| 350 | } |
| 351 | |
Ed Tanous | faa34cc | 2021-06-03 13:27:02 -0700 | [diff] [blame] | 352 | inline void requestRoutesSession(App& app) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 353 | { |
Ed Tanous | faa34cc | 2021-06-03 13:27:02 -0700 | [diff] [blame] | 354 | BMCWEB_ROUTE(app, "/redfish/v1/SessionService/Sessions/<str>/") |
Ed Tanous | a1e0871 | 2022-07-07 16:10:39 -0700 | [diff] [blame] | 355 | .privileges(redfish::privileges::headSession) |
| 356 | .methods(boost::beast::http::verb::head)( |
| 357 | std::bind_front(handleSessionHead, std::ref(app))); |
| 358 | |
| 359 | BMCWEB_ROUTE(app, "/redfish/v1/SessionService/Sessions/<str>/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 360 | .privileges(redfish::privileges::getSession) |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 361 | .methods(boost::beast::http::verb::get)( |
| 362 | std::bind_front(handleSessionGet, std::ref(app))); |
Kowalski, Kamil | 2b7981f | 2018-01-31 13:24:59 +0100 | [diff] [blame] | 363 | |
Ed Tanous | faa34cc | 2021-06-03 13:27:02 -0700 | [diff] [blame] | 364 | BMCWEB_ROUTE(app, "/redfish/v1/SessionService/Sessions/<str>/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 365 | .privileges(redfish::privileges::deleteSession) |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 366 | .methods(boost::beast::http::verb::delete_)( |
| 367 | std::bind_front(handleSessionDelete, std::ref(app))); |
Ed Tanous | faa34cc | 2021-06-03 13:27:02 -0700 | [diff] [blame] | 368 | |
| 369 | BMCWEB_ROUTE(app, "/redfish/v1/SessionService/Sessions/") |
Ed Tanous | a1e0871 | 2022-07-07 16:10:39 -0700 | [diff] [blame] | 370 | .privileges(redfish::privileges::headSessionCollection) |
| 371 | .methods(boost::beast::http::verb::head)( |
| 372 | std::bind_front(handleSessionCollectionHead, std::ref(app))); |
| 373 | |
| 374 | BMCWEB_ROUTE(app, "/redfish/v1/SessionService/Sessions/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 375 | .privileges(redfish::privileges::getSessionCollection) |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 376 | .methods(boost::beast::http::verb::get)( |
| 377 | std::bind_front(handleSessionCollectionGet, std::ref(app))); |
Ed Tanous | faa34cc | 2021-06-03 13:27:02 -0700 | [diff] [blame] | 378 | |
Ed Tanous | e76cd86 | 2022-03-14 09:12:00 -0700 | [diff] [blame] | 379 | // Note, the next two routes technically don't match the privilege |
Ed Tanous | 724340d | 2022-03-14 09:10:07 -0700 | [diff] [blame] | 380 | // registry given the way login mechanisms work. The base privilege |
| 381 | // registry lists this endpoint as requiring login privilege, but because |
| 382 | // this is the endpoint responsible for giving the login privilege, and it |
| 383 | // is itself its own route, it needs to not require Login |
Ed Tanous | faa34cc | 2021-06-03 13:27:02 -0700 | [diff] [blame] | 384 | BMCWEB_ROUTE(app, "/redfish/v1/SessionService/Sessions/") |
| 385 | .privileges({}) |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 386 | .methods(boost::beast::http::verb::post)( |
| 387 | std::bind_front(handleSessionCollectionPost, std::ref(app))); |
Kowalski, Kamil | 2b7981f | 2018-01-31 13:24:59 +0100 | [diff] [blame] | 388 | |
Ed Tanous | e76cd86 | 2022-03-14 09:12:00 -0700 | [diff] [blame] | 389 | BMCWEB_ROUTE(app, "/redfish/v1/SessionService/Sessions/Members/") |
| 390 | .privileges({}) |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 391 | .methods(boost::beast::http::verb::post)( |
| 392 | std::bind_front(handleSessionCollectionPost, std::ref(app))); |
Ed Tanous | e76cd86 | 2022-03-14 09:12:00 -0700 | [diff] [blame] | 393 | |
Ed Tanous | faa34cc | 2021-06-03 13:27:02 -0700 | [diff] [blame] | 394 | BMCWEB_ROUTE(app, "/redfish/v1/SessionService/") |
Ed Tanous | a1e0871 | 2022-07-07 16:10:39 -0700 | [diff] [blame] | 395 | .privileges(redfish::privileges::headSessionService) |
| 396 | .methods(boost::beast::http::verb::head)( |
| 397 | std::bind_front(handleSessionServiceHead, std::ref(app))); |
| 398 | |
| 399 | BMCWEB_ROUTE(app, "/redfish/v1/SessionService/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 400 | .privileges(redfish::privileges::getSessionService) |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 401 | .methods(boost::beast::http::verb::get)( |
| 402 | std::bind_front(handleSessionServiceGet, std::ref(app))); |
Borawski.Lukasz | 5d27b85 | 2018-02-08 13:24:24 +0100 | [diff] [blame] | 403 | |
Ed Tanous | faa34cc | 2021-06-03 13:27:02 -0700 | [diff] [blame] | 404 | BMCWEB_ROUTE(app, "/redfish/v1/SessionService/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 405 | .privileges(redfish::privileges::patchSessionService) |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 406 | .methods(boost::beast::http::verb::patch)( |
| 407 | std::bind_front(handleSessionServicePatch, std::ref(app))); |
Ed Tanous | faa34cc | 2021-06-03 13:27:02 -0700 | [diff] [blame] | 408 | } |
Borawski.Lukasz | 5d27b85 | 2018-02-08 13:24:24 +0100 | [diff] [blame] | 409 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 410 | } // namespace redfish |