summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/components/policy/src/policy/include/policy/policy_helper.h4
-rw-r--r--src/components/policy/src/policy/include/policy/policy_manager_impl.h5
-rw-r--r--src/components/policy/src/policy/src/policy_helper.cc18
-rw-r--r--src/components/policy/src/policy/src/policy_manager_impl.cc63
-rw-r--r--src/components/policy/src/policy/src/sql_pt_ext_representation.cc6
-rw-r--r--src/components/policy/src/policy/src/sql_pt_representation.cc6
6 files changed, 52 insertions, 50 deletions
diff --git a/src/components/policy/src/policy/include/policy/policy_helper.h b/src/components/policy/src/policy/include/policy/policy_helper.h
index 976efd431..04ee51be0 100644
--- a/src/components/policy/src/policy/include/policy/policy_helper.h
+++ b/src/components/policy/src/policy/include/policy/policy_helper.h
@@ -81,7 +81,8 @@ bool operator!=(const policy_table::ApplicationParams& first,
*/
struct CheckAppPolicy {
CheckAppPolicy(PolicyManagerImpl* pm,
- const utils::SharedPtr<policy_table::Table> update);
+ const utils::SharedPtr<policy_table::Table> update,
+ const utils::SharedPtr<policy_table::Table> snapshot);
bool HasSameGroups(const AppPoliciesValueType& app_policy,
AppPermissions* perms) const;
bool IsNewAppication(const std::string& application_id) const;
@@ -95,6 +96,7 @@ struct CheckAppPolicy {
private:
PolicyManagerImpl* pm_;
const utils::SharedPtr<policy_table::Table> update_;
+ const utils::SharedPtr<policy_table::Table> snapshot_;
};
/*
diff --git a/src/components/policy/src/policy/include/policy/policy_manager_impl.h b/src/components/policy/src/policy/include/policy/policy_manager_impl.h
index 922c72208..07ef8570c 100644
--- a/src/components/policy/src/policy/include/policy/policy_manager_impl.h
+++ b/src/components/policy/src/policy/include/policy/policy_manager_impl.h
@@ -162,7 +162,8 @@ class PolicyManagerImpl : public PolicyManager {
* @param Policy table update struct
*/
void CheckPermissionsChanges(
- const utils::SharedPtr<policy_table::Table> update);
+ const utils::SharedPtr<policy_table::Table> update,
+ const utils::SharedPtr<policy_table::Table> snapshot);
/**
* @brief Fill structure to be sent with OnPermissionsChanged notification
@@ -227,7 +228,6 @@ class PolicyManagerImpl : public PolicyManager {
PolicyListener* listener_;
PolicyTable policy_table_;
- utils::SharedPtr<policy_table::Table> policy_table_snapshot_;
bool exchange_in_progress_;
bool update_required_;
bool exchange_pending_;
@@ -235,6 +235,7 @@ class PolicyManagerImpl : public PolicyManager {
sync_primitives::Lock update_required_lock_;
sync_primitives::Lock exchange_pending_lock_;
sync_primitives::Lock update_request_list_lock_;
+ sync_primitives::Lock apps_registration_lock_;
std::map<std::string, AppPermissions> app_permissions_diff_;
/**
diff --git a/src/components/policy/src/policy/src/policy_helper.cc b/src/components/policy/src/policy/src/policy_helper.cc
index d7cf671ec..6c86c9b63 100644
--- a/src/components/policy/src/policy/src/policy_helper.cc
+++ b/src/components/policy/src/policy/src/policy_helper.cc
@@ -90,16 +90,18 @@ bool operator!=(const policy_table::ApplicationParams& first,
}
CheckAppPolicy::CheckAppPolicy(
- PolicyManagerImpl* pm, const utils::SharedPtr<policy_table::Table> update)
+ PolicyManagerImpl* pm,
+ const utils::SharedPtr<policy_table::Table> update,
+ const utils::SharedPtr<policy_table::Table> snapshot)
: pm_(pm),
- update_(update) {
+ update_(update),
+ snapshot_(snapshot) {
}
bool CheckAppPolicy::HasSameGroups(const AppPoliciesValueType& app_policy,
AppPermissions* perms) const {
const std::string app_id = app_policy.first;
- AppPoliciesConstItr it = pm_->policy_table_snapshot_->policy_table
- .app_policies.find(app_id);
+ AppPoliciesConstItr it = snapshot_->policy_table.app_policies.find(app_id);
if (app_policy.second.is_string()) {
return (it->second.is_string() &&
@@ -159,8 +161,8 @@ bool CheckAppPolicy::HasSameGroups(const AppPoliciesValueType& app_policy,
}
bool CheckAppPolicy::IsNewAppication(const std::string& application_id) const {
- const policy_table::ApplicationPolicies& current_policies = pm_
- ->policy_table_snapshot_->policy_table.app_policies;
+ const policy_table::ApplicationPolicies& current_policies =
+ snapshot_->policy_table.app_policies;
AppPoliciesConstItr it_app_policies_curr = current_policies.begin();
AppPoliciesConstItr it_app_policies_curr_end = current_policies.end();
@@ -270,8 +272,8 @@ bool CheckAppPolicy::NicknamesMatch(
}
bool CheckAppPolicy::operator()(const AppPoliciesValueType& app_policy) {
- policy_table::ApplicationPolicies& current_policies = pm_
- ->policy_table_snapshot_->policy_table.app_policies;
+ policy_table::ApplicationPolicies& current_policies =
+ snapshot_->policy_table.app_policies;
const std::string app_id = app_policy.first;
diff --git a/src/components/policy/src/policy/src/policy_manager_impl.cc b/src/components/policy/src/policy/src/policy_manager_impl.cc
index ac5c734e5..c6e9faaf7 100644
--- a/src/components/policy/src/policy/src/policy_manager_impl.cc
+++ b/src/components/policy/src/policy/src/policy_manager_impl.cc
@@ -118,17 +118,7 @@ bool PolicyManagerImpl::LoadPTFromFile(const std::string& file_name) {
final_result = final_result && policy_table_.pt_data()->Save(*table);
LOG4CXX_INFO(
logger_,
- "Loading from file was " << (final_result ? "successful" : "unsuccessful"));
-
- // Initial setting of snapshot data
- if (policy_table_.pt_data()->IsPTPreloaded() && !policy_table_snapshot_) {
- policy_table_snapshot_ = policy_table_.pt_data()->GenerateSnapshot();
- if (!policy_table_snapshot_) {
- LOG4CXX_WARN(logger_,
- "Failed to create initial snapshot of policy table");
- return false;
- }
- }
+ "Loading from file was " << (final_result ? "successful" : "unsuccessful"));
RefreshRetrySequence();
return final_result;
@@ -172,30 +162,40 @@ bool PolicyManagerImpl::LoadPT(const std::string& file,
return false;
}
+ sync_primitives::AutoLock lock(apps_registration_lock_);
+
+ // Get current DB data, since it could be updated during awaiting of PTU
+ utils::SharedPtr<policy_table::Table> policy_table_snapshot =
+ policy_table_.pt_data()->GenerateSnapshot();
+ if (!policy_table_snapshot) {
+ LOG4CXX_ERROR(logger_, "Failed to create snapshot of policy table");
+ return false;
+ }
+
// Replace predefined policies with its actual setting, e.g. "123":"default"
// to actual values of default section
UnwrapAppPolicies(pt_update->policy_table.app_policies);
// Check and update permissions for applications, send notifications
- CheckPermissionsChanges(pt_update);
+ CheckPermissionsChanges(pt_update, policy_table_snapshot);
// Replace current data with updated
- policy_table_snapshot_->policy_table.functional_groupings = pt_update
+ policy_table_snapshot->policy_table.functional_groupings = pt_update
->policy_table.functional_groupings;
- policy_table_snapshot_->policy_table.module_config = pt_update->policy_table
+ policy_table_snapshot->policy_table.module_config = pt_update->policy_table
.module_config;
bool is_message_part_updated = pt_update->policy_table
.consumer_friendly_messages.is_initialized();
if (is_message_part_updated) {
- policy_table_snapshot_->policy_table.consumer_friendly_messages->messages =
+ policy_table_snapshot->policy_table.consumer_friendly_messages->messages =
pt_update->policy_table.consumer_friendly_messages->messages;
}
// Save data to DB
- if (!policy_table_.pt_data()->Save(*policy_table_snapshot_)) {
+ if (!policy_table_.pt_data()->Save(*policy_table_snapshot)) {
LOG4CXX_WARN(logger_, "Unsuccessful save of updated policy table.");
return false;
}
@@ -227,12 +227,13 @@ bool PolicyManagerImpl::LoadPT(const std::string& file,
}
void PolicyManagerImpl::CheckPermissionsChanges(
- const utils::SharedPtr<policy_table::Table> pt_update) {
+ const utils::SharedPtr<policy_table::Table> pt_update,
+ const utils::SharedPtr<policy_table::Table> snapshot) {
LOG4CXX_INFO(logger_, "Checking incoming permissions.");
std::for_each(pt_update->policy_table.app_policies.begin(),
pt_update->policy_table.app_policies.end(),
- CheckAppPolicy(this, pt_update));
+ CheckAppPolicy(this, pt_update, snapshot));
}
void PolicyManagerImpl::PrepareNotificationData(
@@ -317,30 +318,13 @@ EndpointUrls PolicyManagerImpl::GetUpdateUrls(int service_type) {
BinaryMessageSptr PolicyManagerImpl::RequestPTUpdate() {
LOG4CXX_INFO(logger_, "Creating PT Snapshot");
- policy_table_snapshot_ = policy_table_.pt_data()->GenerateSnapshot();
- if (!policy_table_snapshot_) {
+ utils::SharedPtr<policy_table::Table> policy_table_snapshot =
+ policy_table_.pt_data()->GenerateSnapshot();
+ if (!policy_table_snapshot) {
LOG4CXX_ERROR(logger_, "Failed to create snapshot of policy table");
return NULL;
}
- policy_table::ApplicationPolicies& apps = policy_table_snapshot_->
- policy_table.app_policies;
- std::map<std::string,
- rpc::Stringifyable<rpc::Nullable<
- rpc::policy_table_interface_base::ApplicationParams>>>::iterator it =
- apps.begin();
- // TODO(AOleynik): Should we check here for 'device' also?
- for (; apps.end() != it; ++it) {
- if (policy_table_.pt_data()->IsDefaultPolicy(it->first)) {
- it->second.set_to_string(kDefaultId);
- continue;
- }
- if (policy_table_.pt_data()->IsPredataPolicy(it->first)) {
- it->second.set_to_string(kPreDataConsentId);
- continue;
- }
- }
-
set_exchange_in_progress(true);
if (!exchange_pending_) {
set_update_required(false);
@@ -355,7 +339,7 @@ BinaryMessageSptr PolicyManagerImpl::RequestPTUpdate() {
}
#endif // EXTENDED_POLICY
- Json::Value value = policy_table_snapshot_->ToJsonValue();
+ Json::Value value = policy_table_snapshot->ToJsonValue();
Json::FastWriter writer;
std::string message_string = writer.write(value);
return new BinaryMessage(message_string.begin(), message_string.end());
@@ -461,6 +445,7 @@ void PolicyManagerImpl::CheckAppPolicyState(const std::string& application_id) {
LOG4CXX_INFO(logger_, "CheckAppPolicyState");
const std::string device_id = GetCurrentDeviceId(application_id);
DeviceConsent device_consent = GetUserConsentForDevice(device_id);
+ sync_primitives::AutoLock lock(apps_registration_lock_);
if (!policy_table_.pt_data()->IsApplicationRepresented(application_id)) {
LOG4CXX_INFO(
logger_,
diff --git a/src/components/policy/src/policy/src/sql_pt_ext_representation.cc b/src/components/policy/src/policy/src/sql_pt_ext_representation.cc
index 1d0d87d6c..36028b0b4 100644
--- a/src/components/policy/src/policy/src/sql_pt_ext_representation.cc
+++ b/src/components/policy/src/policy/src/sql_pt_ext_representation.cc
@@ -709,6 +709,12 @@ bool SQLPTExtRepresentation::GatherApplicationPolicies(
(*apps)[app_id] = params;
continue;
}
+ if (IsDefaultPolicy(app_id)) {
+ (*apps)[app_id].set_to_string(kDefaultId);
+ }
+ if (IsPredataPolicy(app_id)) {
+ (*apps)[app_id].set_to_string(kPreDataConsentId);
+ }
policy_table::Priority priority;
policy_table::EnumFromJsonString(query.GetString(1), &priority);
params.priority = priority;
diff --git a/src/components/policy/src/policy/src/sql_pt_representation.cc b/src/components/policy/src/policy/src/sql_pt_representation.cc
index 2c6f936e3..bcb1d0ddd 100644
--- a/src/components/policy/src/policy/src/sql_pt_representation.cc
+++ b/src/components/policy/src/policy/src/sql_pt_representation.cc
@@ -566,6 +566,12 @@ bool SQLPTRepresentation::GatherApplicationPolicies(
(*apps)[app_id] = params;
continue;
}
+ if (IsDefaultPolicy(app_id)) {
+ (*apps)[app_id].set_to_string(kDefaultId);
+ }
+ if (IsPredataPolicy(app_id)) {
+ (*apps)[app_id].set_to_string(kPreDataConsentId);
+ }
policy_table::Priority priority;
policy_table::EnumFromJsonString(query.GetString(1), &priority);
params.priority = priority;