예제 #1
0
 /// <summary>
 /// Gets the authorization policy
 /// </summary>
 /// <param name="policyName">String representing the policy</param>
 /// <returns></returns>
 /// <remarks>
 /// Gets a CSLA permissions policy if the policy name corresponds
 /// to a CSLA policy, otherwise gets a policy from the fallback
 /// provider.
 /// </remarks>
 public Task <AuthorizationPolicy> GetPolicyAsync(string policyName)
 {
     if (CslaPolicy.TryGetPermissionRequirement(policyName, out CslaPermissionRequirement requirement))
     {
         var policy = new AuthorizationPolicyBuilder();
         policy.AddRequirements(requirement);
         return(Task.FromResult(policy.Build()));
     }
     else
     {
         return(GetFallbackPolicyAsync());
     }
 }
예제 #2
0
        /// <summary>
        /// Gets the authorization policy
        /// </summary>
        /// <param name="policyName">String representing the policy</param>
        /// <returns></returns>
        /// <remarks>
        /// Gets a CSLA permissions policy if the policy name corresponds
        /// to a CSLA policy, otherwise gets a policy from the fallback
        /// provider.
        /// </remarks>
        public Task <AuthorizationPolicy> GetPolicyAsync(string policyName)
        {
            var policy = _options.GetPolicy(policyName);

            if (policy is null && CslaPolicy.TryGetPermissionRequirement(policyName, out CslaPermissionRequirement requirement))
            {
                var policyBuilder = new AuthorizationPolicyBuilder();
                policyBuilder.AddRequirements(requirement);
                policy = policyBuilder.Build();

                _options.AddPolicy(policyName, policy);
            }

            return(Task.FromResult(policy));
        }
예제 #3
0
 /// <summary>
 /// Creates instance of type
 /// </summary>
 /// <param name="action">Authorization action</param>
 /// <param name="objectType">Business domain type</param>
 public HasPermissionAttribute(Rules.AuthorizationActions action, Type objectType)
     : base(CslaPolicy.GetPolicy(action, objectType))
 {
 }