コード例 #1
0
        private static IReadOnlyList <AuthorizeAttribute> CustomAuthorizeAttributes(ValidationRuleActionInternal actionRule)
        {
            var attributesFromAction = actionRule.CustomAuthorizeAttributesFromAction();

            return(attributesFromAction.Any()
                ? attributesFromAction
                : actionRule.CustomAuthorizeAttributesFromController());
        }
コード例 #2
0
        private static string ActualAttributesMessage(ValidationRuleActionInternal actionRule)
        {
            var authorizeAttributesForDisplay = CustomAuthorizeAttributes(actionRule)
                                                .Select(AuthorizeAttributeAndPolicyNameForDisplay).ToList();

            var formattedAuthAttributes = string.Join(", ", authorizeAttributesForDisplay);

            //todo: cleanup. works but messy
            var anonymousAttributeForDisplay = authorizeAttributesForDisplay.Any()
                ? string.Empty
                : actionRule.ActionHasAllowAnonymousAttribute() ||
                                               actionRule.ControllerHasAllowAnonymousAttribute()
                    ? AttributeForDisplay(new AllowAnonymousAttribute())
                    : ""; //todo: why not string.empty here?

            var actualAttributesFormatted = $"{formattedAuthAttributes}{anonymousAttributeForDisplay}";
            var actualAttributesMessage   = $"\t actual attribute(s): \t{actualAttributesFormatted}";

            return(actualAttributesMessage);
        }
コード例 #3
0
        /// <summary>
        /// Creates a result message with human readable text formatted for console output
        /// </summary>
        /// <param name="actionRule"></param>
        public static ValidationResult Create(ValidationRuleActionInternal actionRule, bool isValid)
        {
            var requiredAttribute        = AttributeForDisplay(actionRule.AttributeRequired);
            var requiredAttributeMessage = $"\t required attribute: \t{requiredAttribute}";

            var messageBuilder = new StringBuilder();

            messageBuilder
            .AppendLine($"{actionRule.ControllerName}.{actionRule.ActionNameForDisplayWithParameters()}");

            if (!isValid)
            {
                messageBuilder.AppendLine(ActualAttributesMessage(actionRule));
            }

            messageBuilder.AppendLine(requiredAttributeMessage);

            return(new ValidationResult(
                       isValid: isValid,
                       message: messageBuilder.ToString()));
        }