Ejemplo n.º 1
0
        private void GenerateIndicatorPanelDetail(RiskModelCategory category, RuleBase <HealthcheckData> hcrule)
        {
            string safeRuleId = hcrule.RiskId.Replace("$", "dollar");

            object[] frameworks;
            string   prefix = string.Empty;

            frameworks = hcrule.GetType().GetCustomAttributes(typeof(RuleMitreAttackMitigationAttribute), true);
            if (frameworks != null && frameworks.Length > 0)
            {
                prefix += "[M]";
            }
            frameworks = hcrule.GetType().GetCustomAttributes(typeof(RuleMitreAttackTechniqueAttribute), true);
            if (frameworks != null && frameworks.Length > 0)
            {
                prefix += "[T]";
            }

            GenerateAccordionDetail("rules" + safeRuleId, "rules" + category.ToString(), prefix + hcrule.Title + " (" + hcrule.RiskId + ")", null,
                                    () =>
            {
                Add("<h3>");

                Add(hcrule.Title);
                Add("</h3>\r\n<strong>Rule ID:</strong><p class=\"text-justify\">");
                Add(hcrule.RiskId);
                Add("</p>\r\n<strong>Description:</strong><p class=\"text-justify\">");
                Add(NewLineToBR(hcrule.Description));
                Add("</p>\r\n<strong>Technical explanation:</strong><p class=\"text-justify\">");
                Add(NewLineToBR(hcrule.TechnicalExplanation));
                Add("</p>\r\n<strong>Advised solution:</strong><p class=\"text-justify\">");
                Add(NewLineToBR(hcrule.Solution));
                Add(@"</p>");
                object[] models = hcrule.GetType().GetCustomAttributes(typeof(RuleIntroducedInAttribute), true);
                if (models != null && models.Length != 0)
                {
                    var model = (PingCastle.Rules.RuleIntroducedInAttribute)models[0];
                    Add("<strong>Introduced in:</strong>");
                    Add("<p class=\"text-justify\">");
                    Add(model.Version.ToString());
                    Add(@"</p>");
                }
                Add("<strong>Points:</strong><p>");
                Add(NewLineToBR(hcrule.GetComputationModelString()));
                Add("</p>\r\n");
                if (!String.IsNullOrEmpty(hcrule.Documentation))
                {
                    Add("<strong>Documentation:</strong><p>");
                    Add(hcrule.Documentation);
                    Add("</p>");
                }
            });
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Strong typed rule invocation.
        /// </summary>
        /// <typeparam name="TParameter">The type of the rule parameter.</typeparam>
        /// <param name="rule">The rule to be evaluated.</param>
        /// <param name="ruleParameter">The parameter for invoking the rule.</param>
        /// <param name="valueName">The name of the data to be checked.</param>
        /// <returns>True if the rule check is ok, false if the rule is violated.</returns>
        public bool ExecuteRuleExpression <TParameter>(RuleBase <TData, TParameter> rule, TParameter ruleParameter, string valueName)
        {
            // if there is no rule, we cannot say that the rule is validated
            if (rule == null)
            {
                return(true);
            }

            // let the concrete execution class decide if we want to execute the expression
            if (!this.BeforeInvoke(rule, ruleParameter, valueName))
            {
                return(true);
            }

            var validationResult = false;

            try
            {
                // execute the expression
                validationResult = rule.CheckExpression(this.Value, ruleParameter);
            }
            catch (NullReferenceException)
            {
            }
            catch (Exception ex)
            {
                if (!this.HandleInvokeException(ex, rule, ruleParameter, valueName))
                {
                    throw;
                }
            }

            var ruleType = rule.GetType();
            var result   = new RuleValidationResult(
                ruleType,
                string.Format(
                    CultureInfo.CurrentCulture,
                    Resources.RuleValidationResultStandardMessage,
                    ruleType.Namespace + "." + ruleType.Name,
                    valueName,
                    string.Format(CultureInfo.CurrentCulture, rule.Message, ruleParameter, valueName)),
                valueName,
                validationResult);

            foreach (var action in Bouncer.GetAfterInvokeActions())
            {
                action.Invoke(result);
            }

            this.AfterInvoke(result);

            if (this.PreviousExecuter != null)
            {
                this.PreviousExecuter.AssertAll();
            }

            return(validationResult);
        }