private byte[] GetCompressedFileData(ValidationContext validationContext)
 {
     try
     {
         string text = ClassificationRuleCollectionValidationUtils.ValidateRulePackageContents(validationContext, this.rulePackXDocument);
         byte[] uncompressedSerializedRulePackageData = null;
         if (!string.IsNullOrEmpty(text))
         {
             uncompressedSerializedRulePackageData = Encoding.Unicode.GetBytes(text);
         }
         return(ClassificationRuleCollectionValidationUtils.PackAndValidateCompressedRulePackage(uncompressedSerializedRulePackageData, validationContext));
     }
     catch (ClassificationRuleCollectionSharingViolationException exception)
     {
         this.task.WriteError(exception, ErrorCategory.InvalidOperation, null);
     }
     catch (ClassificationRuleCollectionInternalValidationException ex)
     {
         this.task.WriteError(ex, (-2147287038 == ex.Error) ? ErrorCategory.ObjectNotFound : ErrorCategory.InvalidResult, null);
     }
     catch (ClassificationRuleCollectionTimeoutException exception2)
     {
         this.task.WriteError(exception2, ErrorCategory.OperationTimeout, null);
     }
     catch (LocalizedException exception3)
     {
         this.task.WriteError(exception3, ErrorCategory.InvalidData, null);
     }
     return(null);
 }
        protected override IConfigurable PrepareDataObject()
        {
            TaskLogger.LogEnter();
            TransportRule transportRule;

            if (this.InstallDefaultCollection && this.existingRulePack != null)
            {
                transportRule = this.existingRulePack;
            }
            else
            {
                transportRule = (TransportRule)base.PrepareDataObject();
                transportRule.SetId(ClassificationDefinitionUtils.GetClassificationRuleCollectionContainerId(base.DataSession).GetChildId(this.rulePackageIdentifier));
                transportRule.OrganizationId = base.CurrentOrganizationId;
            }
            byte[] replicationSignature = null;
            try
            {
                replicationSignature = ClassificationRuleCollectionValidationUtils.PackAndValidateCompressedRulePackage(this.FileData, this.validationContext);
            }
            catch (LocalizedException exception)
            {
                base.WriteError(exception, ErrorCategory.InvalidData, null);
            }
            transportRule.AdminDisplayName = this.defaultName;
            transportRule.Xml = null;
            transportRule.ReplicationSignature = replicationSignature;
            TaskLogger.LogExit();
            return(transportRule);
        }
        private string ValidateAndReadMetadata(byte[] rulePackageRawData)
        {
            string result = null;

            try
            {
                XDocument xdocument = XmlProcessingUtils.ValidateRulePackageXmlContentsLite(rulePackageRawData);
                this.rulePackageIdentifier = XmlProcessingUtils.GetRulePackId(xdocument);
                this.rulePackVersion       = (this.InstallDefaultCollection ? XmlProcessingUtils.SetRulePackVersionFromAssemblyFileVersion(xdocument) : XmlProcessingUtils.GetRulePackVersion(xdocument));
                ClassificationRuleCollectionIdParameter classificationRuleCollectionIdParameter = ClassificationRuleCollectionIdParameter.Parse("*");
                classificationRuleCollectionIdParameter.ShouldIncludeOutOfBoxCollections = true;
                List <TransportRule> list = base.GetDataObjects <TransportRule>(classificationRuleCollectionIdParameter, base.DataSession, ClassificationDefinitionUtils.GetClassificationRuleCollectionContainerId(base.DataSession)).ToList <TransportRule>();
                this.existingRulePack  = list.FirstOrDefault((TransportRule transportRule) => transportRule.Name.Equals(this.rulePackageIdentifier, StringComparison.OrdinalIgnoreCase));
                this.validationContext = new ValidationContext(this.InstallDefaultCollection ? ClassificationRuleCollectionOperationType.ImportOrUpdate : ClassificationRuleCollectionOperationType.Import, base.CurrentOrganizationId, this.InstallDefaultCollection || (VariantConfiguration.InvariantNoFlightingSnapshot.Global.MultiTenancy.Enabled && this.OutOfBoxCollection), false, (IConfigurationSession)base.DataSession, this.existingRulePack, null, null);
                if (this.validationContext.DcValidationConfig != null && list.Count >= this.validationContext.DcValidationConfig.MaxRulePackages)
                {
                    base.WriteError(new ClassificationRuleCollectionNumberExceedLimit(this.validationContext.DcValidationConfig.MaxRulePackages), ErrorCategory.InvalidOperation, null);
                }
                result = ClassificationRuleCollectionValidationUtils.ValidateRulePackageContents(this.validationContext, xdocument);
                this.rulePackageDetailsElement = XmlProcessingUtils.GetRulePackageMetadataElement(xdocument);
                ClassificationRuleCollectionLocalizableDetails classificationRuleCollectionLocalizableDetails = XmlProcessingUtils.ReadDefaultRulePackageMetadata(this.rulePackageDetailsElement);
                this.defaultName = classificationRuleCollectionLocalizableDetails.Name;
                ClassificationRuleCollectionLocalizableDetails classificationRuleCollectionLocalizableDetails2 = XmlProcessingUtils.ReadRulePackageMetadata(this.rulePackageDetailsElement, CultureInfo.CurrentCulture);
                this.localizedName = ((classificationRuleCollectionLocalizableDetails2 != null && classificationRuleCollectionLocalizableDetails2.Name != null) ? classificationRuleCollectionLocalizableDetails2.Name : this.defaultName);
            }
            catch (ClassificationRuleCollectionVersionValidationException ex)
            {
                this.WriteWarning(ex.LocalizedString);
            }
            catch (ClassificationRuleCollectionAlreadyExistsException exception)
            {
                base.WriteError(exception, ErrorCategory.InvalidOperation, null);
            }
            catch (ClassificationRuleCollectionInternalValidationException ex2)
            {
                base.WriteError(ex2, (-2147287038 == ex2.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);
        }
Beispiel #4
0
        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);
        }
Beispiel #5
0
        protected override void StampChangesOn(IConfigurable dataObject)
        {
            TaskLogger.LogEnter();
            TransportRule transportRule = (TransportRule)dataObject;

            byte[] replicationSignature = null;
            try
            {
                replicationSignature = ClassificationRuleCollectionValidationUtils.PackAndValidateCompressedRulePackage(this.FileData, this.validationContext);
            }
            catch (LocalizedException exception)
            {
                base.WriteError(exception, ErrorCategory.InvalidData, null);
            }
            transportRule.AdminDisplayName     = this.defaultName;
            transportRule.ReplicationSignature = replicationSignature;
            base.StampChangesOn(dataObject);
            TaskLogger.LogEnter();
        }
        internal static IList <string> GetDeletedRulesInUse(IConfigDataProvider dataSession, TransportRule existingRulePackObject, ISet <string> referencingRules = null, XDocument updatedRulePackXDoc = null)
        {
            ExAssert.RetailAssert(dataSession != null && existingRulePackObject != null, "The data session and rule package object to be updated / deleted must be specified in order to check if any deleted rules are in-use by ETR.");
            HashSet <string> hashSet;

            try
            {
                XDocument ruleCollectionDocumentFromTransportRule = ClassificationDefinitionUtils.GetRuleCollectionDocumentFromTransportRule(existingRulePackObject);
                hashSet = new HashSet <string>(XmlProcessingUtils.GetAllRuleIds(ruleCollectionDocumentFromTransportRule), ClassificationDefinitionConstants.RuleIdComparer);
            }
            catch (ArgumentException)
            {
                ((ClassificationDefinitionsDiagnosticsReporter)ClassificationDefinitionsDiagnosticsReporter.Instance).Tracer.TraceWarning <string>(0L, "Deleting classification rule collection '{0}' with null compressed data.", existingRulePackObject.DistinguishedName);
                return(Enumerable.Empty <string>().ToList <string>());
            }
            catch (AggregateException ex)
            {
                ((ClassificationDefinitionsDiagnosticsReporter)ClassificationDefinitionsDiagnosticsReporter.Instance).Tracer.TraceWarning <string, string>(0L, "Deleting classification rule collection '{0}' with invalid compressed data or invalid decompressed data. Details: {1}", existingRulePackObject.DistinguishedName, ex.Flatten().ToString());
                return(Enumerable.Empty <string>().ToList <string>());
            }
            catch (XmlException ex2)
            {
                ((ClassificationDefinitionsDiagnosticsReporter)ClassificationDefinitionsDiagnosticsReporter.Instance).Tracer.TraceWarning <string, string>(0L, "Deleting classification rule collection '{0}' with invalid XML contents. Details: {1}", existingRulePackObject.DistinguishedName, new AggregateException(new Exception[]
                {
                    ex2
                }).Flatten().ToString());
                return(Enumerable.Empty <string>().ToList <string>());
            }
            if (updatedRulePackXDoc != null)
            {
                foreach (string item in XmlProcessingUtils.GetAllRuleIds(updatedRulePackXDoc))
                {
                    hashSet.Remove(item);
                }
            }
            return(ClassificationRuleCollectionValidationUtils.ProcessClassificationReferences(DlpUtils.GetDataClassificationsInUse(dataSession, hashSet, ClassificationDefinitionConstants.RuleIdComparer), referencingRules));
        }
Beispiel #7
0
 private IList <string> GetAllRulesInUse(TransportRule transportRule, ISet <string> referencingRules = null)
 {
     ExAssert.RetailAssert(((IDirectorySession)base.DataSession).SessionSettings.CurrentOrganizationId.Equals(transportRule.OrganizationId), "Remove-ClassificationRuleCollection session must be underscoped to tenant organization to check whether the collection is in-use.");
     return(ClassificationRuleCollectionValidationUtils.GetDeletedRulesInUse(base.DataSession, transportRule, referencingRules, null));
 }