summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAKalinich-Luxoft <AKalinich@luxoft.com>2017-10-09 18:47:44 +0300
committerValerii <vmalkov@luxoft.com>2018-01-26 15:17:35 +0200
commitb2589108906e79dc82a9a3f21d55a277c4a976a2 (patch)
tree8a0fea0c0bae6e15088aa8439983b0476adb3c0b
parent76c50bb7176631e7340375c4a64339980266dea5 (diff)
downloadsdl_core-b2589108906e79dc82a9a3f21d55a277c4a976a2.tar.gz
Added param checking by policy for notifications for mobile apps
There was missed logic to check notification parameters according policy table for notifications. Was added similar functions as for requests.
-rw-r--r--src/components/application_manager/include/application_manager/commands/command_notification_impl.h39
-rw-r--r--src/components/application_manager/src/commands/command_notification_impl.cc133
2 files changed, 164 insertions, 8 deletions
diff --git a/src/components/application_manager/include/application_manager/commands/command_notification_impl.h b/src/components/application_manager/include/application_manager/commands/command_notification_impl.h
index dabbe4fe31..1de5ab8ed0 100644
--- a/src/components/application_manager/include/application_manager/commands/command_notification_impl.h
+++ b/src/components/application_manager/include/application_manager/commands/command_notification_impl.h
@@ -44,13 +44,46 @@ class CommandNotificationImpl : public CommandImpl {
public:
CommandNotificationImpl(const MessageSharedPtr& message,
ApplicationManager& application_manager);
+ /**
+ * @brief CommandNotificationImpl class destructor
+ **/
virtual ~CommandNotificationImpl();
- virtual bool Init();
- virtual bool CleanUp();
- virtual void Run();
+
+ /**
+ * @brief Init required by command resources
+ **/
+ bool Init() OVERRIDE;
+
+ /**
+ * @brief Cleanup all resources used by command
+ **/
+ bool CleanUp() OVERRIDE;
+
+ /**
+ * @brief Execute corresponding command by calling the action on reciever
+ **/
+ void Run() OVERRIDE;
+
+ /**
+ * @brief Sends notification message to Mobile
+ */
void SendNotification();
private:
+ /**
+ * @brief Checks message permissions and parameters according to policy table
+ * permissions
+ */
+ bool CheckAllowedParameters(const MessageSharedPtr message) const;
+
+ /**
+ * @brief Remove from current message parameters disallowed by policy table
+ * @param param_permissions Current message permissions structure
+ */
+ void RemoveDisallowedParameters(
+ const MessageSharedPtr message,
+ const CommandParametersPermissions& param_permissions) const;
+
DISALLOW_COPY_AND_ASSIGN(CommandNotificationImpl);
};
diff --git a/src/components/application_manager/src/commands/command_notification_impl.cc b/src/components/application_manager/src/commands/command_notification_impl.cc
index b6b0e7d500..80613f10c1 100644
--- a/src/components/application_manager/src/commands/command_notification_impl.cc
+++ b/src/components/application_manager/src/commands/command_notification_impl.cc
@@ -34,10 +34,37 @@
#include "application_manager/application_manager.h"
#include "application_manager/message_helper.h"
+#include "utils/shared_ptr.h"
+#include "utils/make_shared.h"
+
namespace application_manager {
namespace commands {
+namespace {
+
+struct ParamsDeleter {
+ ParamsDeleter(smart_objects::SmartObject& params,
+ const std::string& log_message)
+ : params_(params), log_message_(log_message) {}
+
+ void operator()(const RPCParams::value_type& value) {
+ if (params_.keyExists(value)) {
+ params_.erase(value);
+#ifdef ENABLE_LOG
+ CREATE_LOGGERPTR_LOCAL(logger, "Commands");
+ LOG4CXX_DEBUG(logger, log_message_ << value);
+#endif // ENABLE_LOG
+ }
+ }
+
+ private:
+ smart_objects::SmartObject& params_;
+ std::string log_message_;
+};
+
+} // namespace
+
CommandNotificationImpl::CommandNotificationImpl(
const MessageSharedPtr& message, ApplicationManager& application_manager)
: CommandImpl(message, application_manager) {}
@@ -52,18 +79,114 @@ bool CommandNotificationImpl::CleanUp() {
return true;
}
+bool CommandNotificationImpl::CheckAllowedParameters(
+ const MessageSharedPtr message) const {
+ LOG4CXX_AUTO_TRACE(logger_);
+
+ const uint32_t connection_key =
+ (*message)[strings::params][strings::connection_key].asUInt();
+ if (0 == connection_key) {
+ LOG4CXX_DEBUG(logger_,
+ "No app_id was specified. Parameters checking skipped");
+ return true;
+ }
+
+ const ApplicationSharedPtr app =
+ application_manager_.application(connection_key);
+ if (!app) {
+ LOG4CXX_ERROR(logger_,
+ "There is no registered application with "
+ "connection key '"
+ << connection_key << "'");
+ return false;
+ }
+
+ RPCParams params;
+
+ const smart_objects::SmartObject& s_map = (*message)[strings::msg_params];
+ if (smart_objects::SmartType_Map == s_map.getType()) {
+ smart_objects::SmartMap::const_iterator iter = s_map.map_begin();
+ smart_objects::SmartMap::const_iterator iter_end = s_map.map_end();
+
+ for (; iter != iter_end; ++iter) {
+ if (helpers::Compare<smart_objects::SmartType,
+ helpers::NEQ,
+ helpers::ALL>(iter->second.getType(),
+ smart_objects::SmartType_Null,
+ smart_objects::SmartType_Invalid)) {
+ LOG4CXX_DEBUG(logger_, "Notification param: " << iter->first);
+ params.insert(iter->first);
+ }
+ }
+ }
+
+ CommandParametersPermissions params_permissions;
+ mobile_apis::Result::eType check_result =
+ application_manager_.CheckPolicyPermissions(
+ app,
+ MessageHelper::StringifiedFunctionID(
+ static_cast<mobile_api::FunctionID::eType>(function_id())),
+ params,
+ &params_permissions);
+
+ // Check, if RPC is allowed by policy
+ if (mobile_apis::Result::SUCCESS != check_result) {
+ LOG4CXX_ERROR(logger_,
+ "Notification for app " << app->app_id()
+ << " is disallowed by Policies.");
+ return false;
+ }
+
+ // If no parameters specified in policy table, no restriction will be
+ // applied for parameters
+ if (params_permissions.allowed_params.empty() &&
+ params_permissions.disallowed_params.empty() &&
+ params_permissions.undefined_params.empty()) {
+ return true;
+ }
+
+ RemoveDisallowedParameters(message, params_permissions);
+
+ return true;
+}
+
+void CommandNotificationImpl::RemoveDisallowedParameters(
+ const MessageSharedPtr message,
+ const CommandParametersPermissions& param_permissions) const {
+ LOG4CXX_AUTO_TRACE(logger_);
+ smart_objects::SmartObject& params = (*message)[strings::msg_params];
+
+ // Remove from request all disallowed parameters
+ ParamsDeleter deleter_user(params,
+ "Following parameter is disallowed by user: ");
+ std::for_each(param_permissions.disallowed_params.begin(),
+ param_permissions.disallowed_params.end(),
+ deleter_user);
+
+ // Remove from request all undefined yet parameters
+ ParamsDeleter deleter_policy(params,
+ "Following parameter is disallowed by policy: ");
+ std::for_each(param_permissions.undefined_params.begin(),
+ param_permissions.undefined_params.end(),
+ deleter_policy);
+}
+
void CommandNotificationImpl::Run() {}
void CommandNotificationImpl::SendNotification() {
- (*message_)[strings::params][strings::protocol_type] = mobile_protocol_type_;
- (*message_)[strings::params][strings::protocol_version] = protocol_version_;
- (*message_)[strings::params][strings::message_type] =
+ MessageSharedPtr message =
+ utils::MakeShared<smart_objects::SmartObject>(*message_);
+ (*message)[strings::params][strings::protocol_type] = mobile_protocol_type_;
+ (*message)[strings::params][strings::protocol_version] = protocol_version_;
+ (*message)[strings::params][strings::message_type] =
static_cast<int32_t>(application_manager::MessageType::kNotification);
LOG4CXX_INFO(logger_, "SendNotification");
- MessageHelper::PrintSmartObject(*message_);
+ MessageHelper::PrintSmartObject(*message);
- application_manager_.SendMessageToMobile(message_);
+ if (CheckAllowedParameters(message)) {
+ application_manager_.SendMessageToMobile(message);
+ }
}
} // namespace commands