James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 3 | #include "forward_unauthorized.hpp" |
| 4 | #include "http_request.hpp" |
| 5 | #include "http_response.hpp" |
| 6 | #include "http_utility.hpp" |
| 7 | #include "pam_authenticate.hpp" |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 8 | #include "webroutes.hpp" |
| 9 | |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 10 | #include <boost/container/flat_set.hpp> |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 11 | |
| 12 | #include <random> |
Ed Tanous | b5a7693 | 2020-09-29 16:16:58 -0700 | [diff] [blame] | 13 | #include <utility> |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 14 | |
| 15 | namespace crow |
| 16 | { |
| 17 | |
Nan Zhou | d055a34 | 2022-05-25 01:15:34 +0000 | [diff] [blame] | 18 | namespace authentication |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 19 | { |
| 20 | |
Ed Tanous | b1d736f | 2023-02-10 12:24:00 -0800 | [diff] [blame] | 21 | inline void cleanupTempSession(const Request& req) |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 22 | { |
| 23 | // TODO(ed) THis should really be handled by the persistent data |
| 24 | // middleware, but because it is upstream, it doesn't have access to the |
| 25 | // session information. Should the data middleware persist the current |
| 26 | // user session? |
| 27 | if (req.session != nullptr && |
| 28 | req.session->persistence == |
Ed Tanous | 52cc112 | 2020-07-18 13:51:21 -0700 | [diff] [blame] | 29 | persistent_data::PersistenceType::SINGLE_REQUEST) |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 30 | { |
| 31 | persistent_data::SessionStore::getInstance().removeSession(req.session); |
| 32 | } |
| 33 | } |
| 34 | |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 35 | inline std::shared_ptr<persistent_data::UserSession> |
Sunitha Harish | c0ea7ae | 2020-10-30 02:37:30 -0500 | [diff] [blame] | 36 | performBasicAuth(const boost::asio::ip::address& clientIp, |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 37 | std::string_view authHeader) |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 38 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 39 | BMCWEB_LOG_DEBUG("[AuthMiddleware] Basic authentication"); |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 40 | |
Ed Tanous | 11ba397 | 2022-07-11 09:50:41 -0700 | [diff] [blame] | 41 | if (!authHeader.starts_with("Basic ")) |
John Edward Broadbent | 97a056a | 2021-09-10 14:56:19 -0700 | [diff] [blame] | 42 | { |
| 43 | return nullptr; |
| 44 | } |
| 45 | |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 46 | std::string_view param = authHeader.substr(strlen("Basic ")); |
John Edward Broadbent | 97a056a | 2021-09-10 14:56:19 -0700 | [diff] [blame] | 47 | std::string authData; |
| 48 | |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 49 | if (!crow::utility::base64Decode(param, authData)) |
| 50 | { |
| 51 | return nullptr; |
| 52 | } |
| 53 | std::size_t separator = authData.find(':'); |
| 54 | if (separator == std::string::npos) |
| 55 | { |
| 56 | return nullptr; |
| 57 | } |
| 58 | |
| 59 | std::string user = authData.substr(0, separator); |
| 60 | separator += 1; |
| 61 | if (separator > authData.size()) |
| 62 | { |
| 63 | return nullptr; |
| 64 | } |
| 65 | std::string pass = authData.substr(separator); |
| 66 | |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 67 | BMCWEB_LOG_DEBUG("[AuthMiddleware] Authenticating user: {}", user); |
| 68 | BMCWEB_LOG_DEBUG("[AuthMiddleware] User IPAddress: {}", |
| 69 | clientIp.to_string()); |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 70 | |
| 71 | int pamrc = pamAuthenticateUser(user, pass); |
| 72 | bool isConfigureSelfOnly = pamrc == PAM_NEW_AUTHTOK_REQD; |
| 73 | if ((pamrc != PAM_SUCCESS) && !isConfigureSelfOnly) |
| 74 | { |
| 75 | return nullptr; |
| 76 | } |
| 77 | |
| 78 | // TODO(ed) generateUserSession is a little expensive for basic |
| 79 | // auth, as it generates some random identifiers that will never be |
| 80 | // used. This should have a "fast" path for when user tokens aren't |
| 81 | // needed. |
| 82 | // This whole flow needs to be revisited anyway, as we can't be |
| 83 | // calling directly into pam for every request |
| 84 | return persistent_data::SessionStore::getInstance().generateUserSession( |
Ed Tanous | bb759e3 | 2022-08-02 17:07:54 -0700 | [diff] [blame] | 85 | user, clientIp, std::nullopt, |
Sunitha Harish | d323922 | 2021-02-24 15:33:29 +0530 | [diff] [blame] | 86 | persistent_data::PersistenceType::SINGLE_REQUEST, isConfigureSelfOnly); |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 87 | } |
| 88 | |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 89 | inline std::shared_ptr<persistent_data::UserSession> |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 90 | performTokenAuth(std::string_view authHeader) |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 91 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 92 | BMCWEB_LOG_DEBUG("[AuthMiddleware] Token authentication"); |
Ed Tanous | 11ba397 | 2022-07-11 09:50:41 -0700 | [diff] [blame] | 93 | if (!authHeader.starts_with("Token ")) |
John Edward Broadbent | 97a056a | 2021-09-10 14:56:19 -0700 | [diff] [blame] | 94 | { |
| 95 | return nullptr; |
| 96 | } |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 97 | std::string_view token = authHeader.substr(strlen("Token ")); |
John Edward Broadbent | 59b98b2 | 2021-07-13 15:36:32 -0700 | [diff] [blame] | 98 | auto sessionOut = |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 99 | persistent_data::SessionStore::getInstance().loginSessionByToken(token); |
John Edward Broadbent | 59b98b2 | 2021-07-13 15:36:32 -0700 | [diff] [blame] | 100 | return sessionOut; |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 101 | } |
| 102 | |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 103 | inline std::shared_ptr<persistent_data::UserSession> |
John Edward Broadbent | 59b98b2 | 2021-07-13 15:36:32 -0700 | [diff] [blame] | 104 | performXtokenAuth(const boost::beast::http::header<true>& reqHeader) |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 105 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 106 | BMCWEB_LOG_DEBUG("[AuthMiddleware] X-Auth-Token authentication"); |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 107 | |
John Edward Broadbent | 59b98b2 | 2021-07-13 15:36:32 -0700 | [diff] [blame] | 108 | std::string_view token = reqHeader["X-Auth-Token"]; |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 109 | if (token.empty()) |
| 110 | { |
| 111 | return nullptr; |
| 112 | } |
John Edward Broadbent | 59b98b2 | 2021-07-13 15:36:32 -0700 | [diff] [blame] | 113 | auto sessionOut = |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 114 | persistent_data::SessionStore::getInstance().loginSessionByToken(token); |
John Edward Broadbent | 59b98b2 | 2021-07-13 15:36:32 -0700 | [diff] [blame] | 115 | return sessionOut; |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 116 | } |
| 117 | |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 118 | inline std::shared_ptr<persistent_data::UserSession> |
Ed Tanous | 1d86960 | 2022-12-19 13:48:12 -0800 | [diff] [blame] | 119 | performCookieAuth(boost::beast::http::verb method [[maybe_unused]], |
John Edward Broadbent | 59b98b2 | 2021-07-13 15:36:32 -0700 | [diff] [blame] | 120 | const boost::beast::http::header<true>& reqHeader) |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 121 | { |
Ed Tanous | 9f217c2 | 2024-04-19 17:22:43 -0700 | [diff] [blame] | 122 | using headers = boost::beast::http::header<true>; |
| 123 | std::pair<headers::const_iterator, headers::const_iterator> cookies = |
| 124 | reqHeader.equal_range(boost::beast::http::field::cookie); |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 125 | |
Ed Tanous | 9f217c2 | 2024-04-19 17:22:43 -0700 | [diff] [blame] | 126 | for (auto it = cookies.first; it != cookies.second; it++) |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 127 | { |
Ed Tanous | 9f217c2 | 2024-04-19 17:22:43 -0700 | [diff] [blame] | 128 | std::string_view cookieValue = it->value(); |
| 129 | BMCWEB_LOG_DEBUG("Checking cookie {}", cookieValue); |
| 130 | auto startIndex = cookieValue.find("SESSION="); |
| 131 | if (startIndex == std::string::npos) |
| 132 | { |
| 133 | BMCWEB_LOG_DEBUG( |
| 134 | "Cookie was present, but didn't look like a session {}", |
| 135 | cookieValue); |
| 136 | continue; |
| 137 | } |
| 138 | startIndex += sizeof("SESSION=") - 1; |
| 139 | auto endIndex = cookieValue.find(';', startIndex); |
| 140 | if (endIndex == std::string::npos) |
| 141 | { |
| 142 | endIndex = cookieValue.size(); |
| 143 | } |
| 144 | std::string_view authKey = cookieValue.substr(startIndex, |
| 145 | endIndex - startIndex); |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 146 | |
Ed Tanous | 9f217c2 | 2024-04-19 17:22:43 -0700 | [diff] [blame] | 147 | std::shared_ptr<persistent_data::UserSession> sessionOut = |
| 148 | persistent_data::SessionStore::getInstance().loginSessionByToken( |
| 149 | authKey); |
| 150 | if (sessionOut == nullptr) |
| 151 | { |
| 152 | return nullptr; |
| 153 | } |
| 154 | sessionOut->cookieAuth = true; |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 155 | |
Ed Tanous | 576db69 | 2024-05-10 16:37:56 -0700 | [diff] [blame] | 156 | if constexpr (!BMCWEB_INSECURE_DISABLE_CSRF) |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 157 | { |
| 158 | // RFC7231 defines methods that need csrf protection |
| 159 | if (method != boost::beast::http::verb::get) |
Ed Tanous | 9f217c2 | 2024-04-19 17:22:43 -0700 | [diff] [blame] | 160 | { |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 161 | std::string_view csrf = reqHeader["X-XSRF-TOKEN"]; |
| 162 | // Make sure both tokens are filled |
| 163 | if (csrf.empty() || sessionOut->csrfToken.empty()) |
| 164 | { |
| 165 | return nullptr; |
| 166 | } |
| 167 | |
| 168 | if (csrf.size() != persistent_data::sessionTokenSize) |
| 169 | { |
| 170 | return nullptr; |
| 171 | } |
| 172 | // Reject if csrf token not available |
| 173 | if (!crow::utility::constantTimeStringCompare( |
| 174 | csrf, sessionOut->csrfToken)) |
| 175 | { |
| 176 | return nullptr; |
| 177 | } |
Ed Tanous | 9f217c2 | 2024-04-19 17:22:43 -0700 | [diff] [blame] | 178 | } |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 179 | } |
Ed Tanous | 3eaecac | 2024-05-08 16:26:24 -0700 | [diff] [blame] | 180 | return sessionOut; |
Ed Tanous | 9f217c2 | 2024-04-19 17:22:43 -0700 | [diff] [blame] | 181 | } |
| 182 | return nullptr; |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 183 | } |
| 184 | |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 185 | inline std::shared_ptr<persistent_data::UserSession> |
John Edward Broadbent | 59b98b2 | 2021-07-13 15:36:32 -0700 | [diff] [blame] | 186 | performTLSAuth(Response& res, |
| 187 | const boost::beast::http::header<true>& reqHeader, |
Ed Tanous | b5a7693 | 2020-09-29 16:16:58 -0700 | [diff] [blame] | 188 | const std::weak_ptr<persistent_data::UserSession>& session) |
James Feist | 6964c98 | 2020-07-28 16:10:23 -0700 | [diff] [blame] | 189 | { |
James Feist | 6964c98 | 2020-07-28 16:10:23 -0700 | [diff] [blame] | 190 | if (auto sp = session.lock()) |
| 191 | { |
| 192 | // set cookie only if this is req from the browser. |
John Edward Broadbent | 59b98b2 | 2021-07-13 15:36:32 -0700 | [diff] [blame] | 193 | if (reqHeader["User-Agent"].empty()) |
James Feist | 6964c98 | 2020-07-28 16:10:23 -0700 | [diff] [blame] | 194 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 195 | BMCWEB_LOG_DEBUG(" TLS session: {} will be used for this request.", |
| 196 | sp->uniqueId); |
James Feist | 6964c98 | 2020-07-28 16:10:23 -0700 | [diff] [blame] | 197 | return sp; |
| 198 | } |
Karol Niczyj | ade2fe7 | 2022-04-27 18:04:58 +0200 | [diff] [blame] | 199 | // TODO: change this to not switch to cookie auth |
Ed Tanous | 994fd86 | 2023-06-06 13:37:03 -0700 | [diff] [blame] | 200 | res.addHeader(boost::beast::http::field::set_cookie, |
Karol Niczyj | ade2fe7 | 2022-04-27 18:04:58 +0200 | [diff] [blame] | 201 | "XSRF-TOKEN=" + sp->csrfToken + |
Ed Tanous | 994fd86 | 2023-06-06 13:37:03 -0700 | [diff] [blame] | 202 | "; SameSite=Strict; Secure"); |
| 203 | res.addHeader(boost::beast::http::field::set_cookie, |
| 204 | "SESSION=" + sp->sessionToken + |
| 205 | "; SameSite=Strict; Secure; HttpOnly"); |
| 206 | res.addHeader(boost::beast::http::field::set_cookie, |
| 207 | "IsAuthenticated=true; Secure"); |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 208 | BMCWEB_LOG_DEBUG( |
| 209 | " TLS session: {} with cookie will be used for this request.", |
| 210 | sp->uniqueId); |
Karol Niczyj | ade2fe7 | 2022-04-27 18:04:58 +0200 | [diff] [blame] | 211 | return sp; |
James Feist | 6964c98 | 2020-07-28 16:10:23 -0700 | [diff] [blame] | 212 | } |
James Feist | 6964c98 | 2020-07-28 16:10:23 -0700 | [diff] [blame] | 213 | return nullptr; |
| 214 | } |
| 215 | |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 216 | // checks if request can be forwarded without authentication |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 217 | inline bool isOnAllowlist(std::string_view url, boost::beast::http::verb method) |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 218 | { |
John Edward Broadbent | 59b98b2 | 2021-07-13 15:36:32 -0700 | [diff] [blame] | 219 | if (boost::beast::http::verb::get == method) |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 220 | { |
John Edward Broadbent | 59b98b2 | 2021-07-13 15:36:32 -0700 | [diff] [blame] | 221 | if (url == "/redfish/v1" || url == "/redfish/v1/" || |
| 222 | url == "/redfish" || url == "/redfish/" || |
| 223 | url == "/redfish/v1/odata" || url == "/redfish/v1/odata/") |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 224 | { |
| 225 | return true; |
| 226 | } |
John Edward Broadbent | 59b98b2 | 2021-07-13 15:36:32 -0700 | [diff] [blame] | 227 | if (crow::webroutes::routes.find(std::string(url)) != |
Ed Tanous | d4d2579 | 2020-09-29 15:15:03 -0700 | [diff] [blame] | 228 | crow::webroutes::routes.end()) |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 229 | { |
| 230 | return true; |
| 231 | } |
| 232 | } |
| 233 | |
| 234 | // it's allowed to POST on session collection & login without |
| 235 | // authentication |
John Edward Broadbent | 59b98b2 | 2021-07-13 15:36:32 -0700 | [diff] [blame] | 236 | if (boost::beast::http::verb::post == method) |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 237 | { |
John Edward Broadbent | 59b98b2 | 2021-07-13 15:36:32 -0700 | [diff] [blame] | 238 | if ((url == "/redfish/v1/SessionService/Sessions") || |
| 239 | (url == "/redfish/v1/SessionService/Sessions/") || |
Ed Tanous | e76cd86 | 2022-03-14 09:12:00 -0700 | [diff] [blame] | 240 | (url == "/redfish/v1/SessionService/Sessions/Members") || |
| 241 | (url == "/redfish/v1/SessionService/Sessions/Members/") || |
John Edward Broadbent | 59b98b2 | 2021-07-13 15:36:32 -0700 | [diff] [blame] | 242 | (url == "/login")) |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 243 | { |
| 244 | return true; |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | return false; |
| 249 | } |
| 250 | |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 251 | inline std::shared_ptr<persistent_data::UserSession> authenticate( |
| 252 | const boost::asio::ip::address& ipAddress [[maybe_unused]], |
| 253 | Response& res [[maybe_unused]], |
| 254 | boost::beast::http::verb method [[maybe_unused]], |
| 255 | const boost::beast::http::header<true>& reqHeader, |
| 256 | [[maybe_unused]] const std::shared_ptr<persistent_data::UserSession>& |
| 257 | session) |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 258 | { |
Ed Tanous | 52cc112 | 2020-07-18 13:51:21 -0700 | [diff] [blame] | 259 | const persistent_data::AuthConfigMethods& authMethodsConfig = |
| 260 | persistent_data::SessionStore::getInstance().getAuthMethodsConfig(); |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 261 | |
John Edward Broadbent | 59b98b2 | 2021-07-13 15:36:32 -0700 | [diff] [blame] | 262 | std::shared_ptr<persistent_data::UserSession> sessionOut = nullptr; |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 263 | if constexpr (BMCWEB_MUTUAL_TLS_AUTH) |
James Feist | 6964c98 | 2020-07-28 16:10:23 -0700 | [diff] [blame] | 264 | { |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 265 | if (authMethodsConfig.tls) |
| 266 | { |
| 267 | sessionOut = performTLSAuth(res, reqHeader, session); |
| 268 | } |
James Feist | 6964c98 | 2020-07-28 16:10:23 -0700 | [diff] [blame] | 269 | } |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 270 | if constexpr (BMCWEB_XTOKEN_AUTH) |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 271 | { |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 272 | if (sessionOut == nullptr && authMethodsConfig.xtoken) |
| 273 | { |
| 274 | sessionOut = performXtokenAuth(reqHeader); |
| 275 | } |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 276 | } |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 277 | if constexpr (BMCWEB_COOKIE_AUTH) |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 278 | { |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 279 | if (sessionOut == nullptr && authMethodsConfig.cookie) |
| 280 | { |
| 281 | sessionOut = performCookieAuth(method, reqHeader); |
| 282 | } |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 283 | } |
John Edward Broadbent | 59b98b2 | 2021-07-13 15:36:32 -0700 | [diff] [blame] | 284 | std::string_view authHeader = reqHeader["Authorization"]; |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 285 | BMCWEB_LOG_DEBUG("authHeader={}", authHeader); |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 286 | if constexpr (BMCWEB_SESSION_AUTH) |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 287 | { |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 288 | if (sessionOut == nullptr && authMethodsConfig.sessionToken) |
| 289 | { |
| 290 | sessionOut = performTokenAuth(authHeader); |
| 291 | } |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 292 | } |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 293 | if constexpr (BMCWEB_BASIC_AUTH) |
John Edward Broadbent | 97a056a | 2021-09-10 14:56:19 -0700 | [diff] [blame] | 294 | { |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 295 | if (sessionOut == nullptr && authMethodsConfig.basic) |
| 296 | { |
| 297 | sessionOut = performBasicAuth(ipAddress, authHeader); |
| 298 | } |
John Edward Broadbent | 97a056a | 2021-09-10 14:56:19 -0700 | [diff] [blame] | 299 | } |
| 300 | if (sessionOut != nullptr) |
| 301 | { |
| 302 | return sessionOut; |
| 303 | } |
| 304 | |
John Edward Broadbent | 59b98b2 | 2021-07-13 15:36:32 -0700 | [diff] [blame] | 305 | return nullptr; |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 306 | } |
| 307 | |
Nan Zhou | d055a34 | 2022-05-25 01:15:34 +0000 | [diff] [blame] | 308 | } // namespace authentication |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 309 | } // namespace crow |