Exemplo n.º 1
0
        internal static DataClassificationPresentationObject Create(string ruleIdentifier, DataClassificationLocalizableDetails defaultRuleDetails, XElement ruleElement, XElement resourceElement, ClassificationRuleCollectionPresentationObject rulePackPresentationObject)
        {
            ArgumentValidator.ThrowIfNullOrEmpty("ruleIdentifier", ruleIdentifier);
            ArgumentValidator.ThrowIfNull("defaultRuleDetails", defaultRuleDetails);
            ArgumentValidator.ThrowIfNull("ruleElement", ruleElement);
            ArgumentValidator.ThrowIfNull("resourceElement", resourceElement);
            ArgumentValidator.ThrowIfNull("rulePackPresentationObject", rulePackPresentationObject);
            MultiValuedProperty <Fingerprint> multiValuedProperty = null;

            if (rulePackPresentationObject.IsFingerprintRuleCollection && ruleElement.Document != null)
            {
                multiValuedProperty = XmlProcessingUtils.ReadAllReferredFingerprints(ruleElement);
            }
            return(new DataClassificationPresentationObject
            {
                defaultDetails = defaultRuleDetails,
                localizedNames = XmlProcessingUtils.ReadAllRuleNames(resourceElement),
                localizedDescriptions = XmlProcessingUtils.ReadAllRuleDescriptions(resourceElement),
                fingerprints = multiValuedProperty,
                Identity = DataClassificationPresentationObject.CreateDataClassificationIdentifier(ruleIdentifier, rulePackPresentationObject),
                ClassificationType = (rulePackPresentationObject.IsFingerprintRuleCollection ? ClassificationTypeEnum.Fingerprint : DataClassificationPresentationObject.Parse(ruleElement.Name.LocalName)),
                ClassificationRuleCollection = rulePackPresentationObject,
                RecommendedConfidence = XmlProcessingUtils.ReadRuleRecommendedConfidence(ruleElement),
                MinEngineVersion = XmlProcessingUtils.GetRulePackElementVersion(ruleElement)
            });
        }
        protected override void WriteResult(IConfigurable dataObject)
        {
            TaskLogger.LogEnter();
            TransportRule transportRule = dataObject as TransportRule;

            if (transportRule != null)
            {
                XDocument ruleCollectionDocumentFromTransportRule = ClassificationDefinitionUtils.GetRuleCollectionDocumentFromTransportRule(transportRule);
                if (ruleCollectionDocumentFromTransportRule != null)
                {
                    string[] ruleIdQueries = new string[]
                    {
                        ((DataClassificationObjectId)this.implementation.DataClassificationPresentationObject.Identity).Name
                    };
                    List <QueryMatchResult> list = XmlProcessingUtils.GetMatchingRulesById(ruleCollectionDocumentFromTransportRule, ruleIdQueries).ToList <QueryMatchResult>();
                    if (list.Count > 0)
                    {
                        ClassificationRuleCollectionPresentationObject rulePackPresentationObject = ClassificationRuleCollectionPresentationObject.Create(transportRule);
                        DataClassificationPresentationObject           result = DataClassificationPresentationObject.Create(list[0].MatchingRuleId, list[0].MatchingRuleXElement, list[0].MatchingResourceXElement, rulePackPresentationObject);
                        this.WriteResult(result);
                    }
                }
            }
            else
            {
                base.WriteResult(dataObject);
            }
            TaskLogger.LogExit();
        }
Exemplo n.º 3
0
 internal static DataClassificationPresentationObject Create(string ruleIdentifier, XElement ruleElement, XElement resourceElement, ClassificationRuleCollectionPresentationObject rulePackPresentationObject)
 {
     ArgumentValidator.ThrowIfNullOrEmpty("ruleIdentifier", ruleIdentifier);
     ArgumentValidator.ThrowIfNull("ruleElement", ruleElement);
     ArgumentValidator.ThrowIfNull("resourceElement", resourceElement);
     return(DataClassificationPresentationObject.Create(ruleIdentifier, XmlProcessingUtils.ReadDefaultRuleMetadata(resourceElement), ruleElement, resourceElement, rulePackPresentationObject));
 }
        public TransportRule Initialize(IConfigDataProvider dataSession, DataClassificationIdParameter identity, OptionalIdentityData optionalData)
        {
            ArgumentValidator.ThrowIfNull("dataSession", dataSession);
            ArgumentValidator.ThrowIfNull("identity", identity);
            identity.ShouldIncludeOutOfBoxCollections = false;
            this.task.WriteVerbose(TaskVerboseStringHelper.GetFindByIdParameterVerboseString(identity, dataSession, typeof(TransportRule), null));
            IEnumerable <TransportRule> enumerable = null;

            try
            {
                LocalizedString?localizedString;
                enumerable = identity.GetObjects <TransportRule>(null, dataSession, optionalData, out localizedString);
            }
            finally
            {
                this.task.WriteVerbose(TaskVerboseStringHelper.GetSourceVerboseString(dataSession));
            }
            string[] array = new string[]
            {
                identity.DataClassificationIdentity
            };
            List <QueryMatchResult> list = new List <QueryMatchResult>();

            foreach (TransportRule transportRule in enumerable)
            {
                XDocument rulePackXDoc;
                if (this.TryParseADRulePack(transportRule, out rulePackXDoc) && XmlProcessingUtils.IsFingerprintRuleCollection(rulePackXDoc))
                {
                    List <QueryMatchResult> list2 = XmlProcessingUtils.GetMatchingRulesById(rulePackXDoc, array).ToList <QueryMatchResult>();
                    if (list2.Count == 0)
                    {
                        list2 = XmlProcessingUtils.GetMatchingRulesByName(rulePackXDoc, array, NameMatchingOptions.InvariantNameOrLocalizedNameMatch, true).ToList <QueryMatchResult>();
                    }
                    list.AddRange(list2);
                    if (list.Count == 1)
                    {
                        this.adRulePack           = transportRule;
                        this.ruleXElement         = list[0].MatchingRuleXElement;
                        this.ruleResourceXElement = list[0].MatchingResourceXElement;
                        this.rulePackXDocument    = this.ruleXElement.Document;
                        ClassificationRuleCollectionPresentationObject rulePackPresentationObject = ClassificationRuleCollectionPresentationObject.Create(this.adRulePack, this.rulePackXDocument);
                        this.DataClassificationPresentationObject = DataClassificationPresentationObject.Create(list[0].MatchingRuleId, list[0].MatchingRuleXElement, list[0].MatchingResourceXElement, rulePackPresentationObject);
                    }
                    else if (list.Count > 1)
                    {
                        break;
                    }
                }
            }
            if (list.Count <= 0)
            {
                throw new ManagementObjectNotFoundException(Strings.ErrorCannotFindFingerprintDataClassification(identity.ToString()));
            }
            if (list.Count > 1)
            {
                throw new ManagementObjectAmbiguousException(Strings.ErrorManagementObjectAmbiguous(identity.ToString()));
            }
            return(this.adRulePack);
        }
Exemplo n.º 5
0
        private static List <DataClassificationPresentationObject> CreateDataClassificationPresentationObjects(TransportRule transportRuleObject, XDocument rulePackXDoc)
        {
            ClassificationRuleCollectionPresentationObject rulePackPresentationObject = ClassificationRuleCollectionPresentationObject.Create(transportRuleObject, rulePackXDoc);
            IEnumerable <QueryMatchResult> matchingRulesById = XmlProcessingUtils.GetMatchingRulesById(rulePackXDoc, null);

            return((from rawDataClassificationResult in matchingRulesById
                    select DataClassificationPresentationObject.Create(rawDataClassificationResult.MatchingRuleId, rawDataClassificationResult.MatchingRuleXElement, rawDataClassificationResult.MatchingResourceXElement, rulePackPresentationObject)).ToList <DataClassificationPresentationObject>());
        }
        public TransportRule Initialize(TransportRule adRulePack, XDocument rulePackXDoc)
        {
            ArgumentValidator.ThrowIfNull("adRulepack", adRulePack);
            ArgumentValidator.ThrowIfNull("rulePackXDoc", rulePackXDoc);
            this.adRulePack        = adRulePack;
            this.rulePackXDocument = rulePackXDoc;
            ClassificationRuleCollectionPresentationObject rulePackPresentationObject = ClassificationRuleCollectionPresentationObject.Create(this.adRulePack, this.rulePackXDocument);

            this.DataClassificationPresentationObject = DataClassificationPresentationObject.Create(rulePackPresentationObject);
            return(this.adRulePack);
        }
Exemplo n.º 7
0
 internal void SetLocalizedDescription(CultureInfo locale, string value)
 {
     ArgumentValidator.ThrowIfNull("locale", locale);
     if (locale.Equals(this.defaultDetails.Culture) && !string.Equals(this.defaultDetails.Description, value))
     {
         this.defaultDetails.Description = value;
         this.IsDirty = true;
     }
     if (!this.localizedDescriptions.ContainsKey(locale) || !string.Equals(this.localizedDescriptions[locale], value, StringComparison.Ordinal))
     {
         DataClassificationPresentationObject.SetLocalizedResource(this.localizedDescriptions, locale, value);
         this.IsDirty = true;
     }
 }
Exemplo n.º 8
0
 internal static DataClassificationPresentationObject Create(ClassificationRuleCollectionPresentationObject rulePackPresentationObject)
 {
     return(new DataClassificationPresentationObject
     {
         defaultDetails = new DataClassificationLocalizableDetails(),
         localizedNames = new Dictionary <CultureInfo, string>(),
         localizedDescriptions = new Dictionary <CultureInfo, string>(),
         ClassificationRuleCollection = rulePackPresentationObject,
         Identity = DataClassificationPresentationObject.CreateDataClassificationIdentifier(Guid.NewGuid().ToString(), rulePackPresentationObject),
         ClassificationType = (rulePackPresentationObject.IsFingerprintRuleCollection ? ClassificationTypeEnum.Fingerprint : ClassificationTypeEnum.Affinity),
         RecommendedConfidence = new uint?(75U),
         MinEngineVersion = ClassificationDefinitionConstants.TextProcessorTypeToVersions[TextProcessorType.Fingerprint],
         IsDirty = true
     });
 }
Exemplo n.º 9
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);
        }
Exemplo n.º 10
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));
 }