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