diff options
Diffstat (limited to 'src/components/policy/policy_regular/src')
3 files changed, 152 insertions, 46 deletions
diff --git a/src/components/policy/policy_regular/src/cache_manager.cc b/src/components/policy/policy_regular/src/cache_manager.cc index 743b9eff6c..7a6f98f536 100644 --- a/src/components/policy/policy_regular/src/cache_manager.cc +++ b/src/components/policy/policy_regular/src/cache_manager.cc @@ -766,35 +766,55 @@ void CacheManager::GetEnabledCloudApps( #endif // CLOUD_APP_WEBSOCKET_TRANSPORT_SUPPORT } -bool CacheManager::GetCloudAppParameters( - const std::string& policy_app_id, - bool& enabled, - std::string& endpoint, - std::string& certificate, - std::string& auth_token, - std::string& cloud_transport_type, - std::string& hybrid_app_preference) const { +std::vector<std::string> CacheManager::GetEnabledLocalApps() const { +#if !defined(WEBSOCKET_SERVER_TRANSPORT_SUPPORT) + return std::vector<std::string>(); +#else + std::vector<std::string> enabled_apps; + const policy_table::ApplicationPolicies& app_policies = + pt_->policy_table.app_policies_section.apps; + for (const auto& app_policies_item : app_policies) { + const auto app_policy = app_policies_item.second; + // Local (WebEngine) applications + // should not have "endpoint" field + if (app_policy.endpoint.is_initialized()) { + continue; + } + if (app_policy.enabled.is_initialized() && *app_policy.enabled) { + enabled_apps.push_back(app_policies_item.first); + } + } + return enabled_apps; +#endif // WEBSOCKET_SERVER_TRANSPORT_SUPPORT +} + +bool CacheManager::GetAppProperties(const std::string& policy_app_id, + AppProperties& out_app_properties) const { const policy_table::ApplicationPolicies& policies = pt_->policy_table.app_policies_section.apps; policy_table::ApplicationPolicies::const_iterator policy_iter = policies.find(policy_app_id); if (policies.end() != policy_iter) { auto app_policy = (*policy_iter).second; - endpoint = app_policy.endpoint.is_initialized() ? *app_policy.endpoint - : std::string(); - auth_token = app_policy.auth_token.is_initialized() ? *app_policy.auth_token - : std::string(); - cloud_transport_type = app_policy.cloud_transport_type.is_initialized() - ? *app_policy.cloud_transport_type - : std::string(); - certificate = app_policy.certificate.is_initialized() - ? *app_policy.certificate - : std::string(); - hybrid_app_preference = + out_app_properties.endpoint = app_policy.endpoint.is_initialized() + ? *app_policy.endpoint + : std::string(); + out_app_properties.auth_token = app_policy.auth_token.is_initialized() + ? *app_policy.auth_token + : std::string(); + out_app_properties.transport_type = + app_policy.cloud_transport_type.is_initialized() + ? *app_policy.cloud_transport_type + : std::string(); + out_app_properties.certificate = app_policy.certificate.is_initialized() + ? *app_policy.certificate + : std::string(); + out_app_properties.hybrid_app_preference = app_policy.hybrid_app_preference.is_initialized() ? EnumToJsonString(*app_policy.hybrid_app_preference) : std::string(); - enabled = app_policy.enabled.is_initialized() && *app_policy.enabled; + out_app_properties.enabled = + app_policy.enabled.is_initialized() && *app_policy.enabled; return true; } return false; diff --git a/src/components/policy/policy_regular/src/policy_helper.cc b/src/components/policy/policy_regular/src/policy_helper.cc index b689ed81ba..08f1fbb177 100644 --- a/src/components/policy/policy_regular/src/policy_helper.cc +++ b/src/components/policy/policy_regular/src/policy_helper.cc @@ -388,6 +388,12 @@ void CheckAppPolicy::AddResult(const std::string& app_id, bool CheckAppPolicy::operator()(const AppPoliciesValueType& app_policy) { const std::string app_id = app_policy.first; + const bool app_properties_changed = IsAppPropertiesChanged(app_policy); + const bool is_predefined_app = IsPredefinedApp(app_policy); + if (!is_predefined_app && app_properties_changed) { + AddResult(app_id, RESULT_APP_PROPERTIES_CHANGED); + } + if (!IsKnownAppication(app_id)) { LOG4CXX_WARN(logger_, "Application:" << app_id << " is not present in snapshot."); @@ -608,6 +614,74 @@ bool CheckAppPolicy::IsRequestSubTypeChanged( return diff.size(); } +bool CheckAppPolicy::IsAppPropertiesProvided( + const AppPoliciesValueType& app_policy) const { + LOG4CXX_AUTO_TRACE(logger_); + if (app_policy.second.hybrid_app_preference.is_initialized() || + app_policy.second.endpoint.is_initialized() || + app_policy.second.enabled.is_initialized() || + app_policy.second.auth_token.is_initialized() || + app_policy.second.cloud_transport_type.is_initialized() || + app_policy.second.nicknames.is_initialized()) { + return true; + } + return false; +} + +bool CheckAppPolicy::IsAppPropertiesChanged( + const AppPoliciesValueType& app_policy) const { + LOG4CXX_AUTO_TRACE(logger_); + + if (!IsAppPropertiesProvided(app_policy)) { + return false; + } + + if (!IsKnownAppication(app_policy.first)) { + LOG4CXX_DEBUG( + logger_, + "AppProperties provided for new application: " << app_policy.first); + return true; + } + + policy::AppPoliciesConstItr it = + snapshot_->policy_table.app_policies_section.apps.find(app_policy.first); + const auto snapshot_properties = *it; + + if (app_policy.second.enabled.is_initialized() && + app_policy.second.enabled != snapshot_properties.second.enabled) { + LOG4CXX_DEBUG(logger_, "\"enabled\" was changed"); + return true; + } + + if (app_policy.second.endpoint.is_initialized() && + app_policy.second.endpoint != snapshot_properties.second.endpoint) { + LOG4CXX_DEBUG(logger_, "\"endpoint\" was changed"); + return true; + } + + if (app_policy.second.hybrid_app_preference.is_initialized() && + app_policy.second.hybrid_app_preference != + snapshot_properties.second.hybrid_app_preference) { + LOG4CXX_DEBUG(logger_, "\"hybrid_app_preference\" was changed"); + return true; + } + + if (app_policy.second.auth_token.is_initialized() && + app_policy.second.auth_token != snapshot_properties.second.auth_token) { + LOG4CXX_DEBUG(logger_, "\"auth_token\" was changed"); + return true; + } + + if (app_policy.second.cloud_transport_type.is_initialized() && + app_policy.second.cloud_transport_type != + snapshot_properties.second.cloud_transport_type) { + LOG4CXX_DEBUG(logger_, "\"cloud_transport_type\" was changed"); + return true; + } + + return false; +} + bool CheckAppPolicy::IsEncryptionRequiredFlagChanged( const AppPoliciesValueType& app_policy) const { auto get_app_encryption_needed = @@ -699,7 +773,6 @@ void FillActionsForAppPolicies::operator()( const policy::CheckAppPolicyResults::value_type& value) { const std::string app_id = value.first; const auto app_policy = app_policies_.find(app_id); - if (app_policies_.end() == app_policy) { return; } @@ -717,6 +790,9 @@ void FillActionsForAppPolicies::operator()( case RESULT_PERMISSIONS_REVOKED_AND_CONSENT_NEEDED: actions_[app_id].is_consent_needed = true; break; + case RESULT_APP_PROPERTIES_CHANGED: + actions_[app_id].app_properties_changed = true; + break; case RESULT_CONSENT_NOT_REQUIRED: case RESULT_PERMISSIONS_REVOKED: case RESULT_REQUEST_TYPE_CHANGED: 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 22205763a9..ff1ed5d5a9 100644 --- a/src/components/policy/policy_regular/src/policy_manager_impl.cc +++ b/src/components/policy/policy_regular/src/policy_manager_impl.cc @@ -466,6 +466,10 @@ void PolicyManagerImpl::ProcessActionsForAppPolicies( continue; } + if (it_actions->second.app_properties_changed) { + app_properties_changed_list_.push_back(app_policy->first); + } + const auto devices_ids = listener()->GetDevicesIds(app_policy->first); for (const auto& device_id : devices_ids) { if (it_actions->second.is_consent_needed) { @@ -493,6 +497,12 @@ void PolicyManagerImpl::ProcessActionsForAppPolicies( } } +void PolicyManagerImpl::SendOnAppPropertiesChangeNotification( + const std::string& policy_app_id) const { + LOG4CXX_AUTO_TRACE(logger_); + listener_->SendOnAppPropertiesChangeNotification(policy_app_id); +} + void PolicyManagerImpl::ResumePendingAppPolicyActions() { LOG4CXX_AUTO_TRACE(logger_); @@ -505,6 +515,11 @@ void PolicyManagerImpl::ResumePendingAppPolicyActions() { SendPermissionsToApp(send_permissions_params.first, send_permissions_params.second); } + + for (auto& app : app_properties_changed_list_) { + SendOnAppPropertiesChangeNotification(app); + } + send_permissions_list_.clear(); } @@ -681,6 +696,12 @@ void PolicyManagerImpl::OnAppsSearchCompleted(const bool trigger_ptu) { } } +void PolicyManagerImpl::OnLocalAppAdded() { + LOG4CXX_AUTO_TRACE(logger_); + update_status_manager_.ScheduleUpdate(); + StartPTExchange(); +} + void PolicyManagerImpl::OnAppRegisteredOnMobile( const std::string& device_id, const std::string& application_id) { StartPTExchange(); @@ -737,21 +758,13 @@ void PolicyManagerImpl::GetEnabledCloudApps( cache_->GetEnabledCloudApps(enabled_apps); } -bool PolicyManagerImpl::GetCloudAppParameters( - const std::string& policy_app_id, - bool& enabled, - std::string& endpoint, - std::string& certificate, - std::string& auth_token, - std::string& cloud_transport_type, - std::string& hybrid_app_preference) const { - return cache_->GetCloudAppParameters(policy_app_id, - enabled, - endpoint, - certificate, - auth_token, - cloud_transport_type, - hybrid_app_preference); +std::vector<std::string> PolicyManagerImpl::GetEnabledLocalApps() const { + return cache_->GetEnabledLocalApps(); +} + +bool PolicyManagerImpl::GetAppProperties( + const std::string& policy_app_id, AppProperties& out_app_properties) const { + return cache_->GetAppProperties(policy_app_id, out_app_properties); } void PolicyManagerImpl::InitCloudApp(const std::string& policy_app_id) { @@ -1580,10 +1593,10 @@ bool PolicyManagerImpl::InitPT(const std::string& file_name, if (!certificate_data.empty()) { listener_->OnCertificateUpdated(certificate_data); } - std::vector<std::string> enabled_apps; - cache_->GetEnabledCloudApps(enabled_apps); - for (auto it = enabled_apps.begin(); it != enabled_apps.end(); ++it) { - SendAuthTokenUpdated(*it); + std::vector<std::string> enabled_cloud_apps; + cache_->GetEnabledCloudApps(enabled_cloud_apps); + for (auto app : enabled_cloud_apps) { + SendAuthTokenUpdated(app); } } return ret; @@ -1734,12 +1747,9 @@ void PolicyManagerImpl::SendAppPermissionsChanged( } void PolicyManagerImpl::SendAuthTokenUpdated(const std::string policy_app_id) { - bool enabled = false; - std::string end, cert, ctt, hap; - std::string auth_token; - cache_->GetCloudAppParameters( - policy_app_id, enabled, end, cert, auth_token, ctt, hap); - listener_->OnAuthTokenUpdated(policy_app_id, auth_token); + AppProperties app_properties; + cache_->GetAppProperties(policy_app_id, app_properties); + listener_->OnAuthTokenUpdated(policy_app_id, app_properties.auth_token); } void PolicyManagerImpl::OnPrimaryGroupsChanged( |