Read AllGroups property from user manager
This bmcweb code is to create users as per the available groups,
and make the code dynamic.
Tested: Created a new user and did redfish post query.
Verified through busctl introspection, available groups were listed
for the new user.
Signed-off-by: Ayushi Smriti <smriti.ayushi@linux.intel.com>
Change-Id: Ifec6d71d9721e4bfef53c9e38b17e9b7864777e6
diff --git a/redfish-core/lib/account_service.hpp b/redfish-core/lib/account_service.hpp
index 6cbbdce..16c8731 100644
--- a/redfish-core/lib/account_service.hpp
+++ b/redfish-core/lib/account_service.hpp
@@ -1079,49 +1079,77 @@
}
roleId = priv;
+ // Reading AllGroups property
crow::connections::systemBus->async_method_call(
- [asyncResp, username, password{std::move(password)}](
- const boost::system::error_code ec) {
+ [asyncResp, username, password{std::move(password)}, roleId,
+ enabled](const boost::system::error_code ec,
+ const std::variant<std::vector<std::string>>& allGroups) {
if (ec)
{
- messages::resourceAlreadyExists(
- asyncResp->res, "#ManagerAccount.v1_0_3.ManagerAccount",
- "UserName", username);
+ BMCWEB_LOG_DEBUG << "ERROR with async_method_call";
+ messages::internalError(asyncResp->res);
return;
}
- if (!pamUpdatePassword(username, password))
+ const std::vector<std::string>* allGroupsList =
+ std::get_if<std::vector<std::string>>(&allGroups);
+
+ if (allGroupsList == nullptr || allGroupsList->empty())
{
- // At this point we have a user that's been created, but
- // the password set failed. Something is wrong, so
- // delete the user that we've already created
- crow::connections::systemBus->async_method_call(
- [asyncResp](const boost::system::error_code ec) {
- if (ec)
- {
- messages::internalError(asyncResp->res);
- return;
- }
-
- messages::invalidObject(asyncResp->res, "Password");
- },
- "xyz.openbmc_project.User.Manager",
- "/xyz/openbmc_project/user/" + username,
- "xyz.openbmc_project.Object.Delete", "Delete");
-
- BMCWEB_LOG_ERROR << "pamUpdatePassword Failed";
+ messages::internalError(asyncResp->res);
return;
}
- messages::created(asyncResp->res);
- asyncResp->res.addHeader(
- "Location",
- "/redfish/v1/AccountService/Accounts/" + username);
+ crow::connections::systemBus->async_method_call(
+ [asyncResp, username, password{std::move(password)}](
+ const boost::system::error_code ec) {
+ if (ec)
+ {
+ messages::resourceAlreadyExists(
+ asyncResp->res,
+ "#ManagerAccount.v1_0_3.ManagerAccount",
+ "UserName", username);
+ return;
+ }
+
+ if (!pamUpdatePassword(username, password))
+ {
+ // At this point we have a user that's been created,
+ // but the password set failed.Something is wrong,
+ // so delete the user that we've already created
+ crow::connections::systemBus->async_method_call(
+ [asyncResp](
+ const boost::system::error_code ec) {
+ if (ec)
+ {
+ messages::internalError(asyncResp->res);
+ return;
+ }
+
+ messages::invalidObject(asyncResp->res,
+ "Password");
+ },
+ "xyz.openbmc_project.User.Manager",
+ "/xyz/openbmc_project/user/" + username,
+ "xyz.openbmc_project.Object.Delete", "Delete");
+
+ BMCWEB_LOG_ERROR << "pamUpdatePassword Failed";
+ return;
+ }
+
+ messages::created(asyncResp->res);
+ asyncResp->res.addHeader(
+ "Location",
+ "/redfish/v1/AccountService/Accounts/" + username);
+ },
+ "xyz.openbmc_project.User.Manager",
+ "/xyz/openbmc_project/user",
+ "xyz.openbmc_project.User.Manager", "CreateUser", username,
+ *allGroupsList, *roleId, *enabled);
},
"xyz.openbmc_project.User.Manager", "/xyz/openbmc_project/user",
- "xyz.openbmc_project.User.Manager", "CreateUser", username,
- std::array<const char*, 4>{"ipmi", "redfish", "ssh", "web"},
- *roleId, *enabled);
+ "org.freedesktop.DBus.Properties", "Get",
+ "xyz.openbmc_project.User.Manager", "AllGroups");
}
};