xref: /openbmc/bmcweb/features/redfish/lib/redfish_sessions.hpp (revision ce22f6099e7e28ae26591348bf484ebedbc1ed42)
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 
18*ce22f609SPaul Fertser #include "account_service.hpp"
193ccb3adbSEd Tanous #include "app.hpp"
20f4c4dcf4SKowalski, Kamil #include "error_messages.hpp"
213ccb3adbSEd Tanous #include "http/utility.hpp"
2252cc112dSEd Tanous #include "persistent_data.hpp"
233ccb3adbSEd Tanous #include "query.hpp"
243ccb3adbSEd Tanous #include "registries/privilege_registry.hpp"
253ccb3adbSEd Tanous #include "utils/json_utils.hpp"
267e860f15SJohn Edward Broadbent 
27ef4c65b7SEd Tanous #include <boost/url/format.hpp>
28ef4c65b7SEd Tanous 
291abe55efSEd Tanous namespace redfish
301abe55efSEd Tanous {
312b7981f6SKowalski, Kamil 
324f48d5f6SEd Tanous inline void fillSessionObject(crow::Response& res,
33faa34ccfSEd Tanous                               const persistent_data::UserSession& session)
341abe55efSEd Tanous {
35faa34ccfSEd Tanous     res.jsonValue["Id"] = session.uniqueId;
36faa34ccfSEd Tanous     res.jsonValue["UserName"] = session.username;
37*ce22f609SPaul Fertser     nlohmann::json::array_t roles;
38*ce22f609SPaul Fertser     roles.emplace_back(redfish::getRoleIdFromPrivilege(session.userRole));
39*ce22f609SPaul Fertser     res.jsonValue["Roles"] = std::move(roles);
40ef4c65b7SEd Tanous     res.jsonValue["@odata.id"] = boost::urls::format(
41ef4c65b7SEd Tanous         "/redfish/v1/SessionService/Sessions/{}", session.uniqueId);
42*ce22f609SPaul Fertser     res.jsonValue["@odata.type"] = "#Session.v1_7_0.Session";
43faa34ccfSEd Tanous     res.jsonValue["Name"] = "User Session";
44faa34ccfSEd Tanous     res.jsonValue["Description"] = "Manager User Session";
45faa34ccfSEd Tanous     res.jsonValue["ClientOriginIPAddress"] = session.clientIp;
46bb759e3aSEd Tanous     if (session.clientId)
47bb759e3aSEd Tanous     {
48bb759e3aSEd Tanous         res.jsonValue["Context"] = *session.clientId;
49bb759e3aSEd Tanous     }
502b7981f6SKowalski, Kamil }
512b7981f6SKowalski, Kamil 
52724340d7SEd Tanous inline void
53a1e0871dSEd Tanous     handleSessionHead(crow::App& app, const crow::Request& req,
54faa34ccfSEd Tanous                       const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
55a1e0871dSEd Tanous                       const std::string& /*sessionId*/)
56724340d7SEd Tanous {
573ba00073SCarson Labrado     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
5845ca1b86SEd Tanous     {
5945ca1b86SEd Tanous         return;
6045ca1b86SEd Tanous     }
61a1e0871dSEd Tanous     asyncResp->res.addHeader(
62a1e0871dSEd Tanous         boost::beast::http::field::link,
63a1e0871dSEd Tanous         "</redfish/v1/JsonSchemas/Session/Session.json>; rel=describedby");
64a1e0871dSEd Tanous }
65a1e0871dSEd Tanous 
66a1e0871dSEd Tanous inline void
67a1e0871dSEd Tanous     handleSessionGet(crow::App& app, const crow::Request& req,
68a1e0871dSEd Tanous                      const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
69a1e0871dSEd Tanous                      const std::string& sessionId)
70a1e0871dSEd Tanous {
7165ffbcb3SEd Tanous     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
7265ffbcb3SEd Tanous     {
7365ffbcb3SEd Tanous         return;
7465ffbcb3SEd Tanous     }
7565ffbcb3SEd Tanous     asyncResp->res.addHeader(
7665ffbcb3SEd Tanous         boost::beast::http::field::link,
7765ffbcb3SEd Tanous         "</redfish/v1/JsonSchemas/Session/Session.json>; rel=describedby");
78a1e0871dSEd Tanous 
79faa34ccfSEd Tanous     // Note that control also reaches here via doPost and doDelete.
80724340d7SEd Tanous     auto session =
81724340d7SEd Tanous         persistent_data::SessionStore::getInstance().getSessionByUid(sessionId);
822b7981f6SKowalski, Kamil 
831abe55efSEd Tanous     if (session == nullptr)
841abe55efSEd Tanous     {
85724340d7SEd Tanous         messages::resourceNotFound(asyncResp->res, "Session", sessionId);
86faa34ccfSEd Tanous         return;
87faa34ccfSEd Tanous     }
88faa34ccfSEd Tanous 
89faa34ccfSEd Tanous     fillSessionObject(asyncResp->res, *session);
90724340d7SEd Tanous }
91faa34ccfSEd Tanous 
92724340d7SEd Tanous inline void
9345ca1b86SEd Tanous     handleSessionDelete(crow::App& app, const crow::Request& req,
94faa34ccfSEd Tanous                         const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
95724340d7SEd Tanous                         const std::string& sessionId)
96724340d7SEd Tanous {
973ba00073SCarson Labrado     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
9845ca1b86SEd Tanous     {
9945ca1b86SEd Tanous         return;
10045ca1b86SEd Tanous     }
101724340d7SEd Tanous     auto session =
102724340d7SEd Tanous         persistent_data::SessionStore::getInstance().getSessionByUid(sessionId);
103faa34ccfSEd Tanous 
104faa34ccfSEd Tanous     if (session == nullptr)
105faa34ccfSEd Tanous     {
106724340d7SEd Tanous         messages::resourceNotFound(asyncResp->res, "Session", sessionId);
1072b7981f6SKowalski, Kamil         return;
1082b7981f6SKowalski, Kamil     }
1092b7981f6SKowalski, Kamil 
110900f9497SJoseph Reynolds     // Perform a proper ConfigureSelf authority check.  If a
111900f9497SJoseph Reynolds     // session is being used to DELETE some other user's session,
112900f9497SJoseph Reynolds     // then the ConfigureSelf privilege does not apply.  In that
113900f9497SJoseph Reynolds     // case, perform the authority check again without the user's
114900f9497SJoseph Reynolds     // ConfigureSelf privilege.
1150fd29865Swukaihua-fii-na     if (req.session != nullptr && !session->username.empty() &&
1160fd29865Swukaihua-fii-na         session->username != req.session->username)
117900f9497SJoseph Reynolds     {
1186c51eab1SEd Tanous         Privileges effectiveUserPrivileges =
1193e72c202SNinad Palsule             redfish::getUserPrivileges(*req.session);
1206c51eab1SEd Tanous 
121724340d7SEd Tanous         if (!effectiveUserPrivileges.isSupersetOf({"ConfigureUsers"}))
122900f9497SJoseph Reynolds         {
1238d1b46d7Szhanghch05             messages::insufficientPrivilege(asyncResp->res);
124900f9497SJoseph Reynolds             return;
125900f9497SJoseph Reynolds         }
126900f9497SJoseph Reynolds     }
127900f9497SJoseph Reynolds 
128724340d7SEd Tanous     persistent_data::SessionStore::getInstance().removeSession(session);
1295cc148afSEd Tanous     messages::success(asyncResp->res);
130724340d7SEd Tanous }
131f4c4dcf4SKowalski, Kamil 
132724340d7SEd Tanous inline nlohmann::json getSessionCollectionMembers()
133724340d7SEd Tanous {
13455c7b7a2SEd Tanous     std::vector<const std::string*> sessionIds =
13552cc112dSEd Tanous         persistent_data::SessionStore::getInstance().getUniqueIds(
13652cc112dSEd Tanous             false, persistent_data::PersistenceType::TIMEOUT);
137724340d7SEd Tanous     nlohmann::json ret = nlohmann::json::array();
1381abe55efSEd Tanous     for (const std::string* uid : sessionIds)
1391abe55efSEd Tanous     {
1401476687dSEd Tanous         nlohmann::json::object_t session;
141ef4c65b7SEd Tanous         session["@odata.id"] =
142ef4c65b7SEd Tanous             boost::urls::format("/redfish/v1/SessionService/Sessions/{}", *uid);
143b2ba3072SPatrick Williams         ret.emplace_back(std::move(session));
1442b7981f6SKowalski, Kamil     }
145724340d7SEd Tanous     return ret;
146724340d7SEd Tanous }
147724340d7SEd Tanous 
148a1e0871dSEd Tanous inline void handleSessionCollectionHead(
14945ca1b86SEd Tanous     crow::App& app, const crow::Request& req,
150724340d7SEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
151724340d7SEd Tanous {
1523ba00073SCarson Labrado     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
15345ca1b86SEd Tanous     {
15445ca1b86SEd Tanous         return;
15545ca1b86SEd Tanous     }
156a1e0871dSEd Tanous     asyncResp->res.addHeader(
157a1e0871dSEd Tanous         boost::beast::http::field::link,
158a1e0871dSEd Tanous         "</redfish/v1/JsonSchemas/SessionCollection.json>; rel=describedby");
159a1e0871dSEd Tanous }
160a1e0871dSEd Tanous 
161a1e0871dSEd Tanous inline void handleSessionCollectionGet(
162a1e0871dSEd Tanous     crow::App& app, const crow::Request& req,
163a1e0871dSEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
164a1e0871dSEd Tanous {
16501a89a1fSEd Tanous     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
16601a89a1fSEd Tanous     {
16701a89a1fSEd Tanous         return;
16801a89a1fSEd Tanous     }
16901a89a1fSEd Tanous     asyncResp->res.addHeader(
17001a89a1fSEd Tanous         boost::beast::http::field::link,
17101a89a1fSEd Tanous         "</redfish/v1/JsonSchemas/SessionCollection.json>; rel=describedby");
17201a89a1fSEd Tanous 
173724340d7SEd Tanous     asyncResp->res.jsonValue["Members"] = getSessionCollectionMembers();
174faa34ccfSEd Tanous     asyncResp->res.jsonValue["Members@odata.count"] =
175724340d7SEd Tanous         asyncResp->res.jsonValue["Members"].size();
1768d1b46d7Szhanghch05     asyncResp->res.jsonValue["@odata.type"] =
1778d1b46d7Szhanghch05         "#SessionCollection.SessionCollection";
1788d1b46d7Szhanghch05     asyncResp->res.jsonValue["@odata.id"] =
1797a859ffeSGunnar Mills         "/redfish/v1/SessionService/Sessions";
1808d1b46d7Szhanghch05     asyncResp->res.jsonValue["Name"] = "Session Collection";
1818d1b46d7Szhanghch05     asyncResp->res.jsonValue["Description"] = "Session Collection";
182724340d7SEd Tanous }
1832b7981f6SKowalski, Kamil 
184724340d7SEd Tanous inline void handleSessionCollectionMembersGet(
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     }
192724340d7SEd Tanous     asyncResp->res.jsonValue = getSessionCollectionMembers();
193724340d7SEd Tanous }
194724340d7SEd Tanous 
1954ee8e211SEd Tanous inline void handleSessionCollectionPost(
19645ca1b86SEd Tanous     crow::App& app, const crow::Request& req,
197724340d7SEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
198724340d7SEd Tanous {
1993ba00073SCarson Labrado     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
20045ca1b86SEd Tanous     {
20145ca1b86SEd Tanous         return;
20245ca1b86SEd Tanous     }
2039712f8acSEd Tanous     std::string username;
2049712f8acSEd Tanous     std::string password;
205bb759e3aSEd Tanous     std::optional<std::string> clientId;
206724340d7SEd Tanous     if (!json_util::readJsonPatch(req, asyncResp->res, "UserName", username,
207d678d4fcSEd Tanous                                   "Password", password, "Context", clientId))
2081abe55efSEd Tanous     {
2092b7981f6SKowalski, Kamil         return;
2102b7981f6SKowalski, Kamil     }
2112b7981f6SKowalski, Kamil 
212820ce598SEd Tanous     if (password.empty() || username.empty() ||
2138d1b46d7Szhanghch05         asyncResp->res.result() != boost::beast::http::status::ok)
2141abe55efSEd Tanous     {
2151abe55efSEd Tanous         if (username.empty())
2161abe55efSEd Tanous         {
2178d1b46d7Szhanghch05             messages::propertyMissing(asyncResp->res, "UserName");
218f4c4dcf4SKowalski, Kamil         }
219f4c4dcf4SKowalski, Kamil 
2201abe55efSEd Tanous         if (password.empty())
2211abe55efSEd Tanous         {
2228d1b46d7Szhanghch05             messages::propertyMissing(asyncResp->res, "Password");
223820ce598SEd Tanous         }
224820ce598SEd Tanous 
225820ce598SEd Tanous         return;
226f4c4dcf4SKowalski, Kamil     }
2272b7981f6SKowalski, Kamil 
2283bf4e632SJoseph Reynolds     int pamrc = pamAuthenticateUser(username, password);
2293bf4e632SJoseph Reynolds     bool isConfigureSelfOnly = pamrc == PAM_NEW_AUTHTOK_REQD;
2303bf4e632SJoseph Reynolds     if ((pamrc != PAM_SUCCESS) && !isConfigureSelfOnly)
2311abe55efSEd Tanous     {
23239662a3bSEd Tanous         messages::resourceAtUriUnauthorized(asyncResp->res, req.url(),
233f12894f8SJason M. Bills                                             "Invalid username or password");
234820ce598SEd Tanous         return;
2352b7981f6SKowalski, Kamil     }
2366f115bbbSManojkiran Eda 
237820ce598SEd Tanous     // User is authenticated - create session
23852cc112dSEd Tanous     std::shared_ptr<persistent_data::UserSession> session =
239724340d7SEd Tanous         persistent_data::SessionStore::getInstance().generateUserSession(
24041d61c82SJiaqing Zhao             username, req.ipAddress, clientId,
241724340d7SEd Tanous             persistent_data::PersistenceType::TIMEOUT, isConfigureSelfOnly);
24202e53aefSBrad Bishop     if (session == nullptr)
24302e53aefSBrad Bishop     {
24402e53aefSBrad Bishop         messages::internalError(asyncResp->res);
24502e53aefSBrad Bishop         return;
24602e53aefSBrad Bishop     }
24702e53aefSBrad Bishop 
2488d1b46d7Szhanghch05     asyncResp->res.addHeader("X-Auth-Token", session->sessionToken);
249faa34ccfSEd Tanous     asyncResp->res.addHeader(
250724340d7SEd Tanous         "Location", "/redfish/v1/SessionService/Sessions/" + session->uniqueId);
2518d1b46d7Szhanghch05     asyncResp->res.result(boost::beast::http::status::created);
2523bf4e632SJoseph Reynolds     if (session->isConfigureSelfOnly)
2533bf4e632SJoseph Reynolds     {
2543bf4e632SJoseph Reynolds         messages::passwordChangeRequired(
255724340d7SEd Tanous             asyncResp->res,
256ef4c65b7SEd Tanous             boost::urls::format("/redfish/v1/AccountService/Accounts/{}",
257ef4c65b7SEd Tanous                                 session->username));
2582b7981f6SKowalski, Kamil     }
2592b7981f6SKowalski, Kamil 
260faa34ccfSEd Tanous     fillSessionObject(asyncResp->res, *session);
261724340d7SEd Tanous }
262a1e0871dSEd Tanous inline void handleSessionServiceHead(
263a1e0871dSEd Tanous     crow::App& app, const crow::Request& req,
264a1e0871dSEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
265a1e0871dSEd Tanous {
266a1e0871dSEd Tanous     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
267a1e0871dSEd Tanous     {
268a1e0871dSEd Tanous         return;
269a1e0871dSEd Tanous     }
270a1e0871dSEd Tanous     asyncResp->res.addHeader(
271a1e0871dSEd Tanous         boost::beast::http::field::link,
272a1e0871dSEd Tanous         "</redfish/v1/JsonSchemas/SessionService/SessionService.json>; rel=describedby");
273a1e0871dSEd Tanous }
274724340d7SEd Tanous inline void
27545ca1b86SEd Tanous     handleSessionServiceGet(crow::App& app, const crow::Request& req,
276724340d7SEd Tanous                             const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
2772b7981f6SKowalski, Kamil 
278724340d7SEd Tanous {
27978e3900fSGunnar Mills     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
28078e3900fSGunnar Mills     {
28178e3900fSGunnar Mills         return;
28278e3900fSGunnar Mills     }
28378e3900fSGunnar Mills     asyncResp->res.addHeader(
28478e3900fSGunnar Mills         boost::beast::http::field::link,
28578e3900fSGunnar Mills         "</redfish/v1/JsonSchemas/SessionService/SessionService.json>; rel=describedby");
28678e3900fSGunnar Mills 
2878d1b46d7Szhanghch05     asyncResp->res.jsonValue["@odata.type"] =
2888d1b46d7Szhanghch05         "#SessionService.v1_0_2.SessionService";
2897a859ffeSGunnar Mills     asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/SessionService";
2908d1b46d7Szhanghch05     asyncResp->res.jsonValue["Name"] = "Session Service";
2918d1b46d7Szhanghch05     asyncResp->res.jsonValue["Id"] = "SessionService";
2928d1b46d7Szhanghch05     asyncResp->res.jsonValue["Description"] = "Session Service";
2938d1b46d7Szhanghch05     asyncResp->res.jsonValue["SessionTimeout"] =
294724340d7SEd Tanous         persistent_data::SessionStore::getInstance().getTimeoutInSeconds();
2958d1b46d7Szhanghch05     asyncResp->res.jsonValue["ServiceEnabled"] = true;
2960f74e643SEd Tanous 
2971476687dSEd Tanous     asyncResp->res.jsonValue["Sessions"]["@odata.id"] =
2981476687dSEd Tanous         "/redfish/v1/SessionService/Sessions";
299724340d7SEd Tanous }
300f2a4a606SManojkiran Eda 
301724340d7SEd Tanous inline void handleSessionServicePatch(
30245ca1b86SEd Tanous     crow::App& app, const crow::Request& req,
303724340d7SEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
304724340d7SEd Tanous {
3053ba00073SCarson Labrado     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
30645ca1b86SEd Tanous     {
30745ca1b86SEd Tanous         return;
30845ca1b86SEd Tanous     }
309f2a4a606SManojkiran Eda     std::optional<int64_t> sessionTimeout;
310724340d7SEd Tanous     if (!json_util::readJsonPatch(req, asyncResp->res, "SessionTimeout",
311724340d7SEd Tanous                                   sessionTimeout))
312f2a4a606SManojkiran Eda     {
313f2a4a606SManojkiran Eda         return;
314f2a4a606SManojkiran Eda     }
315f2a4a606SManojkiran Eda 
316f2a4a606SManojkiran Eda     if (sessionTimeout)
317f2a4a606SManojkiran Eda     {
3188ece0e45SEd Tanous         // The minimum & maximum allowed values for session timeout
319faa34ccfSEd Tanous         // are 30 seconds and 86400 seconds respectively as per the
320faa34ccfSEd Tanous         // session service schema mentioned at
321f2a4a606SManojkiran Eda         // https://redfish.dmtf.org/schemas/v1/SessionService.v1_1_7.json
322f2a4a606SManojkiran Eda 
323f2a4a606SManojkiran Eda         if (*sessionTimeout <= 86400 && *sessionTimeout >= 30)
324f2a4a606SManojkiran Eda         {
325724340d7SEd Tanous             std::chrono::seconds sessionTimeoutInseconds(*sessionTimeout);
326724340d7SEd Tanous             persistent_data::SessionStore::getInstance().updateSessionTimeout(
327724340d7SEd Tanous                 sessionTimeoutInseconds);
328724340d7SEd Tanous             messages::propertyValueModified(asyncResp->res, "SessionTimeOut",
329f2a4a606SManojkiran Eda                                             std::to_string(*sessionTimeout));
330f2a4a606SManojkiran Eda         }
331f2a4a606SManojkiran Eda         else
332f2a4a606SManojkiran Eda         {
333e2616cc5SEd Tanous             messages::propertyValueNotInList(asyncResp->res, *sessionTimeout,
3348d1b46d7Szhanghch05                                              "SessionTimeOut");
335f2a4a606SManojkiran Eda         }
336f2a4a606SManojkiran Eda     }
337724340d7SEd Tanous }
338724340d7SEd Tanous 
339724340d7SEd Tanous inline void requestRoutesSession(App& app)
340724340d7SEd Tanous {
341724340d7SEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/SessionService/Sessions/<str>/")
342a1e0871dSEd Tanous         .privileges(redfish::privileges::headSession)
343a1e0871dSEd Tanous         .methods(boost::beast::http::verb::head)(
344a1e0871dSEd Tanous             std::bind_front(handleSessionHead, std::ref(app)));
345a1e0871dSEd Tanous 
346a1e0871dSEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/SessionService/Sessions/<str>/")
347724340d7SEd Tanous         .privileges(redfish::privileges::getSession)
34845ca1b86SEd Tanous         .methods(boost::beast::http::verb::get)(
34945ca1b86SEd Tanous             std::bind_front(handleSessionGet, std::ref(app)));
350724340d7SEd Tanous 
351724340d7SEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/SessionService/Sessions/<str>/")
352724340d7SEd Tanous         .privileges(redfish::privileges::deleteSession)
35345ca1b86SEd Tanous         .methods(boost::beast::http::verb::delete_)(
35445ca1b86SEd Tanous             std::bind_front(handleSessionDelete, std::ref(app)));
355724340d7SEd Tanous 
356724340d7SEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/SessionService/Sessions/")
357a1e0871dSEd Tanous         .privileges(redfish::privileges::headSessionCollection)
358a1e0871dSEd Tanous         .methods(boost::beast::http::verb::head)(
359a1e0871dSEd Tanous             std::bind_front(handleSessionCollectionHead, std::ref(app)));
360a1e0871dSEd Tanous 
361a1e0871dSEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/SessionService/Sessions/")
362724340d7SEd Tanous         .privileges(redfish::privileges::getSessionCollection)
36345ca1b86SEd Tanous         .methods(boost::beast::http::verb::get)(
36445ca1b86SEd Tanous             std::bind_front(handleSessionCollectionGet, std::ref(app)));
365724340d7SEd Tanous 
366e76cd868SEd Tanous     // Note, the next two routes technically don't match the privilege
367724340d7SEd Tanous     // registry given the way login mechanisms work.  The base privilege
368724340d7SEd Tanous     // registry lists this endpoint as requiring login privilege, but because
369724340d7SEd Tanous     // this is the endpoint responsible for giving the login privilege, and it
370724340d7SEd Tanous     // is itself its own route, it needs to not require Login
371724340d7SEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/SessionService/Sessions/")
372724340d7SEd Tanous         .privileges({})
37345ca1b86SEd Tanous         .methods(boost::beast::http::verb::post)(
37445ca1b86SEd Tanous             std::bind_front(handleSessionCollectionPost, std::ref(app)));
375724340d7SEd Tanous 
376e76cd868SEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/SessionService/Sessions/Members/")
377e76cd868SEd Tanous         .privileges({})
37845ca1b86SEd Tanous         .methods(boost::beast::http::verb::post)(
37945ca1b86SEd Tanous             std::bind_front(handleSessionCollectionPost, std::ref(app)));
380e76cd868SEd Tanous 
381724340d7SEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/SessionService/")
382a1e0871dSEd Tanous         .privileges(redfish::privileges::headSessionService)
383a1e0871dSEd Tanous         .methods(boost::beast::http::verb::head)(
384a1e0871dSEd Tanous             std::bind_front(handleSessionServiceHead, std::ref(app)));
385a1e0871dSEd Tanous 
386a1e0871dSEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/SessionService/")
387724340d7SEd Tanous         .privileges(redfish::privileges::getSessionService)
38845ca1b86SEd Tanous         .methods(boost::beast::http::verb::get)(
38945ca1b86SEd Tanous             std::bind_front(handleSessionServiceGet, std::ref(app)));
390724340d7SEd Tanous 
391724340d7SEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/SessionService/")
392724340d7SEd Tanous         .privileges(redfish::privileges::patchSessionService)
39345ca1b86SEd Tanous         .methods(boost::beast::http::verb::patch)(
39445ca1b86SEd Tanous             std::bind_front(handleSessionServicePatch, std::ref(app)));
395f2a4a606SManojkiran Eda }
3965d27b854SBorawski.Lukasz 
3972b7981f6SKowalski, Kamil } // namespace redfish
398