protected override bool EvaluateMatch(Tuple <TransportRule, XDocument> rulePackDataObject, Func <string, CultureInfo, CompareOptions, bool> objectPropertyMatchOperator)
        {
            ExAssert.RetailAssert(rulePackDataObject != null && rulePackDataObject.Item1 != null && rulePackDataObject.Item2 != null, "The rule pack data object passed to the name matcher must not be null");
            bool flag = false;

            DlpUtils.DataClassificationQueryContext dataClassificationQueryContext = new DlpUtils.DataClassificationQueryContext(rulePackDataObject.Item1.OrganizationId, ClassificationDefinitionsDiagnosticsReporter.Instance)
            {
                CurrentRuleCollectionTransportRuleObject = rulePackDataObject.Item1,
                CurrentRuleCollectionXDoc = rulePackDataObject.Item2
            };
            XElement operationArgument;

            if (!DlpUtils.TryExecuteOperation <XmlException, XDocument, XElement>(dataClassificationQueryContext, new Func <XDocument, XElement>(XmlProcessingUtils.GetRulePackageMetadataElement), dataClassificationQueryContext.CurrentRuleCollectionXDoc, out operationArgument))
            {
                return(flag);
            }
            ClassificationRuleCollectionLocalizableDetails classificationRuleCollectionLocalizableDetails;

            if (!DlpUtils.TryExecuteOperation <XmlException, XElement, ClassificationRuleCollectionLocalizableDetails>(dataClassificationQueryContext, new Func <XElement, ClassificationRuleCollectionLocalizableDetails>(XmlProcessingUtils.ReadDefaultRulePackageMetadata), operationArgument, out classificationRuleCollectionLocalizableDetails))
            {
                return(flag);
            }
            flag = objectPropertyMatchOperator(classificationRuleCollectionLocalizableDetails.Name, classificationRuleCollectionLocalizableDetails.Culture, CompareOptions.IgnoreCase);
            if (!flag)
            {
                Dictionary <CultureInfo, ClassificationRuleCollectionLocalizableDetails> source;
                if (!DlpUtils.TryExecuteOperation <XmlException, XElement, Dictionary <CultureInfo, ClassificationRuleCollectionLocalizableDetails> >(dataClassificationQueryContext, new Func <XElement, Dictionary <CultureInfo, ClassificationRuleCollectionLocalizableDetails> >(XmlProcessingUtils.ReadAllRulePackageMetadata), operationArgument, out source))
                {
                    return(flag);
                }
                flag = source.Any((KeyValuePair <CultureInfo, ClassificationRuleCollectionLocalizableDetails> localizedDetail) => objectPropertyMatchOperator(localizedDetail.Value.Name, localizedDetail.Key, CompareOptions.IgnoreCase));
            }
            return(flag);
        }
示例#2
0
        private static void EnsureResultsIntegrity(DlpUtils.DataClassificationQueryContext queryContext, QueryMatchResult queryMatchResult, Dictionary <string, DataClassificationPresentationObject> allQueryResultsDictionary, ClassificationRuleCollectionPresentationObject currentRulePackagePresentationObject)
        {
            DataClassificationPresentationObject dataClassificationPresentationObject;

            if (!allQueryResultsDictionary.TryGetValue(queryMatchResult.MatchingRuleId, out dataClassificationPresentationObject))
            {
                return;
            }
            if (ClassificationDefinitionConstants.RuleCollectionIdComparer.Equals(dataClassificationPresentationObject.ClassificationRuleCollection.Name, currentRulePackagePresentationObject.Name))
            {
                throw new ArgumentException(Strings.DataClassificationNonUniqueQuery(dataClassificationPresentationObject.LocalizedName, dataClassificationPresentationObject.Identity.ToString(), dataClassificationPresentationObject.ClassificationRuleCollection.Name));
            }
            queryContext.CurrentDiagnosticsReporter.WriteDuplicateRuleIdAcrossRulePacksDiagnosticsInformation(0, queryContext.CurrentOrganizationId, dataClassificationPresentationObject.ClassificationRuleCollection.DistinguishedName, queryContext.CurrentRuleCollectionTransportRuleObject.DistinguishedName, queryMatchResult.MatchingRuleId);
            throw new ArgumentException(Strings.DataClassificationAmbiguousIdentity(queryMatchResult.QueryString, currentRulePackagePresentationObject.Name, dataClassificationPresentationObject.LocalizedName, dataClassificationPresentationObject.Identity.ToString(), dataClassificationPresentationObject.ClassificationRuleCollection.Name));
        }
示例#3
0
        private static bool PopulateMatchResults(DlpUtils.DataClassificationQueryContext queryContext, Dictionary <string, DataClassificationPresentationObject> queriedNameDictionary, IEnumerable <QueryMatchResult> nameMatchResultsFromCurrentRulePack, Dictionary <string, DataClassificationPresentationObject> queriedGuidDictionary, IEnumerable <QueryMatchResult> idMatchResultsFromCurrentRulePack, Dictionary <string, DataClassificationPresentationObject> allQueryResultsDictionary)
        {
            ClassificationRuleCollectionPresentationObject classificationRuleCollectionPresentationObject;

            if (!DlpUtils.CreateClassificationRuleCollectionPresentationObject(queryContext, out classificationRuleCollectionPresentationObject))
            {
                return(false);
            }
            List <Tuple <QueryMatchResult, DataClassificationPresentationObject> > list;

            if (!DlpUtils.CreateDataClassificationPresentationObjects(queryContext, classificationRuleCollectionPresentationObject, nameMatchResultsFromCurrentRulePack, out list))
            {
                return(false);
            }
            List <Tuple <QueryMatchResult, DataClassificationPresentationObject> > list2;

            if (!DlpUtils.CreateDataClassificationPresentationObjects(queryContext, classificationRuleCollectionPresentationObject, idMatchResultsFromCurrentRulePack, out list2))
            {
                return(false);
            }
            foreach (Tuple <QueryMatchResult, DataClassificationPresentationObject> tuple in list)
            {
                QueryMatchResult item = tuple.Item1;
                DataClassificationPresentationObject item2 = tuple.Item2;
                if (queriedNameDictionary[item.QueryString] != null)
                {
                    throw new ArgumentException(Strings.DataClassificationAmbiguousName(item.QueryString));
                }
                DlpUtils.EnsureResultsIntegrity(queryContext, item, allQueryResultsDictionary, classificationRuleCollectionPresentationObject);
                queriedNameDictionary[item.QueryString] = item2;
                allQueryResultsDictionary.Add(item.MatchingRuleId, item2);
            }
            foreach (Tuple <QueryMatchResult, DataClassificationPresentationObject> tuple2 in list2)
            {
                QueryMatchResult item3 = tuple2.Item1;
                DataClassificationPresentationObject item4 = tuple2.Item2;
                DataClassificationPresentationObject dataClassificationPresentationObject = queriedGuidDictionary[item3.QueryString];
                if (dataClassificationPresentationObject != null)
                {
                    queryContext.CurrentDiagnosticsReporter.WriteDuplicateRuleIdAcrossRulePacksDiagnosticsInformation(0, queryContext.CurrentOrganizationId, dataClassificationPresentationObject.ClassificationRuleCollection.DistinguishedName, queryContext.CurrentRuleCollectionTransportRuleObject.DistinguishedName, item3.MatchingRuleId);
                    throw new ArgumentException(Strings.DataClassificationAmbiguousIdentifier(item3.QueryString));
                }
                DlpUtils.EnsureResultsIntegrity(queryContext, item3, allQueryResultsDictionary, classificationRuleCollectionPresentationObject);
                queriedGuidDictionary[item3.QueryString] = item4;
                allQueryResultsDictionary.Add(item3.MatchingRuleId, item4);
            }
            return(true);
        }
示例#4
0
        private static bool CreateDataClassificationPresentationObjects(DlpUtils.DataClassificationQueryContext queryContext, ClassificationRuleCollectionPresentationObject ruleCollectionPresentationObject, IEnumerable <QueryMatchResult> queryMatchResults, out List <Tuple <QueryMatchResult, DataClassificationPresentationObject> > presentationObjects)
        {
            presentationObjects = null;
            List <Tuple <QueryMatchResult, DataClassificationPresentationObject> > list = new List <Tuple <QueryMatchResult, DataClassificationPresentationObject> >();

            foreach (QueryMatchResult queryMatchResult in queryMatchResults)
            {
                DataClassificationPresentationObject item;
                if (!DlpUtils.CreateDataClassificationPresentationObject(queryContext, queryMatchResult.MatchingRuleId, queryMatchResult.MatchingRuleXElement, queryMatchResult.MatchingResourceXElement, ruleCollectionPresentationObject, out item))
                {
                    return(false);
                }
                list.Add(new Tuple <QueryMatchResult, DataClassificationPresentationObject>(queryMatchResult, item));
            }
            presentationObjects = list;
            return(true);
        }
示例#5
0
        internal static IEnumerable <DataClassificationPresentationObject> QueryDataClassification(IEnumerable <string> queriedIdentities, OrganizationId organizationId, IConfigurationSession openedDataSession = null, IClassificationDefinitionsDataReader dataReader = null, IClassificationDefinitionsDiagnosticsReporter diagnosticsReporter = null)
        {
            ArgumentValidator.ThrowIfNull("queriedIdentities", queriedIdentities);
            if (object.ReferenceEquals(null, organizationId))
            {
                throw new ArgumentNullException("organizationId");
            }
            List <string> list = new List <string>();
            Dictionary <string, DataClassificationPresentationObject> queriedNameDictionary     = new Dictionary <string, DataClassificationPresentationObject>(StringComparer.Ordinal);
            Dictionary <string, DataClassificationPresentationObject> queriedGuidDictionary     = new Dictionary <string, DataClassificationPresentationObject>(ClassificationDefinitionConstants.RuleIdComparer);
            Dictionary <string, DataClassificationPresentationObject> allQueryResultsDictionary = new Dictionary <string, DataClassificationPresentationObject>(ClassificationDefinitionConstants.RuleIdComparer);

            foreach (string text in queriedIdentities)
            {
                if (!string.IsNullOrEmpty(text))
                {
                    list.Add(text);
                    Guid guid;
                    if (GuidHelper.TryParseGuid(text, out guid))
                    {
                        queriedGuidDictionary.Add(text, null);
                    }
                    else
                    {
                        queriedNameDictionary.Add(text, null);
                    }
                }
            }
            if (!list.Any <string>())
            {
                return(Enumerable.Empty <DataClassificationPresentationObject>());
            }
            DlpUtils.DataClassificationQueryContext dataClassificationQueryContext = new DlpUtils.DataClassificationQueryContext(organizationId, diagnosticsReporter ?? ClassificationDefinitionsDiagnosticsReporter.Instance);
            bool flag  = queriedNameDictionary.Any <KeyValuePair <string, DataClassificationPresentationObject> >();
            bool flag2 = queriedGuidDictionary.Any <KeyValuePair <string, DataClassificationPresentationObject> >();

            foreach (Tuple <TransportRule, XDocument> tuple in DlpUtils.AggregateOobAndCustomClassificationDefinitions(organizationId, openedDataSession, null, null, dataReader, dataClassificationQueryContext.CurrentDiagnosticsReporter))
            {
                dataClassificationQueryContext.CurrentRuleCollectionTransportRuleObject = tuple.Item1;
                dataClassificationQueryContext.CurrentRuleCollectionXDoc = tuple.Item2;
                IEnumerable <QueryMatchResult> nameMatchResultsFromCurrentRulePack = Enumerable.Empty <QueryMatchResult>();
                if (!flag || DlpUtils.GetNameQueryMatchResult(dataClassificationQueryContext, queriedNameDictionary.Keys, out nameMatchResultsFromCurrentRulePack))
                {
                    IEnumerable <QueryMatchResult> idMatchResultsFromCurrentRulePack = Enumerable.Empty <QueryMatchResult>();
                    if (!flag2 || DlpUtils.GetIdQueryMatchResult(dataClassificationQueryContext, queriedGuidDictionary.Keys, out idMatchResultsFromCurrentRulePack))
                    {
                        DlpUtils.PopulateMatchResults(dataClassificationQueryContext, queriedNameDictionary, nameMatchResultsFromCurrentRulePack, queriedGuidDictionary, idMatchResultsFromCurrentRulePack, allQueryResultsDictionary);
                    }
                }
            }
            return((from presentationObject in list.Select(delegate(string queriedIdentity)
            {
                DataClassificationPresentationObject result;
                if (queriedNameDictionary.TryGetValue(queriedIdentity, out result))
                {
                    return result;
                }
                if (!queriedGuidDictionary.TryGetValue(queriedIdentity, out result))
                {
                    return null;
                }
                return result;
            })
                    where presentationObject != null
                    select presentationObject).ToList <DataClassificationPresentationObject>());
        }
示例#6
0
 private static bool CreateDataClassificationPresentationObject(DlpUtils.DataClassificationQueryContext operationContext, string ruleIdentifier, XElement ruleElement, XElement resourceElement, ClassificationRuleCollectionPresentationObject ruleCollectionPresentationObject, out DataClassificationPresentationObject dataClassificationPresentationObject)
 {
     return(DlpUtils.TryExecuteOperation <XmlException, object, object, DataClassificationPresentationObject>(operationContext, (object unusedStub1, object unusedStub2) => DataClassificationPresentationObject.Create(ruleIdentifier, ruleElement, resourceElement, ruleCollectionPresentationObject), null, null, out dataClassificationPresentationObject));
 }
示例#7
0
 private static bool CreateClassificationRuleCollectionPresentationObject(DlpUtils.DataClassificationQueryContext operationContext, out ClassificationRuleCollectionPresentationObject presentationObject)
 {
     return(DlpUtils.TryExecuteOperation <XmlException, TransportRule, XDocument, ClassificationRuleCollectionPresentationObject>(operationContext, new Func <TransportRule, XDocument, ClassificationRuleCollectionPresentationObject>(ClassificationRuleCollectionPresentationObject.Create), operationContext.CurrentRuleCollectionTransportRuleObject, operationContext.CurrentRuleCollectionXDoc, out presentationObject));
 }
示例#8
0
 private static bool GetIdQueryMatchResult(DlpUtils.DataClassificationQueryContext queryContext, IEnumerable <string> queriedIds, out IEnumerable <QueryMatchResult> idMatchResultsFromCurrentRulePack)
 {
     return(DlpUtils.TryExecuteOperation <XmlException, XDocument, IEnumerable <string>, IEnumerable <QueryMatchResult> >(queryContext, new Func <XDocument, IEnumerable <string>, IEnumerable <QueryMatchResult> >(XmlProcessingUtils.GetMatchingRulesById), queryContext.CurrentRuleCollectionXDoc, queriedIds, out idMatchResultsFromCurrentRulePack));
 }
示例#9
0
 private static bool GetNameQueryMatchResult(DlpUtils.DataClassificationQueryContext queryContext, IEnumerable <string> queriedNames, out IEnumerable <QueryMatchResult> nameMatchResultsFromCurrentRulePack)
 {
     return(DlpUtils.TryExecuteOperation <XmlException, XDocument, IEnumerable <string>, IEnumerable <QueryMatchResult> >(queryContext, (XDocument rulePackXDoc, IEnumerable <string> queriedRuleNames) => XmlProcessingUtils.GetMatchingRulesByName(rulePackXDoc, queriedRuleNames, NameMatchingOptions.InvariantNameOrLocalizedNameMatch, true), queryContext.CurrentRuleCollectionXDoc, queriedNames, out nameMatchResultsFromCurrentRulePack));
 }
示例#10
0
 internal static bool TryExecuteOperation <TExceptionToHandle, TArg1, TArg2, TResult>(DlpUtils.DataClassificationQueryContext operationContext, Func <TArg1, TArg2, TResult> protectedOperation, TArg1 operationArgument1, TArg2 operationArgument2, out TResult operationResult) where TExceptionToHandle : Exception
 {
     operationResult = default(TResult);
     try
     {
         operationResult = protectedOperation(operationArgument1, operationArgument2);
     }
     catch (TExceptionToHandle texceptionToHandle)
     {
         TExceptionToHandle texceptionToHandle2 = (TExceptionToHandle)((object)texceptionToHandle);
         operationContext.CurrentDiagnosticsReporter.WriteCorruptRulePackageDiagnosticsInformation(0, operationContext.CurrentOrganizationId, operationContext.CurrentRuleCollectionTransportRuleObject.DistinguishedName, new AggregateException(new Exception[]
         {
             texceptionToHandle2
         }).Flatten());
         return(false);
     }
     return(true);
 }