mirror of https://github.com/abpframework/abp.git
9 changed files with 198 additions and 2 deletions
@ -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,12 @@ |
|||||
|
using System; |
||||
|
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); |
||||
|
|
||||
|
Task<List<ApplicationFinderResult>> SearchByIdsAsync(Guid[] ids); |
||||
|
} |
||||
@ -0,0 +1,46 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp.DependencyInjection; |
||||
|
using Volo.Abp.Domain.Repositories; |
||||
|
using Volo.Abp.Identity; |
||||
|
|
||||
|
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.ClientId), filter: filter, skipCount: (page - 1) * 10, maxResultCount: 10); |
||||
|
return applications.Select(x => new ApplicationFinderResult |
||||
|
{ |
||||
|
Id = x.Id, |
||||
|
ClientId = x.ClientId |
||||
|
}).ToList(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<List<ApplicationFinderResult>> SearchByIdsAsync(Guid[] ids) |
||||
|
{ |
||||
|
using (ApplicationRepository.DisableTracking()) |
||||
|
{ |
||||
|
var applications = await ApplicationRepository.GetListByIdsAsync(ids); |
||||
|
return applications.Select(x => new ApplicationFinderResult |
||||
|
{ |
||||
|
Id = x.Id, |
||||
|
ClientId = x.ClientId |
||||
|
}).ToList(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -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,45 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Threading; |
||||
|
using System.Threading.Tasks; |
||||
|
using OpenIddict.Abstractions; |
||||
|
using Volo.Abp.Authorization.Permissions.Resources; |
||||
|
using Volo.Abp.DependencyInjection; |
||||
|
using Volo.Abp.Localization; |
||||
|
using Volo.Abp.OpenIddict.Applications; |
||||
|
|
||||
|
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<OpenIddictResources>(nameof(ApplicationResourcePermissionProviderKeyLookupService)); |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<List<ResourcePermissionProviderKeyInfo>> SearchAsync(string filter = null, int page = 1, CancellationToken cancellationToken = default) |
||||
|
{ |
||||
|
var users = await ApplicationFinder.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 ApplicationFinder.SearchByIdsAsync(ids.ToArray()); |
||||
|
return users.Select(u => new ResourcePermissionProviderKeyInfo(u.Id.ToString(), u.ClientId)).ToList(); |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue