From 0927f4a4d170b27d383f8d3ca05f5ce44682294e Mon Sep 17 00:00:00 2001 From: Tomasz Marciniak Date: Wed, 1 Jul 2015 10:00:56 +0200 Subject: [PATCH] [KeyManager] allow/denyAccessControl implementation [Verification] Code compiles without errors. Change-Id: I2902a999e9a954e01adbf2a624790cbd65893702 Signed-off-by: Tomasz Marciniak --- src/keymanager/keymanager_instance.cc | 65 +++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/src/keymanager/keymanager_instance.cc b/src/keymanager/keymanager_instance.cc index b4972063..4c1d571b 100755 --- a/src/keymanager/keymanager_instance.cc +++ b/src/keymanager/keymanager_instance.cc @@ -330,11 +330,76 @@ void KeyManagerInstance::LoadFromPKCS12File(const picojson::value& args, void KeyManagerInstance::AllowAccessControl(const picojson::value& args, picojson::object& out) { LoggerD("Enter"); + + const std::string& data_name = args.get("dataName").get(); + const std::string& id = args.get("id").get(); + const double callback_id = args.get("callbackId").get(); + const std::string& access = args.get("accessControlType").get(); + ckmc_access_right_e granted = CKMC_AR_READ; + if ("READ_REMOVE" == access) { + granted = CKMC_AR_READ_REMOVE; + } + + auto allow = [data_name, id, granted](const std::shared_ptr& response) -> void { + int ret = ckmc_allow_access(data_name.c_str(), id.c_str(), granted); + if (CKMC_ERROR_NONE != ret) { + PlatformResult result = PlatformResult(ErrorCode::NO_ERROR); + if (CKMC_ERROR_DB_ALIAS_UNKNOWN == ret) { + result = PlatformResult(ErrorCode::NOT_FOUND_ERR, "Alias not found."); + } else { + result = PlatformResult(ErrorCode::UNKNOWN_ERR, "Failed to allow access."); + } + common::tools::ReportError(result, &response->get()); + } else { + common::tools::ReportSuccess(response->get()); + } + }; + + auto allow_response = [this, callback_id](const std::shared_ptr& response) -> void { + picojson::object& obj = response->get(); + obj.insert(std::make_pair("callbackId", picojson::value(callback_id))); + this->PostMessage(response->serialize().c_str()); + }; + + TaskQueue::GetInstance().Queue( + allow, + allow_response, + std::shared_ptr(new picojson::value(picojson::object()))); } void KeyManagerInstance::DenyAccessControl(const picojson::value& args, picojson::object& out) { LoggerD("Enter"); + + const std::string& data_name = args.get("dataName").get(); + const std::string& id = args.get("id").get(); + const double callback_id = args.get("callbackId").get(); + + auto deny = [data_name, id](const std::shared_ptr& response) -> void { + int ret = ckmc_deny_access(data_name.c_str(), id.c_str()); + if (CKMC_ERROR_NONE != ret) { + PlatformResult result = PlatformResult(ErrorCode::NO_ERROR); + if (CKMC_ERROR_DB_ALIAS_UNKNOWN == ret) { + result = PlatformResult(ErrorCode::NOT_FOUND_ERR, "Alias not found."); + } else { + result = PlatformResult(ErrorCode::UNKNOWN_ERR, "Failed to deny access."); + } + common::tools::ReportError(result, &response->get()); + } else { + common::tools::ReportSuccess(response->get()); + } + }; + + auto deny_response = [this, callback_id](const std::shared_ptr& response) -> void { + picojson::object& obj = response->get(); + obj.insert(std::make_pair("callbackId", picojson::value(callback_id))); + this->PostMessage(response->serialize().c_str()); + }; + + TaskQueue::GetInstance().Queue( + deny, + deny_response, + std::shared_ptr(new picojson::value(picojson::object()))); } } // namespace keymanager -- 2.34.1