mirror of https://github.com/abpframework/abp.git
11 changed files with 199 additions and 3 deletions
@ -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,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); |
|||
} |
|||
@ -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 |
|||
{ |
|||
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(); |
|||
} |
|||
} |
|||
} |
|||
@ -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,45 @@ |
|||
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 users = await ClientFinder.SearchAsync(filter, page); |
|||
return users.Select(u => new ResourcePermissionProviderKeyInfo(u.Id.ToString(), u.ClientId)).ToList(); |
|||
} |
|||
|
|||
public virtual async Task<List<ResourcePermissionProviderKeyInfo>> SearchAsync(string[] keys, CancellationToken cancellationToken = default) |
|||
{ |
|||
var ids = keys |
|||
.Select(key => Guid.TryParse(key, out var id) ? (Guid?)id : null) |
|||
.Where(id => id.HasValue) |
|||
.Select(id => id.Value) |
|||
.Distinct() |
|||
.ToArray(); |
|||
var users = await ClientFinder.SearchByIdsAsync(ids.ToArray()); |
|||
return users.Select(u => new ResourcePermissionProviderKeyInfo(u.Id.ToString(), u.ClientId)).ToList(); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue