Exemplo n.º 1
0
        public override void OnAuthorization(HttpActionContext actionContext)
        {
            if (AuthorizationDisabled(actionContext) || AuthorizeRequest(actionContext.ControllerContext.Request))
            {
                actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.Unauthorized);
                return;
            }
            var claimsPrincipal = actionContext.Request.GetRequestContext().Principal as ClaimsPrincipal;

            if (claimsPrincipal != null)
            {
                var roleClaim = claimsPrincipal.Claims.FirstOrDefault(c => c.Type == ClaimsDeclaration.QuickspatchClientType);

                if (roleClaim != null)
                {
                    var clientType = Convert.ToInt32(roleClaim.Value);
                    if (QuickspatchClientType != (QuickspatchClientType)clientType)
                    {
                        actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.Forbidden);
                    }
                }
                else
                {
                    var diagnosticService = new DiagnosticService();

                    diagnosticService.Debug(string.Format("Validated ticket failed"));

                    actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.Forbidden);
                }
            }
            else
            {
                actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.ExpectationFailed);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Executes the rules defined in a on a domain object.
        /// </summary>
        /// <param name="instance">The domain object instance.</param>
        /// <param name="filter">A filter for rules that are run. The filter is applied
        /// before the rules are run.</param>
        /// <returns>A list of objects; one for each business
        /// rule that has been run on the object.</returns>
        public virtual IEnumerable <BusinessRuleResult> ExecuteRules(
            IEntity instance,
            Func <IBusinessRule <TEntity>, bool> filter)
        {
            // Execute business rules that match the property name (if defined).
            // As the result, create an anonymous type that includes the
            // business rule itself, and the result of its execution.
            List <dynamic> ruleExecution;

            if (filter != null)
            {
                ruleExecution = Rules
                                .ToArray()
                                .Where(filter)
                                .Select(rule => new
                {
                    Result = rule.Execute(instance),
                    Rule   = rule
                })
                                .ToList <dynamic>();
            }
            else
            {
                ruleExecution = Rules
                                .ToArray()
                                .Select(rule => new
                {
                    Result = rule.Execute(instance),
                    Rule   = rule
                })
                                .ToList <dynamic>();
            }

            // Log the execution results.
            foreach (var execution in ruleExecution)
            {
                string message = execution.Result.IsFailed ? LogBusinessRuleFailed : LogBusinessRuleSuccess;
                //Join the porpertyNames to one string seperated by ','
                string fields = "";
                if (execution.Rule.PropertyNames != null && execution.Rule.PropertyNames.Length != 0)
                {
                    fields = string.Join(",", execution.Rule.PropertyNames);
                }

                DiagnosticService.Debug(string.Format("Execute Rule: Message {0} - Rule Type {1} - Instance {2} - Result Message {3} - Field {4} ", message,
                                                      execution.Rule.GetType(), instance, execution.Result.Message, fields));
            }

            // Get the results of all business rule executions, and return them as
            // an array.
            IEnumerable <BusinessRuleResult> results = ruleExecution
                                                       .Select(execution => (BusinessRuleResult)execution.Result);

            return(results.ToArray());
        }