Пример #1
0
        public static IPolicyContainer DelegatePolicy(this IPolicyContainer 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);
        }
Пример #2
0
 public static IPolicyContainer AllowAny(this IPolicyContainer policyContainer)
 {
     policyContainer.AddPolicy(new IgnorePolicy());
     return(policyContainer);
 }
Пример #3
0
 public static IPolicyContainer RequireAllRoles(this IPolicyContainer policyContainer, params object[] roles)
 {
     policyContainer.AddPolicy(new RequireAllRolesPolicy(roles));
     return(policyContainer);
 }
Пример #4
0
 public static IPolicyContainer DenyAuthenticatedAccess(this IPolicyContainer policyContainer)
 {
     policyContainer.AddPolicy(new DenyAuthenticatedAccessPolicy());
     return(policyContainer);
 }
Пример #5
0
 public static IPolicyContainer DenyAnonymousAccess(this IPolicyContainer policyContainer)
 {
     policyContainer.AddPolicy(new DenyAnonymousAccessPolicy());
     return(policyContainer);
 }
Пример #6
0
 public static IPolicyContainer DelegatePolicy(this IPolicyContainer policyContainer, string uniqueName, Func <DelegateSecurityContext, PolicyResult> policyDelegate, Func <PolicyViolationException, ActionResult> violationHandlerDelegate = null)
 {
     policyContainer.AddPolicy(new DelegatePolicy(uniqueName, policyDelegate, violationHandlerDelegate));
     return(policyContainer);
 }