mirror of https://github.com/abpframework/abp.git
committed by
GitHub
85 changed files with 801 additions and 82 deletions
@ -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.Permission.Name, context.ResourceName, context.ResourceKey, 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); |
|||
} |
|||
|
|||
using (CurrentTenant.Change(null)) |
|||
{ |
|||
return await ResourcePermissionStore.IsGrantedAsync(permissionNames, context.ResourceName, context.ResourceKey, Name, clientId); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,10 @@ |
|||
using System; |
|||
|
|||
namespace Volo.Abp.IdentityServer.Clients; |
|||
|
|||
public class ClientFinderResult |
|||
{ |
|||
public Guid Id { get; set; } |
|||
|
|||
public string ClientId { get; set; } |
|||
} |
|||
@ -0,0 +1,9 @@ |
|||
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); |
|||
} |
|||
@ -0,0 +1,31 @@ |
|||
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 |
|||
{ |
|||
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(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,31 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Threading.Tasks; |
|||
using JetBrains.Annotations; |
|||
using Volo.Abp.Authorization.Permissions; |
|||
|
|||
namespace Volo.Abp.PermissionManagement; |
|||
|
|||
public static class ClientResourcePermissionManagerExtensions |
|||
{ |
|||
public static Task<PermissionWithGrantedProviders> GetForClientAsync([NotNull] this IResourcePermissionManager resourcePermissionManager, string resourceName, string resourceKey, string clientId, string permissionName) |
|||
{ |
|||
Check.NotNull(resourcePermissionManager, nameof(resourcePermissionManager)); |
|||
|
|||
return resourcePermissionManager.GetAsync(permissionName, resourceName, resourceKey, ClientPermissionValueProvider.ProviderName, clientId); |
|||
} |
|||
|
|||
public static Task<List<PermissionWithGrantedProviders>> GetAllForClientAsync([NotNull] this IResourcePermissionManager resourcePermissionManager, string resourceName, string resourceKey, string clientId) |
|||
{ |
|||
Check.NotNull(resourcePermissionManager, nameof(resourcePermissionManager)); |
|||
|
|||
return resourcePermissionManager.GetAllAsync(resourceName, resourceKey, ClientPermissionValueProvider.ProviderName, clientId); |
|||
} |
|||
|
|||
public static Task SetForClientAsync([NotNull] this IResourcePermissionManager resourcePermissionManager, string resourceName, string resourceKey, string clientId, [NotNull] string permissionName, bool isGranted) |
|||
{ |
|||
Check.NotNull(resourcePermissionManager, nameof(resourcePermissionManager)); |
|||
|
|||
return resourcePermissionManager.SetAsync(permissionName, resourceName, resourceKey, ClientPermissionValueProvider.ProviderName, clientId, isGranted); |
|||
} |
|||
} |
|||
@ -0,0 +1,31 @@ |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Authorization.Permissions; |
|||
using Volo.Abp.Authorization.Permissions.Resources; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.Domain.Entities.Events.Distributed; |
|||
using Volo.Abp.EventBus.Distributed; |
|||
using Volo.Abp.IdentityServer.Clients; |
|||
using Volo.Abp.Uow; |
|||
|
|||
namespace Volo.Abp.PermissionManagement.IdentityServer; |
|||
|
|||
public class ClientDeletedEventHandler : |
|||
IDistributedEventHandler<EntityDeletedEto<ClientEto>>, |
|||
ITransientDependency |
|||
{ |
|||
protected IPermissionManager PermissionManager { get; } |
|||
protected IResourcePermissionManager ResourcePermissionManager { get; } |
|||
|
|||
public ClientDeletedEventHandler(IPermissionManager permissionManager, IResourcePermissionManager resourcePermissionManager) |
|||
{ |
|||
PermissionManager = permissionManager; |
|||
ResourcePermissionManager = resourcePermissionManager; |
|||
} |
|||
|
|||
[UnitOfWork] |
|||
public virtual async Task HandleEventAsync(EntityDeletedEto<ClientEto> eventData) |
|||
{ |
|||
await PermissionManager.DeleteAsync(ClientPermissionValueProvider.ProviderName, eventData.Entity.ClientId); |
|||
await ResourcePermissionManager.DeleteAsync(ClientResourcePermissionValueProvider.ProviderName, eventData.Entity.ClientId); |
|||
} |
|||
} |
|||
@ -0,0 +1,62 @@ |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Authorization.Permissions.Resources; |
|||
using Volo.Abp.Guids; |
|||
using Volo.Abp.MultiTenancy; |
|||
|
|||
namespace Volo.Abp.PermissionManagement.IdentityServer; |
|||
|
|||
public class ClientResourcePermissionManagementProvider : ResourcePermissionManagementProvider |
|||
{ |
|||
public override string Name => ClientResourcePermissionValueProvider.ProviderName; |
|||
|
|||
public ClientResourcePermissionManagementProvider( |
|||
IResourcePermissionGrantRepository permissionGrantRepository, |
|||
IGuidGenerator guidGenerator, |
|||
ICurrentTenant currentTenant) |
|||
: base( |
|||
permissionGrantRepository, |
|||
guidGenerator, |
|||
currentTenant) |
|||
{ |
|||
} |
|||
|
|||
public override Task<ResourcePermissionValueProviderGrantInfo> CheckAsync(string name, string resourceName, string resourceKey, string providerName, string providerKey) |
|||
{ |
|||
using (CurrentTenant.Change(null)) |
|||
{ |
|||
return base.CheckAsync(name, resourceName, resourceKey, providerName, providerKey); |
|||
} |
|||
} |
|||
|
|||
public override Task<MultipleResourcePermissionValueProviderGrantInfo> CheckAsync(string[] names, string resourceName, string resourceKey, string providerName, string providerKey) |
|||
{ |
|||
using (CurrentTenant.Change(null)) |
|||
{ |
|||
return base.CheckAsync(names, resourceName, resourceKey, providerName, providerKey); |
|||
} |
|||
} |
|||
|
|||
public override Task SetAsync(string name, string resourceName, string resourceKey, string providerKey, bool isGranted) |
|||
{ |
|||
using (CurrentTenant.Change(null)) |
|||
{ |
|||
return base.SetAsync(name, resourceName, resourceKey, providerKey, isGranted); |
|||
} |
|||
} |
|||
|
|||
protected override async Task GrantAsync(string name, string resourceName, string resourceKey, string providerKey) |
|||
{ |
|||
using (CurrentTenant.Change(null)) |
|||
{ |
|||
await base.GrantAsync(name, resourceName, resourceKey, providerKey); |
|||
} |
|||
} |
|||
|
|||
protected override Task RevokeAsync(string name, string resourceName, string resourceKey, string providerKey) |
|||
{ |
|||
using (CurrentTenant.Change(null)) |
|||
{ |
|||
return base.RevokeAsync(name, resourceName, resourceKey, providerKey); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,39 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Authorization.Permissions.Resources; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.IdentityServer.Clients; |
|||
using Volo.Abp.IdentityServer.Localization; |
|||
using Volo.Abp.Localization; |
|||
|
|||
namespace Volo.Abp.PermissionManagement.IdentityServer; |
|||
|
|||
public class ClientResourcePermissionProviderKeyLookupService : IResourcePermissionProviderKeyLookupService, ITransientDependency |
|||
{ |
|||
public string Name => ClientResourcePermissionValueProvider.ProviderName; |
|||
|
|||
public ILocalizableString DisplayName { get; } |
|||
|
|||
protected IClientFinder ClientFinder { get; } |
|||
|
|||
public ClientResourcePermissionProviderKeyLookupService(IClientFinder clientFinder) |
|||
{ |
|||
ClientFinder = clientFinder; |
|||
DisplayName = LocalizableString.Create<AbpIdentityServerResource>(nameof(ClientResourcePermissionProviderKeyLookupService)); |
|||
} |
|||
|
|||
public virtual async Task<List<ResourcePermissionProviderKeyInfo>> SearchAsync(string filter = null, int page = 1, CancellationToken cancellationToken = default) |
|||
{ |
|||
var clients = await ClientFinder.SearchAsync(filter, page); |
|||
return clients.Select(x => new ResourcePermissionProviderKeyInfo(x.ClientId, x.ClientId)).ToList(); |
|||
} |
|||
|
|||
public virtual Task<List<ResourcePermissionProviderKeyInfo>> SearchAsync(string[] keys, CancellationToken cancellationToken = default) |
|||
{ |
|||
// Keys are ClientIds
|
|||
return Task.FromResult(keys.Select(x => new ResourcePermissionProviderKeyInfo(x, x)).ToList()); |
|||
} |
|||
} |
|||
@ -0,0 +1,10 @@ |
|||
using System; |
|||
|
|||
namespace Volo.Abp.OpenIddict.Applications; |
|||
|
|||
public class ApplicationFinderResult |
|||
{ |
|||
public Guid Id { get; set; } |
|||
|
|||
public string ClientId { get; set; } |
|||
} |
|||
@ -0,0 +1,9 @@ |
|||
using System.Collections.Generic; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace Volo.Abp.OpenIddict.Applications; |
|||
|
|||
public interface IApplicationFinder |
|||
{ |
|||
Task<List<ApplicationFinderResult>> SearchAsync(string filter, int page = 1); |
|||
} |
|||
@ -0,0 +1,13 @@ |
|||
using System; |
|||
|
|||
namespace Volo.Abp.OpenIddict.Applications; |
|||
|
|||
[Serializable] |
|||
public class OpenIddictApplicationClientIdChangedEto |
|||
{ |
|||
public Guid Id { get; set; } |
|||
|
|||
public string ClientId { get; set; } |
|||
|
|||
public string OldClientId { get; set; } |
|||
} |
|||
@ -0,0 +1,43 @@ |
|||
using System; |
|||
|
|||
namespace Volo.Abp.OpenIddict.Applications; |
|||
|
|||
[Serializable] |
|||
public class OpenIddictApplicationEto |
|||
{ |
|||
public Guid Id { get; set; } |
|||
|
|||
public string ApplicationType { get; set; } |
|||
|
|||
public string ClientId { get; set; } |
|||
|
|||
public string ClientSecret { get; set; } |
|||
|
|||
public string ClientType { get; set; } |
|||
|
|||
public string ConsentType { get; set; } |
|||
|
|||
public string DisplayName { get; set; } |
|||
|
|||
public string DisplayNames { get; set; } |
|||
|
|||
public string JsonWebKeySet { get; set; } |
|||
|
|||
public string Permissions { get; set; } |
|||
|
|||
public string PostLogoutRedirectUris { get; set; } |
|||
|
|||
public string Properties { get; set; } |
|||
|
|||
public string RedirectUris { get; set; } |
|||
|
|||
public string Requirements { get; set; } |
|||
|
|||
public string Settings { get; set; } |
|||
|
|||
public string FrontChannelLogoutUri { get; set; } |
|||
|
|||
public string ClientUri { get; set; } |
|||
|
|||
public string LogoUri { get; set; } |
|||
} |
|||
@ -0,0 +1,13 @@ |
|||
using Riok.Mapperly.Abstractions; |
|||
using Volo.Abp.Mapperly; |
|||
using Volo.Abp.OpenIddict.Applications; |
|||
|
|||
namespace Volo.Abp.OpenIddict; |
|||
|
|||
[Mapper(RequiredMappingStrategy = RequiredMappingStrategy.Target)] |
|||
public partial class OpenIddictApplicationToOpenIddictApplicationEtoMapper : MapperBase<OpenIddictApplication, OpenIddictApplicationEto> |
|||
{ |
|||
public override partial OpenIddictApplicationEto Map(OpenIddictApplication source); |
|||
|
|||
public override partial void Map(OpenIddictApplication source, OpenIddictApplicationEto destination); |
|||
} |
|||
@ -0,0 +1,31 @@ |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.Domain.Repositories; |
|||
|
|||
namespace Volo.Abp.OpenIddict.Applications; |
|||
|
|||
public class AbpApplicationFinder : IApplicationFinder, ITransientDependency |
|||
{ |
|||
protected IOpenIddictApplicationRepository ApplicationRepository { get; } |
|||
|
|||
public AbpApplicationFinder(IOpenIddictApplicationRepository applicationRepository) |
|||
{ |
|||
ApplicationRepository = applicationRepository; |
|||
} |
|||
|
|||
public virtual async Task<List<ApplicationFinderResult>> SearchAsync(string filter, int page = 1) |
|||
{ |
|||
using (ApplicationRepository.DisableTracking()) |
|||
{ |
|||
page = page < 1 ? 1 : page; |
|||
var applications = await ApplicationRepository.GetListAsync(nameof(OpenIddictApplication.CreationTime), filter: filter, skipCount: (page - 1) * 10, maxResultCount: 10); |
|||
return applications.Select(x => new ApplicationFinderResult |
|||
{ |
|||
Id = x.Id, |
|||
ClientId = x.ClientId |
|||
}).ToList(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,31 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Threading.Tasks; |
|||
using JetBrains.Annotations; |
|||
using Volo.Abp.Authorization.Permissions; |
|||
|
|||
namespace Volo.Abp.PermissionManagement; |
|||
|
|||
public static class ClientResourcePermissionManagerExtensions |
|||
{ |
|||
public static Task<PermissionWithGrantedProviders> GetForClientAsync([NotNull] this IResourcePermissionManager resourcePermissionManager, string resourceName, string resourceKey, string clientId, string permissionName) |
|||
{ |
|||
Check.NotNull(resourcePermissionManager, nameof(resourcePermissionManager)); |
|||
|
|||
return resourcePermissionManager.GetAsync(permissionName, resourceName, resourceKey, ClientPermissionValueProvider.ProviderName, clientId); |
|||
} |
|||
|
|||
public static Task<List<PermissionWithGrantedProviders>> GetAllForClientAsync([NotNull] this IResourcePermissionManager resourcePermissionManager, string resourceName, string resourceKey, string clientId) |
|||
{ |
|||
Check.NotNull(resourcePermissionManager, nameof(resourcePermissionManager)); |
|||
|
|||
return resourcePermissionManager.GetAllAsync(resourceName, resourceKey, ClientPermissionValueProvider.ProviderName, clientId); |
|||
} |
|||
|
|||
public static Task SetForClientAsync([NotNull] this IResourcePermissionManager resourcePermissionManager, string resourceName, string resourceKey, string clientId, [NotNull] string permissionName, bool isGranted) |
|||
{ |
|||
Check.NotNull(resourcePermissionManager, nameof(resourcePermissionManager)); |
|||
|
|||
return resourcePermissionManager.SetAsync(permissionName, resourceName, resourceKey, ClientPermissionValueProvider.ProviderName, clientId, isGranted); |
|||
} |
|||
} |
|||
@ -0,0 +1,59 @@ |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Authorization.Permissions.Resources; |
|||
using Volo.Abp.Guids; |
|||
using Volo.Abp.MultiTenancy; |
|||
|
|||
namespace Volo.Abp.PermissionManagement.OpenIddict; |
|||
|
|||
public class ApplicationResourcePermissionManagementProvider : ResourcePermissionManagementProvider |
|||
{ |
|||
public override string Name => ClientResourcePermissionValueProvider.ProviderName; |
|||
|
|||
public ApplicationResourcePermissionManagementProvider( |
|||
IResourcePermissionGrantRepository resourcePermissionGrantRepository, |
|||
IGuidGenerator guidGenerator, |
|||
ICurrentTenant currentTenant) |
|||
: base(resourcePermissionGrantRepository, guidGenerator, currentTenant) |
|||
{ |
|||
} |
|||
|
|||
public override Task<ResourcePermissionValueProviderGrantInfo> CheckAsync(string name, string resourceName, string resourceKey, string providerName, string providerKey) |
|||
{ |
|||
using (CurrentTenant.Change(null)) |
|||
{ |
|||
return base.CheckAsync(name, resourceName, resourceKey, providerName, providerKey); |
|||
} |
|||
} |
|||
|
|||
public override Task<MultipleResourcePermissionValueProviderGrantInfo> CheckAsync(string[] names, string resourceName, string resourceKey, string providerName, string providerKey) |
|||
{ |
|||
using (CurrentTenant.Change(null)) |
|||
{ |
|||
return base.CheckAsync(names, resourceName, resourceKey, providerName, providerKey); |
|||
} |
|||
} |
|||
|
|||
public override Task SetAsync(string name, string resourceName, string resourceKey, string providerKey, bool isGranted) |
|||
{ |
|||
using (CurrentTenant.Change(null)) |
|||
{ |
|||
return base.SetAsync(name, resourceName, resourceKey, providerKey, isGranted); |
|||
} |
|||
} |
|||
|
|||
protected override async Task GrantAsync(string name, string resourceName, string resourceKey, string providerKey) |
|||
{ |
|||
using (CurrentTenant.Change(null)) |
|||
{ |
|||
await base.GrantAsync(name, resourceName, resourceKey, providerKey); |
|||
} |
|||
} |
|||
|
|||
protected override Task RevokeAsync(string name, string resourceName, string resourceKey, string providerKey) |
|||
{ |
|||
using (CurrentTenant.Change(null)) |
|||
{ |
|||
return base.RevokeAsync(name, resourceName, resourceKey, providerKey); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,39 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Authorization.Permissions.Resources; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.Localization; |
|||
using Volo.Abp.OpenIddict.Applications; |
|||
using Volo.Abp.OpenIddict.Localization; |
|||
|
|||
namespace Volo.Abp.PermissionManagement.OpenIddict; |
|||
|
|||
public class ApplicationResourcePermissionProviderKeyLookupService : IResourcePermissionProviderKeyLookupService, ITransientDependency |
|||
{ |
|||
public string Name => ClientResourcePermissionValueProvider.ProviderName; |
|||
|
|||
public ILocalizableString DisplayName { get; } |
|||
|
|||
protected IApplicationFinder ApplicationFinder { get; } |
|||
|
|||
public ApplicationResourcePermissionProviderKeyLookupService(IApplicationFinder applicationFinder) |
|||
{ |
|||
ApplicationFinder = applicationFinder; |
|||
DisplayName = LocalizableString.Create<AbpOpenIddictResource>(nameof(ApplicationResourcePermissionProviderKeyLookupService)); |
|||
} |
|||
|
|||
public virtual async Task<List<ResourcePermissionProviderKeyInfo>> SearchAsync(string filter = null, int page = 1, CancellationToken cancellationToken = default) |
|||
{ |
|||
var applications = await ApplicationFinder.SearchAsync(filter, page); |
|||
return applications.Select(x => new ResourcePermissionProviderKeyInfo(x.ClientId, x.ClientId)).ToList(); |
|||
} |
|||
|
|||
public virtual Task<List<ResourcePermissionProviderKeyInfo>> SearchAsync(string[] keys, CancellationToken cancellationToken = default) |
|||
{ |
|||
// Keys are ClientIds
|
|||
return Task.FromResult(keys.Select(x => new ResourcePermissionProviderKeyInfo(x, x)).ToList()); |
|||
} |
|||
} |
|||
@ -0,0 +1,45 @@ |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Authorization.Permissions; |
|||
using Volo.Abp.Authorization.Permissions.Resources; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.EventBus.Distributed; |
|||
using Volo.Abp.OpenIddict.Applications; |
|||
|
|||
namespace Volo.Abp.PermissionManagement.OpenIddict; |
|||
|
|||
public class OpenIddictApplicationClientIdChangedHandler : |
|||
IDistributedEventHandler<OpenIddictApplicationClientIdChangedEto>, |
|||
ITransientDependency |
|||
{ |
|||
protected IPermissionManager PermissionManager { get; } |
|||
protected IPermissionGrantRepository PermissionGrantRepository { get; } |
|||
protected IResourcePermissionManager ResourcePermissionManager { get; } |
|||
protected IResourcePermissionGrantRepository ResourcePermissionGrantRepository { get; } |
|||
|
|||
public OpenIddictApplicationClientIdChangedHandler( |
|||
IPermissionManager permissionManager, |
|||
IPermissionGrantRepository permissionGrantRepository, |
|||
IResourcePermissionManager resourcePermissionManager, |
|||
IResourcePermissionGrantRepository resourcePermissionGrantRepository) |
|||
{ |
|||
PermissionManager = permissionManager; |
|||
PermissionGrantRepository = permissionGrantRepository; |
|||
ResourcePermissionManager = resourcePermissionManager; |
|||
ResourcePermissionGrantRepository = resourcePermissionGrantRepository; |
|||
} |
|||
|
|||
public async Task HandleEventAsync(OpenIddictApplicationClientIdChangedEto eventData) |
|||
{ |
|||
var permissionGrantsInRole = await PermissionGrantRepository.GetListAsync(ClientPermissionValueProvider.ProviderName, eventData.OldClientId); |
|||
foreach (var permissionGrant in permissionGrantsInRole) |
|||
{ |
|||
await PermissionManager.UpdateProviderKeyAsync(permissionGrant, eventData.ClientId); |
|||
} |
|||
|
|||
var resourcePermissionGrantsInRole = await ResourcePermissionGrantRepository.GetListAsync(ClientResourcePermissionValueProvider.ProviderName, eventData.OldClientId); |
|||
foreach (var resourcePermissionGrant in resourcePermissionGrantsInRole) |
|||
{ |
|||
await ResourcePermissionManager.UpdateProviderKeyAsync(resourcePermissionGrant, eventData.ClientId); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,31 @@ |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Authorization.Permissions; |
|||
using Volo.Abp.Authorization.Permissions.Resources; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.Domain.Entities.Events.Distributed; |
|||
using Volo.Abp.EventBus.Distributed; |
|||
using Volo.Abp.OpenIddict.Applications; |
|||
using Volo.Abp.Uow; |
|||
|
|||
namespace Volo.Abp.PermissionManagement.OpenIddict; |
|||
|
|||
public class OpenIddictApplicationDeletedEventHandler : |
|||
IDistributedEventHandler<EntityDeletedEto<OpenIddictApplicationEto>>, |
|||
ITransientDependency |
|||
{ |
|||
protected IPermissionManager PermissionManager { get; } |
|||
protected IResourcePermissionManager ResourcePermissionManager { get; } |
|||
|
|||
public OpenIddictApplicationDeletedEventHandler(IPermissionManager permissionManager, IResourcePermissionManager resourcePermissionManager) |
|||
{ |
|||
PermissionManager = permissionManager; |
|||
ResourcePermissionManager = resourcePermissionManager; |
|||
} |
|||
|
|||
[UnitOfWork] |
|||
public virtual async Task HandleEventAsync(EntityDeletedEto<OpenIddictApplicationEto> eventData) |
|||
{ |
|||
await PermissionManager.DeleteAsync(ClientPermissionValueProvider.ProviderName, eventData.Entity.ClientId); |
|||
await ResourcePermissionManager.DeleteAsync(ClientResourcePermissionValueProvider.ProviderName, eventData.Entity.ClientId); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue