private static bool HandleClassificationEngineValidatorException(Exception exception, OrganizationId currentOrganizationId) { COMException ex = exception as COMException; if (ex == null) { return(false); } int errorCode = ex.ErrorCode; if (errorCode == -2147220981) { throw new ClassificationRuleCollectionValidationException(Strings.ClassificationRuleCollectionEngineValidationFailure, ex); } if (errorCode == -2147220978) { List <string> list = (List <string>)ex.Data[ClassificationEngineValidator.BadRegexesKey]; string names = string.Join(Strings.ClassificationRuleCollectionOffendingListSeparator, list); throw ClassificationDefinitionUtils.PopulateExceptionSource <ClassificationRuleCollectionRegexValidationException, List <string> >(new ClassificationRuleCollectionRegexValidationException(Strings.ClassificationRuleCollectionRegexValidationFailure(names), ex), list); } int errorCode2 = ex.ErrorCode; ClassificationDefinitionsDiagnosticsReporter.Instance.WriteClassificationEngineUnexpectedFailureInValidation(0, currentOrganizationId, errorCode2); throw new ClassificationRuleCollectionInternalValidationException(errorCode2, ex); }
protected override void InternalValidate() { if (base.OptionalIdentityData != null) { base.OptionalIdentityData.ConfigurationContainerRdn = ClassificationDefinitionConstants.ClassificationDefinitionsRdn; } base.InternalValidate(); if (base.HasErrors) { return; } ExAssert.RetailAssert(base.DataObject != null, "DataObject must not be null at this point as it should have been resolved by the base class."); if (!ClassificationDefinitionUtils.IsAdObjectAClassificationRuleCollection(base.DataObject)) { base.WriteError(new ClassificationRuleCollectionInvalidObjectException(Strings.ClassificationRuleCollectionInvalidObject), ErrorCategory.InvalidOperation, null); } if (VariantConfiguration.GetSnapshot(MachineSettingsContext.Local, null, null).Global.MultiTenancy.Enabled&& OrganizationId.ForestWideOrgId.Equals(((IDirectorySession)base.DataSession).SessionSettings.CurrentOrganizationId) && !this.Identity.IsHierarchical) { base.WriteError(new ClassificationRuleCollectionIllegalScopeException(Strings.ClassificationRuleCollectionIllegalScopedRemoveOperation), ErrorCategory.InvalidOperation, null); } SortedSet <string> sortedSet = new SortedSet <string>(); IList <string> allRulesInUse = this.GetAllRulesInUse(base.DataObject, sortedSet); if (allRulesInUse.Count > 0) { LocalizedString message = Strings.ClassificationRuleCollectionSharingViolationRemoveOperationVerbose(this.Identity.ToString(), string.Join(Strings.ClassificationRuleCollectionOffendingListSeparator, allRulesInUse), string.Join(Strings.ClassificationRuleCollectionOffendingListSeparator, sortedSet)); ClassificationRuleCollectionSharingViolationException exception = ClassificationDefinitionUtils.PopulateExceptionSource <ClassificationRuleCollectionSharingViolationException, IList <string> >(new ClassificationRuleCollectionSharingViolationException(message), allRulesInUse); base.WriteError(exception, ErrorCategory.InvalidOperation, null); } }
private static IEnumerable <QueryMatchResult> ExecuteQueryMatching(IEnumerable <QueryMatchResult> mainQuery, Func <Dictionary <string, QueryMatchResult>, IEnumerable <KeyValuePair <string, XElement> > > queryForResolvingRuleAssociation, Action <Dictionary <string, QueryMatchResult>, KeyValuePair <string, XElement> > setAssociationData, Func <string, LocalizedString> createErrorMessageForMissingAssociation) { Dictionary <string, QueryMatchResult> queryMatchResults; try { queryMatchResults = mainQuery.ToDictionary((QueryMatchResult queryMatchResult) => queryMatchResult.MatchingRuleId, ClassificationDefinitionConstants.RuleIdComparer); if (queryMatchResults.Count == 0) { return(Enumerable.Empty <QueryMatchResult>()); } Dictionary <string, XElement> matchingAssociatedElements = queryForResolvingRuleAssociation(queryMatchResults).ToDictionary((KeyValuePair <string, XElement> ruleIdRefAndResourceElement) => ruleIdRefAndResourceElement.Key, (KeyValuePair <string, XElement> ruleIdRefAndResourceElement) => ruleIdRefAndResourceElement.Value, ClassificationDefinitionConstants.RuleIdComparer); if (queryMatchResults.Count != matchingAssociatedElements.Count) { List <string> list = (from ruleId in queryMatchResults.Keys where !matchingAssociatedElements.ContainsKey(ruleId) select ruleId).ToList <string>(); LocalizedString value = createErrorMessageForMissingAssociation(string.Join(Strings.ClassificationRuleCollectionOffendingListSeparator, list)); throw ClassificationDefinitionUtils.PopulateExceptionSource <XmlException, List <string> >(new XmlException(value), list); } Parallel.ForEach <KeyValuePair <string, XElement> >(matchingAssociatedElements, delegate(KeyValuePair <string, XElement> matchingAssociation) { setAssociationData(queryMatchResults, matchingAssociation); }); } catch (AggregateException ex) { throw new XmlException(Strings.ClassificationRuleCollectionUnexpectedContents, ex.Flatten()); } return(queryMatchResults.Values); }
private static void ValidateRuleComplexity(IEnumerable <KeyValuePair <string, RuleComplexityData> > rulePackComplexityData, IDataClassificationComplexityValidator complexityValidator) { List <string> list = (from ruleComplexityData in rulePackComplexityData where complexityValidator.IsRuleComplexityLimitExceeded(ruleComplexityData.Value) select ruleComplexityData.Key).ToList <string>(); if (list.Count > 0) { LocalizedString message = complexityValidator.CreateExceptionMessage(list); throw ClassificationDefinitionUtils.PopulateExceptionSource <ClassificationRuleCollectionComplexityValidationException, List <string> >(new ClassificationRuleCollectionComplexityValidationException(message), list); } }
private static void ValidateKeywordProcessorsPerformance(XDocument rulePackXDocument, int keywordLengthLimit) { List <string> list = (from keywordProcessorDefinition in KeywordProcessorsValidator.GetKeywordProcessorsTerms(rulePackXDocument).AsParallel <KeyValuePair <string, List <string> > >() where keywordProcessorDefinition.Value.Any((string term) => term.Length > keywordLengthLimit) select keywordProcessorDefinition.Key).ToList <string>(); if (list.Count > 0) { LocalizedString message = Strings.ClassificationRuleCollectionKeywordTooLong(keywordLengthLimit, string.Join(Strings.ClassificationRuleCollectionOffendingListSeparator, list)); throw ClassificationDefinitionUtils.PopulateExceptionSource <ClassificationRuleCollectionKeywordValidationException, List <string> >(new ClassificationRuleCollectionKeywordValidationException(message), list); } }
private static void ValidateUpdatedOobRulePackIsSuperSet(IEnumerable <string> existingOobRuleIds, IEnumerable <string> updatedOobRuleIds) { if (existingOobRuleIds == null) { return; } List <string> list = existingOobRuleIds.Except(updatedOobRuleIds, ClassificationDefinitionConstants.RuleIdComparer).ToList <string>(); if (list.Count > 0) { LocalizedString message = Strings.ClassificationRuleCollectionOobRulesRemoved(string.Join(Strings.ClassificationRuleCollectionOffendingListSeparator, list)); throw ClassificationDefinitionUtils.PopulateExceptionSource <ClassificationRuleCollectionIdentifierValidationException, List <string> >(new ClassificationRuleCollectionIdentifierValidationException(message), list); } }
private static void ValidateDefaultValueLangCodesConsistency(XDocument rulePackXDocument) { List <string> list = (from ruleResourceElement in rulePackXDocument.Descendants(XmlProcessingUtils.GetMceNsQualifiedNodeName("Resource")).AsParallel <XElement>() let defaultNameLangCode = ruleResourceElement.Elements(XmlProcessingUtils.GetMceNsQualifiedNodeName("Name")).Single((XElement nameElement) => nameElement.Attribute("default") != null && (bool)nameElement.Attribute("default")).Attribute("langcode").Value let defaultDescriptionLangCode = ruleResourceElement.Elements(XmlProcessingUtils.GetMceNsQualifiedNodeName("Description")).Single((XElement descriptionElement) => descriptionElement.Attribute("default") != null && (bool)descriptionElement.Attribute("default")).Attribute("langcode").Value where !new CultureInfo(defaultNameLangCode).Equals(new CultureInfo(defaultDescriptionLangCode)) select ruleResourceElement.Attribute("idRef").Value).ToList <string>(); if (list.Count > 0) { LocalizedString message = Strings.ClassificationRuleCollectionInconsistentDefaultInRuleResource(string.Join(Strings.ClassificationRuleCollectionOffendingListSeparator, list)); throw ClassificationDefinitionUtils.PopulateExceptionSource <ClassificationRuleCollectionLocalizationInfoValidationException, List <string> >(new ClassificationRuleCollectionLocalizationInfoValidationException(message), list); } }
private static void ValidateDefaultValueCount(XDocument rulePackXDocument) { List <string> list = (from ruleResourceElement in rulePackXDocument.Descendants(XmlProcessingUtils.GetMceNsQualifiedNodeName("Resource")).AsParallel <XElement>().Where(delegate(XElement ruleResourceElement) { if (ruleResourceElement.Elements(XmlProcessingUtils.GetMceNsQualifiedNodeName("Name")).Count((XElement nameElement) => nameElement.Attribute("default") != null && (bool)nameElement.Attribute("default")) == 1) { return(ruleResourceElement.Elements(XmlProcessingUtils.GetMceNsQualifiedNodeName("Description")).Count((XElement descriptionElement) => descriptionElement.Attribute("default") != null && (bool)descriptionElement.Attribute("default")) != 1); } return(true); }) select ruleResourceElement.Attribute("idRef").Value).ToList <string>(); if (list.Count > 0) { LocalizedString message = Strings.ClassificationRuleCollectionIncorrectNumberOfDefaultInRuleResources(string.Join(Strings.ClassificationRuleCollectionOffendingListSeparator, list)); throw ClassificationDefinitionUtils.PopulateExceptionSource <ClassificationRuleCollectionLocalizationInfoValidationException, List <string> >(new ClassificationRuleCollectionLocalizationInfoValidationException(message), list); } }
private void ValidateProcessorIdAndMatchReferences(XDocument rulePackXDocument) { ExAssert.RetailAssert(rulePackXDocument != null, "Extra rule package validation must take place after XML schema validation passed!"); IDictionary <string, ExchangeBuild> textProcessorsFromTextProcessorGrouping = TextProcessorUtils.GetTextProcessorsFromTextProcessorGrouping(this.cannedOobTextProcessorsGroupedByType, null); ICollection <string> keys = textProcessorsFromTextProcessorGrouping.Keys; Dictionary <TextProcessorType, TextProcessorGrouping> textProcessorsGroupings = TextProcessorUtils.GetRulePackScopedTextProcessorsGroupedByType(rulePackXDocument).ToDictionary((TextProcessorGrouping textProcessorGroup) => textProcessorGroup.Key); IDictionary <string, ExchangeBuild> textProcessorsFromTextProcessorGrouping2 = TextProcessorUtils.GetTextProcessorsFromTextProcessorGrouping(textProcessorsGroupings, null); ICollection <string> keys2 = textProcessorsFromTextProcessorGrouping2.Keys; List <string> list = keys.AsParallel <string>().Union(keys2.AsParallel <string>(), ClassificationDefinitionConstants.TextProcessorIdComparer).ToList <string>(); if (list.Count != keys.Count + keys2.Count) { List <string> list2 = keys.AsParallel <string>().Intersect(keys2.AsParallel <string>(), ClassificationDefinitionConstants.TextProcessorIdComparer).ToList <string>(); LocalizedString message = Strings.ClassificationRuleCollectionReservedProcessorIdViolation(string.Join(Strings.ClassificationRuleCollectionOffendingListSeparator, list2)); throw ClassificationDefinitionUtils.PopulateExceptionSource <ClassificationRuleCollectionIdentifierValidationException, List <string> >(new ClassificationRuleCollectionIdentifierValidationException(message), list2); } HashSet <string> hashSet = new HashSet <string>(ClassificationDefinitionConstants.TextProcessorIdComparer); IEnumerable <KeyValuePair <string, ExchangeBuild> > textProcessorReferences = TextProcessorUtils.GetTextProcessorReferences(rulePackXDocument.Root); foreach (KeyValuePair <string, ExchangeBuild> keyValuePair in textProcessorReferences) { ExchangeBuild objB; if ((!textProcessorsFromTextProcessorGrouping2.TryGetValue(keyValuePair.Key, out objB) && !textProcessorsFromTextProcessorGrouping.TryGetValue(keyValuePair.Key, out objB)) || !(keyValuePair.Value >= objB)) { hashSet.Add(keyValuePair.Key); } } IDictionary <string, ExchangeBuild> textProcessorsFromTextProcessorGrouping3 = TextProcessorUtils.GetTextProcessorsFromTextProcessorGrouping(this.cannedOobTextProcessorsGroupedByType, (TextProcessorType textProcessorType) => textProcessorType == TextProcessorType.Fingerprint); IDictionary <string, ExchangeBuild> textProcessorsFromTextProcessorGrouping4 = TextProcessorUtils.GetTextProcessorsFromTextProcessorGrouping(textProcessorsGroupings, (TextProcessorType textProcessorType) => textProcessorType == TextProcessorType.Fingerprint); IEnumerable <KeyValuePair <string, ExchangeBuild> > textProcessorReferences2 = TextProcessorUtils.GetTextProcessorReferences(rulePackXDocument.Root, ClassificationDefinitionConstants.MceIdMatchElementNames); foreach (KeyValuePair <string, ExchangeBuild> keyValuePair2 in textProcessorReferences2) { if (textProcessorsFromTextProcessorGrouping4.ContainsKey(keyValuePair2.Key) || textProcessorsFromTextProcessorGrouping3.ContainsKey(keyValuePair2.Key)) { hashSet.Add(keyValuePair2.Key); } } if (hashSet.Count > 0) { LocalizedString message2 = Strings.ClassificationRuleCollectionInvalidProcessorReferenceViolation(string.Join(Strings.ClassificationRuleCollectionOffendingListSeparator, hashSet)); throw ClassificationDefinitionUtils.PopulateExceptionSource <ClassificationRuleCollectionProcessorReferenceValidationException, HashSet <string> >(new ClassificationRuleCollectionProcessorReferenceValidationException(message2), hashSet); } }
private string ValidateAgainstBusinessRulesAndReadMetadata(XDocument rulePackXDoc) { ExAssert.RetailAssert(this.rulePackageIdentifier != null && this.DataObject != null, "Business rules validation in Set-ClassificationRuleCollection must take place after the DataObject resolution"); string result = string.Empty; try { this.validationContext = new ValidationContext(ClassificationRuleCollectionOperationType.Update, base.CurrentOrganizationId, VariantConfiguration.InvariantNoFlightingSnapshot.Global.MultiTenancy.Enabled && this.OutOfBoxCollection, false, (IConfigurationSession)base.DataSession, this.DataObject, null, null); result = ClassificationRuleCollectionValidationUtils.ValidateRulePackageContents(this.validationContext, rulePackXDoc); ClassificationRuleCollectionLocalizableDetails classificationRuleCollectionLocalizableDetails = XmlProcessingUtils.ReadDefaultRulePackageMetadata(rulePackXDoc); this.defaultName = classificationRuleCollectionLocalizableDetails.Name; ClassificationRuleCollectionLocalizableDetails classificationRuleCollectionLocalizableDetails2 = XmlProcessingUtils.ReadRulePackageMetadata(rulePackXDoc, CultureInfo.CurrentCulture); this.localizedName = ((classificationRuleCollectionLocalizableDetails2 != null && classificationRuleCollectionLocalizableDetails2.Name != null) ? classificationRuleCollectionLocalizableDetails2.Name : this.defaultName); if (VariantConfiguration.InvariantNoFlightingSnapshot.Global.MultiTenancy.Enabled && OrganizationId.ForestWideOrgId.Equals(((IDirectorySession)base.DataSession).SessionSettings.CurrentOrganizationId)) { this.WriteWarning(Strings.ClassificationRuleCollectionIneffectiveSharingViolationCheck); } SortedSet <string> sortedSet = new SortedSet <string>(); IList <string> deletedRulesInUse = ClassificationRuleCollectionValidationUtils.GetDeletedRulesInUse(base.DataSession, this.DataObject, sortedSet, rulePackXDoc); if (deletedRulesInUse.Count > 0) { LocalizedString message = Strings.ClassificationRuleCollectionSharingViolationSetOperationVerbose(this.localizedName ?? this.rulePackageIdentifier, string.Join(Strings.ClassificationRuleCollectionOffendingListSeparator, deletedRulesInUse), string.Join(Strings.ClassificationRuleCollectionOffendingListSeparator, sortedSet)); throw ClassificationDefinitionUtils.PopulateExceptionSource <ClassificationRuleCollectionSharingViolationException, IList <string> >(new ClassificationRuleCollectionSharingViolationException(message), deletedRulesInUse); } } catch (ClassificationRuleCollectionSharingViolationException exception) { base.WriteError(exception, ErrorCategory.InvalidOperation, null); } catch (ClassificationRuleCollectionInternalValidationException ex) { base.WriteError(ex, (-2147287038 == ex.Error) ? ErrorCategory.ObjectNotFound : ErrorCategory.InvalidResult, null); } catch (ClassificationRuleCollectionTimeoutException exception2) { base.WriteError(exception2, ErrorCategory.OperationTimeout, null); } catch (LocalizedException exception3) { base.WriteError(exception3, ErrorCategory.InvalidData, null); } return(result); }
private static void ValidateNoRuleIdentifiersConflicts(Dictionary <string, HashSet <string> > existingClassificationIdentifiers, IList <string> ruleIdentifiersToValidate) { ExAssert.RetailAssert(ruleIdentifiersToValidate != null, "Classification rule identifiers to be checked for conflicts with existing classification rule identifiers must not be null"); if (existingClassificationIdentifiers == null || existingClassificationIdentifiers.Count == 0 || ruleIdentifiersToValidate.Count == 0) { return; } List <string> list = new List <string>(); foreach (HashSet <string> @object in existingClassificationIdentifiers.Values) { list.AddRange(ruleIdentifiersToValidate.Where(new Func <string, bool>(@object.Contains))); } if (list.Count > 0) { LocalizedString message = Strings.ClassificationRuleCollectionExistingRuleIdViolation(string.Join(Strings.ClassificationRuleCollectionOffendingListSeparator, list)); throw ClassificationDefinitionUtils.PopulateExceptionSource <ClassificationRuleCollectionIdentifierValidationException, List <string> >(new ClassificationRuleCollectionIdentifierValidationException(message), list); } }
private static void ValidateRuleIdentifiersUniqueness(IList <string> ruleIdentifiersToValidate) { if (DataClassificationIdentifierValidator.isRuleIdComparerCaseSensitive) { return; } ExAssert.RetailAssert(ruleIdentifiersToValidate != null, "Classification rule identifiers to be checked for case insensitive uniqueness must not be null"); if (ruleIdentifiersToValidate.Count == 0) { return; } HashSet <string> uniqueRuleIdsSet = new HashSet <string>(ClassificationDefinitionConstants.RuleIdComparer); List <string> list = (from ruleId in ruleIdentifiersToValidate where !uniqueRuleIdsSet.Add(ruleId) select ruleId).ToList <string>(); if (list.Count > 0) { LocalizedString message = Strings.ClassificationRuleCollectionNonUniqueRuleIdViolation(string.Join(Strings.ClassificationRuleCollectionOffendingListSeparator, list)); throw ClassificationDefinitionUtils.PopulateExceptionSource <ClassificationRuleCollectionIdentifierValidationException, List <string> >(new ClassificationRuleCollectionIdentifierValidationException(message), list); } }
protected void ValidateResourceLangCodes(IEnumerable <string> langCodes, Func <IEnumerable <string>, LocalizedString> invalidLangCodesExceptionMessageBuilder, Func <IEnumerable <string>, LocalizedString> nonUniqueLangCodesExceptionMessageBuilder) { ExAssert.RetailAssert(langCodes != null, "The langcode(s) passed to ValidateResourceLangCodes must not be null!"); ExAssert.RetailAssert(invalidLangCodesExceptionMessageBuilder != null, "The invalid langcode(s) exception message builder passed to ValidateResourceLangCodes must not be null!"); ExAssert.RetailAssert(nonUniqueLangCodesExceptionMessageBuilder != null, "The non-unique langcode(s) exception message builder passed to ValidateResourceLangCodes must not be null!"); IList <string> list; IList <string> list2; if (!LocalizedInfoValidator.ValidateResourceLangCodes(langCodes, out list, out list2)) { if (list.Count > 0) { LocalizedString localizedExceptionMessage = invalidLangCodesExceptionMessageBuilder(from invalidLangCode in list select string.Format("\"{0}\"", invalidLangCode)); throw ClassificationDefinitionUtils.PopulateExceptionSource <LocalizedException, IList <string> >(this.CreateInvalidLangCodeException(localizedExceptionMessage), list); } if (list2.Count > 0) { LocalizedString localizedExceptionMessage2 = nonUniqueLangCodesExceptionMessageBuilder(list2); throw ClassificationDefinitionUtils.PopulateExceptionSource <LocalizedException, IList <string> >(this.CreateNonUniqueLangCodeException(localizedExceptionMessage2), list2); } } }