mirror of https://github.com/abpframework/abp.git
8 changed files with 179 additions and 6 deletions
@ -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,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