protected override IConfigurable PrepareDataObject() { TaskLogger.LogEnter(); TransportRule transportRule = (TransportRule)base.PrepareDataObject(); if (base.HasErrors) { return(null); } try { transportRule.Xml = RuleParser.GetDisabledRuleXml(transportRule.Xml); } catch (ParserException exception) { base.WriteError(exception, ErrorCategory.InvalidData, null); return(null); } if (Utils.Exchange12HubServersExist(this)) { this.WriteWarning(Strings.SetRuleSyncAcrossDifferentVersionsNeeded); } TaskLogger.LogExit(); return(transportRule); }
protected override void InternalProcessRecord() { MalwareFilterRule malwareFilterRule = new MalwareFilterRule(null, base.Name, base.Priority, base.Enabled ? RuleState.Enabled : RuleState.Disabled, base.Comments, base.Conditions, base.Exceptions, new MalwareFilterPolicyIdParameter(this.policyObject.Name)); int priority = base.Fields.IsModified("Priority") ? malwareFilterRule.Priority : -1; TransportRule transportRule = null; try { TransportRule rule = malwareFilterRule.ToInternalRule(); ADRuleStorageManager adruleStorageManager = new ADRuleStorageManager(this.ruleCollectionName, base.DataSession); adruleStorageManager.LoadRuleCollection(); adruleStorageManager.NewRule(rule, this.ResolveCurrentOrganization(), ref priority, out transportRule); } catch (RulesValidationException exception) { base.WriteError(exception, ErrorCategory.InvalidArgument, base.Name); } catch (InvalidPriorityException exception2) { base.WriteError(exception2, ErrorCategory.InvalidArgument, null); } catch (ParserException exception3) { base.WriteError(exception3, ErrorCategory.InvalidData, null); } malwareFilterRule.Priority = priority; malwareFilterRule.SetTransportRule(transportRule); base.WriteObject(malwareFilterRule); }
private bool TryParseADRulePack(TransportRule adRulePack, out XDocument rulePackXDocument) { ArgumentValidator.ThrowIfNull("adRulePack", adRulePack); rulePackXDocument = null; Exception ex = null; try { rulePackXDocument = ClassificationDefinitionUtils.GetRuleCollectionDocumentFromTransportRule(adRulePack); } catch (ArgumentException ex2) { ex = ex2; } catch (AggregateException ex3) { ex = ex3; } catch (XmlException ex4) { ex = ex4; } if (ex != null) { this.task.WriteWarning(Strings.WarningInvalidRuleCollectionADObject(adRulePack.Identity.ToString(), ex.Message)); } return(rulePackXDocument != null); }
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); }
protected override void InternalProcessRecord() { HostedContentFilterRule hostedContentFilterRule = new HostedContentFilterRule(null, base.Name, base.Priority, base.Enabled ? RuleState.Enabled : RuleState.Disabled, base.Comments, base.Conditions, base.Exceptions, new HostedContentFilterPolicyIdParameter(this.policyObject.Name)); if (this.policyObject.EnableEndUserSpamNotifications && !hostedContentFilterRule.IsEsnCompatible) { base.WriteError(new OperationNotAllowedException(Strings.ErrorCannotScopeEsnPolicy(this.policyObject.Name)), ErrorCategory.InvalidOperation, null); } int priority = base.Fields.IsModified("Priority") ? hostedContentFilterRule.Priority : -1; TransportRule transportRule = null; try { TransportRule rule = hostedContentFilterRule.ToInternalRule(); ADRuleStorageManager adruleStorageManager = new ADRuleStorageManager(this.ruleCollectionName, base.DataSession); adruleStorageManager.LoadRuleCollection(); adruleStorageManager.NewRule(rule, this.ResolveCurrentOrganization(), ref priority, out transportRule); FfoDualWriter.SaveToFfo <TransportRule>(this, transportRule, TenantSettingSyncLogType.DUALSYNCTR, null); } catch (RulesValidationException exception) { base.WriteError(exception, ErrorCategory.InvalidArgument, base.Name); } catch (InvalidPriorityException exception2) { base.WriteError(exception2, ErrorCategory.InvalidArgument, null); } catch (ParserException exception3) { base.WriteError(exception3, ErrorCategory.InvalidData, null); } hostedContentFilterRule.Priority = priority; hostedContentFilterRule.SetTransportRule(transportRule); base.WriteObject(hostedContentFilterRule); }
public static TransportRule ResolvePolicyRuleObject <T>(T policy, IConfigDataProvider session, string ruleCollectionName) where T : ADObject, new() { if (typeof(T) != typeof(MalwareFilterPolicy) && typeof(T) != typeof(HostedContentFilterPolicy)) { throw new NotSupportedException(); } try { ADRuleStorageManager adruleStorageManager = new ADRuleStorageManager(ruleCollectionName, session); adruleStorageManager.LoadRuleCollection(); foreach (Rule rule in adruleStorageManager.GetRuleCollection()) { TransportRule transportRule = (TransportRule)rule; if (transportRule.Actions != null && transportRule.Actions.Count > 0 && transportRule.Actions[0].Arguments != null && transportRule.Actions[0].Arguments.Count == 2) { string strA = transportRule.Actions[0].Arguments[1].GetValue(null) as string; if (string.Compare(strA, policy.Name, true) == 0) { return(transportRule); } } } } catch (RuleCollectionNotInAdException) { return(null); } return(null); }
private static void UpdateRuleADObjectFromPresentationObject(SupervisionTransportRule adRuleObject, Microsoft.Exchange.MessagingPolicies.Rules.Tasks.Rule rule) { TransportRule rule2 = rule.ToInternalRule(); string xml = TransportRuleSerializer.Instance.SaveRuleToString(rule2); adRuleObject.Xml = xml; }
protected override IConfigurable PrepareDataObject() { TaskLogger.LogEnter(); TransportRule transportRule = (TransportRule)base.PrepareDataObject(); if (base.HasErrors) { return(null); } TransportRule transportRule2; try { transportRule2 = (TransportRule)TransportRuleParser.Instance.GetRule(transportRule.Xml); } catch (ParserException exception) { base.WriteError(exception, ErrorCategory.InvalidData, null); return(null); } if (transportRule2.IsTooAdvancedToParse) { base.WriteError(new InvalidOperationException(Strings.CannotModifyRuleDueToVersion(transportRule2.Name)), ErrorCategory.InvalidOperation, null); return(null); } OrganizationId organizationId = transportRule.OrganizationId; if (organizationId != OrganizationId.ForestWideOrgId) { ADRuleStorageManager adruleStorageManager; try { adruleStorageManager = new ADRuleStorageManager(base.RuleCollectionName, base.DataSession); } catch (RuleCollectionNotInAdException exception2) { base.WriteError(exception2, ErrorCategory.InvalidOperation, null); return(null); } adruleStorageManager.LoadRuleCollection(); InvalidOperationException ex = Utils.CheckRuleForOrganizationLimits((IConfigurationSession)base.DataSession, base.TenantGlobalCatalogSession, adruleStorageManager, organizationId, transportRule2, false); if (ex != null) { base.WriteError(ex, ErrorCategory.InvalidOperation, null); return(null); } } if (Utils.Exchange12HubServersExist(this)) { this.WriteWarning(Strings.SetRuleSyncAcrossDifferentVersionsNeeded); } transportRule2.Enabled = RuleState.Enabled; transportRule2.Mode = (base.Fields.IsModified("Mode") ? this.Mode : RuleMode.Enforce); string xml = TransportRuleSerializer.Instance.SaveRuleToString(transportRule2); transportRule.Xml = xml; TaskLogger.LogExit(); return(transportRule); }
internal static JournalRuleObject CreateCorruptJournalRuleObject(TransportRule transportRule, LocalizedString errorText) { return(new JournalRuleObject(transportRule.Name, false, null, SmtpAddress.Empty, JournalRuleScope.Global, null, GccType.None) { isValid = false, errorText = errorText }); }
internal static MalwareFilterRule CreateCorruptRule(int priority, TransportRule transportRule, LocalizedString errorText) { return(new MalwareFilterRule(transportRule, transportRule.Name, priority, RuleState.Disabled, null, null, null, null) { isValid = false, errorText = errorText }); }
internal static bool IsAdObjectAClassificationRuleCollection(TransportRule transportRule) { if (transportRule == null) { throw new ArgumentNullException("transportRule"); } return(((ADObjectId)transportRule.Identity).Parent.DistinguishedName.Equals(transportRule.Session.GetOrgContainerId().GetDescendantId(ClassificationDefinitionConstants.ClassificationDefinitionsRdn).ToDNString(), StringComparison.OrdinalIgnoreCase)); }
public RulePresentationObjectBase(TransportRule transportRule) { if (transportRule != null) { this.transportRule = transportRule; return; } this.transportRule = new TransportRule(); }
private void ThrowIfAnyEnabledTransportRuleHaveEncryptOrDecryptAction() { IEnumerable <TransportRule> transportRulesMatchingDelegate = Utils.GetTransportRulesMatchingDelegate(this.ConfigurationSession, new Utils.TransportRuleSelectionDelegate(SetIRMConfiguration.IsTransportRuleEnabledAndHasEncryptMessageOrDecryptMessageAction), null); TransportRule transportRule = transportRulesMatchingDelegate.FirstOrDefault <TransportRule>(); if (transportRule != null) { base.WriteError(new EtrHasE4eActionException(transportRule.Name), ExchangeErrorCategory.Client, base.Identity); } }
public static bool IsEmptyCondition(TransportRule rule) { if (rule == null) { throw new ArgumentNullException("rule"); } OutlookProtectionRulePresentationObject outlookProtectionRulePresentationObject = new OutlookProtectionRulePresentationObject(rule); return(outlookProtectionRulePresentationObject.IsEmptyCondition()); }
public void AddTransportRule() { // DEPENDENCIES _servTR = container.GetRequiredService <ITransportRuleService>(); // ARRANGE _tr = (TransportRule)Records.transportRule.Clone(); // ACT _servTR.Create(_tr, _user); }
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); }
internal static ClassificationRuleCollectionPresentationObject Create(TransportRule transportRule) { if (transportRule == null) { throw new ArgumentNullException("transportRule"); } ClassificationRuleCollectionPresentationObject classificationRuleCollectionPresentationObject = new ClassificationRuleCollectionPresentationObject(transportRule); classificationRuleCollectionPresentationObject.Initialize(); return(classificationRuleCollectionPresentationObject); }
private HostedContentFilterRule GetPolicyScopingRule() { TransportRule transportRule = HygieneUtils.ResolvePolicyRuleObject <HostedContentFilterPolicy>(this.DataObject, this.ConfigurationSession, "HostedContentFilterVersioned"); if (transportRule != null) { TransportRule transportRule2 = this.GetTransportRule(transportRule.Name); return(HostedContentFilterRule.CreateFromInternalRule(transportRule, -1, transportRule2)); } return(null); }
public int GetSequenceNumberToUpdatePriority(TransportRule rule, int newPriority) { if (rule == null) { throw new ArgumentNullException("rule"); } if (newPriority < 0) { throw new ArgumentOutOfRangeException("newPriority"); } return(this.GetSequenceNumberForPriority(newPriority, rule.Priority)); }
private static TransportRule GetTransportRuleUnParsed(IConfigDataProvider dataSession, string collectionName, QueryFilter filter) { ADRuleStorageManager adruleStorageManager = new ADRuleStorageManager(collectionName, dataSession); adruleStorageManager.LoadRuleCollectionWithoutParsing(filter); TransportRule result = null; if (adruleStorageManager.Count > 0) { adruleStorageManager.GetRuleWithoutParsing(0, out result); } return(result); }
protected HygieneFilterRule(TransportRule transportRule, string name, int priority, RuleState state, string comments, TransportRulePredicate[] conditions, TransportRulePredicate[] exceptions, ADIdParameter policyId) : base(transportRule) { if (transportRule == null) { base.Name = name; } this.Priority = priority; this.State = state; this.Comments = comments; this.conditions = conditions; this.exceptions = exceptions; this.PolicyId = policyId; }
private TransportRule GetTransportRule(string ruleName) { ADRuleStorageManager adruleStorageManager = new ADRuleStorageManager("HostedContentFilterVersioned", base.DataSession); adruleStorageManager.LoadRuleCollectionWithoutParsing(new TextFilter(ADObjectSchema.Name, ruleName, MatchOptions.FullString, MatchFlags.Default)); TransportRule result = null; if (adruleStorageManager.Count > 0) { adruleStorageManager.GetRuleWithoutParsing(0, out result); } return(result); }
internal override IConfigurable CreateTaskRuleFromInternalRule(TransportRule rule, int priority, TransportRule transportRule) { HostedContentFilterRule result; try { result = HostedContentFilterRule.CreateFromInternalRule(rule, priority, transportRule); } catch (CorruptFilterRuleException ex) { result = HostedContentFilterRule.CreateCorruptRule(priority, transportRule, ex.LocalizedString); } return(result); }
protected override void InternalValidate() { base.InternalValidate(); TransportRule dataObject = this.DataObject; if (dataObject == null) { ExAssert.RetailAssert(false, "EnableTransportRule.InternalValidate data object is invalid"); } TransportRule rule = (TransportRule)TransportRuleParser.Instance.GetRule(dataObject.Xml); Rule rule2 = Rule.CreateFromInternalRule(TransportRulePredicate.GetAvailablePredicateMappings(), TransportRuleAction.GetAvailableActionMappings(), rule, dataObject.Priority, dataObject); IEnumerable <RightsProtectMessageAction> source = (from action in rule2.Actions where action is RightsProtectMessageAction select action as RightsProtectMessageAction).ToList <RightsProtectMessageAction>(); if (source.Any <RightsProtectMessageAction>()) { if (!RmsClientManager.IRMConfig.IsInternalLicensingEnabledForTenant(base.CurrentOrganizationId)) { base.WriteError(new IrmLicensingIsDisabledException(), ErrorCategory.InvalidArgument, null); } RmsTemplateIdentity template = source.First <RightsProtectMessageAction>().Template; RmsTemplateDataProvider session = new RmsTemplateDataProvider((IConfigurationSession)base.DataSession); base.GetDataObject <RmsTemplatePresentation>(new RmsTemplateIdParameter(template), session, null, new LocalizedString?(Strings.OutlookProtectionRuleRmsTemplateNotFound(template.TemplateName)), new LocalizedString?(Strings.OutlookProtectionRuleRmsTemplateNotUnique(template.TemplateName))); } bool flag; if (!rule2.Actions.Any((TransportRuleAction action) => action is ApplyOMEAction)) { flag = rule2.Actions.Any((TransportRuleAction action) => action is RemoveOMEAction); } else { flag = true; } bool flag2 = flag; if (flag2) { IRMConfiguration irmconfiguration = IRMConfiguration.Read((IConfigurationSession)base.DataSession); if (irmconfiguration == null || !irmconfiguration.InternalLicensingEnabled) { base.WriteError(new E4eLicensingIsDisabledExceptionEnableRule(), ErrorCategory.InvalidArgument, null); } if (RmsClientManager.IRMConfig.GetRmsTemplate(base.CurrentOrganizationId, RmsTemplate.InternetConfidential.Id) == null) { base.WriteError(new E4eRuleRmsTemplateNotFoundException(RmsTemplate.InternetConfidential.Name), ErrorCategory.InvalidArgument, null); } } }
internal static ClassificationRuleCollectionPresentationObject Create(TransportRule transportRule, Version rulePackageVersion, XElement rulePackageDetailsElement, bool isEncrypted) { if (transportRule == null) { throw new ArgumentNullException("transportRule"); } if (null == rulePackageVersion) { throw new ArgumentNullException("rulePackageVersion"); } ClassificationRuleCollectionPresentationObject classificationRuleCollectionPresentationObject = new ClassificationRuleCollectionPresentationObject(transportRule); classificationRuleCollectionPresentationObject.Initialize(rulePackageVersion, rulePackageDetailsElement, isEncrypted, XmlProcessingUtils.IsFingerprintRuleCollection(rulePackageDetailsElement.Document)); return(classificationRuleCollectionPresentationObject); }
protected override void InternalValidate() { base.InternalValidate(); this.policyObject = HygieneUtils.ResolvePolicyObject <MalwareFilterPolicy>(this, this.ConfigurationSession, this.MalwareFilterPolicy); TransportRule transportRule = HygieneUtils.ResolvePolicyRuleObject <MalwareFilterPolicy>(this.policyObject, this.ConfigurationSession, this.ruleCollectionName); if (transportRule != null) { base.WriteError(new OperationNotAllowedException(Strings.ErrorPolicyRuleExists(this.policyObject.Name, transportRule.Name)), ErrorCategory.InvalidOperation, null); } if (this.policyObject != null && this.policyObject.IsDefault) { base.WriteError(new OperationNotAllowedException(Strings.ErrorDefaultPolicyCannotHaveRule(this.policyObject.Name)), ErrorCategory.InvalidOperation, null); } }
private void SetRuleWithoutPriorityChange(ADRuleStorageManager storedRules) { TransportRule transportRule = (TransportRule)TransportRuleParser.Instance.GetRule(this.DataObject.Xml); HygieneFilterRule hygieneFilterRule = this.CreateTaskRuleFromInternalRule(transportRule, -1); this.UpdateRuleFromParameters(hygieneFilterRule); this.ValidateRuleEsnCompatibility(hygieneFilterRule); transportRule = hygieneFilterRule.ToInternalRule(); this.DataObject.Xml = TransportRuleSerializer.Instance.SaveRuleToString(transportRule); if (base.Fields.IsModified("Name") && !storedRules.CanRename((ADObjectId)this.DataObject.Identity, ((ADObjectId)this.DataObject.Identity).Name, transportRule.Name)) { base.WriteError(new ArgumentException(Strings.RuleNameAlreadyExist, "Name"), ErrorCategory.InvalidArgument, this.Name); } base.InternalProcessRecord(); }
public FluentRecordBase AddTransportRule( ) { // // DEPENDENCIES _servTR = container.Resolve <ITransportRuleService>(); // // ARRANGE _tr = (TransportRule)Records.transportRule.Clone(); // // ACT _servTR.Create(_tr, _user); return(this); }
internal static JournalNdrValidationCheckResult ValidateJournalNdrMailboxSetting(IConfigDataProvider dataProvider, SmtpAddress journalNdrToAddress) { ADJournalRuleStorageManager adjournalRuleStorageManager = null; bool flag = false; try { adjournalRuleStorageManager = new ADJournalRuleStorageManager("JournalingVersioned", dataProvider); } catch (RuleCollectionNotInAdException) { } if (adjournalRuleStorageManager != null) { adjournalRuleStorageManager.LoadRuleCollection(); RoutingAddress value = new RoutingAddress(journalNdrToAddress.ToString()); if (value == RoutingAddress.NullReversePath) { if (adjournalRuleStorageManager.Count > 0) { return(JournalNdrValidationCheckResult.JournalNdrCannotBeNullReversePath); } } else { foreach (Microsoft.Exchange.MessagingPolicies.Rules.Rule rule in adjournalRuleStorageManager.GetRuleCollection()) { TransportRule transportRule = (TransportRule)rule; JournalRuleObject journalRuleObject = new JournalRuleObject(); journalRuleObject.Deserialize(transportRule as JournalingRule); if (journalRuleObject.Recipient != null && journalRuleObject.Recipient != null && journalNdrToAddress == journalRuleObject.Recipient.Value) { return(JournalNdrValidationCheckResult.JournalNdrExistInJournalRuleRecipient); } if (journalNdrToAddress == journalRuleObject.JournalEmailAddress) { flag = true; } } } } if (!flag) { return(JournalNdrValidationCheckResult.JournalNdrValidationPassed); } return(JournalNdrValidationCheckResult.JournalNdrExistInJournalRuleJournalEmailAddress); }
internal MalwareFilterRule(TransportRule transportRule, string name, int priority, RuleState state, string comments, TransportRulePredicate[] conditions, TransportRulePredicate[] exceptions, MalwareFilterPolicyIdParameter policyId) : base(transportRule, name, priority, state, comments, conditions, exceptions, policyId) { if (base.Conditions != null) { foreach (TransportRulePredicate predicate in base.Conditions) { base.SetParametersFromPredicate(predicate, false); } } if (base.Exceptions != null) { foreach (TransportRulePredicate predicate2 in base.Exceptions) { base.SetParametersFromPredicate(predicate2, true); } } }