Remove sessions when user is deleted

An Internal server Error will happen if you delete the login user.
Match the "InterfacesRemoved" signal for monitoring the user status and
delete the session to fix this bug.

Tested:
1. Add a new user such as test
2. Login with the new user in web
3. Delete or rename the user by web and ipmi command
4. Refresh the web and a new user was needed to login in the web

Signed-off-by: Xie Ning <xiening.xll@bytedance.com>
Change-Id: I2b53edb71d9a4e904c7da54393539f87eeb2d7a3
diff --git a/include/user_monitor.hpp b/include/user_monitor.hpp
new file mode 100644
index 0000000..bd8ed24
--- /dev/null
+++ b/include/user_monitor.hpp
@@ -0,0 +1,30 @@
+#pragma once
+#include "dbus_singleton.hpp"
+#include "dbus_utility.hpp"
+#include "persistent_data.hpp"
+
+#include <sdbusplus/bus/match.hpp>
+#include <sdbusplus/message/types.hpp>
+
+namespace bmcweb
+{
+
+inline void onUserRemoved(sdbusplus::message::message& msg)
+{
+    sdbusplus::message::object_path p;
+    msg.read(p);
+    std::string username = p.filename();
+    persistent_data::SessionStore::getInstance().removeSessionsByUsername(
+        username);
+}
+
+inline void registerUserRemovedSignal()
+{
+    std::string userRemovedMatchStr =
+        sdbusplus::bus::match::rules::interfacesRemoved(
+            "/xyz/openbmc_project/user");
+
+    static sdbusplus::bus::match_t userRemovedMatch(
+        *crow::connections::systemBus, userRemovedMatchStr, onUserRemoved);
+}
+} // namespace bmcweb