Example #1
0
        public static IConventionPolicyContainer DelegatePolicy(this IConventionPolicyContainer policyContainer, string uniqueName, Func <DelegateSecurityContext, bool> policyDelegate, Func <PolicyViolationException, ActionResult> violationHandlerDelegate = null, string failureMessage = "Access denied")
        {
            Func <DelegateSecurityContext, PolicyResult> booleanPolicyDelegate =
                context => policyDelegate.Invoke(context)
                    ? PolicyResult.CreateSuccessResult(context.Policy)
                    : PolicyResult.CreateFailureResult(context.Policy, failureMessage);

            policyContainer.AddPolicy(new DelegatePolicy(uniqueName, booleanPolicyDelegate, violationHandlerDelegate));
            return(policyContainer);
        }
Example #2
0
 internal PolicyViolationException(PolicyResult policyResult)
     : base(policyResult.Message)
 {
     PolicyResult = policyResult;
     PolicyType   = PolicyResult.PolicyType;
 }
 internal PolicyViolationException(PolicyResult policyResult)
     : base(policyResult.Message)
 {
     PolicyResult = policyResult;
     PolicyType = PolicyResult.PolicyType;
 }