|
1 |
| -@namespace Microsoft.AspNetCore.Components |
| 1 | +@* |
| 2 | + Ideally, this would be an internal (and probably abstract) class. So temporarily |
| 3 | + this is in an "internal" namespace and should become actually internal in the future. |
| 4 | +*@ |
| 5 | +@namespace Microsoft.AspNetCore.Components.Internal |
2 | 6 | @using System.Security.Claims
|
3 | 7 | @using Microsoft.AspNetCore.Authorization
|
4 | 8 | @inject IAuthorizationService AuthorizationService
|
|
18 | 22 | }
|
19 | 23 |
|
20 | 24 | @functions {
|
21 |
| - private IAuthorizeData[] selfAsAuthorizeData; |
22 | 25 | private AuthenticationState currentAuthenticationState;
|
23 | 26 | private bool isAuthorized;
|
24 | 27 |
|
|
45 | 48 | /// </summary>
|
46 | 49 | [Parameter] public RenderFragment Authorizing { get; private set; }
|
47 | 50 |
|
48 |
| - /// <summary> |
49 |
| - /// The policy name that determines whether the content can be displayed. |
50 |
| - /// </summary> |
51 |
| - [Parameter] public string Policy { get; private set; } |
52 |
| - |
53 |
| - /// <summary> |
54 |
| - /// A comma delimited list of roles that are allowed to display the content. |
55 |
| - /// </summary> |
56 |
| - [Parameter] public string Roles { get; private set; } |
57 |
| - |
58 | 51 | /// <summary>
|
59 | 52 | /// The resource to which access is being controlled.
|
60 | 53 | /// </summary>
|
61 | 54 | [Parameter] public object Resource { get; private set; }
|
62 | 55 |
|
63 |
| - protected override void OnInit() |
64 |
| - { |
65 |
| - selfAsAuthorizeData = new[] |
66 |
| - { |
67 |
| - new AuthorizeDataAdapter((AuthorizeView)(object)this) |
68 |
| - }; |
69 |
| - } |
70 |
| - |
71 | 56 | protected override async Task OnParametersSetAsync()
|
72 | 57 | {
|
73 | 58 | // We allow 'ChildContent' for convenience in basic cases, and 'Authorized' for symmetry
|
|
89 | 74 | isAuthorized = await IsAuthorizedAsync(currentAuthenticationState.User);
|
90 | 75 | }
|
91 | 76 |
|
| 77 | + // TODO: Make abstract instead |
| 78 | + protected virtual IAuthorizeData[] AuthorizeData |
| 79 | + { |
| 80 | + get => throw new NotImplementedException($"{nameof(AuthorizeData)} must be overridden and supplied by a derived class."); |
| 81 | + } |
| 82 | + |
92 | 83 | private async Task<bool> IsAuthorizedAsync(ClaimsPrincipal user)
|
93 | 84 | {
|
94 | 85 | var policy = await AuthorizationPolicy.CombineAsync(
|
95 |
| - AuthorizationPolicyProvider, selfAsAuthorizeData); |
| 86 | + AuthorizationPolicyProvider, AuthorizeData); |
96 | 87 | var result = await AuthorizationService.AuthorizeAsync(user, Resource, policy);
|
97 | 88 | return result.Succeeded;
|
98 | 89 | }
|
|
0 commit comments