CSLA.NET 5.4.2
CSLA .NET is a software development framework that helps you build a reusable, maintainable object-oriented business layer for your app.
CslaPermissionsPolicyProvider.cs
Go to the documentation of this file.
1//-----------------------------------------------------------------------
2// <copyright file="CslaPermissionsPolicyProvider.cs" company="Marimer LLC">
3// Copyright (c) Marimer LLC. All rights reserved.
4// Website: https://cslanet.com
5// </copyright>
6// <summary>CSLA permissions policy provider</summary>
7//-----------------------------------------------------------------------
8
9using System;
10using System.Threading.Tasks;
11using Microsoft.AspNetCore.Authorization;
12using Microsoft.Extensions.Options;
13
14namespace Csla.Blazor
15{
19 public class CslaPermissionsPolicyProvider : IAuthorizationPolicyProvider
20 {
21 private readonly AuthorizationOptions _options;
22
27 public CslaPermissionsPolicyProvider(IOptions<AuthorizationOptions> options)
28 {
29 if (options == null)
30 {
31 throw new ArgumentNullException(nameof(options));
32 }
33
34 _options = options.Value;
35 }
36
41 public Task<AuthorizationPolicy> GetDefaultPolicyAsync() => Task.FromResult(_options.DefaultPolicy);
46 public Task<AuthorizationPolicy> GetFallbackPolicyAsync() => Task.FromResult(_options.FallbackPolicy);
47
58 public Task<AuthorizationPolicy> GetPolicyAsync(string policyName)
59 {
60 var policy = _options.GetPolicy(policyName);
61 if (policy is null && CslaPolicy.TryGetPermissionRequirement(policyName, out CslaPermissionRequirement requirement))
62 {
63 var policyBuilder = new AuthorizationPolicyBuilder();
64 policyBuilder.AddRequirements(requirement);
65 policy = policyBuilder.Build();
66
67 _options.AddPolicy(policyName, policy);
68 }
69
70 return Task.FromResult(policy);
71 }
72 }
73}
Task< AuthorizationPolicy > GetDefaultPolicyAsync()
Gets the default policy
CslaPermissionsPolicyProvider(IOptions< AuthorizationOptions > options)
Creates an instance of the type
Task< AuthorizationPolicy > GetFallbackPolicyAsync()
Gets the fallback policy
Task< AuthorizationPolicy > GetPolicyAsync(string policyName)
Gets the authorization policy