Serialization: Adding Serialization for MFA
This commit will add the persistency of Dbus properties related to MFA.
The configuration file will be stored under
/var/lib/usr_mgr.conf.
Change-Id: Ib7fdc467c7cb094d328ae670df3bb4352e4a7b91
Signed-off-by: Abhilash Raju <abhilash.kollam@gmail.com>
diff --git a/users.cpp b/users.cpp
index 0300358..9008008 100644
--- a/users.cpp
+++ b/users.cpp
@@ -76,10 +76,13 @@
UsersIface::userPrivilege(priv, true);
UsersIface::userGroups(groups, true);
UsersIface::userEnabled(enabled, true);
-
+ load(manager.getSerializer());
this->emit_object_added();
}
-
+Users::~Users()
+{
+ manager.getSerializer().erase(userName);
+}
/** @brief delete user method.
* This method deletes the user as requested
*
@@ -323,6 +326,10 @@
{
iter->second(*this);
}
+ std::string path = std::format("{}/bypassedprotocol", getUserName());
+ manager.getSerializer().serialize(
+ path, MultiFactorAuthConfiguration::convertTypeToString(value));
+ manager.getSerializer().store();
return Interfaces::bypassedProtocol(value, skipSignal);
}
@@ -362,5 +369,22 @@
clearGoogleAuthenticator(*this);
}
+void Users::load(JsonSerializer& ts)
+{
+ std::optional<std::string> protocol;
+ std::string path = std::format("{}/bypassedprotocol", userName);
+ ts.deserialize(path, protocol);
+ if (protocol)
+ {
+ MultiFactorAuthType type =
+ MultiFactorAuthConfiguration::convertTypeFromString(*protocol);
+ bypassedProtocol(type, true);
+ return;
+ }
+ bypassedProtocol(MultiFactorAuthType::None, true);
+ ts.serialize(path, MultiFactorAuthConfiguration::convertTypeToString(
+ MultiFactorAuthType::None));
+}
+
} // namespace user
} // namespace phosphor