xref: /openbmc/bmcweb/features/redfish/lib/redfish_sessions.hpp (revision bb759e3aeaadfec9f3aac4485f253bcc8a523e4c)
12b7981f6SKowalski, Kamil /*
22b7981f6SKowalski, Kamil // Copyright (c) 2018 Intel Corporation
32b7981f6SKowalski, Kamil //
42b7981f6SKowalski, Kamil // Licensed under the Apache License, Version 2.0 (the "License");
52b7981f6SKowalski, Kamil // you may not use this file except in compliance with the License.
62b7981f6SKowalski, Kamil // You may obtain a copy of the License at
72b7981f6SKowalski, Kamil //
82b7981f6SKowalski, Kamil //      http://www.apache.org/licenses/LICENSE-2.0
92b7981f6SKowalski, Kamil //
102b7981f6SKowalski, Kamil // Unless required by applicable law or agreed to in writing, software
112b7981f6SKowalski, Kamil // distributed under the License is distributed on an "AS IS" BASIS,
122b7981f6SKowalski, Kamil // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
132b7981f6SKowalski, Kamil // See the License for the specific language governing permissions and
142b7981f6SKowalski, Kamil // limitations under the License.
152b7981f6SKowalski, Kamil */
162b7981f6SKowalski, Kamil #pragma once
1743a095abSBorawski.Lukasz 
18f4c4dcf4SKowalski, Kamil #include "error_messages.hpp"
1952cc112dSEd Tanous #include "persistent_data.hpp"
202b7981f6SKowalski, Kamil 
217e860f15SJohn Edward Broadbent #include <app.hpp>
22ace85d60SEd Tanous #include <http/utility.hpp>
2345ca1b86SEd Tanous #include <query.hpp>
24ed398213SEd Tanous #include <registries/privilege_registry.hpp>
25840098bfSEd Tanous #include <utils/json_utils.hpp>
267e860f15SJohn Edward Broadbent 
271abe55efSEd Tanous namespace redfish
281abe55efSEd Tanous {
292b7981f6SKowalski, Kamil 
304f48d5f6SEd Tanous inline void fillSessionObject(crow::Response& res,
31faa34ccfSEd Tanous                               const persistent_data::UserSession& session)
321abe55efSEd Tanous {
33faa34ccfSEd Tanous     res.jsonValue["Id"] = session.uniqueId;
34faa34ccfSEd Tanous     res.jsonValue["UserName"] = session.username;
35faa34ccfSEd Tanous     res.jsonValue["@odata.id"] =
36faa34ccfSEd Tanous         "/redfish/v1/SessionService/Sessions/" + session.uniqueId;
37*bb759e3aSEd Tanous     res.jsonValue["@odata.type"] = "#Session.v1_5_0.Session";
38faa34ccfSEd Tanous     res.jsonValue["Name"] = "User Session";
39faa34ccfSEd Tanous     res.jsonValue["Description"] = "Manager User Session";
40faa34ccfSEd Tanous     res.jsonValue["ClientOriginIPAddress"] = session.clientIp;
41*bb759e3aSEd Tanous     if (session.clientId)
42*bb759e3aSEd Tanous     {
43*bb759e3aSEd Tanous         res.jsonValue["Context"] = *session.clientId;
44*bb759e3aSEd Tanous     }
45*bb759e3aSEd Tanous // The below implementation is deprecated in leiu of Session.Context
46c0ea7ae1SSunitha Harish #ifdef BMCWEB_ENABLE_IBM_MANAGEMENT_CONSOLE
47faa34ccfSEd Tanous     res.jsonValue["Oem"]["OpenBMC"]["@odata.type"] =
4808bdcc71SSunitha Harish         "#OemSession.v1_0_0.Session";
49*bb759e3aSEd Tanous     res.jsonValue["Oem"]["OpenBMC"]["ClientID"] = session.clientId.value_or("");
5008bdcc71SSunitha Harish #endif
512b7981f6SKowalski, Kamil }
522b7981f6SKowalski, Kamil 
53724340d7SEd Tanous inline void
54a1e0871dSEd Tanous     handleSessionHead(crow::App& app, const crow::Request& req,
55faa34ccfSEd Tanous                       const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
56a1e0871dSEd Tanous                       const std::string& /*sessionId*/)
57724340d7SEd Tanous {
58a1e0871dSEd Tanous 
593ba00073SCarson Labrado     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
6045ca1b86SEd Tanous     {
6145ca1b86SEd Tanous         return;
6245ca1b86SEd Tanous     }
63a1e0871dSEd Tanous     asyncResp->res.addHeader(
64a1e0871dSEd Tanous         boost::beast::http::field::link,
65a1e0871dSEd Tanous         "</redfish/v1/JsonSchemas/Session/Session.json>; rel=describedby");
66a1e0871dSEd Tanous }
67a1e0871dSEd Tanous 
68a1e0871dSEd Tanous inline void
69a1e0871dSEd Tanous     handleSessionGet(crow::App& app, const crow::Request& req,
70a1e0871dSEd Tanous                      const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
71a1e0871dSEd Tanous                      const std::string& sessionId)
72a1e0871dSEd Tanous {
73a1e0871dSEd Tanous     handleSessionHead(app, req, asyncResp, sessionId);
74a1e0871dSEd Tanous 
75faa34ccfSEd Tanous     // Note that control also reaches here via doPost and doDelete.
76724340d7SEd Tanous     auto session =
77724340d7SEd Tanous         persistent_data::SessionStore::getInstance().getSessionByUid(sessionId);
782b7981f6SKowalski, Kamil 
791abe55efSEd Tanous     if (session == nullptr)
801abe55efSEd Tanous     {
81724340d7SEd Tanous         messages::resourceNotFound(asyncResp->res, "Session", sessionId);
82faa34ccfSEd Tanous         return;
83faa34ccfSEd Tanous     }
84faa34ccfSEd Tanous 
85faa34ccfSEd Tanous     fillSessionObject(asyncResp->res, *session);
86724340d7SEd Tanous }
87faa34ccfSEd Tanous 
88724340d7SEd Tanous inline void
8945ca1b86SEd Tanous     handleSessionDelete(crow::App& app, const crow::Request& req,
90faa34ccfSEd Tanous                         const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
91724340d7SEd Tanous                         const std::string& sessionId)
92724340d7SEd Tanous {
933ba00073SCarson Labrado     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
9445ca1b86SEd Tanous     {
9545ca1b86SEd Tanous         return;
9645ca1b86SEd Tanous     }
97724340d7SEd Tanous     auto session =
98724340d7SEd Tanous         persistent_data::SessionStore::getInstance().getSessionByUid(sessionId);
99faa34ccfSEd Tanous 
100faa34ccfSEd Tanous     if (session == nullptr)
101faa34ccfSEd Tanous     {
102724340d7SEd Tanous         messages::resourceNotFound(asyncResp->res, "Session", sessionId);
1032b7981f6SKowalski, Kamil         return;
1042b7981f6SKowalski, Kamil     }
1052b7981f6SKowalski, Kamil 
106900f9497SJoseph Reynolds     // Perform a proper ConfigureSelf authority check.  If a
107900f9497SJoseph Reynolds     // session is being used to DELETE some other user's session,
108900f9497SJoseph Reynolds     // then the ConfigureSelf privilege does not apply.  In that
109900f9497SJoseph Reynolds     // case, perform the authority check again without the user's
110900f9497SJoseph Reynolds     // ConfigureSelf privilege.
1110fd29865Swukaihua-fii-na     if (req.session != nullptr && !session->username.empty() &&
1120fd29865Swukaihua-fii-na         session->username != req.session->username)
113900f9497SJoseph Reynolds     {
1146c51eab1SEd Tanous         Privileges effectiveUserPrivileges =
1156c51eab1SEd Tanous             redfish::getUserPrivileges(req.userRole);
1166c51eab1SEd Tanous 
117724340d7SEd Tanous         if (!effectiveUserPrivileges.isSupersetOf({"ConfigureUsers"}))
118900f9497SJoseph Reynolds         {
1198d1b46d7Szhanghch05             messages::insufficientPrivilege(asyncResp->res);
120900f9497SJoseph Reynolds             return;
121900f9497SJoseph Reynolds         }
122900f9497SJoseph Reynolds     }
123900f9497SJoseph Reynolds 
124724340d7SEd Tanous     persistent_data::SessionStore::getInstance().removeSession(session);
1255cc148afSEd Tanous     messages::success(asyncResp->res);
126724340d7SEd Tanous }
127f4c4dcf4SKowalski, Kamil 
128724340d7SEd Tanous inline nlohmann::json getSessionCollectionMembers()
129724340d7SEd Tanous {
13055c7b7a2SEd Tanous     std::vector<const std::string*> sessionIds =
13152cc112dSEd Tanous         persistent_data::SessionStore::getInstance().getUniqueIds(
13252cc112dSEd Tanous             false, persistent_data::PersistenceType::TIMEOUT);
133724340d7SEd Tanous     nlohmann::json ret = nlohmann::json::array();
1341abe55efSEd Tanous     for (const std::string* uid : sessionIds)
1351abe55efSEd Tanous     {
1361476687dSEd Tanous         nlohmann::json::object_t session;
1371476687dSEd Tanous         session["@odata.id"] = "/redfish/v1/SessionService/Sessions/" + *uid;
1381476687dSEd Tanous         ret.push_back(std::move(session));
1392b7981f6SKowalski, Kamil     }
140724340d7SEd Tanous     return ret;
141724340d7SEd Tanous }
142724340d7SEd Tanous 
143a1e0871dSEd Tanous inline void handleSessionCollectionHead(
14445ca1b86SEd Tanous     crow::App& app, const crow::Request& req,
145724340d7SEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
146724340d7SEd Tanous {
147a1e0871dSEd Tanous 
1483ba00073SCarson Labrado     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
14945ca1b86SEd Tanous     {
15045ca1b86SEd Tanous         return;
15145ca1b86SEd Tanous     }
152a1e0871dSEd Tanous     asyncResp->res.addHeader(
153a1e0871dSEd Tanous         boost::beast::http::field::link,
154a1e0871dSEd Tanous         "</redfish/v1/JsonSchemas/SessionCollection.json>; rel=describedby");
155a1e0871dSEd Tanous }
156a1e0871dSEd Tanous 
157a1e0871dSEd Tanous inline void handleSessionCollectionGet(
158a1e0871dSEd Tanous     crow::App& app, const crow::Request& req,
159a1e0871dSEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
160a1e0871dSEd Tanous {
161a1e0871dSEd Tanous     handleSessionCollectionHead(app, req, asyncResp);
162724340d7SEd Tanous     asyncResp->res.jsonValue["Members"] = getSessionCollectionMembers();
163faa34ccfSEd Tanous     asyncResp->res.jsonValue["Members@odata.count"] =
164724340d7SEd Tanous         asyncResp->res.jsonValue["Members"].size();
1658d1b46d7Szhanghch05     asyncResp->res.jsonValue["@odata.type"] =
1668d1b46d7Szhanghch05         "#SessionCollection.SessionCollection";
1678d1b46d7Szhanghch05     asyncResp->res.jsonValue["@odata.id"] =
1688d1b46d7Szhanghch05         "/redfish/v1/SessionService/Sessions/";
1698d1b46d7Szhanghch05     asyncResp->res.jsonValue["Name"] = "Session Collection";
1708d1b46d7Szhanghch05     asyncResp->res.jsonValue["Description"] = "Session Collection";
171724340d7SEd Tanous }
1722b7981f6SKowalski, Kamil 
173724340d7SEd Tanous inline void handleSessionCollectionMembersGet(
17445ca1b86SEd Tanous     crow::App& app, const crow::Request& req,
175724340d7SEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
176724340d7SEd Tanous {
1773ba00073SCarson Labrado     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
17845ca1b86SEd Tanous     {
17945ca1b86SEd Tanous         return;
18045ca1b86SEd Tanous     }
181724340d7SEd Tanous     asyncResp->res.jsonValue = getSessionCollectionMembers();
182724340d7SEd Tanous }
183724340d7SEd Tanous 
1844ee8e211SEd Tanous inline void handleSessionCollectionPost(
18545ca1b86SEd Tanous     crow::App& app, const crow::Request& req,
186724340d7SEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
187724340d7SEd Tanous {
1883ba00073SCarson Labrado     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
18945ca1b86SEd Tanous     {
19045ca1b86SEd Tanous         return;
19145ca1b86SEd Tanous     }
1929712f8acSEd Tanous     std::string username;
1939712f8acSEd Tanous     std::string password;
19408bdcc71SSunitha Harish     std::optional<nlohmann::json> oemObject;
195*bb759e3aSEd Tanous     std::optional<std::string> clientId;
196724340d7SEd Tanous     if (!json_util::readJsonPatch(req, asyncResp->res, "UserName", username,
197*bb759e3aSEd Tanous                                   "Password", password, "Context", clientId,
198*bb759e3aSEd Tanous                                   "Oem", oemObject))
1991abe55efSEd Tanous     {
2002b7981f6SKowalski, Kamil         return;
2012b7981f6SKowalski, Kamil     }
2022b7981f6SKowalski, Kamil 
203820ce598SEd Tanous     if (password.empty() || username.empty() ||
2048d1b46d7Szhanghch05         asyncResp->res.result() != boost::beast::http::status::ok)
2051abe55efSEd Tanous     {
2061abe55efSEd Tanous         if (username.empty())
2071abe55efSEd Tanous         {
2088d1b46d7Szhanghch05             messages::propertyMissing(asyncResp->res, "UserName");
209f4c4dcf4SKowalski, Kamil         }
210f4c4dcf4SKowalski, Kamil 
2111abe55efSEd Tanous         if (password.empty())
2121abe55efSEd Tanous         {
2138d1b46d7Szhanghch05             messages::propertyMissing(asyncResp->res, "Password");
214820ce598SEd Tanous         }
215820ce598SEd Tanous 
216820ce598SEd Tanous         return;
217f4c4dcf4SKowalski, Kamil     }
2182b7981f6SKowalski, Kamil 
2193bf4e632SJoseph Reynolds     int pamrc = pamAuthenticateUser(username, password);
2203bf4e632SJoseph Reynolds     bool isConfigureSelfOnly = pamrc == PAM_NEW_AUTHTOK_REQD;
2213bf4e632SJoseph Reynolds     if ((pamrc != PAM_SUCCESS) && !isConfigureSelfOnly)
2221abe55efSEd Tanous     {
223724340d7SEd Tanous         messages::resourceAtUriUnauthorized(asyncResp->res, req.urlView,
224f12894f8SJason M. Bills                                             "Invalid username or password");
225820ce598SEd Tanous         return;
2262b7981f6SKowalski, Kamil     }
22708bdcc71SSunitha Harish #ifdef BMCWEB_ENABLE_IBM_MANAGEMENT_CONSOLE
22808bdcc71SSunitha Harish     if (oemObject)
22908bdcc71SSunitha Harish     {
23008bdcc71SSunitha Harish         std::optional<nlohmann::json> bmcOem;
231724340d7SEd Tanous         if (!json_util::readJson(*oemObject, asyncResp->res, "OpenBMC", bmcOem))
23208bdcc71SSunitha Harish         {
23308bdcc71SSunitha Harish             return;
23408bdcc71SSunitha Harish         }
235*bb759e3aSEd Tanous 
236*bb759e3aSEd Tanous         std::optional<std::string> oemClientId;
237*bb759e3aSEd Tanous         if (!json_util::readJson(*bmcOem, asyncResp->res, "ClientID",
238*bb759e3aSEd Tanous                                  oemClientId))
23908bdcc71SSunitha Harish         {
24008bdcc71SSunitha Harish             BMCWEB_LOG_ERROR << "Could not read ClientId";
24108bdcc71SSunitha Harish             return;
24208bdcc71SSunitha Harish         }
243*bb759e3aSEd Tanous         if (oemClientId)
244*bb759e3aSEd Tanous         {
245*bb759e3aSEd Tanous             if (clientId)
246*bb759e3aSEd Tanous             {
247*bb759e3aSEd Tanous                 messages::propertyValueConflict(*oemClientId, *clientId);
248*bb759e3aSEd Tanous                 return;
249*bb759e3aSEd Tanous             }
250*bb759e3aSEd Tanous             clientId = *oemClientId;
251*bb759e3aSEd Tanous         }
25208bdcc71SSunitha Harish     }
25308bdcc71SSunitha Harish #endif
2546f115bbbSManojkiran Eda 
255820ce598SEd Tanous     // User is authenticated - create session
25652cc112dSEd Tanous     std::shared_ptr<persistent_data::UserSession> session =
257724340d7SEd Tanous         persistent_data::SessionStore::getInstance().generateUserSession(
25841d61c82SJiaqing Zhao             username, req.ipAddress, clientId,
259724340d7SEd Tanous             persistent_data::PersistenceType::TIMEOUT, isConfigureSelfOnly);
26002e53aefSBrad Bishop     if (session == nullptr)
26102e53aefSBrad Bishop     {
26202e53aefSBrad Bishop         messages::internalError(asyncResp->res);
26302e53aefSBrad Bishop         return;
26402e53aefSBrad Bishop     }
26502e53aefSBrad Bishop 
2668d1b46d7Szhanghch05     asyncResp->res.addHeader("X-Auth-Token", session->sessionToken);
267faa34ccfSEd Tanous     asyncResp->res.addHeader(
268724340d7SEd Tanous         "Location", "/redfish/v1/SessionService/Sessions/" + session->uniqueId);
2698d1b46d7Szhanghch05     asyncResp->res.result(boost::beast::http::status::created);
2703bf4e632SJoseph Reynolds     if (session->isConfigureSelfOnly)
2713bf4e632SJoseph Reynolds     {
2723bf4e632SJoseph Reynolds         messages::passwordChangeRequired(
273724340d7SEd Tanous             asyncResp->res,
274724340d7SEd Tanous             crow::utility::urlFromPieces("redfish", "v1", "AccountService",
27585e6471bSBrad Bishop                                          "Accounts", session->username));
2762b7981f6SKowalski, Kamil     }
2772b7981f6SKowalski, Kamil 
278faa34ccfSEd Tanous     fillSessionObject(asyncResp->res, *session);
279724340d7SEd Tanous }
280a1e0871dSEd Tanous inline void handleSessionServiceHead(
281a1e0871dSEd Tanous     crow::App& app, const crow::Request& req,
282a1e0871dSEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
283a1e0871dSEd Tanous {
284a1e0871dSEd Tanous 
285a1e0871dSEd Tanous     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
286a1e0871dSEd Tanous     {
287a1e0871dSEd Tanous         return;
288a1e0871dSEd Tanous     }
289a1e0871dSEd Tanous     asyncResp->res.addHeader(
290a1e0871dSEd Tanous         boost::beast::http::field::link,
291a1e0871dSEd Tanous         "</redfish/v1/JsonSchemas/SessionService/SessionService.json>; rel=describedby");
292a1e0871dSEd Tanous }
293724340d7SEd Tanous inline void
29445ca1b86SEd Tanous     handleSessionServiceGet(crow::App& app, const crow::Request& req,
295724340d7SEd Tanous                             const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
2962b7981f6SKowalski, Kamil 
297724340d7SEd Tanous {
298a1e0871dSEd Tanous     handleSessionServiceHead(app, req, asyncResp);
2998d1b46d7Szhanghch05     asyncResp->res.jsonValue["@odata.type"] =
3008d1b46d7Szhanghch05         "#SessionService.v1_0_2.SessionService";
301724340d7SEd Tanous     asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/SessionService/";
3028d1b46d7Szhanghch05     asyncResp->res.jsonValue["Name"] = "Session Service";
3038d1b46d7Szhanghch05     asyncResp->res.jsonValue["Id"] = "SessionService";
3048d1b46d7Szhanghch05     asyncResp->res.jsonValue["Description"] = "Session Service";
3058d1b46d7Szhanghch05     asyncResp->res.jsonValue["SessionTimeout"] =
306724340d7SEd Tanous         persistent_data::SessionStore::getInstance().getTimeoutInSeconds();
3078d1b46d7Szhanghch05     asyncResp->res.jsonValue["ServiceEnabled"] = true;
3080f74e643SEd Tanous 
3091476687dSEd Tanous     asyncResp->res.jsonValue["Sessions"]["@odata.id"] =
3101476687dSEd Tanous         "/redfish/v1/SessionService/Sessions";
311724340d7SEd Tanous }
312f2a4a606SManojkiran Eda 
313724340d7SEd Tanous inline void handleSessionServicePatch(
31445ca1b86SEd Tanous     crow::App& app, const crow::Request& req,
315724340d7SEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
316724340d7SEd Tanous {
3173ba00073SCarson Labrado     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
31845ca1b86SEd Tanous     {
31945ca1b86SEd Tanous         return;
32045ca1b86SEd Tanous     }
321f2a4a606SManojkiran Eda     std::optional<int64_t> sessionTimeout;
322724340d7SEd Tanous     if (!json_util::readJsonPatch(req, asyncResp->res, "SessionTimeout",
323724340d7SEd Tanous                                   sessionTimeout))
324f2a4a606SManojkiran Eda     {
325f2a4a606SManojkiran Eda         return;
326f2a4a606SManojkiran Eda     }
327f2a4a606SManojkiran Eda 
328f2a4a606SManojkiran Eda     if (sessionTimeout)
329f2a4a606SManojkiran Eda     {
330faa34ccfSEd Tanous         // The mininum & maximum allowed values for session timeout
331faa34ccfSEd Tanous         // are 30 seconds and 86400 seconds respectively as per the
332faa34ccfSEd Tanous         // session service schema mentioned at
333f2a4a606SManojkiran Eda         // https://redfish.dmtf.org/schemas/v1/SessionService.v1_1_7.json
334f2a4a606SManojkiran Eda 
335f2a4a606SManojkiran Eda         if (*sessionTimeout <= 86400 && *sessionTimeout >= 30)
336f2a4a606SManojkiran Eda         {
337724340d7SEd Tanous             std::chrono::seconds sessionTimeoutInseconds(*sessionTimeout);
338724340d7SEd Tanous             persistent_data::SessionStore::getInstance().updateSessionTimeout(
339724340d7SEd Tanous                 sessionTimeoutInseconds);
340724340d7SEd Tanous             messages::propertyValueModified(asyncResp->res, "SessionTimeOut",
341f2a4a606SManojkiran Eda                                             std::to_string(*sessionTimeout));
342f2a4a606SManojkiran Eda         }
343f2a4a606SManojkiran Eda         else
344f2a4a606SManojkiran Eda         {
345724340d7SEd Tanous             messages::propertyValueNotInList(asyncResp->res,
346724340d7SEd Tanous                                              std::to_string(*sessionTimeout),
3478d1b46d7Szhanghch05                                              "SessionTimeOut");
348f2a4a606SManojkiran Eda         }
349f2a4a606SManojkiran Eda     }
350724340d7SEd Tanous }
351724340d7SEd Tanous 
352724340d7SEd Tanous inline void requestRoutesSession(App& app)
353724340d7SEd Tanous {
354724340d7SEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/SessionService/Sessions/<str>/")
355a1e0871dSEd Tanous         .privileges(redfish::privileges::headSession)
356a1e0871dSEd Tanous         .methods(boost::beast::http::verb::head)(
357a1e0871dSEd Tanous             std::bind_front(handleSessionHead, std::ref(app)));
358a1e0871dSEd Tanous 
359a1e0871dSEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/SessionService/Sessions/<str>/")
360724340d7SEd Tanous         .privileges(redfish::privileges::getSession)
36145ca1b86SEd Tanous         .methods(boost::beast::http::verb::get)(
36245ca1b86SEd Tanous             std::bind_front(handleSessionGet, std::ref(app)));
363724340d7SEd Tanous 
364724340d7SEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/SessionService/Sessions/<str>/")
365724340d7SEd Tanous         .privileges(redfish::privileges::deleteSession)
36645ca1b86SEd Tanous         .methods(boost::beast::http::verb::delete_)(
36745ca1b86SEd Tanous             std::bind_front(handleSessionDelete, std::ref(app)));
368724340d7SEd Tanous 
369724340d7SEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/SessionService/Sessions/")
370a1e0871dSEd Tanous         .privileges(redfish::privileges::headSessionCollection)
371a1e0871dSEd Tanous         .methods(boost::beast::http::verb::head)(
372a1e0871dSEd Tanous             std::bind_front(handleSessionCollectionHead, std::ref(app)));
373a1e0871dSEd Tanous 
374a1e0871dSEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/SessionService/Sessions/")
375724340d7SEd Tanous         .privileges(redfish::privileges::getSessionCollection)
37645ca1b86SEd Tanous         .methods(boost::beast::http::verb::get)(
37745ca1b86SEd Tanous             std::bind_front(handleSessionCollectionGet, std::ref(app)));
378724340d7SEd Tanous 
379e76cd868SEd Tanous     // Note, the next two routes technically don't match the privilege
380724340d7SEd Tanous     // registry given the way login mechanisms work.  The base privilege
381724340d7SEd Tanous     // registry lists this endpoint as requiring login privilege, but because
382724340d7SEd Tanous     // this is the endpoint responsible for giving the login privilege, and it
383724340d7SEd Tanous     // is itself its own route, it needs to not require Login
384724340d7SEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/SessionService/Sessions/")
385724340d7SEd Tanous         .privileges({})
38645ca1b86SEd Tanous         .methods(boost::beast::http::verb::post)(
38745ca1b86SEd Tanous             std::bind_front(handleSessionCollectionPost, std::ref(app)));
388724340d7SEd Tanous 
389e76cd868SEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/SessionService/Sessions/Members/")
390e76cd868SEd Tanous         .privileges({})
39145ca1b86SEd Tanous         .methods(boost::beast::http::verb::post)(
39245ca1b86SEd Tanous             std::bind_front(handleSessionCollectionPost, std::ref(app)));
393e76cd868SEd Tanous 
394724340d7SEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/SessionService/")
395a1e0871dSEd Tanous         .privileges(redfish::privileges::headSessionService)
396a1e0871dSEd Tanous         .methods(boost::beast::http::verb::head)(
397a1e0871dSEd Tanous             std::bind_front(handleSessionServiceHead, std::ref(app)));
398a1e0871dSEd Tanous 
399a1e0871dSEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/SessionService/")
400724340d7SEd Tanous         .privileges(redfish::privileges::getSessionService)
40145ca1b86SEd Tanous         .methods(boost::beast::http::verb::get)(
40245ca1b86SEd Tanous             std::bind_front(handleSessionServiceGet, std::ref(app)));
403724340d7SEd Tanous 
404724340d7SEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/SessionService/")
405724340d7SEd Tanous         .privileges(redfish::privileges::patchSessionService)
40645ca1b86SEd Tanous         .methods(boost::beast::http::verb::patch)(
40745ca1b86SEd Tanous             std::bind_front(handleSessionServicePatch, std::ref(app)));
408f2a4a606SManojkiran Eda }
4095d27b854SBorawski.Lukasz 
4102b7981f6SKowalski, Kamil } // namespace redfish
411