From d7b32f7f9ef87d4c218bca9ba7b4d252ed252d51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Sun, 25 Jun 2023 16:58:20 +0300 Subject: [PATCH] Introduce IdentityUserIntegrationService --- .../IIdentityUserIntegrationService.cs | 11 ++++++++ .../IdentityUserIntegrationService.cs | 19 +++++++++++++ .../Volo/Abp/Identity/IUserRoleFinder.cs | 3 +++ .../Volo/Abp/Identity/UserRoleFinder.cs | 6 +++++ .../Abp/Identity/HttpClientUserRoleFinder.cs | 11 +++++++- .../IdentityUserIntegrationController.cs | 27 +++++++++++++++++++ ...ermissionManagementDomainIdentityModule.cs | 4 +-- .../RolePermissionManagementProvider.cs | 6 ++--- 8 files changed, 81 insertions(+), 6 deletions(-) create mode 100644 modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/Integration/IIdentityUserIntegrationService.cs create mode 100644 modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/Integration/IdentityUserIntegrationService.cs create mode 100644 modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/Integration/IdentityUserIntegrationController.cs diff --git a/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/Integration/IIdentityUserIntegrationService.cs b/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/Integration/IIdentityUserIntegrationService.cs new file mode 100644 index 0000000000..e690b8bd0a --- /dev/null +++ b/modules/identity/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/Integration/IIdentityUserIntegrationService.cs @@ -0,0 +1,11 @@ +using System; +using System.Threading.Tasks; +using Volo.Abp.Application.Services; + +namespace Volo.Abp.Identity.Integration; + +[IntegrationService] +public interface IIdentityUserIntegrationService : IApplicationService +{ + Task GetRoleNamesAsync(Guid id); +} \ No newline at end of file diff --git a/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/Integration/IdentityUserIntegrationService.cs b/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/Integration/IdentityUserIntegrationService.cs new file mode 100644 index 0000000000..5b95d40c9d --- /dev/null +++ b/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/Integration/IdentityUserIntegrationService.cs @@ -0,0 +1,19 @@ +using System; +using System.Threading.Tasks; + +namespace Volo.Abp.Identity.Integration; + +public class IdentityUserIntegrationService : IdentityAppServiceBase, IIdentityUserIntegrationService +{ + protected IIdentityUserRepository UserRepository { get; } + + public IdentityUserIntegrationService(IIdentityUserRepository userRepository) + { + UserRepository = userRepository; + } + + public async Task GetRoleNamesAsync(Guid id) + { + return (await UserRepository.GetRoleNamesAsync(id)).ToArray(); + } +} \ No newline at end of file diff --git a/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/Identity/IUserRoleFinder.cs b/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/Identity/IUserRoleFinder.cs index 31a865fc99..1835f38952 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/Identity/IUserRoleFinder.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/Identity/IUserRoleFinder.cs @@ -5,5 +5,8 @@ namespace Volo.Abp.Identity; public interface IUserRoleFinder { + [Obsolete("Use GetRoleNamesAsync instead.")] Task GetRolesAsync(Guid userId); + + Task GetRoleNamesAsync(Guid userId); } diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/UserRoleFinder.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/UserRoleFinder.cs index ff19e61988..3ec1b2fbb1 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/UserRoleFinder.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/UserRoleFinder.cs @@ -13,8 +13,14 @@ public class UserRoleFinder : IUserRoleFinder, ITransientDependency IdentityUserRepository = identityUserRepository; } + [Obsolete("Use GetRoleNamesAsync instead.")] public virtual async Task GetRolesAsync(Guid userId) { return (await IdentityUserRepository.GetRoleNamesAsync(userId)).ToArray(); } + + public async Task GetRoleNamesAsync(Guid userId) + { + return (await IdentityUserRepository.GetRoleNamesAsync(userId)).ToArray(); + } } diff --git a/modules/identity/src/Volo.Abp.Identity.HttpApi.Client/Volo/Abp/Identity/HttpClientUserRoleFinder.cs b/modules/identity/src/Volo.Abp.Identity.HttpApi.Client/Volo/Abp/Identity/HttpClientUserRoleFinder.cs index b747b416c2..201c9f3eb0 100644 --- a/modules/identity/src/Volo.Abp.Identity.HttpApi.Client/Volo/Abp/Identity/HttpClientUserRoleFinder.cs +++ b/modules/identity/src/Volo.Abp.Identity.HttpApi.Client/Volo/Abp/Identity/HttpClientUserRoleFinder.cs @@ -2,6 +2,7 @@ using System.Linq; using System.Threading.Tasks; using Volo.Abp.DependencyInjection; +using Volo.Abp.Identity.Integration; namespace Volo.Abp.Identity; @@ -9,15 +10,23 @@ namespace Volo.Abp.Identity; public class HttpClientUserRoleFinder : IUserRoleFinder, ITransientDependency { protected IIdentityUserAppService _userAppService { get; } + protected IIdentityUserIntegrationService _userIntegrationService { get; } - public HttpClientUserRoleFinder(IIdentityUserAppService userAppService) + public HttpClientUserRoleFinder(IIdentityUserAppService userAppService, IIdentityUserIntegrationService userIntegrationService) { _userAppService = userAppService; + _userIntegrationService = userIntegrationService; } + [Obsolete("Use GetRoleNamesAsync instead.")] public virtual async Task GetRolesAsync(Guid userId) { var output = await _userAppService.GetRolesAsync(userId); return output.Items.Select(r => r.Name).ToArray(); } + + public async Task GetRoleNamesAsync(Guid userId) + { + return await _userIntegrationService.GetRoleNamesAsync(userId); + } } diff --git a/modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/Integration/IdentityUserIntegrationController.cs b/modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/Integration/IdentityUserIntegrationController.cs new file mode 100644 index 0000000000..3cb180e62b --- /dev/null +++ b/modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/Integration/IdentityUserIntegrationController.cs @@ -0,0 +1,27 @@ +using System; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using Volo.Abp.AspNetCore.Mvc; + +namespace Volo.Abp.Identity.Integration; + +[RemoteService(Name = IdentityRemoteServiceConsts.RemoteServiceName)] +[Area(IdentityRemoteServiceConsts.ModuleName)] +[ControllerName("UserIntegration")] +[Route("integration-api/identity/users")] +public class IdentityUserIntegrationController : AbpControllerBase, IIdentityUserIntegrationService +{ + protected IIdentityUserIntegrationService UserIntegrationService { get; } + + public IdentityUserIntegrationController(IIdentityUserIntegrationService userIntegrationService) + { + UserIntegrationService = userIntegrationService; + } + + [HttpGet] + [Route("{id}/role-names")] + public virtual Task GetRoleNamesAsync(Guid id) + { + return UserIntegrationService.GetRoleNamesAsync(id); + } +} \ No newline at end of file diff --git a/modules/identity/src/Volo.Abp.PermissionManagement.Domain.Identity/Volo/Abp/PermissionManagement/Identity/AbpPermissionManagementDomainIdentityModule.cs b/modules/identity/src/Volo.Abp.PermissionManagement.Domain.Identity/Volo/Abp/PermissionManagement/Identity/AbpPermissionManagementDomainIdentityModule.cs index 924fbf4a36..e710d5b165 100644 --- a/modules/identity/src/Volo.Abp.PermissionManagement.Domain.Identity/Volo/Abp/PermissionManagement/Identity/AbpPermissionManagementDomainIdentityModule.cs +++ b/modules/identity/src/Volo.Abp.PermissionManagement.Domain.Identity/Volo/Abp/PermissionManagement/Identity/AbpPermissionManagementDomainIdentityModule.cs @@ -17,8 +17,8 @@ public class AbpPermissionManagementDomainIdentityModule : AbpModule options.ManagementProviders.Add(); options.ManagementProviders.Add(); - //TODO: Can we prevent duplication of permission names without breaking the design and making the system complicated - options.ProviderPolicies[UserPermissionValueProvider.ProviderName] = "AbpIdentity.Users.ManagePermissions"; + //TODO: Can we prevent duplication of permission names without breaking the design and making the system complicated + options.ProviderPolicies[UserPermissionValueProvider.ProviderName] = "AbpIdentity.Users.ManagePermissions"; options.ProviderPolicies[RolePermissionValueProvider.ProviderName] = "AbpIdentity.Roles.ManagePermissions"; }); } diff --git a/modules/identity/src/Volo.Abp.PermissionManagement.Domain.Identity/Volo/Abp/PermissionManagement/Identity/RolePermissionManagementProvider.cs b/modules/identity/src/Volo.Abp.PermissionManagement.Domain.Identity/Volo/Abp/PermissionManagement/Identity/RolePermissionManagementProvider.cs index a4a6cd60f2..b51110204a 100644 --- a/modules/identity/src/Volo.Abp.PermissionManagement.Domain.Identity/Volo/Abp/PermissionManagement/Identity/RolePermissionManagementProvider.cs +++ b/modules/identity/src/Volo.Abp.PermissionManagement.Domain.Identity/Volo/Abp/PermissionManagement/Identity/RolePermissionManagementProvider.cs @@ -28,14 +28,14 @@ public class RolePermissionManagementProvider : PermissionManagementProvider UserRoleFinder = userRoleFinder; } - public override async Task CheckAsync(string name, string providerName, string providerKey) + public async override Task CheckAsync(string name, string providerName, string providerKey) { var multipleGrantInfo = await CheckAsync(new[] { name }, providerName, providerKey); return multipleGrantInfo.Result.Values.First(); } - public override async Task CheckAsync(string[] names, string providerName, string providerKey) + public async override Task CheckAsync(string[] names, string providerName, string providerKey) { var multiplePermissionValueProviderGrantInfo = new MultiplePermissionValueProviderGrantInfo(names); var permissionGrants = new List(); @@ -49,7 +49,7 @@ public class RolePermissionManagementProvider : PermissionManagementProvider if (providerName == UserPermissionValueProvider.ProviderName) { var userId = Guid.Parse(providerKey); - var roleNames = await UserRoleFinder.GetRolesAsync(userId); + var roleNames = await UserRoleFinder.GetRoleNamesAsync(userId); foreach (var roleName in roleNames) {