MCPcopy Create free account
hub / github.com/Icinga/icinga2 / EnsureAuthenticatedUser

Function EnsureAuthenticatedUser

lib/remote/httpserverconnection.cpp:300–330  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

298}
299
300static inline
301bool EnsureAuthenticatedUser(
302 const HttpApiRequest& request,
303 HttpApiResponse& response,
304 boost::asio::yield_context& yc
305)
306{
307 namespace http = boost::beast::http;
308
309 if (!request.User()) {
310 Log(LogWarning, "HttpServerConnection")
311 << "Unauthorized request: " << request.method_string() << ' ' << request.target();
312
313 response.result(http::status::unauthorized);
314 response.set(http::field::www_authenticate, "Basic realm=\"Icinga 2\"");
315 response.set(http::field::connection, "close");
316
317 if (request[http::field::accept] == "application/json") {
318 HttpUtility::SendJsonError(response, nullptr, 401, "Unauthorized. Please check your user credentials.");
319 } else {
320 response.set(http::field::content_type, "text/html");
321 response.body() << "<h1>Unauthorized. Please check your user credentials.</h1>";
322 }
323
324 response.Flush(yc);
325
326 return false;
327 }
328
329 return true;
330}
331
332static inline
333bool EnsureValidBody(

Callers 1

ProcessMessagesMethod · 0.85

Calls 3

LogClass · 0.85
UserMethod · 0.45
FlushMethod · 0.45

Tested by

no test coverage detected