-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Add ClientResourcePermissionValueProvider implementation #24515
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
ab114be
Add ClientResourcePermissionValueProvider implementation
maliming 7050ef9
Implement application finder and resource permission management provi…
maliming 499f127
Implement client finder and resource permission management providers
maliming 60ec72e
Add localization for ResourcePermissionProviderKeyLookupService in mu…
maliming fdff013
Remove post-configuration for resource management providers
maliming e1b7487
Refactor permission value provider methods for consistency and clarity
maliming 4a671e4
Fix spacing in SetAsync method parameters
maliming a7d0391
Fix spacing in RevokeAsync method parameters
maliming 202109a
Add resource management providers for IdentityServer and OpenIddict
maliming bdd7607
Fix parameter order and minor code cleanups
maliming c385660
Fix modal header to display resource name correctly
maliming 31ff63c
Add ClientResourcePermissionManagerExtensions classes
maliming 562914f
Refactor resource permission key lookup to use names/ClientIds
maliming 5e4228b
Add distributed event handling for OpenIddict app changes
maliming 7dd53d8
Add ClientDeletedEventHandler for permission cleanup
maliming af584e4
Update localization for ApplicationResourcePermissionProviderKeyLooku…
maliming File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
...ion/Volo/Abp/Authorization/Permissions/Resources/ClientResourcePermissionValueProvider.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| using System.Linq; | ||
| using System.Threading.Tasks; | ||
| using Volo.Abp.MultiTenancy; | ||
| using Volo.Abp.Security.Claims; | ||
|
|
||
| namespace Volo.Abp.Authorization.Permissions.Resources; | ||
|
|
||
| public class ClientResourcePermissionValueProvider : ResourcePermissionValueProvider | ||
| { | ||
| public const string ProviderName = "C"; | ||
|
|
||
| public override string Name => ProviderName; | ||
|
|
||
| protected ICurrentTenant CurrentTenant { get; } | ||
|
|
||
| public ClientResourcePermissionValueProvider(IResourcePermissionStore resourcePermissionStore, ICurrentTenant currentTenant) | ||
| : base(resourcePermissionStore) | ||
| { | ||
| CurrentTenant = currentTenant; | ||
| } | ||
|
|
||
| public override async Task<PermissionGrantResult> CheckAsync(ResourcePermissionValueCheckContext context) | ||
| { | ||
| var clientId = context.Principal?.FindFirst(AbpClaimTypes.ClientId)?.Value; | ||
|
|
||
| if (clientId == null) | ||
| { | ||
| return PermissionGrantResult.Undefined; | ||
| } | ||
|
|
||
| using (CurrentTenant.Change(null)) | ||
| { | ||
| return await ResourcePermissionStore.IsGrantedAsync(context.ResourceName, context.ResourceKey, context.Permission.Name, Name, clientId) | ||
| ? PermissionGrantResult.Granted | ||
| : PermissionGrantResult.Undefined; | ||
| } | ||
| } | ||
|
|
||
| public override async Task<MultiplePermissionGrantResult> CheckAsync(ResourcePermissionValuesCheckContext context) | ||
| { | ||
| var permissionNames = context.Permissions.Select(x => x.Name).Distinct().ToArray(); | ||
| Check.NotNullOrEmpty(permissionNames, nameof(permissionNames)); | ||
|
|
||
| var clientId = context.Principal?.FindFirst(AbpClaimTypes.ClientId)?.Value; | ||
| if (clientId == null) | ||
| { | ||
| return new MultiplePermissionGrantResult(permissionNames); ; | ||
maliming marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| using (CurrentTenant.Change(null)) | ||
| { | ||
| return await ResourcePermissionStore.IsGrantedAsync(permissionNames, context.ResourceName, context.ResourceKey, Name, clientId); | ||
| } | ||
| } | ||
| } | ||
10 changes: 10 additions & 0 deletions
10
...lo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Clients/ClientFinderResult.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| using System; | ||
|
|
||
| namespace Volo.Abp.IdentityServer.Clients; | ||
|
|
||
| public class ClientFinderResult | ||
| { | ||
| public Guid Id { get; set; } | ||
|
|
||
| public string ClientId { get; set; } | ||
| } |
12 changes: 12 additions & 0 deletions
12
...rc/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Clients/IClientFinder.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace Volo.Abp.IdentityServer.Clients; | ||
|
|
||
| public interface IClientFinder | ||
| { | ||
| Task<List<ClientFinderResult>> SearchAsync(string filter, int page = 1); | ||
|
|
||
| Task<List<ClientFinderResult>> SearchByIdsAsync(Guid[] ids); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
...server/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientFinder.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Threading.Tasks; | ||
| using Volo.Abp.DependencyInjection; | ||
| using Volo.Abp.Domain.Repositories; | ||
|
|
||
| namespace Volo.Abp.IdentityServer.Clients; | ||
|
|
||
| public class ClientFinder: IClientFinder, ITransientDependency | ||
maliming marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| protected IClientRepository ClientRepository { get; } | ||
|
|
||
| public ClientFinder(IClientRepository clientRepository) | ||
| { | ||
| ClientRepository = clientRepository; | ||
| } | ||
|
|
||
| public virtual async Task<List<ClientFinderResult>> SearchAsync(string filter, int page = 1) | ||
| { | ||
| using (ClientRepository.DisableTracking()) | ||
| { | ||
| page = page < 1 ? 1 : page; | ||
| var clients = await ClientRepository.GetListAsync(nameof(Client.ClientName), filter: filter, skipCount: (page - 1) * 10, maxResultCount: 10); | ||
| return clients.Select(x => new ClientFinderResult | ||
| { | ||
| Id = x.Id, | ||
| ClientId = x.ClientId | ||
| }).ToList(); | ||
| } | ||
| } | ||
|
|
||
| public virtual async Task<List<ClientFinderResult>> SearchByIdsAsync(Guid[] ids) | ||
| { | ||
| using (ClientRepository.DisableTracking()) | ||
| { | ||
| var clients = await ClientRepository.GetListByIdsAsync(ids); | ||
| return clients.Select(x => new ClientFinderResult | ||
| { | ||
| Id = x.Id, | ||
| ClientId = x.ClientId | ||
| }).ToList(); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.