summaryrefslogtreecommitdiff
path: root/src/components/policy/policy_external/src/policy_helper.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/policy/policy_external/src/policy_helper.cc')
-rw-r--r--src/components/policy/policy_external/src/policy_helper.cc157
1 files changed, 140 insertions, 17 deletions
diff --git a/src/components/policy/policy_external/src/policy_helper.cc b/src/components/policy/policy_external/src/policy_helper.cc
index bb0a36df68..99e4450065 100644
--- a/src/components/policy/policy_external/src/policy_helper.cc
+++ b/src/components/policy/policy_external/src/policy_helper.cc
@@ -46,7 +46,8 @@ namespace {
CREATE_LOGGERPTR_GLOBAL(logger_, "Policy")
-bool Compare(const StringsValueType& first, const StringsValueType& second) {
+bool CompareStrings(const StringsValueType& first,
+ const StringsValueType& second) {
const std::string& first_str = first;
const std::string& second_str = second;
return (strcasecmp(first_str.c_str(), second_str.c_str()) < 0);
@@ -137,10 +138,10 @@ bool policy::CheckAppPolicy::HasRevokedGroups(
snapshot_->policy_table.app_policies_section.apps.find(app_policy.first);
policy_table::Strings groups_new = app_policy.second.groups;
- std::sort(groups_new.begin(), groups_new.end(), Compare);
+ std::sort(groups_new.begin(), groups_new.end(), CompareStrings);
policy_table::Strings groups_curr = (*it).second.groups;
- std::sort(groups_curr.begin(), groups_curr.end(), Compare);
+ std::sort(groups_curr.begin(), groups_curr.end(), CompareStrings);
StringsConstItr it_groups_new = groups_new.begin();
StringsConstItr it_groups_new_end = groups_new.end();
@@ -154,7 +155,7 @@ bool policy::CheckAppPolicy::HasRevokedGroups(
it_groups_new,
it_groups_new_end,
std::back_inserter(revoked_group_list),
- Compare);
+ CompareStrings);
// Remove groups which are not required user consent
policy_table::Strings::iterator it_revoked = revoked_group_list.begin();
@@ -174,6 +175,76 @@ bool policy::CheckAppPolicy::HasRevokedGroups(
return !revoked_group_list.empty();
}
+bool policy::CheckAppPolicy::HasUpdatedGroups(
+ const policy::AppPoliciesValueType& app_policy,
+ policy_table::Strings* updated_groups) const {
+ AppPoliciesConstItr it =
+ snapshot_->policy_table.app_policies_section.apps.find(app_policy.first);
+
+ policy_table::Strings groups_new = app_policy.second.groups;
+ std::sort(groups_new.begin(), groups_new.end(), CompareStrings);
+
+ policy_table::Strings groups_curr = (*it).second.groups;
+ std::sort(groups_curr.begin(), groups_curr.end(), CompareStrings);
+
+ policy_table::Strings intersection_list;
+ std::set_intersection(groups_new.begin(),
+ groups_new.end(),
+ groups_curr.begin(),
+ groups_curr.end(),
+ std::back_inserter(intersection_list));
+
+ auto IsGroupContentUpdated =
+ [this](const StringsValueType& groupName) -> bool {
+ const auto& func_group_from_update =
+ update_->policy_table.functional_groupings.find(groupName);
+ const auto& func_group_from_snapshot =
+ snapshot_->policy_table.functional_groupings.find(groupName);
+
+ const auto& update_fg_rpcs = func_group_from_update->second.rpcs;
+ const auto& snapshot_fg_rpcs = func_group_from_snapshot->second.rpcs;
+
+ if (update_fg_rpcs.is_null() || snapshot_fg_rpcs.is_null()) {
+ return !(update_fg_rpcs.is_null() && snapshot_fg_rpcs.is_null());
+ }
+
+ if (update_fg_rpcs.size() != snapshot_fg_rpcs.size()) {
+ return true;
+ }
+
+ for (const auto& rpc : update_fg_rpcs) {
+ const auto& old_rpc = snapshot_fg_rpcs.find(rpc.first);
+ if (snapshot_fg_rpcs.end() == old_rpc) {
+ return true;
+ }
+
+ const bool hmi_levels_same =
+ old_rpc->second.hmi_levels == rpc.second.hmi_levels;
+ const bool parameters_same =
+ *(old_rpc->second.parameters) == *(rpc.second.parameters);
+
+ if (!hmi_levels_same || !parameters_same) {
+ return true;
+ }
+ }
+
+ return false;
+ };
+
+ policy_table::Strings updated_group_list;
+ for (const auto& item : intersection_list) {
+ if (IsGroupContentUpdated(item)) {
+ updated_group_list.push_back(item);
+ }
+ }
+
+ if (updated_groups) {
+ *updated_groups = updated_group_list;
+ }
+
+ return !updated_group_list.empty();
+}
+
bool policy::CheckAppPolicy::HasNewGroups(
const policy::AppPoliciesValueType& app_policy,
policy_table::Strings* new_groups) const {
@@ -181,10 +252,10 @@ bool policy::CheckAppPolicy::HasNewGroups(
snapshot_->policy_table.app_policies_section.apps.find(app_policy.first);
policy_table::Strings groups_new = app_policy.second.groups;
- std::sort(groups_new.begin(), groups_new.end(), Compare);
+ std::sort(groups_new.begin(), groups_new.end(), CompareStrings);
policy_table::Strings groups_curr = (*it).second.groups;
- std::sort(groups_curr.begin(), groups_curr.end(), Compare);
+ std::sort(groups_curr.begin(), groups_curr.end(), CompareStrings);
StringsConstItr it_groups_new = groups_new.begin();
StringsConstItr it_groups_new_end = groups_new.end();
@@ -192,13 +263,55 @@ bool policy::CheckAppPolicy::HasNewGroups(
StringsConstItr it_groups_curr = groups_curr.begin();
StringsConstItr it_groups_curr_end = groups_curr.end();
+ auto CompareGroupContent =
+ [this](const StringsValueType& update_group_name,
+ const StringsValueType& snapshot_group_name) -> bool {
+ if (CompareStrings(update_group_name, snapshot_group_name)) {
+ return true;
+ }
+
+ const auto& func_group_from_update =
+ update_->policy_table.functional_groupings.find(update_group_name);
+ const auto& func_group_from_snapshot =
+ snapshot_->policy_table.functional_groupings.find(snapshot_group_name);
+
+ const auto& update_fg_rpcs = func_group_from_update->second.rpcs;
+ const auto& snapshot_fg_rpcs = func_group_from_snapshot->second.rpcs;
+
+ if (update_fg_rpcs.is_null() || snapshot_fg_rpcs.is_null()) {
+ return !(update_fg_rpcs.is_null() && snapshot_fg_rpcs.is_null());
+ }
+
+ if (update_fg_rpcs.size() != snapshot_fg_rpcs.size()) {
+ return true;
+ }
+
+ for (const auto& rpc : update_fg_rpcs) {
+ const auto& old_rpc = snapshot_fg_rpcs.find(rpc.first);
+ if (snapshot_fg_rpcs.end() == old_rpc) {
+ return true;
+ }
+
+ const bool hmi_levels_same =
+ old_rpc->second.hmi_levels == rpc.second.hmi_levels;
+ const bool parameters_same =
+ *(old_rpc->second.parameters) == *(rpc.second.parameters);
+
+ if (!hmi_levels_same || !parameters_same) {
+ return true;
+ }
+ }
+
+ return false;
+ };
+
policy_table::Strings new_group_list;
std::set_difference(it_groups_new,
it_groups_new_end,
it_groups_curr,
it_groups_curr_end,
std::back_inserter(new_group_list),
- Compare);
+ CompareGroupContent);
if (new_groups) {
*new_groups = new_group_list;
@@ -210,14 +323,23 @@ bool policy::CheckAppPolicy::HasNewGroups(
bool policy::CheckAppPolicy::HasConsentNeededGroups(
const policy::AppPoliciesValueType& app_policy) const {
policy_table::Strings new_groups;
- if (!HasNewGroups(app_policy, &new_groups)) {
+ policy_table::Strings updated_groups;
+ if (!HasNewGroups(app_policy, &new_groups) &&
+ !HasUpdatedGroups(app_policy, &updated_groups)) {
return false;
}
- StringsConstItr it_new = new_groups.begin();
- StringsConstItr it_new_end = new_groups.end();
- for (; it_new != it_new_end; ++it_new) {
- if (IsConsentRequired(app_policy.first, *it_new)) {
+ policy_table::Strings groups_to_check_consent;
+ std::set_union(new_groups.begin(),
+ new_groups.end(),
+ updated_groups.begin(),
+ updated_groups.end(),
+ std::back_inserter(groups_to_check_consent));
+
+ StringsConstItr it = groups_to_check_consent.begin();
+ StringsConstItr it_end = groups_to_check_consent.end();
+ for (; it != it_end; ++it) {
+ if (IsConsentRequired(app_policy.first, *it)) {
return true;
}
}
@@ -454,14 +576,16 @@ PermissionsCheckResult CheckAppPolicy::CheckPermissionsChanges(
const bool encryption_required_flag_changed =
IsEncryptionRequiredFlagChanged(app_policy);
+ bool has_updated_groups = HasUpdatedGroups(app_policy);
+
if (has_revoked_groups && has_consent_needed_groups) {
return RESULT_PERMISSIONS_REVOKED_AND_CONSENT_NEEDED;
} else if (has_revoked_groups) {
return RESULT_PERMISSIONS_REVOKED;
} else if (has_consent_needed_groups) {
return RESULT_CONSENT_NEEDED;
- } else if (has_new_groups) {
- return RESULT_CONSENT_NOT_REQIURED;
+ } else if (has_new_groups || has_updated_groups) {
+ return RESULT_CONSENT_NOT_REQUIRED;
} else if (encryption_required_flag_changed) {
return RESULT_ENCRYPTION_REQUIRED_FLAG_CHANGED;
}
@@ -654,7 +778,7 @@ void FillActionsForAppPolicies::operator()(
case RESULT_PERMISSIONS_REVOKED_AND_CONSENT_NEEDED:
actions_[app_id].is_consent_needed = true;
break;
- case RESULT_CONSENT_NOT_REQIURED:
+ case RESULT_CONSENT_NOT_REQUIRED:
case RESULT_PERMISSIONS_REVOKED:
case RESULT_REQUEST_TYPE_CHANGED:
case RESULT_REQUEST_SUBTYPE_CHANGED:
@@ -762,8 +886,7 @@ void FillNotificationData::UpdateParameters(
}
for (; it_parameters != it_parameters_end; ++it_parameters) {
- out_parameter[current_key_].insert(
- policy_table::EnumToJsonString(*it_parameters));
+ out_parameter[current_key_].insert(*it_parameters);
}
// We should reset ALL DISALLOWED flags if at least one parameter is allowed