]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#1590] Added http-auth logger
authorFrancis Dupont <fdupont@isc.org>
Sun, 18 Apr 2021 09:51:24 +0000 (11:51 +0200)
committerTomek Mrugalski <tomek@isc.org>
Wed, 5 May 2021 14:08:18 +0000 (16:08 +0200)
14 files changed:
doc/sphinx/mes-files.txt
doc/sphinx/mes_files.mk
src/lib/http/Makefile.am
src/lib/http/auth_log.cc [new file with mode: 0644]
src/lib/http/auth_log.h [new file with mode: 0644]
src/lib/http/auth_messages.cc [new file with mode: 0644]
src/lib/http/auth_messages.h [new file with mode: 0644]
src/lib/http/auth_messages.mes [new file with mode: 0644]
src/lib/http/basic_auth_config.cc
src/lib/http/http_log.cc
src/lib/http/http_log.h
src/lib/http/http_messages.cc
src/lib/http/http_messages.h
src/lib/http/http_messages.mes

index 697508bede2488c23764e6f90aee083d681e786c..4bebe4a22b2fad67fda3ff0a1a56334c2d818401 100644 (file)
@@ -10,6 +10,7 @@ src/lib/hooks/hooks_messages.mes
 src/lib/dhcpsrv/dhcpsrv_messages.mes
 src/lib/dhcpsrv/alloc_engine_messages.mes
 src/lib/dhcpsrv/hosts_messages.mes
+src/lib/http/auth_messages.mes
 src/lib/http/http_messages.mes
 src/lib/dhcp_ddns/dhcp_ddns_messages.mes
 src/lib/database/db_messages.mes
index b585e648a96d43f047f2464881837cd3bcdb97e3..8ad89ee1c688ec5be787f2f8459c7572040c336c 100644 (file)
@@ -10,6 +10,7 @@ mes_files += $(top_srcdir)/src/lib/hooks/hooks_messages.mes
 mes_files += $(top_srcdir)/src/lib/dhcpsrv/dhcpsrv_messages.mes
 mes_files += $(top_srcdir)/src/lib/dhcpsrv/alloc_engine_messages.mes
 mes_files += $(top_srcdir)/src/lib/dhcpsrv/hosts_messages.mes
+mes_files += $(top_srcdir)/src/lib/http/auth_messages.mes
 mes_files += $(top_srcdir)/src/lib/http/http_messages.mes
 mes_files += $(top_srcdir)/src/lib/dhcp_ddns/dhcp_ddns_messages.mes
 mes_files += $(top_srcdir)/src/lib/database/db_messages.mes
index 08c492daf60a43c7cadad7a4839d19fa2b2c820c..ccca75b5586f48b0cd7613dead04fb8396b0642c 100644 (file)
@@ -38,9 +38,11 @@ libkea_http_la_SOURCES += response_creator.cc response_creator.h
 libkea_http_la_SOURCES += response_creator_factory.h
 libkea_http_la_SOURCES += response_json.cc response_json.h
 libkea_http_la_SOURCES += url.cc url.h
-libkea_http_la_SOURCES += basic_auth.cc basic_auth.h
 libkea_http_la_SOURCES += auth_config.h
+libkea_http_la_SOURCES += auth_log.cc auth_log.h
+libkea_http_la_SOURCES += auth_messages.cc auth_messages.h
 libkea_http_la_SOURCES += basic_auth_config.cc basic_auth_config.h
+libkea_http_la_SOURCES += basic_auth.cc basic_auth.h
 
 libkea_http_la_CXXFLAGS = $(AM_CXXFLAGS)
 libkea_http_la_CPPFLAGS = $(AM_CPPFLAGS)
@@ -63,6 +65,7 @@ libkea_http_la_LIBADD += $(LOG4CPLUS_LIBS) $(BOOST_LIBS) $(CRYPTO_LIBS)
 # is required.  To make it easy to rebuild messages without going through
 # reconfigure, a new target messages-clean has been added.
 maintainer-clean-local:
+       rm -f auth_messages.cc auth_messages.h
        rm -f http_messages.h http_messages.cc
 
 # To regenerate messages files, one can do:
@@ -76,9 +79,12 @@ messages-clean: maintainer-clean-local
 if GENERATE_MESSAGES
 
 # Define rule to build logging source files from message file
-messages: http_messages.h http_messages.cc
+messages: auth_messages.cc auth_messages.h http_messages.h http_messages.cc
        @echo Message files regenerated
 
+auth_messages.cc auth_messages.h: auth_messages.mes
+       $(top_builddir)/src/lib/log/compiler/kea-msg-compiler $(top_srcdir)/src/lib/http/auth_messages.mes
+
 http_messages.h http_messages.cc: http_messages.mes
        $(top_builddir)/src/lib/log/compiler/kea-msg-compiler $(top_srcdir)/src/lib/http/http_messages.mes
 
@@ -93,6 +99,8 @@ endif
 libkea_http_includedir = $(pkgincludedir)/http
 libkea_http_include_HEADERS = \
        auth_config.h \
+       auth_log.h \
+       auth_messages.h \
        basic_auth.h \
        basic_auth_config.h \
        client.h \
diff --git a/src/lib/http/auth_log.cc b/src/lib/http/auth_log.cc
new file mode 100644 (file)
index 0000000..cc5f9f9
--- /dev/null
@@ -0,0 +1,21 @@
+// Copyright (C) 2021 Internet Systems Consortium, Inc. ("ISC")
+//
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+/// Defines the logger used by the HTTP authentication.
+
+#include <config.h>
+
+#include <http/auth_log.h>
+
+namespace isc {
+namespace http {
+
+/// @brief Defines the logger used by the HTTP authentication.
+isc::log::Logger auth_logger("http-auth");
+
+} // namespace http
+} // namespace isc
+
diff --git a/src/lib/http/auth_log.h b/src/lib/http/auth_log.h
new file mode 100644 (file)
index 0000000..8ebf5c3
--- /dev/null
@@ -0,0 +1,23 @@
+// Copyright (C) 2021 Internet Systems Consortium, Inc. ("ISC")
+//
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef AUTH_LOG_H
+#define AUTH_LOG_H
+
+#include <log/logger_support.h>
+#include <log/macros.h>
+#include <http/auth_messages.h>
+
+namespace isc {
+namespace http {
+
+/// Define the HTTP authentication logger.
+extern isc::log::Logger auth_logger;
+
+} // namespace http
+} // namespace isc
+
+#endif // AUTH_LOG_H
diff --git a/src/lib/http/auth_messages.cc b/src/lib/http/auth_messages.cc
new file mode 100644 (file)
index 0000000..ebf9da5
--- /dev/null
@@ -0,0 +1,31 @@
+// File created from ../../../src/lib/http/auth_messages.mes
+
+#include <cstddef>
+#include <log/message_types.h>
+#include <log/message_initializer.h>
+
+namespace isc {
+namespace http {
+
+extern const isc::log::MessageID HTTP_CLIENT_REQUEST_AUTHORIZED = "HTTP_CLIENT_REQUEST_AUTHORIZED";
+extern const isc::log::MessageID HTTP_CLIENT_REQUEST_BAD_AUTH_HEADER = "HTTP_CLIENT_REQUEST_BAD_AUTH_HEADER";
+extern const isc::log::MessageID HTTP_CLIENT_REQUEST_NOT_AUTHORIZED = "HTTP_CLIENT_REQUEST_NOT_AUTHORIZED";
+extern const isc::log::MessageID HTTP_CLIENT_REQUEST_NO_AUTH_HEADER = "HTTP_CLIENT_REQUEST_NO_AUTH_HEADER";
+
+} // namespace http
+} // namespace isc
+
+namespace {
+
+const char* values[] = {
+    "HTTP_CLIENT_REQUEST_AUTHORIZED", "received HTTP request authorized for '%1'",
+    "HTTP_CLIENT_REQUEST_BAD_AUTH_HEADER", "received HTTP request with malformed authentication header: %1",
+    "HTTP_CLIENT_REQUEST_NOT_AUTHORIZED", "received HTTP request with not matching authentication header",
+    "HTTP_CLIENT_REQUEST_NO_AUTH_HEADER", "received HTTP request without required authentication header",
+    NULL
+};
+
+const isc::log::MessageInitializer initializer(values);
+
+} // Anonymous namespace
+
diff --git a/src/lib/http/auth_messages.h b/src/lib/http/auth_messages.h
new file mode 100644 (file)
index 0000000..ff02ef5
--- /dev/null
@@ -0,0 +1,19 @@
+// File created from ../../../src/lib/http/auth_messages.mes
+
+#ifndef AUTH_MESSAGES_H
+#define AUTH_MESSAGES_H
+
+#include <log/message_types.h>
+
+namespace isc {
+namespace http {
+
+extern const isc::log::MessageID HTTP_CLIENT_REQUEST_AUTHORIZED;
+extern const isc::log::MessageID HTTP_CLIENT_REQUEST_BAD_AUTH_HEADER;
+extern const isc::log::MessageID HTTP_CLIENT_REQUEST_NOT_AUTHORIZED;
+extern const isc::log::MessageID HTTP_CLIENT_REQUEST_NO_AUTH_HEADER;
+
+} // namespace http
+} // namespace isc
+
+#endif // AUTH_MESSAGES_H
diff --git a/src/lib/http/auth_messages.mes b/src/lib/http/auth_messages.mes
new file mode 100644 (file)
index 0000000..685bdb3
--- /dev/null
@@ -0,0 +1,24 @@
+# Copyright (C) 2021 Internet Systems Consortium, Inc. ("ISC")
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+$NAMESPACE isc::http
+
+% HTTP_CLIENT_REQUEST_AUTHORIZED received HTTP request authorized for '%1'
+This information message is issued when the server receives with a matching
+authentication header. The argument provides the user id.
+
+% HTTP_CLIENT_REQUEST_BAD_AUTH_HEADER received HTTP request with malformed authentication header: %1
+This information message is issued when the server receives a request with
+a malformed authentication header. The argument explains the problem.
+
+% HTTP_CLIENT_REQUEST_NOT_AUTHORIZED received HTTP request with not matching authentication header
+This information message is issued when the server receives a request with
+authentication header carrying not recognized credential: the user
+provided incorrect user id and/or password.
+
+% HTTP_CLIENT_REQUEST_NO_AUTH_HEADER received HTTP request without required authentication header
+This information message is issued when the server receives a request without
+a required authentication header.
index 87106663aa88414d7b357d73017ec2878d7c9313..5530cf8c50037054daa1c4f2dfbe7c8c1907976c 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2020 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2020-2021 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -6,8 +6,8 @@
 
 #include <config.h>
 
+#include <http/auth_log.h>
 #include <http/basic_auth_config.h>
-#include <http/http_log.h>
 #include <util/strutil.h>
 
 using namespace isc;
@@ -226,17 +226,17 @@ BasicHttpAuthConfig::checkAuth(const HttpResponseCreator& creator,
         // Verify the credential is in the list.
         const auto it = credentials.find(value);
         if (it != credentials.end()) {
-            LOG_INFO(http_logger, HTTP_CLIENT_REQUEST_AUTHORIZED)
+            LOG_INFO(auth_logger, HTTP_CLIENT_REQUEST_AUTHORIZED)
                 .arg(it->second);
             authentic = true;
         } else {
-            LOG_INFO(http_logger, HTTP_CLIENT_REQUEST_NOT_AUTHORIZED);
+            LOG_INFO(auth_logger, HTTP_CLIENT_REQUEST_NOT_AUTHORIZED);
             authentic = false;
         }
     } catch (const HttpMessageNonExistingHeader&) {
-        LOG_INFO(http_logger, HTTP_CLIENT_REQUEST_NO_AUTH_HEADER);
+        LOG_INFO(auth_logger, HTTP_CLIENT_REQUEST_NO_AUTH_HEADER);
     } catch (const BadValue& ex) {
-        LOG_INFO(http_logger, HTTP_CLIENT_REQUEST_BAD_AUTH_HEADER)
+        LOG_INFO(auth_logger, HTTP_CLIENT_REQUEST_BAD_AUTH_HEADER)
             .arg(ex.what());
     }
     if (authentic) {
index a41289f974c440dd2921db09026c132f0e8468fa..8e1994d9ef9a52c77bad8410859027c7fcb6ab9c 100644 (file)
@@ -1,10 +1,10 @@
-// Copyright (C) 2016-2018 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2016-2021 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
-/// Defines the logger used by the top-level component of kea-dhcp-ddns.
+/// Defines the logger used by the libkea-http library.
 
 #include <config.h>
 
index 4460358e6b88439527c33a7ef4afeec3114e3724..0b7d8ad0c039b0701df1468a50e6e5e48b88af8a 100644 (file)
@@ -14,7 +14,7 @@
 namespace isc {
 namespace http {
 
-/// Define the loggers used within libkea-http library.
+/// Define the logger used within libkea-http library.
 extern isc::log::Logger http_logger;
 
 } // namespace http
index d043ad323e7b84ecc0bcc302f2881bd0a7266bee..dc24176ead3350d4fedff7fb1703e1c0e3308753 100644 (file)
@@ -13,10 +13,6 @@ extern const isc::log::MessageID HTTP_BAD_CLIENT_REQUEST_RECEIVED_DETAILS = "HTT
 extern const isc::log::MessageID HTTP_BAD_SERVER_RESPONSE_RECEIVED = "HTTP_BAD_SERVER_RESPONSE_RECEIVED";
 extern const isc::log::MessageID HTTP_BAD_SERVER_RESPONSE_RECEIVED_DETAILS = "HTTP_BAD_SERVER_RESPONSE_RECEIVED_DETAILS";
 extern const isc::log::MessageID HTTP_CLIENT_MT_STARTED = "HTTP_CLIENT_MT_STARTED";
-extern const isc::log::MessageID HTTP_CLIENT_REQUEST_AUTHORIZED = "HTTP_CLIENT_REQUEST_AUTHORIZED";
-extern const isc::log::MessageID HTTP_CLIENT_REQUEST_BAD_AUTH_HEADER = "HTTP_CLIENT_REQUEST_BAD_AUTH_HEADER";
-extern const isc::log::MessageID HTTP_CLIENT_REQUEST_NOT_AUTHORIZED = "HTTP_CLIENT_REQUEST_NOT_AUTHORIZED";
-extern const isc::log::MessageID HTTP_CLIENT_REQUEST_NO_AUTH_HEADER = "HTTP_CLIENT_REQUEST_NO_AUTH_HEADER";
 extern const isc::log::MessageID HTTP_CLIENT_REQUEST_RECEIVED = "HTTP_CLIENT_REQUEST_RECEIVED";
 extern const isc::log::MessageID HTTP_CLIENT_REQUEST_RECEIVED_DETAILS = "HTTP_CLIENT_REQUEST_RECEIVED_DETAILS";
 extern const isc::log::MessageID HTTP_CLIENT_REQUEST_SEND = "HTTP_CLIENT_REQUEST_SEND";
@@ -50,10 +46,6 @@ const char* values[] = {
     "HTTP_BAD_SERVER_RESPONSE_RECEIVED", "bad response received when communicating with %1: %2",
     "HTTP_BAD_SERVER_RESPONSE_RECEIVED_DETAILS", "detailed information about bad response received from %1:\n%2",
     "HTTP_CLIENT_MT_STARTED", "HttpClient has been started in multi-threaded mode running %1 threads",
-    "HTTP_CLIENT_REQUEST_AUTHORIZED", "received HTTP request authorized for '%1'",
-    "HTTP_CLIENT_REQUEST_BAD_AUTH_HEADER", "received HTTP request with malformed authentication header: %1",
-    "HTTP_CLIENT_REQUEST_NOT_AUTHORIZED", "received HTTP request with not matching authentication header",
-    "HTTP_CLIENT_REQUEST_NO_AUTH_HEADER", "received HTTP request without required authentication header",
     "HTTP_CLIENT_REQUEST_RECEIVED", "received HTTP request from %1",
     "HTTP_CLIENT_REQUEST_RECEIVED_DETAILS", "detailed information about well-formed request received from %1:\n%2",
     "HTTP_CLIENT_REQUEST_SEND", "sending HTTP request %1 to %2",
index 5735df006b7be37e797acb4eb6fd36374e9efc95..d24a6ce4fdc5cce4e3bdac773e711b1fc32f62fc 100644 (file)
@@ -14,10 +14,6 @@ extern const isc::log::MessageID HTTP_BAD_CLIENT_REQUEST_RECEIVED_DETAILS;
 extern const isc::log::MessageID HTTP_BAD_SERVER_RESPONSE_RECEIVED;
 extern const isc::log::MessageID HTTP_BAD_SERVER_RESPONSE_RECEIVED_DETAILS;
 extern const isc::log::MessageID HTTP_CLIENT_MT_STARTED;
-extern const isc::log::MessageID HTTP_CLIENT_REQUEST_AUTHORIZED;
-extern const isc::log::MessageID HTTP_CLIENT_REQUEST_BAD_AUTH_HEADER;
-extern const isc::log::MessageID HTTP_CLIENT_REQUEST_NOT_AUTHORIZED;
-extern const isc::log::MessageID HTTP_CLIENT_REQUEST_NO_AUTH_HEADER;
 extern const isc::log::MessageID HTTP_CLIENT_REQUEST_RECEIVED;
 extern const isc::log::MessageID HTTP_CLIENT_REQUEST_RECEIVED_DETAILS;
 extern const isc::log::MessageID HTTP_CLIENT_REQUEST_SEND;
index 389abd6597dce9bc82cd35c6b1887f741bf975d6..7683162ab3c9a167b9681370fa34656ff7993d78 100644 (file)
@@ -42,23 +42,6 @@ truncated by the logger if it is too large to be printed.
 This debug message is issued when a multi-threaded HTTP client instance has
 been created.  The argument specifies the maximum number of threads.
 
-% HTTP_CLIENT_REQUEST_AUTHORIZED received HTTP request authorized for '%1'
-This information message is issued when the server receives with a matching
-authentication header. The argument provides the user id.
-
-% HTTP_CLIENT_REQUEST_BAD_AUTH_HEADER received HTTP request with malformed authentication header: %1
-This information message is issued when the server receives a request with
-a malformed authentication header. The argument explains the problem.
-
-% HTTP_CLIENT_REQUEST_NOT_AUTHORIZED received HTTP request with not matching authentication header
-This information message is issued when the server receives a request with
-authentication header carrying not recognized credential: the user
-provided incorrect user id and/or password.
-
-% HTTP_CLIENT_REQUEST_NO_AUTH_HEADER received HTTP request without required authentication header
-This information message is issued when the server receives a request without
-a required authentication header.
-
 % HTTP_CLIENT_REQUEST_RECEIVED received HTTP request from %1
 This debug message is issued when the server finished receiving a HTTP
 request from the remote endpoint. The address of the remote endpoint is