internal void Save(XDocument rulePackXDoc) { ArgumentValidator.ThrowIfNull("rulePackXDoc", rulePackXDoc); if (this.Fingerprints == null || this.Fingerprints.Count <= 0) { throw new DataClassificationFingerprintsMissingException(this.Name); } if (this.Fingerprints.Count((Fingerprint fingerprint) => string.IsNullOrEmpty(fingerprint.Description)) > 0) { throw new DataClassificationFingerprintsDescriptionMissingException(this.Name); } if (this.Fingerprints.Distinct(Fingerprint.Comparer).Count <Fingerprint>() != this.Fingerprints.Count) { throw new DataClassificationFingerprintsDuplicatedException(this.Name); } DataClassificationObjectId dataClassificationObjectId = this.Identity as DataClassificationObjectId; foreach (Fingerprint fingerprint2 in this.Fingerprints) { if (string.IsNullOrEmpty(fingerprint2.Identity)) { fingerprint2.Identity = XmlProcessingUtils.AddFingerprintTextProcessor(rulePackXDoc, fingerprint2); } } XmlProcessingUtils.AddDataClassification(rulePackXDoc, dataClassificationObjectId.Name, this.MinEngineVersion.ToString(), this.GetRuleXElement()); XmlProcessingUtils.AddLocalizedResource(rulePackXDoc, dataClassificationObjectId.Name, this.GetResourceXElement()); }
internal static IEnumerable <QueryMatchResult> GetMatchingRulesById(XDocument rulePackXDocument, IEnumerable <string> ruleIdQueries = null) { ArgumentValidator.ThrowIfNull("rulePackXDocument", rulePackXDocument); HashSet <string> ruleIdQuerySet = (ruleIdQueries != null) ? new HashSet <string>(ruleIdQueries, ClassificationDefinitionConstants.RuleIdComparer) : null; return(XmlProcessingUtils.GetMatchingRulesById(rulePackXDocument, ruleIdQuerySet)); }
internal static ClassificationRuleCollectionLocalizableDetails ReadRulePackageMetadata(XDocument rulePackXDoc, CultureInfo cultureInfo = null) { ArgumentValidator.ThrowIfNull("rulePackXDoc", rulePackXDoc); XElement rulePackageMetadataElement = XmlProcessingUtils.GetRulePackageMetadataElement(rulePackXDoc); return(XmlProcessingUtils.ReadRulePackageMetadata(rulePackageMetadataElement, cultureInfo)); }
public void Validate(ValidationContext context, XDocument rulePackXDocument) { if (context.ExistingRulePackDataObject == null) { return; } Version version = null; try { version = context.GetExistingRulePackVersion(); } catch (XmlException) { if (context.IsPayloadOobRuleCollection) { throw; } } if (null == version) { return; } Version rulePackVersion = XmlProcessingUtils.GetRulePackVersion(rulePackXDocument); ClassificationRuleCollectionVersionValidator.ValidateOobRulePackVersionGreaterThanOrEqual(rulePackVersion, version); }
public bool DecryptRulePackage(out byte[] outputDecryptedRulePackageData, out byte[] outputEncryptedRulePackageDataWithSymmetricKey) { XmlNode encryptionNode = this.GetEncryptionNode(); if (encryptionNode == null) { outputDecryptedRulePackageData = null; outputEncryptedRulePackageDataWithSymmetricKey = null; return(false); } byte[] array = this.AsymmetricDecrypt(this.GetEncryptionParameter(encryptionNode, "ns:Key")); byte[] array2 = this.AsymmetricDecrypt(this.GetEncryptionParameter(encryptionNode, "ns:IV")); using (this.algorithm = new AesCryptoServiceProvider()) { this.algorithm.Key = array; this.algorithm.IV = array2; this.DecryptEntities(); this.DecryptAffinities(); this.DecryptRegexes(); this.DecryptKeywordLists(); } this.RemoveEncryptionNode(); outputDecryptedRulePackageData = XmlProcessingUtils.XmlDocumentToUtf16EncodedBytes(this.document); outputEncryptedRulePackageDataWithSymmetricKey = this.ReplaceSymmetricAlgorithmParameters(array, array2); return(true); }
private XElement GetRuleXElement() { List <XElement> list = new List <XElement>(); foreach (Fingerprint fingerprint in this.Fingerprints) { list.Add(new XElement(XmlProcessingUtils.GetMceNsQualifiedNodeName("Match"), new XAttribute("idRef", fingerprint.Identity))); } XElement xelement = list[0]; if (list.Count > 1) { xelement = new XElement(XmlProcessingUtils.GetMceNsQualifiedNodeName("Any"), new object[] { new XAttribute("minMatches", 1), list }); } XElement xelement2 = new XElement(XmlProcessingUtils.GetMceNsQualifiedNodeName("Evidence"), new object[] { new XAttribute("confidenceLevel", 75), xelement }); return(new XElement(XmlProcessingUtils.GetMceNsQualifiedNodeName("Affinity"), new object[] { new XAttribute("id", ((DataClassificationObjectId)this.Identity).Name), new XAttribute("evidencesProximity", 300), new XAttribute("thresholdConfidenceLevel", 75), xelement2 })); }
private void ValidateAllRulesLangCodes(XDocument rulePackXDocument) { foreach (XElement ruleResourceElement in rulePackXDocument.Descendants(XmlProcessingUtils.GetMceNsQualifiedNodeName("Resource"))) { this.ValidateRuleLangCodes(ruleResourceElement); } }
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(); }
internal static Dictionary <string, HashSet <string> > GetAllClassificationIdentifiers(OrganizationId organizationId, IConfigurationSession openedDataSession = null, Func <TransportRule, bool> inclusiveFilter = null, QueryFilter additionalFilter = null, IClassificationDefinitionsDataReader dataReader = null, IClassificationDefinitionsDiagnosticsReporter classificationDefinitionsDiagnosticsReporter = null) { IClassificationDefinitionsDiagnosticsReporter classificationDefinitionsDiagnosticsReporter2 = classificationDefinitionsDiagnosticsReporter ?? ClassificationDefinitionsDiagnosticsReporter.Instance; Dictionary <string, HashSet <string> > dictionary = new Dictionary <string, HashSet <string> >(ClassificationDefinitionConstants.RuleCollectionIdComparer); foreach (Tuple <TransportRule, XDocument> tuple in DlpUtils.AggregateOobAndCustomClassificationDefinitions(organizationId, openedDataSession, inclusiveFilter, additionalFilter, dataReader, classificationDefinitionsDiagnosticsReporter2)) { TransportRule item = tuple.Item1; XDocument item2 = tuple.Item2; ExAssert.RetailAssert(item2 != null, "XDocument instance returned from AggregateOobAndCustomClassificationDefinitions should never be null!"); string rulePackId; HashSet <string> value; try { rulePackId = XmlProcessingUtils.GetRulePackId(item2); value = new HashSet <string>(XmlProcessingUtils.GetAllRuleIds(item2), ClassificationDefinitionConstants.RuleIdComparer); } catch (XmlException ex) { ClassificationDefinitionsDiagnosticsReporter.Instance.WriteCorruptRulePackageDiagnosticsInformation(0, organizationId, item.DistinguishedName, new AggregateException(new Exception[] { ex }).Flatten()); continue; } ExAssert.RetailAssert(!dictionary.ContainsKey(rulePackId), "Duplicate classification rule collection ID '{0}' under tenant's organization '{1}' is a should never ever happen case", new object[] { rulePackId, organizationId.ToString() }); dictionary.Add(rulePackId, value); } return(dictionary); }
internal static XDocument CreateRuleCollectionDocumentFromTemplate(string rulePackId, string organizationId, string organizationName) { ArgumentValidator.ThrowIfNullOrEmpty("rulePackId", rulePackId); ArgumentValidator.ThrowIfNullOrEmpty("organizationId", organizationId); ArgumentValidator.ThrowIfNullOrEmpty("organizationName", organizationName); string text = string.Empty; using (Stream stream = ClassificationDefinitionUtils.LoadStreamFromEmbeddedResource("FingerprintRulePackTemplate.xml")) { using (StreamReader streamReader = new StreamReader(stream)) { text = streamReader.ReadToEnd(); } } if (string.IsNullOrEmpty(text)) { throw new FingerprintRulePackTemplateCorruptedException("FingerprintRulePackTemplate.xml"); } XDocument xdocument = XDocument.Parse(text); XElement xelement = xdocument.Root.Element(XmlProcessingUtils.GetMceNsQualifiedNodeName("RulePack")); xelement.SetAttributeValue("id", rulePackId); XElement xelement2 = xelement.Element(XmlProcessingUtils.GetMceNsQualifiedNodeName("Publisher")); xelement2.SetAttributeValue("id", organizationId); foreach (XElement xelement3 in xelement.Descendants(XmlProcessingUtils.GetMceNsQualifiedNodeName("PublisherName"))) { xelement3.SetValue(organizationName); } XmlProcessingUtils.SetRulePackVersionFromAssemblyFileVersion(xdocument); return(xdocument); }
private static IEnumerable <string> GetInvalidRegexes(MicrosoftClassificationEngine classificationEngine, RulePackageLoader rulePackageLoader, XDocument rulePackXDoc) { foreach (KeyValuePair <string, string> regexProcessor in XmlProcessingUtils.GetRegexesInRulePackage(rulePackXDoc)) { string value = ClassificationEngineValidator.regexTestTemplate.Value; KeyValuePair <string, string> keyValuePair = regexProcessor; string rulePackage = string.Format(value, keyValuePair.Value); RULE_PACKAGE_DETAILS rule_PACKAGE_DETAILS = default(RULE_PACKAGE_DETAILS); rule_PACKAGE_DETAILS.RulePackageSetID = "not-used-here"; KeyValuePair <string, string> keyValuePair2 = regexProcessor; rule_PACKAGE_DETAILS.RulePackageID = keyValuePair2.Key; rule_PACKAGE_DETAILS.RuleIDs = null; RULE_PACKAGE_DETAILS rulePackageDetails = rule_PACKAGE_DETAILS; rulePackageLoader.SetRulePackage(rulePackageDetails.RulePackageID, rulePackage); string badRegex = null; try { RULE_PACKAGE_DETAILS rule_PACKAGE_DETAILS2 = rulePackageDetails; classificationEngine.GetClassificationDefinitions(ref rule_PACKAGE_DETAILS2); } catch (COMException ex) { if (ex.ErrorCode == -2147220978) { KeyValuePair <string, string> keyValuePair3 = regexProcessor; badRegex = keyValuePair3.Key; } } if (badRegex != null) { yield return(badRegex); } } yield break; }
private static void ValidateRegexProcessorsPerformance(XDocument rulePackXDocument, DataClassificationConfig dataClassificationConfig) { ExAssert.RetailAssert(dataClassificationConfig != null, "Must specify DataClassificationConfig instance when calling ValidateRegexProcessorsPerformance"); foreach (KeyValuePair <string, string> keyValuePair in XmlProcessingUtils.GetRegexesInRulePackage(rulePackXDocument)) { try { if (keyValuePair.Value.Length > dataClassificationConfig.RegExLength) { LocalizedString localizedString = Strings.ClassificationRuleCollectionPatternTooLong(dataClassificationConfig.RegExLength); throw new ValidationArgumentException(localizedString, null); } if (dataClassificationConfig.RegExGrammarLimit) { Pattern.ValidatePatternDoesNotBeginOrEndWithWildcards(keyValuePair.Value); Pattern.ValidatePatternDoesNotContainGroupsOrAssertionsWithWildcards(keyValuePair.Value); Pattern.ValidatePatternDoesNotContainMultiMatchOnGroupsOrAssertions(keyValuePair.Value); Pattern.ValidatePatternDoesNotHaveSequentialIdenticalMultiMatches(keyValuePair.Value); Pattern.ValidatePatternDoesNotContainEmptyAlternations(keyValuePair.Value); } } catch (ValidationArgumentException ex) { LocalizedString message = Strings.ClassificationRuleCollectionRegexPerformanceValidationFailure(keyValuePair.Key, ex.Message); throw new ClassificationRuleCollectionRegexValidationException(message, ex); } } }
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)); }
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) }); }
internal static string AddFingerprintTextProcessor(XDocument rulePackXDoc, Fingerprint fingerprint) { ArgumentValidator.ThrowIfNull("rulePackXDoc", rulePackXDoc); ArgumentValidator.ThrowIfNull("fingerprint", fingerprint); XElement xelement = rulePackXDoc.Descendants(XmlProcessingUtils.GetMceNsQualifiedNodeName("LocalizedStrings")).FirstOrDefault <XElement>(); if (xelement == null) { throw new ClassificationRuleCollectionInvalidObjectException(Strings.ClassificationRuleCollectionInvalidObject); } XElement fingerprintProcessor = XmlProcessingUtils.GetFingerprintProcessor(rulePackXDoc, fingerprint); if (fingerprintProcessor == null) { fingerprint.Identity = Guid.NewGuid().ToString(); fingerprint.ActualDescription = fingerprint.Description; xelement.AddBeforeSelf(fingerprint.ToXElement()); } else { fingerprint.Identity = XmlProcessingUtils.GetAttributeValue(fingerprintProcessor, "id"); string attributeValue = XmlProcessingUtils.GetAttributeValue(fingerprintProcessor, "description"); if (string.IsNullOrEmpty(attributeValue) && !string.IsNullOrEmpty(fingerprint.Description)) { fingerprintProcessor.SetAttributeValue("description", fingerprint.Description); fingerprint.ActualDescription = fingerprint.Description; } else { fingerprint.ActualDescription = attributeValue; } } return(fingerprint.Identity); }
internal static IEnumerable <KeyValuePair <string, string> > GetRegexesInRulePackage(XDocument rulePackXDoc) { ArgumentValidator.ThrowIfNull("rulePackXDoc", rulePackXDoc); return(from regexElement in rulePackXDoc.Descendants(XmlProcessingUtils.GetMceNsQualifiedNodeName("Regex")) let regexProcessorId = regexElement.Attribute("id").Value select new KeyValuePair <string, string>(regexProcessorId, regexElement.Value)); }
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); }
internal static IEnumerable <QueryMatchResult> GetMatchingRulesByName(XDocument rulePackXDocument, IEnumerable <string> ruleNameQueries, NameMatchingOptions matchingOption = NameMatchingOptions.InvariantNameOrLocalizedNameMatch, bool ignoreCase = true) { ArgumentValidator.ThrowIfNull("rulePackXDocument", rulePackXDocument); ArgumentValidator.ThrowIfNull("ruleNameQueries", ruleNameQueries); ArgumentValidator.ThrowIfInvalidValue <NameMatchingOptions>("matchingOption", matchingOption, (NameMatchingOptions nameMatchingOption) => nameMatchingOption == NameMatchingOptions.InvariantNameMatchOnly || NameMatchingOptions.InvariantNameOrLocalizedNameMatch == nameMatchingOption); List <string> ruleNameQueriesList = new List <string>((from query in ruleNameQueries where !string.IsNullOrEmpty(query) select query).OrderBy((string query) => query, ignoreCase ? StringComparer.OrdinalIgnoreCase : StringComparer.Ordinal)); if (ruleNameQueriesList.Count == 0) { return(Enumerable.Empty <QueryMatchResult>()); } CultureInfo currentThreadCulture = CultureInfo.CurrentCulture; ParallelQuery <QueryMatchResult> parallelQuery; if (matchingOption != NameMatchingOptions.InvariantNameMatchOnly) { parallelQuery = from resourceElement in rulePackXDocument.Descendants(XmlProcessingUtils.GetMceNsQualifiedNodeName("Resource")).AsParallel <XElement>() let queryHitIndex = XmlProcessingUtils.GetInvariantOrLocalizedNameHitIndex(ruleNameQueriesList, resourceElement, currentThreadCulture, ignoreCase) where queryHitIndex >= 0 let ruleIdRef = resourceElement.Attribute("idRef").Value let finalRuleIdRef = string.IsNullOrEmpty(ruleIdRef) ? null : ruleIdRef select new QueryMatchResult { QueryString = ruleNameQueriesList[queryHitIndex], MatchingResourceXElement = resourceElement, MatchingRuleId = finalRuleIdRef, MatchingRuleXElement = null }; } else { parallelQuery = from resourceElement in rulePackXDocument.Descendants(XmlProcessingUtils.GetMceNsQualifiedNodeName("Resource")).AsParallel <XElement>() let invariantLocalizedNameDetails = XmlProcessingUtils.ReadDefaultRuleMetadata(resourceElement) let queryHitIndex = ruleNameQueriesList.BinarySearch(invariantLocalizedNameDetails.Name, StringComparer.Create(invariantLocalizedNameDetails.Culture, ignoreCase)) where queryHitIndex >= 0 let ruleIdRef = resourceElement.Attribute("idRef").Value let finalRuleIdRef = string.IsNullOrEmpty(ruleIdRef) ? null : ruleIdRef select new QueryMatchResult { QueryString = ruleNameQueriesList[queryHitIndex], MatchingResourceXElement = resourceElement, MatchingRuleId = finalRuleIdRef, MatchingRuleXElement = null }; } ParallelQuery <QueryMatchResult> mainQuery = parallelQuery; return(XmlProcessingUtils.ExecuteQueryMatching(mainQuery, (Dictionary <string, QueryMatchResult> queryMatchResultsDictionary) => from ruleElement in rulePackXDocument.Descendants().AsParallel <XElement>() where ClassificationDefinitionConstants.MceRuleElementNames.Contains(ruleElement.Name.LocalName) let ruleId = (string)ruleElement.Attribute("id") let finalRuleId = string.IsNullOrEmpty(ruleId) ? null : ruleId where queryMatchResultsDictionary.ContainsKey(finalRuleId) select new KeyValuePair <string, XElement>(finalRuleId, ruleElement), delegate(Dictionary <string, QueryMatchResult> queryMatchResultsDictionary, KeyValuePair <string, XElement> matchAssociation) { queryMatchResultsDictionary[matchAssociation.Key].MatchingRuleXElement = matchAssociation.Value; }, new Func <string, LocalizedString>(Strings.ClassificationRuleCollectionOrphanedResourceViolation))); }
internal ISet <string> GetRuleIdentifiersFromExistingRulePack() { if (this.existingrulePackXDocument == null) { return(null); } return(new HashSet <string>(XmlProcessingUtils.GetAllRuleIds(this.existingrulePackXDocument), ClassificationDefinitionConstants.RuleIdComparer)); }
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>()); }
private static IEnumerable <KeyValuePair <string, List <string> > > GetKeywordProcessorsTerms(XDocument rulePackXDocument) { return(from keywordElement in rulePackXDocument.Descendants(XmlProcessingUtils.GetMceNsQualifiedNodeName("Keyword")) let keywordProcessorId = keywordElement.Attribute("id").Value let keywordTermsList = (from termElement in keywordElement.Descendants(XmlProcessingUtils.GetMceNsQualifiedNodeName("Term")).AsParallel <XElement>() select termElement.Value).ToList <string>() select new KeyValuePair <string, List <string> >(keywordProcessorId, keywordTermsList)); }
protected virtual void Initialize(XDocument rulePackXDoc) { Version rulePackVersion = XmlProcessingUtils.GetRulePackVersion(rulePackXDoc); XElement rulePackageMetadataElement = XmlProcessingUtils.GetRulePackageMetadataElement(rulePackXDoc); bool isEncrypted = RulePackageDecrypter.IsRulePackageEncrypted(rulePackXDoc); this.Initialize(rulePackVersion, rulePackageMetadataElement, isEncrypted, XmlProcessingUtils.IsFingerprintRuleCollection(rulePackXDoc)); }
internal Version GetExistingRulePackVersion() { if (this.existingrulePackXDocument == null) { return(null); } return(XmlProcessingUtils.GetRulePackVersion(this.existingrulePackXDocument)); }
protected virtual void Initialize(Version rulePackVersion, XElement rulePackageDetailsElement, bool isEncrypted, bool isFingerprintRuleCollection) { this.Version = rulePackVersion; this.defaultDetails = XmlProcessingUtils.ReadDefaultRulePackageMetadata(rulePackageDetailsElement); this.localizableDetails = XmlProcessingUtils.ReadAllRulePackageMetadata(rulePackageDetailsElement); this.IsEncrypted = isEncrypted; this.IsFingerprintRuleCollection = isFingerprintRuleCollection; }
public void Validate(ValidationContext context, XDocument rulePackXDocument) { List <XElement> list = XmlProcessingUtils.GetFingerprintProcessorsInRulePackage(rulePackXDocument).ToList <XElement>(); if (context != null && context.IsPayloadFingerprintsRuleCollection) { int num = (int)DataClassificationConfigSchema.MaxFingerprints.DefaultValue; if (context.DcValidationConfig != null) { num = context.DcValidationConfig.MaxFingerprints; } if (list.Count > num) { throw new ClassificationRuleCollectionFingerprintValidationException(Strings.ClassificationRuleCollectionFingerprintsExceedLimit(list.Count, num), null); } } Dictionary <string, HashSet <string> > dictionary = new Dictionary <string, HashSet <string> >(); List <string> list2 = new List <string>(); foreach (XElement xelement in list) { byte[] array = null; try { array = Convert.FromBase64String(xelement.Value); } catch (FormatException) { } if (array == null || array.Length % 2 != 0) { list2.Add(xelement.Attribute("id").Value); } else { string item = string.Format("{0}_{1}", xelement.Attribute("threshold").Value, xelement.Attribute("shingleCount").Value); HashSet <string> hashSet = null; dictionary.TryGetValue(xelement.Value, out hashSet); if (hashSet == null) { hashSet = new HashSet <string>(); } if (!hashSet.Contains(item)) { hashSet.Add(item); } else { list2.Add(xelement.Attribute("id").Value); } dictionary[xelement.Value] = hashSet; } } if (list2.Count > 0) { throw new ClassificationRuleCollectionFingerprintValidationException(Strings.ClassificationRuleCollectionFingerprintValidationFailure(string.Join(Strings.ClassificationRuleCollectionOffendingListSeparator, list2)), null); } }
internal XElement ToXElement() { XElement xelement = new XElement(XmlProcessingUtils.GetMceNsQualifiedNodeName("Fingerprint"), new object[] { new XAttribute("id", this.Identity), new XAttribute("shingleCount", this.ShingleCount), new XAttribute("threshold", 50), this.Value }); xelement.SetAttributeValue("description", this.Description); return(xelement); }
private void InternalSave(ValidationContext validationContext, bool force) { ArgumentValidator.ThrowIfNull("validationContext", validationContext); bool flag = XmlProcessingUtils.OptimizeRulePackXDoc(this.rulePackXDocument, validationContext.DcValidationConfig); if (force || flag || this.DataClassificationPresentationObject.IsDirty) { XElement rulePackageMetadataElement = XmlProcessingUtils.GetRulePackageMetadataElement(this.rulePackXDocument); ClassificationRuleCollectionLocalizableDetails classificationRuleCollectionLocalizableDetails = XmlProcessingUtils.ReadDefaultRulePackageMetadata(rulePackageMetadataElement); this.adRulePack.AdminDisplayName = classificationRuleCollectionLocalizableDetails.Name; this.adRulePack.ReplicationSignature = this.GetCompressedFileData(validationContext); } }
internal static ClassificationRuleCollectionLocalizableDetails ReadRulePackageMetadata(XElement rulePackDetailsElement, CultureInfo cultureInfo = null) { ArgumentValidator.ThrowIfNull("rulePackDetailsElement", rulePackDetailsElement); ClassificationRuleCollectionLocalizableDetails result; try { string langCodeToUse = (cultureInfo != null) ? cultureInfo.Name : rulePackDetailsElement.Attribute("defaultLangCode").Value; XElement xelement = (from localizedDetails in rulePackDetailsElement.Elements(XmlProcessingUtils.GetMceNsQualifiedNodeName("LocalizedDetails")).AsParallel <XElement>() where langCodeToUse.Equals(localizedDetails.Attribute("langcode").Value, StringComparison.OrdinalIgnoreCase) select localizedDetails).SingleOrDefault <XElement>(); if (xelement != null) { string value = xelement.Element(XmlProcessingUtils.GetMceNsQualifiedNodeName("Name")).Value; string value2 = xelement.Element(XmlProcessingUtils.GetMceNsQualifiedNodeName("PublisherName")).Value; string value3 = xelement.Element(XmlProcessingUtils.GetMceNsQualifiedNodeName("Description")).Value; result = new ClassificationRuleCollectionLocalizableDetails { Name = value, PublisherName = value2, Description = value3, Culture = new CultureInfo(langCodeToUse, false) }; } else { if (cultureInfo == null) { throw new XmlException(Strings.ClassificationRuleCollectionUnexpectedContents); } result = null; } } catch (NullReferenceException innerException) { throw new XmlException(Strings.ClassificationRuleCollectionUnexpectedContents, innerException); } catch (InvalidOperationException innerException2) { throw new XmlException(Strings.ClassificationRuleCollectionUnexpectedContents, innerException2); } catch (AggregateException ex) { throw new XmlException(Strings.ClassificationRuleCollectionUnexpectedContents, ex.Flatten()); } catch (CultureNotFoundException innerException3) { throw new XmlException(Strings.ClassificationRuleCollectionUnexpectedContents, innerException3); } return(result); }
private XDocument ValidateAgainstSchema(byte[] rulePackageRawData) { XDocument result = null; try { result = XmlProcessingUtils.ValidateRulePackageXmlContentsLite(rulePackageRawData); } catch (LocalizedException exception) { base.WriteError(exception, ErrorCategory.InvalidData, null); } return(result); }
public void Validate(ValidationContext context, XDocument rulePackXDocument) { if (context.IsPayloadOobRuleCollection) { return; } string text = context.ValidatedRuleCollectionDocument ?? XmlProcessingUtils.XDocumentToStringWithDeclaration(rulePackXDocument); ClassificationRuleCollectionRuntimeValidator.ValidateRulePackageContentsAgainstMce(context.CurrentOrganizationId, rulePackXDocument, text); if (context.ValidatedRuleCollectionDocument == null) { context.ValidatedRuleCollectionDocument = text; } }