private IDictionary <string, string> GetFieldCollectionRules() { var policies = _privacyPolicyRepository.GetPolicies(_collectionName, false); var targetPolicies = new List <PrivacyPolicy>(); foreach (var policy in policies) { bool isTarget = _expressionService.Evaluate(policy.Target, _user, null, _environment); if (isTarget) { targetPolicies.Add(policy); } } var fieldCollectionRules = new Dictionary <string, string>(); foreach (var policy in targetPolicies) { foreach (var collectionField in policy.Rules) { bool isApplied = _expressionService.Evaluate(collectionField.Condition, _user, null, _environment); if (isApplied) { InsertPrivacyRule(fieldCollectionRules, collectionField.FieldEffects); } } } return(fieldCollectionRules); }
public ResponseContext ExecuteProcess(Subject subject, Resource resource, string action, EnvironmentObject environment) { environment.Data.AddAnnotation(action); _collectionPrivacyRules = GetFieldCollectionRules(subject, resource, action, environment); var recordPrivacyPolicies = _privacyPolicyRepository.GetPolicies(resource.Name, true).ToArray(); var privacyRecords = new JArray(); if (resource.Data.Length > 1000) { Parallel.ForEach(resource.Data, record => { //var privacyFields = GetPrivacyRecordField(subject, record, resource.Name, environment); //if (_collectionPrivacyRules.Count > 0) //{ PrivacyProcessing(record, _collectionPrivacyRules, subject, environment, recordPrivacyPolicies); //} }); } else { foreach (var record in resource.Data) { //var privacyFields = GetPrivacyRecordField(subject, record, resource.Name, environment); //var privacyFields = _collectionPrivacyRules.ToDictionary(entry => entry.Key, entry => entry.Value); //if (privacyFields.Count > 0) //{ PrivacyProcessing(record, _collectionPrivacyRules, subject, environment, recordPrivacyPolicies); //privacyRecords.Add(privacyRecord); //} } } //if (privacyRecords.Count == 0) // return new ResponseContext(AccessControlEffect.Permit, null, "No privacy rules is satisfied"); return(new ResponseContext(AccessControlEffect.Permit, resource.Data)); }