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" |
Kowalski, Kamil | 2b7981f | 2018-01-31 13:24:59 +0100 | [diff] [blame] | 19 | #include "node.hpp" |
Ed Tanous | 52cc112 | 2020-07-18 13:51:21 -0700 | [diff] [blame] | 20 | #include "persistent_data.hpp" |
Kowalski, Kamil | 2b7981f | 2018-01-31 13:24:59 +0100 | [diff] [blame] | 21 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 22 | #include <app.hpp> |
| 23 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 24 | namespace redfish |
| 25 | { |
Kowalski, Kamil | 2b7981f | 2018-01-31 13:24:59 +0100 | [diff] [blame] | 26 | |
| 27 | class SessionCollection; |
| 28 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 29 | class Sessions : public Node |
| 30 | { |
| 31 | public: |
Ed Tanous | 52cc112 | 2020-07-18 13:51:21 -0700 | [diff] [blame] | 32 | Sessions(App& app) : |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 33 | Node(app, "/redfish/v1/SessionService/Sessions/<str>/", std::string()) |
| 34 | { |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 35 | entityPrivileges = { |
| 36 | {boost::beast::http::verb::get, {{"Login"}}}, |
| 37 | {boost::beast::http::verb::head, {{"Login"}}}, |
| 38 | {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, |
| 39 | {boost::beast::http::verb::put, {{"ConfigureManager"}}}, |
Joseph Reynolds | 900f949 | 2019-11-25 15:37:29 -0600 | [diff] [blame] | 40 | {boost::beast::http::verb::delete_, |
| 41 | {{"ConfigureManager"}, {"ConfigureSelf"}}}, |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 42 | {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; |
Kowalski, Kamil | 2b7981f | 2018-01-31 13:24:59 +0100 | [diff] [blame] | 43 | } |
| 44 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 45 | private: |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 46 | void doGet(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 47 | const crow::Request&, |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 48 | const std::vector<std::string>& params) override |
| 49 | { |
Joseph Reynolds | 900f949 | 2019-11-25 15:37:29 -0600 | [diff] [blame] | 50 | // Note that control also reaches here via doPost and doDelete. |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 51 | auto session = |
Ed Tanous | 52cc112 | 2020-07-18 13:51:21 -0700 | [diff] [blame] | 52 | persistent_data::SessionStore::getInstance().getSessionByUid( |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 53 | params[0]); |
Kowalski, Kamil | 2b7981f | 2018-01-31 13:24:59 +0100 | [diff] [blame] | 54 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 55 | if (session == nullptr) |
| 56 | { |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 57 | messages::resourceNotFound(asyncResp->res, "Session", params[0]); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 58 | return; |
| 59 | } |
Kowalski, Kamil | f4c4dcf | 2018-01-29 14:55:35 +0100 | [diff] [blame] | 60 | |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 61 | asyncResp->res.jsonValue["Id"] = session->uniqueId; |
| 62 | asyncResp->res.jsonValue["UserName"] = session->username; |
| 63 | asyncResp->res.jsonValue["@odata.id"] = |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 64 | "/redfish/v1/SessionService/Sessions/" + session->uniqueId; |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 65 | asyncResp->res.jsonValue["@odata.type"] = "#Session.v1_3_0.Session"; |
| 66 | asyncResp->res.jsonValue["Name"] = "User Session"; |
| 67 | asyncResp->res.jsonValue["Description"] = "Manager User Session"; |
| 68 | asyncResp->res.jsonValue["ClientOriginIPAddress"] = session->clientIp; |
Sunitha Harish | c0ea7ae | 2020-10-30 02:37:30 -0500 | [diff] [blame] | 69 | #ifdef BMCWEB_ENABLE_IBM_MANAGEMENT_CONSOLE |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 70 | asyncResp->res.jsonValue["Oem"]["OpenBMC"]["@odata.type"] = |
Sunitha Harish | 08bdcc7 | 2020-05-12 05:17:57 -0500 | [diff] [blame] | 71 | "#OemSession.v1_0_0.Session"; |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 72 | asyncResp->res.jsonValue["Oem"]["OpenBMC"]["ClientID"] = |
| 73 | session->clientId; |
Sunitha Harish | 08bdcc7 | 2020-05-12 05:17:57 -0500 | [diff] [blame] | 74 | #endif |
Kowalski, Kamil | 2b7981f | 2018-01-31 13:24:59 +0100 | [diff] [blame] | 75 | } |
| 76 | |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 77 | void doDelete(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 78 | const crow::Request& req, |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 79 | const std::vector<std::string>& params) override |
| 80 | { |
| 81 | // Need only 1 param which should be id of session to be deleted |
| 82 | if (params.size() != 1) |
| 83 | { |
| 84 | // This should be handled by crow and never happen |
| 85 | BMCWEB_LOG_ERROR << "Session DELETE has been called with invalid " |
| 86 | "number of params"; |
Kowalski, Kamil | 2b7981f | 2018-01-31 13:24:59 +0100 | [diff] [blame] | 87 | |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 88 | messages::generalError(asyncResp->res); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 89 | return; |
| 90 | } |
| 91 | |
| 92 | auto session = |
Ed Tanous | 52cc112 | 2020-07-18 13:51:21 -0700 | [diff] [blame] | 93 | persistent_data::SessionStore::getInstance().getSessionByUid( |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 94 | params[0]); |
| 95 | |
| 96 | if (session == nullptr) |
| 97 | { |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 98 | messages::resourceNotFound(asyncResp->res, "Session", params[0]); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 99 | return; |
| 100 | } |
| 101 | |
Joseph Reynolds | 900f949 | 2019-11-25 15:37:29 -0600 | [diff] [blame] | 102 | // Perform a proper ConfigureSelf authority check. If a |
| 103 | // session is being used to DELETE some other user's session, |
| 104 | // then the ConfigureSelf privilege does not apply. In that |
| 105 | // case, perform the authority check again without the user's |
| 106 | // ConfigureSelf privilege. |
| 107 | if (session->username != req.session->username) |
| 108 | { |
Ed Tanous | 6c51eab | 2021-06-03 12:30:29 -0700 | [diff] [blame] | 109 | Privileges effectiveUserPrivileges = |
| 110 | redfish::getUserPrivileges(req.userRole); |
| 111 | |
| 112 | if (!effectiveUserPrivileges.isSupersetOf({{"ConfigureUsers"}})) |
Joseph Reynolds | 900f949 | 2019-11-25 15:37:29 -0600 | [diff] [blame] | 113 | { |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 114 | messages::insufficientPrivilege(asyncResp->res); |
Joseph Reynolds | 900f949 | 2019-11-25 15:37:29 -0600 | [diff] [blame] | 115 | return; |
| 116 | } |
| 117 | } |
| 118 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 119 | // DELETE should return representation of object that will be removed |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 120 | doGet(asyncResp, req, params); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 121 | |
Ed Tanous | 52cc112 | 2020-07-18 13:51:21 -0700 | [diff] [blame] | 122 | persistent_data::SessionStore::getInstance().removeSession(session); |
Kowalski, Kamil | 2b7981f | 2018-01-31 13:24:59 +0100 | [diff] [blame] | 123 | } |
| 124 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 125 | /** |
| 126 | * This allows SessionCollection to reuse this class' doGet method, to |
| 127 | * maintain consistency of returned data, as Collection's doPost should |
Sunitha Harish | 92f6822 | 2020-05-28 05:09:09 -0500 | [diff] [blame] | 128 | * return data for created member which should match member's doGet |
| 129 | * result in 100% |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 130 | */ |
| 131 | friend SessionCollection; |
Kowalski, Kamil | 2b7981f | 2018-01-31 13:24:59 +0100 | [diff] [blame] | 132 | }; |
| 133 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 134 | class SessionCollection : public Node |
| 135 | { |
| 136 | public: |
Ed Tanous | 52cc112 | 2020-07-18 13:51:21 -0700 | [diff] [blame] | 137 | SessionCollection(App& app) : |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 138 | Node(app, "/redfish/v1/SessionService/Sessions/"), memberSession(app) |
| 139 | { |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 140 | entityPrivileges = { |
| 141 | {boost::beast::http::verb::get, {{"Login"}}}, |
| 142 | {boost::beast::http::verb::head, {{"Login"}}}, |
| 143 | {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, |
| 144 | {boost::beast::http::verb::put, {{"ConfigureManager"}}}, |
| 145 | {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, |
| 146 | {boost::beast::http::verb::post, {}}}; |
Kowalski, Kamil | 2b7981f | 2018-01-31 13:24:59 +0100 | [diff] [blame] | 147 | } |
| 148 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 149 | private: |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 150 | void doGet(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 151 | const crow::Request&, const std::vector<std::string>&) override |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 152 | { |
| 153 | std::vector<const std::string*> sessionIds = |
Ed Tanous | 52cc112 | 2020-07-18 13:51:21 -0700 | [diff] [blame] | 154 | persistent_data::SessionStore::getInstance().getUniqueIds( |
| 155 | false, persistent_data::PersistenceType::TIMEOUT); |
Kowalski, Kamil | 2b7981f | 2018-01-31 13:24:59 +0100 | [diff] [blame] | 156 | |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 157 | asyncResp->res.jsonValue["Members@odata.count"] = sessionIds.size(); |
| 158 | asyncResp->res.jsonValue["Members"] = nlohmann::json::array(); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 159 | for (const std::string* uid : sessionIds) |
| 160 | { |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 161 | asyncResp->res.jsonValue["Members"].push_back( |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 162 | {{"@odata.id", "/redfish/v1/SessionService/Sessions/" + *uid}}); |
| 163 | } |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 164 | asyncResp->res.jsonValue["Members@odata.count"] = sessionIds.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"; |
Kowalski, Kamil | 2b7981f | 2018-01-31 13:24:59 +0100 | [diff] [blame] | 171 | } |
| 172 | |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 173 | void doPost(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 174 | const crow::Request& req, |
Ed Tanous | cb13a39 | 2020-07-25 19:02:03 +0000 | [diff] [blame] | 175 | const std::vector<std::string>&) override |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 176 | { |
Ed Tanous | 9712f8a | 2018-09-21 13:38:49 -0700 | [diff] [blame] | 177 | std::string username; |
| 178 | std::string password; |
Sunitha Harish | 08bdcc7 | 2020-05-12 05:17:57 -0500 | [diff] [blame] | 179 | std::optional<nlohmann::json> oemObject; |
| 180 | std::string clientId; |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 181 | if (!json_util::readJson(req, asyncResp->res, "UserName", username, |
| 182 | "Password", password, "Oem", oemObject)) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 183 | { |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 184 | return; |
| 185 | } |
Ed Tanous | b9845d9 | 2018-07-24 14:38:06 -0700 | [diff] [blame] | 186 | |
Ed Tanous | 820ce59 | 2018-10-04 15:54:21 -0700 | [diff] [blame] | 187 | if (password.empty() || username.empty() || |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 188 | asyncResp->res.result() != boost::beast::http::status::ok) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 189 | { |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 190 | if (username.empty()) |
| 191 | { |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 192 | messages::propertyMissing(asyncResp->res, "UserName"); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | if (password.empty()) |
| 196 | { |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 197 | messages::propertyMissing(asyncResp->res, "Password"); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 198 | } |
| 199 | |
Ed Tanous | 820ce59 | 2018-10-04 15:54:21 -0700 | [diff] [blame] | 200 | return; |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 201 | } |
| 202 | |
Joseph Reynolds | 3bf4e63 | 2020-02-06 14:44:32 -0600 | [diff] [blame] | 203 | int pamrc = pamAuthenticateUser(username, password); |
| 204 | bool isConfigureSelfOnly = pamrc == PAM_NEW_AUTHTOK_REQD; |
| 205 | if ((pamrc != PAM_SUCCESS) && !isConfigureSelfOnly) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 206 | { |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 207 | messages::resourceAtUriUnauthorized(asyncResp->res, |
| 208 | std::string(req.url), |
Jason M. Bills | f12894f | 2018-10-09 12:45:45 -0700 | [diff] [blame] | 209 | "Invalid username or password"); |
Ed Tanous | 820ce59 | 2018-10-04 15:54:21 -0700 | [diff] [blame] | 210 | return; |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 211 | } |
Sunitha Harish | 08bdcc7 | 2020-05-12 05:17:57 -0500 | [diff] [blame] | 212 | #ifdef BMCWEB_ENABLE_IBM_MANAGEMENT_CONSOLE |
| 213 | if (oemObject) |
| 214 | { |
| 215 | std::optional<nlohmann::json> bmcOem; |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 216 | if (!json_util::readJson(*oemObject, asyncResp->res, "OpenBMC", |
| 217 | bmcOem)) |
Sunitha Harish | 08bdcc7 | 2020-05-12 05:17:57 -0500 | [diff] [blame] | 218 | { |
Sunitha Harish | 08bdcc7 | 2020-05-12 05:17:57 -0500 | [diff] [blame] | 219 | return; |
| 220 | } |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 221 | if (!json_util::readJson(*bmcOem, asyncResp->res, "ClientID", |
| 222 | clientId)) |
Sunitha Harish | 08bdcc7 | 2020-05-12 05:17:57 -0500 | [diff] [blame] | 223 | { |
| 224 | BMCWEB_LOG_ERROR << "Could not read ClientId"; |
Sunitha Harish | 08bdcc7 | 2020-05-12 05:17:57 -0500 | [diff] [blame] | 225 | return; |
| 226 | } |
| 227 | } |
| 228 | #endif |
Manojkiran Eda | 6f115bb | 2020-06-27 09:52:23 +0530 | [diff] [blame] | 229 | |
Ed Tanous | 820ce59 | 2018-10-04 15:54:21 -0700 | [diff] [blame] | 230 | // User is authenticated - create session |
Ed Tanous | 52cc112 | 2020-07-18 13:51:21 -0700 | [diff] [blame] | 231 | std::shared_ptr<persistent_data::UserSession> session = |
| 232 | persistent_data::SessionStore::getInstance().generateUserSession( |
Sunitha Harish | d323922 | 2021-02-24 15:33:29 +0530 | [diff] [blame] | 233 | username, req.ipAddress.to_string(), clientId, |
| 234 | persistent_data::PersistenceType::TIMEOUT, isConfigureSelfOnly); |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 235 | asyncResp->res.addHeader("X-Auth-Token", session->sessionToken); |
| 236 | asyncResp->res.addHeader("Location", |
| 237 | "/redfish/v1/SessionService/Sessions/" + |
| 238 | session->uniqueId); |
| 239 | asyncResp->res.result(boost::beast::http::status::created); |
Joseph Reynolds | 3bf4e63 | 2020-02-06 14:44:32 -0600 | [diff] [blame] | 240 | if (session->isConfigureSelfOnly) |
| 241 | { |
| 242 | messages::passwordChangeRequired( |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 243 | asyncResp->res, |
Joseph Reynolds | 3bf4e63 | 2020-02-06 14:44:32 -0600 | [diff] [blame] | 244 | "/redfish/v1/AccountService/Accounts/" + session->username); |
| 245 | } |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 246 | memberSession.doGet(asyncResp, req, {session->uniqueId}); |
Kowalski, Kamil | 2b7981f | 2018-01-31 13:24:59 +0100 | [diff] [blame] | 247 | } |
| 248 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 249 | /** |
| 250 | * Member session to ensure consistency between collection's doPost and |
| 251 | * member's doGet, as they should return 100% matching data |
| 252 | */ |
| 253 | Sessions memberSession; |
Kowalski, Kamil | 2b7981f | 2018-01-31 13:24:59 +0100 | [diff] [blame] | 254 | }; |
| 255 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 256 | class SessionService : public Node |
| 257 | { |
| 258 | public: |
Ed Tanous | 52cc112 | 2020-07-18 13:51:21 -0700 | [diff] [blame] | 259 | SessionService(App& app) : Node(app, "/redfish/v1/SessionService/") |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 260 | { |
Ed Tanous | 3ebd75f | 2018-03-05 18:20:01 -0800 | [diff] [blame] | 261 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 262 | entityPrivileges = { |
| 263 | {boost::beast::http::verb::get, {{"Login"}}}, |
| 264 | {boost::beast::http::verb::head, {{"Login"}}}, |
| 265 | {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, |
| 266 | {boost::beast::http::verb::put, {{"ConfigureManager"}}}, |
| 267 | {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, |
| 268 | {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; |
| 269 | } |
Borawski.Lukasz | 5d27b85 | 2018-02-08 13:24:24 +0100 | [diff] [blame] | 270 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 271 | private: |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 272 | void doGet(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 273 | const crow::Request&, const std::vector<std::string>&) override |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 274 | { |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 275 | asyncResp->res.jsonValue["@odata.type"] = |
| 276 | "#SessionService.v1_0_2.SessionService"; |
| 277 | asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/SessionService/"; |
| 278 | asyncResp->res.jsonValue["Name"] = "Session Service"; |
| 279 | asyncResp->res.jsonValue["Id"] = "SessionService"; |
| 280 | asyncResp->res.jsonValue["Description"] = "Session Service"; |
| 281 | asyncResp->res.jsonValue["SessionTimeout"] = |
Ed Tanous | 52cc112 | 2020-07-18 13:51:21 -0700 | [diff] [blame] | 282 | persistent_data::SessionStore::getInstance().getTimeoutInSeconds(); |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 283 | asyncResp->res.jsonValue["ServiceEnabled"] = true; |
Ed Tanous | 0f74e64 | 2018-11-12 15:17:05 -0800 | [diff] [blame] | 284 | |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 285 | asyncResp->res.jsonValue["Sessions"] = { |
Ed Tanous | 0f26153 | 2019-02-08 11:13:29 -0800 | [diff] [blame] | 286 | {"@odata.id", "/redfish/v1/SessionService/Sessions"}}; |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 287 | } |
Manojkiran Eda | f2a4a60 | 2020-08-27 16:04:26 +0530 | [diff] [blame] | 288 | |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 289 | void doPatch(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 290 | const crow::Request& req, |
Manojkiran Eda | f2a4a60 | 2020-08-27 16:04:26 +0530 | [diff] [blame] | 291 | const std::vector<std::string>&) override |
| 292 | { |
Manojkiran Eda | f2a4a60 | 2020-08-27 16:04:26 +0530 | [diff] [blame] | 293 | std::optional<int64_t> sessionTimeout; |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 294 | if (!json_util::readJson(req, asyncResp->res, "SessionTimeout", |
| 295 | sessionTimeout)) |
Manojkiran Eda | f2a4a60 | 2020-08-27 16:04:26 +0530 | [diff] [blame] | 296 | { |
| 297 | return; |
| 298 | } |
| 299 | |
| 300 | if (sessionTimeout) |
| 301 | { |
| 302 | // The mininum & maximum allowed values for session timeout are 30 |
| 303 | // seconds and 86400 seconds respectively as per the session service |
| 304 | // schema mentioned at |
| 305 | // https://redfish.dmtf.org/schemas/v1/SessionService.v1_1_7.json |
| 306 | |
| 307 | if (*sessionTimeout <= 86400 && *sessionTimeout >= 30) |
| 308 | { |
| 309 | std::chrono::seconds sessionTimeoutInseconds(*sessionTimeout); |
| 310 | persistent_data::SessionStore::getInstance() |
| 311 | .updateSessionTimeout(sessionTimeoutInseconds); |
| 312 | messages::propertyValueModified( |
| 313 | asyncResp->res, "SessionTimeOut", |
| 314 | std::to_string(*sessionTimeout)); |
| 315 | } |
| 316 | else |
| 317 | { |
| 318 | messages::propertyValueNotInList( |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 319 | asyncResp->res, std::to_string(*sessionTimeout), |
| 320 | "SessionTimeOut"); |
Manojkiran Eda | f2a4a60 | 2020-08-27 16:04:26 +0530 | [diff] [blame] | 321 | } |
| 322 | } |
| 323 | } |
Borawski.Lukasz | 5d27b85 | 2018-02-08 13:24:24 +0100 | [diff] [blame] | 324 | }; |
| 325 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 326 | } // namespace redfish |