summaryrefslogtreecommitdiff
path: root/src/components/policy/policy_regular
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/policy/policy_regular')
-rw-r--r--src/components/policy/policy_regular/include/policy/cache_manager.h16
-rw-r--r--src/components/policy/policy_regular/include/policy/cache_manager_interface.h9
-rw-r--r--src/components/policy/policy_regular/include/policy/policy_helper.h3
-rw-r--r--src/components/policy/policy_regular/include/policy/policy_manager_impl.h3
-rw-r--r--src/components/policy/policy_regular/src/cache_manager.cc50
-rw-r--r--src/components/policy/policy_regular/src/policy_helper.cc22
-rw-r--r--src/components/policy/policy_regular/src/policy_manager_impl.cc6
-rw-r--r--src/components/policy/policy_regular/src/sql_pt_queries.cc32
8 files changed, 119 insertions, 22 deletions
diff --git a/src/components/policy/policy_regular/include/policy/cache_manager.h b/src/components/policy/policy_regular/include/policy/cache_manager.h
index c5d4c848f4..b711bf6ea2 100644
--- a/src/components/policy/policy_regular/include/policy/cache_manager.h
+++ b/src/components/policy/policy_regular/include/policy/cache_manager.h
@@ -701,6 +701,15 @@ class CacheManager : public CacheManagerInterface {
return pt_;
}
+ /**
+ * @brief OnDeviceSwitching Processes existing policy permissions for devices
+ * switching transport
+ * @param device_id_from Device ID original
+ * @param device_id_to Device ID new
+ */
+ void OnDeviceSwitching(const std::string& device_id_from,
+ const std::string& device_id_to) OVERRIDE;
+
private:
std::string currentDateTime();
struct AppHMITypeToString {
@@ -722,6 +731,13 @@ class CacheManager : public CacheManagerInterface {
void PersistData();
+ /**
+ * @brief Transform to lower case all non default application names in
+ * applications policies section
+ * @param pt polict rable for update
+ */
+ void MakeLowerCaseAppNames(policy_table::Table& pt) const;
+
void ResetCalculatedPermissions();
void AddCalculatedPermissions(const std::string& device_id,
diff --git a/src/components/policy/policy_regular/include/policy/cache_manager_interface.h b/src/components/policy/policy_regular/include/policy/cache_manager_interface.h
index 9712b799dc..9f7c7318db 100644
--- a/src/components/policy/policy_regular/include/policy/cache_manager_interface.h
+++ b/src/components/policy/policy_regular/include/policy/cache_manager_interface.h
@@ -641,6 +641,15 @@ class CacheManagerInterface {
*
*/
virtual utils::SharedPtr<policy_table::Table> pt() const = 0;
+
+ /**
+ * @brief OnDeviceSwitching Processes existing policy permissions for devices
+ * switching transport
+ * @param device_id_from Device ID original
+ * @param device_id_to Device ID new
+ */
+ virtual void OnDeviceSwitching(const std::string& device_id_from,
+ const std::string& device_id_to) = 0;
};
typedef utils::SharedPtr<CacheManagerInterface> CacheManagerInterfaceSPtr;
diff --git a/src/components/policy/policy_regular/include/policy/policy_helper.h b/src/components/policy/policy_regular/include/policy/policy_helper.h
index 996c2917d0..8a60801dd4 100644
--- a/src/components/policy/policy_regular/include/policy/policy_helper.h
+++ b/src/components/policy/policy_regular/include/policy/policy_helper.h
@@ -114,7 +114,8 @@ struct CheckAppPolicy {
const std::vector<FunctionalGroupPermission>& revoked_groups) const;
bool IsKnownAppication(const std::string& application_id) const;
void NotifySystem(const AppPoliciesValueType& app_policy) const;
- void SendPermissionsToApp(const AppPoliciesValueType& app_policy) const;
+ void SendPermissionsToApp(const std::string& app_id,
+ const policy_table::Strings& groups) const;
bool IsAppRevoked(const AppPoliciesValueType& app_policy) const;
bool NicknamesMatch(const AppPoliciesValueType& app_policy) const;
/**
diff --git a/src/components/policy/policy_regular/include/policy/policy_manager_impl.h b/src/components/policy/policy_regular/include/policy/policy_manager_impl.h
index 1b39392c0c..941db1a67f 100644
--- a/src/components/policy/policy_regular/include/policy/policy_manager_impl.h
+++ b/src/components/policy/policy_regular/include/policy/policy_manager_impl.h
@@ -553,6 +553,9 @@ class PolicyManagerImpl : public PolicyManager {
*/
void OnAppRegisteredOnMobile(const std::string& application_id) OVERRIDE;
+ void OnDeviceSwitching(const std::string& device_id_from,
+ const std::string& device_id_to) OVERRIDE;
+
/**
* @brief RetrieveCertificate Allows to obtain certificate in order
* to start secure connection.
diff --git a/src/components/policy/policy_regular/src/cache_manager.cc b/src/components/policy/policy_regular/src/cache_manager.cc
index 377278949b..94a33a1e04 100644
--- a/src/components/policy/policy_regular/src/cache_manager.cc
+++ b/src/components/policy/policy_regular/src/cache_manager.cc
@@ -83,6 +83,21 @@ struct LanguageFinder {
const std::string& language_;
};
+struct PolicyTableUpdater {
+ PolicyTableUpdater(const policy_table::ApplicationParams& default_params)
+ : default_params_(default_params) {}
+
+ void operator()(policy_table::ApplicationPolicies::value_type& pt_value) {
+ if (policy::kDefaultId == pt_value.second.get_string()) {
+ pt_value.second = default_params_;
+ pt_value.second.set_to_string(policy::kDefaultId);
+ }
+ }
+
+ private:
+ const policy_table::ApplicationParams& default_params_;
+};
+
CacheManager::CacheManager()
: CacheManagerInterface()
, pt_(new policy_table::Table)
@@ -244,6 +259,11 @@ bool CacheManager::ApplyUpdate(const policy_table::Table& update_pt) {
"");
} else {
pt_->policy_table.app_policies_section.apps[iter->first] = iter->second;
+ if (kDefaultId == iter->first) {
+ std::for_each(pt_->policy_table.app_policies_section.apps.begin(),
+ pt_->policy_table.app_policies_section.apps.end(),
+ PolicyTableUpdater(iter->second));
+ }
}
}
@@ -1398,6 +1418,27 @@ bool CacheManager::LoadFromBackup() {
return true;
}
+void CacheManager::MakeLowerCaseAppNames(policy_table::Table& pt) const {
+ policy_table::ApplicationPolicies& apps =
+ pt.policy_table.app_policies_section.apps;
+ for (policy_table::ApplicationPolicies::iterator iter = apps.begin();
+ iter != apps.end();) {
+ std::string key = iter->first;
+ if (key == kDefaultId || key == kPreDataConsentId || key == kDeviceId) {
+ ++iter;
+ continue;
+ }
+
+ std::transform(key.begin(), key.end(), key.begin(), ::tolower);
+ if (key.compare(iter->first) != 0) {
+ std::swap(apps[key], iter->second);
+ iter = apps.erase(iter);
+ } else {
+ ++iter;
+ }
+ }
+}
+
bool CacheManager::LoadFromFile(const std::string& file_name,
policy_table::Table& table) {
LOG4CXX_AUTO_TRACE(logger_);
@@ -1426,6 +1467,8 @@ bool CacheManager::LoadFromFile(const std::string& file_name,
LOG4CXX_DEBUG(logger_, "PT out:");
LOG4CXX_DEBUG(logger_, s_writer.write(table.ToJsonValue()));
+ MakeLowerCaseAppNames(table);
+
if (!table.is_valid()) {
rpc::ValidationReport report("policy_table");
table.ReportErrors(&report);
@@ -1433,6 +1476,7 @@ bool CacheManager::LoadFromFile(const std::string& file_name,
"Parsed table is not valid " << rpc::PrettyFormat(report));
return false;
}
+
return true;
}
@@ -1588,6 +1632,12 @@ const PolicySettings& CacheManager::get_settings() const {
return *settings_;
}
+void CacheManager::OnDeviceSwitching(const std::string& device_id_from,
+ const std::string& device_id_to) {
+ LOG4CXX_AUTO_TRACE(logger_);
+ LOG4CXX_INFO(logger_, "Implementation does not support user consents.");
+}
+
CacheManager::BackgroundBackuper::BackgroundBackuper(
CacheManager* cache_manager)
: cache_manager_(cache_manager)
diff --git a/src/components/policy/policy_regular/src/policy_helper.cc b/src/components/policy/policy_regular/src/policy_helper.cc
index b72a041a83..782a65f91a 100644
--- a/src/components/policy/policy_regular/src/policy_helper.cc
+++ b/src/components/policy/policy_regular/src/policy_helper.cc
@@ -267,9 +267,7 @@ void policy::CheckAppPolicy::NotifySystem(
}
void CheckAppPolicy::SendPermissionsToApp(
- const AppPoliciesValueType& app_policy) const {
- const std::string app_id = app_policy.first;
-
+ const std::string& app_id, const policy_table::Strings& groups) const {
const std::string device_id = pm_->GetCurrentDeviceId(app_id);
if (device_id.empty()) {
LOG4CXX_WARN(logger_,
@@ -281,7 +279,7 @@ void CheckAppPolicy::SendPermissionsToApp(
Permissions notification_data;
pm_->PrepareNotificationData(update_->policy_table.functional_groupings,
- app_policy.second.groups,
+ groups,
group_permissons,
notification_data);
@@ -356,6 +354,20 @@ bool CheckAppPolicy::operator()(const AppPoliciesValueType& app_policy) {
"Permissions for application:" << app_id
<< " have been changed.");
+ if (IsPredefinedApp(app_policy)) {
+ for (const policy_table::ApplicationPolicies::value_type& app :
+ snapshot_->policy_table.app_policies_section.apps) {
+ if (app_policy.first == app.second.get_string()) {
+ if (RESULT_CONSENT_NOT_REQIURED != result) {
+ SetPendingPermissions(app, result);
+ NotifySystem(app);
+ }
+ SendPermissionsToApp(app.first, app_policy.second.groups);
+ }
+ }
+ return true;
+ }
+
if (!IsPredefinedApp(app_policy) && RESULT_CONSENT_NOT_REQIURED != result) {
SetPendingPermissions(app_policy, result);
NotifySystem(app_policy);
@@ -363,7 +375,7 @@ bool CheckAppPolicy::operator()(const AppPoliciesValueType& app_policy) {
// Don't sent notification for predefined apps (e.g. default, device etc.)
if (!IsPredefinedApp(app_policy)) {
- SendPermissionsToApp(app_policy);
+ SendPermissionsToApp(app_policy.first, app_policy.second.groups);
}
return true;
}
diff --git a/src/components/policy/policy_regular/src/policy_manager_impl.cc b/src/components/policy/policy_regular/src/policy_manager_impl.cc
index 640b9c1457..055b57d985 100644
--- a/src/components/policy/policy_regular/src/policy_manager_impl.cc
+++ b/src/components/policy/policy_regular/src/policy_manager_impl.cc
@@ -366,6 +366,12 @@ void PolicyManagerImpl::OnAppRegisteredOnMobile(
SendNotificationOnPermissionsUpdated(application_id);
}
+void PolicyManagerImpl::OnDeviceSwitching(const std::string& device_id_from,
+ const std::string& device_id_to) {
+ LOG4CXX_AUTO_TRACE(logger_);
+ cache_->OnDeviceSwitching(device_id_from, device_id_to);
+}
+
const std::vector<std::string> PolicyManagerImpl::GetAppRequestTypes(
const std::string policy_app_id) const {
std::vector<std::string> request_types;
diff --git a/src/components/policy/policy_regular/src/sql_pt_queries.cc b/src/components/policy/policy_regular/src/sql_pt_queries.cc
index 7938eb4085..ef4ef49273 100644
--- a/src/components/policy/policy_regular/src/sql_pt_queries.cc
+++ b/src/components/policy/policy_regular/src/sql_pt_queries.cc
@@ -123,7 +123,7 @@ const std::string kCreateSchema =
"CREATE INDEX `rpc.select_rpc_name_hmi_level` "
" ON `rpc`(`name`,`hmi_level_value`);"
"CREATE TABLE IF NOT EXISTS `application`( "
- " `id` VARCHAR(45) PRIMARY KEY NOT NULL, "
+ " `id` VARCHAR(45) PRIMARY KEY NOT NULL COLLATE NOCASE, "
" `keep_context` BOOLEAN, "
" `steal_focus` BOOLEAN, "
" `default_hmi` VARCHAR(45), "
@@ -147,7 +147,7 @@ const std::string kCreateSchema =
"CREATE INDEX IF NOT EXISTS `application.fk_application_priorities1_idx` "
" ON `application`(`priority_value`); "
"CREATE TABLE IF NOT EXISTS `app_group`( "
- " `application_id` VARCHAR(45) NOT NULL, "
+ " `application_id` VARCHAR(45) NOT NULL COLLATE NOCASE, "
" `functional_group_id` INTEGER NOT NULL, "
" PRIMARY KEY(`application_id`,`functional_group_id`), "
" CONSTRAINT `fk_application_has_functional_group_application1` "
@@ -162,9 +162,9 @@ const std::string kCreateSchema =
" ON `app_group`(`functional_group_id`); "
"CREATE INDEX IF NOT EXISTS "
"`app_group.fk_application_has_functional_group_application1_idx` "
- " ON `app_group`(`application_id`); "
+ " ON `app_group`(`application_id` COLLATE NOCASE); "
"CREATE TABLE IF NOT EXISTS `preconsented_group`( "
- " `application_id` VARCHAR(45) NOT NULL, "
+ " `application_id` VARCHAR(45) NOT NULL COLLATE NOCASE, "
" `functional_group_id` INTEGER NOT NULL, "
" PRIMARY KEY(`application_id`,`functional_group_id`), "
" CONSTRAINT `fk_application_has_functional_group_application2` "
@@ -180,7 +180,7 @@ const std::string kCreateSchema =
" ON `preconsented_group`(`functional_group_id`); "
"CREATE INDEX IF NOT EXISTS "
"`preconsented_group.fk_application_has_functional_group_application2_idx` "
- " ON `preconsented_group`(`application_id`); "
+ " ON `preconsented_group`(`application_id` COLLATE NOCASE); "
"CREATE TABLE IF NOT EXISTS `seconds_between_retry`( "
" `index` INTEGER PRIMARY KEY NOT NULL, "
" `value` INTEGER NOT NULL "
@@ -207,7 +207,7 @@ const std::string kCreateSchema =
"`device_consent_group.fk_device_has_functional_group_device1_idx` "
" ON `device_consent_group`(`device_id`); "
"CREATE TABLE IF NOT EXISTS `app_level`( "
- " `application_id` VARCHAR(45) PRIMARY KEY NOT NULL, "
+ " `application_id` VARCHAR(45) PRIMARY KEY NOT NULL COLLATE NOCASE, "
" `minutes_in_hmi_full` INTEGER DEFAULT 0, "
" `minutes_in_hmi_limited` INTEGER DEFAULT 0, "
" `minutes_in_hmi_background` INTEGER DEFAULT 0, "
@@ -234,24 +234,24 @@ const std::string kCreateSchema =
" REFERENCES `language`(`code`) "
"); "
"CREATE INDEX IF NOT EXISTS `app_level.fk_app_levels_application1_idx` "
- " ON `app_level`(`application_id`); "
+ " ON `app_level`(`application_id` COLLATE NOCASE); "
"CREATE INDEX IF NOT EXISTS `app_level.fk_app_level_language1_idx` "
" ON `app_level`(`app_registration_language_gui`); "
"CREATE INDEX IF NOT EXISTS `app_level.fk_app_level_language2_idx` "
" ON `app_level`(`app_registration_language_vui`); "
"CREATE TABLE IF NOT EXISTS `nickname`( "
- " `name` VARCHAR(100) NOT NULL, "
- " `application_id` VARCHAR(45) NOT NULL, "
+ " `name` VARCHAR(100) NOT NULL COLLATE NOCASE, "
+ " `application_id` VARCHAR(45) NOT NULL COLLATE NOCASE, "
" PRIMARY KEY(`name`,`application_id`), "
" CONSTRAINT `fk_nickname_application1` "
" FOREIGN KEY(`application_id`) "
" REFERENCES `application`(`id`) "
"); "
"CREATE INDEX IF NOT EXISTS `nickname.fk_nickname_application1_idx` "
- " ON `nickname`(`application_id`); "
+ " ON `nickname`(`application_id` COLLATE NOCASE); "
"CREATE TABLE IF NOT EXISTS `app_type`( "
" `name` VARCHAR(50) NOT NULL, "
- " `application_id` VARCHAR(45) NOT NULL, "
+ " `application_id` VARCHAR(45) NOT NULL COLLATE NOCASE, "
" PRIMARY KEY(`name`,`application_id`), "
" CONSTRAINT `fk_app_type_application1` "
" FOREIGN KEY(`application_id`) "
@@ -259,17 +259,17 @@ const std::string kCreateSchema =
"); "
"CREATE TABLE IF NOT EXISTS `request_type`( "
" `request_type` VARCHAR(50) NOT NULL, "
- " `application_id` VARCHAR(45) NOT NULL, "
+ " `application_id` VARCHAR(45) NOT NULL COLLATE NOCASE, "
" PRIMARY KEY(`request_type`,`application_id`), "
" CONSTRAINT `fk_app_type_application1` "
" FOREIGN KEY(`application_id`) "
" REFERENCES `application`(`id`) "
"); "
"CREATE INDEX IF NOT EXISTS `app_type.fk_app_type_application1_idx` "
- " ON `app_type`(`application_id`); "
+ " ON `app_type`(`application_id` COLLATE NOCASE); "
"CREATE TABLE IF NOT EXISTS `consent_group`( "
" `device_id` VARCHAR(100) NOT NULL, "
- " `application_id` VARCHAR(45) NOT NULL, "
+ " `application_id` VARCHAR(45) NOT NULL COLLATE NOCASE, "
" `functional_group_id` INTEGER NOT NULL, "
" `is_consented` BOOL NOT NULL, "
" `input` VARCHAR(45), "
@@ -294,13 +294,13 @@ const std::string kCreateSchema =
"CREATE TABLE IF NOT EXISTS `endpoint`( "
" `service` VARCHAR(100) NOT NULL, "
" `url` VARCHAR(100) NOT NULL, "
- " `application_id` VARCHAR(45) NOT NULL, "
+ " `application_id` VARCHAR(45) NOT NULL COLLATE NOCASE, "
" CONSTRAINT `fk_endpoint_application1` "
" FOREIGN KEY(`application_id`) "
" REFERENCES `application`(`id`) "
"); "
"CREATE INDEX IF NOT EXISTS `endpoint.fk_endpoint_application1_idx` "
- " ON `endpoint`(`application_id`); "
+ " ON `endpoint`(`application_id` COLLATE NOCASE); "
"CREATE TABLE IF NOT EXISTS `message`( "
" `id` INTEGER PRIMARY KEY NOT NULL, "
" `tts` TEXT, "