From 0dea196761cf7cf0eaece8395aa6b7f2a06a84f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20=C3=87otur?= Date: Wed, 18 Mar 2020 12:13:46 +0300 Subject: [PATCH 1/2] virtualized --- .../Abp/Identity/IdentityRoleAppService.cs | 28 +++---- .../Abp/Identity/IdentityUserAppService.cs | 54 ++++++------ .../Volo/Abp/Identity/ProfileAppService.cs | 20 ++--- .../Abp/Identity/AbpIdentityOptionsFactory.cs | 30 +++---- .../Identity/AbpIdentityResultException.cs | 2 +- .../Abp/Identity/IdentityClaimTypeManager.cs | 12 +-- .../Identity/IdentityDataSeedContributor.cs | 8 +- .../Volo/Abp/Identity/IdentityDataSeeder.cs | 40 ++++----- .../Volo/Abp/Identity/IdentityRoleManager.cs | 14 ++-- .../Volo/Abp/Identity/IdentityRoleStore.cs | 48 +++++------ .../Volo/Abp/Identity/IdentityUserLogin.cs | 2 +- .../Volo/Abp/Identity/IdentityUserManager.cs | 6 +- ...sitoryExternalUserLookupServiceProvider.cs | 32 +++---- .../Volo/Abp/Identity/IdentityUserStore.cs | 84 +++++++++---------- .../Volo/Abp/Identity/UserRoleFinder.cs | 6 +- .../EfCoreIdentityClaimTypeRepository.cs | 4 +- .../HttpClientIdentityUserLookupService.cs | 12 +-- .../Abp/Identity/HttpClientUserRoleFinder.cs | 4 +- .../Abp/Identity/IdentityRoleController.cs | 16 ++-- .../Abp/Identity/IdentityUserController.cs | 22 ++--- .../Identity/IdentityUserLookupController.cs | 4 +- .../Volo/Abp/Identity/ProfileController.cs | 16 ++-- .../MongoIdentityClaimTypeRepository.cs | 4 +- .../MongoDB/MongoIdentityRoleRepository.cs | 5 +- .../MongoDB/MongoIdentityUserRepository.cs | 23 +++-- .../AbpIdentityWebMainMenuContributor.cs | 2 +- .../RolePermissionManagementProvider.cs | 6 +- .../Identity/RoleUpdateEventHandler.cs | 2 +- 28 files changed, 250 insertions(+), 256 deletions(-) diff --git a/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityRoleAppService.cs b/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityRoleAppService.cs index b02319bc24..02d5f990f5 100644 --- a/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityRoleAppService.cs +++ b/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityRoleAppService.cs @@ -10,34 +10,34 @@ namespace Volo.Abp.Identity [Authorize(IdentityPermissions.Roles.Default)] public class IdentityRoleAppService : IdentityAppServiceBase, IIdentityRoleAppService { - private readonly IdentityRoleManager _roleManager; - private readonly IIdentityRoleRepository _roleRepository; + protected IdentityRoleManager RoleManager { get; } + protected IIdentityRoleRepository RoleRepository { get; } public IdentityRoleAppService( IdentityRoleManager roleManager, IIdentityRoleRepository roleRepository) { - _roleManager = roleManager; - _roleRepository = roleRepository; + RoleManager = roleManager; + RoleRepository = roleRepository; } public virtual async Task GetAsync(Guid id) { return ObjectMapper.Map( - await _roleManager.GetByIdAsync(id)); + await RoleManager.GetByIdAsync(id)); } public virtual async Task> GetAllListAsync() { - var list = await _roleRepository.GetListAsync(); + var list = await RoleRepository.GetListAsync(); return new ListResultDto( ObjectMapper.Map, List>(list)); } public virtual async Task> GetListAsync(PagedAndSortedResultRequestDto input) { - var list = await _roleRepository.GetListAsync(input.Sorting, input.MaxResultCount, input.SkipCount); - var totalCount = await _roleRepository.GetCountAsync(); + var list = await RoleRepository.GetListAsync(input.Sorting, input.MaxResultCount, input.SkipCount); + var totalCount = await RoleRepository.GetCountAsync(); return new PagedResultDto( totalCount, @@ -53,7 +53,7 @@ namespace Volo.Abp.Identity role.IsDefault = input.IsDefault; role.IsPublic = input.IsPublic; - (await _roleManager.CreateAsync(role)).CheckErrors(); + (await RoleManager.CreateAsync(role)).CheckErrors(); await CurrentUnitOfWork.SaveChangesAsync(); return ObjectMapper.Map(role); @@ -62,15 +62,15 @@ namespace Volo.Abp.Identity [Authorize(IdentityPermissions.Roles.Update)] public virtual async Task UpdateAsync(Guid id, IdentityRoleUpdateDto input) { - var role = await _roleManager.GetByIdAsync(id); + var role = await RoleManager.GetByIdAsync(id); role.ConcurrencyStamp = input.ConcurrencyStamp; - (await _roleManager.SetRoleNameAsync(role, input.Name)).CheckErrors(); + (await RoleManager.SetRoleNameAsync(role, input.Name)).CheckErrors(); role.IsDefault = input.IsDefault; role.IsPublic = input.IsPublic; - (await _roleManager.UpdateAsync(role)).CheckErrors(); + (await RoleManager.UpdateAsync(role)).CheckErrors(); await CurrentUnitOfWork.SaveChangesAsync(); return ObjectMapper.Map(role); @@ -79,13 +79,13 @@ namespace Volo.Abp.Identity [Authorize(IdentityPermissions.Roles.Delete)] public virtual async Task DeleteAsync(Guid id) { - var role = await _roleManager.FindByIdAsync(id.ToString()); + var role = await RoleManager.FindByIdAsync(id.ToString()); if (role == null) { return; } - (await _roleManager.DeleteAsync(role)).CheckErrors(); + (await RoleManager.DeleteAsync(role)).CheckErrors(); } } } diff --git a/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityUserAppService.cs b/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityUserAppService.cs index c1d0f8f28b..71adeef1b0 100644 --- a/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityUserAppService.cs +++ b/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityUserAppService.cs @@ -9,15 +9,15 @@ namespace Volo.Abp.Identity { public class IdentityUserAppService : IdentityAppServiceBase, IIdentityUserAppService { - private readonly IdentityUserManager _userManager; - private readonly IIdentityUserRepository _userRepository; + protected IdentityUserManager UserManager { get; } + protected IIdentityUserRepository UserRepository { get; } public IdentityUserAppService( IdentityUserManager userManager, IIdentityUserRepository userRepository) { - _userManager = userManager; - _userRepository = userRepository; + UserManager = userManager; + UserRepository = userRepository; } //TODO: [Authorize(IdentityPermissions.Users.Default)] should go the IdentityUserAppService class. @@ -25,15 +25,15 @@ namespace Volo.Abp.Identity public virtual async Task GetAsync(Guid id) { return ObjectMapper.Map( - await _userManager.GetByIdAsync(id) + await UserManager.GetByIdAsync(id) ); } [Authorize(IdentityPermissions.Users.Default)] public virtual async Task> GetListAsync(GetIdentityUsersInput input) { - var count = await _userRepository.GetCountAsync(input.Filter); - var list = await _userRepository.GetListAsync(input.Sorting, input.MaxResultCount, input.SkipCount, input.Filter); + var count = await UserRepository.GetCountAsync(input.Filter); + var list = await UserRepository.GetListAsync(input.Sorting, input.MaxResultCount, input.SkipCount, input.Filter); return new PagedResultDto( count, @@ -44,7 +44,7 @@ namespace Volo.Abp.Identity [Authorize(IdentityPermissions.Users.Default)] public virtual async Task> GetRolesAsync(Guid id) { - var roles = await _userRepository.GetRolesAsync(id); + var roles = await UserRepository.GetRolesAsync(id); return new ListResultDto( ObjectMapper.Map, List>(roles) ); @@ -55,7 +55,7 @@ namespace Volo.Abp.Identity { var user = new IdentityUser(GuidGenerator.Create(), input.UserName, input.Email, CurrentTenant.Id); - (await _userManager.CreateAsync(user, input.Password)).CheckErrors(); + (await UserManager.CreateAsync(user, input.Password)).CheckErrors(); await UpdateUserByInput(user, input); await CurrentUnitOfWork.SaveChangesAsync(); @@ -66,17 +66,17 @@ namespace Volo.Abp.Identity [Authorize(IdentityPermissions.Users.Update)] public virtual async Task UpdateAsync(Guid id, IdentityUserUpdateDto input) { - var user = await _userManager.GetByIdAsync(id); + var user = await UserManager.GetByIdAsync(id); user.ConcurrencyStamp = input.ConcurrencyStamp; - (await _userManager.SetUserNameAsync(user, input.UserName)).CheckErrors(); + (await UserManager.SetUserNameAsync(user, input.UserName)).CheckErrors(); await UpdateUserByInput(user, input); - (await _userManager.UpdateAsync(user)).CheckErrors(); + (await UserManager.UpdateAsync(user)).CheckErrors(); if (!input.Password.IsNullOrEmpty()) { - (await _userManager.RemovePasswordAsync(user)).CheckErrors(); - (await _userManager.AddPasswordAsync(user, input.Password)).CheckErrors(); + (await UserManager.RemovePasswordAsync(user)).CheckErrors(); + (await UserManager.AddPasswordAsync(user, input.Password)).CheckErrors(); } await CurrentUnitOfWork.SaveChangesAsync(); @@ -92,28 +92,28 @@ namespace Volo.Abp.Identity throw new BusinessException(code: IdentityErrorCodes.UserSelfDeletion); } - var user = await _userManager.FindByIdAsync(id.ToString()); + var user = await UserManager.FindByIdAsync(id.ToString()); if (user == null) { return; } - (await _userManager.DeleteAsync(user)).CheckErrors(); + (await UserManager.DeleteAsync(user)).CheckErrors(); } [Authorize(IdentityPermissions.Users.Update)] public virtual async Task UpdateRolesAsync(Guid id, IdentityUserUpdateRolesDto input) { - var user = await _userManager.GetByIdAsync(id); - (await _userManager.SetRolesAsync(user, input.RoleNames)).CheckErrors(); - await _userRepository.UpdateAsync(user); + var user = await UserManager.GetByIdAsync(id); + (await UserManager.SetRolesAsync(user, input.RoleNames)).CheckErrors(); + await UserRepository.UpdateAsync(user); } [Authorize(IdentityPermissions.Users.Default)] public virtual async Task FindByUsernameAsync(string username) { return ObjectMapper.Map( - await _userManager.FindByNameAsync(username) + await UserManager.FindByNameAsync(username) ); } @@ -121,31 +121,31 @@ namespace Volo.Abp.Identity public virtual async Task FindByEmailAsync(string email) { return ObjectMapper.Map( - await _userManager.FindByEmailAsync(email) + await UserManager.FindByEmailAsync(email) ); } - private async Task UpdateUserByInput(IdentityUser user, IdentityUserCreateOrUpdateDtoBase input) + protected virtual async Task UpdateUserByInput(IdentityUser user, IdentityUserCreateOrUpdateDtoBase input) { if (!string.Equals(user.Email, input.Email, StringComparison.InvariantCultureIgnoreCase)) { - (await _userManager.SetEmailAsync(user, input.Email)).CheckErrors(); + (await UserManager.SetEmailAsync(user, input.Email)).CheckErrors(); } if (!string.Equals(user.PhoneNumber, input.PhoneNumber, StringComparison.InvariantCultureIgnoreCase)) { - (await _userManager.SetPhoneNumberAsync(user, input.PhoneNumber)).CheckErrors(); + (await UserManager.SetPhoneNumberAsync(user, input.PhoneNumber)).CheckErrors(); } - (await _userManager.SetTwoFactorEnabledAsync(user, input.TwoFactorEnabled)).CheckErrors(); - (await _userManager.SetLockoutEnabledAsync(user, input.LockoutEnabled)).CheckErrors(); + (await UserManager.SetTwoFactorEnabledAsync(user, input.TwoFactorEnabled)).CheckErrors(); + (await UserManager.SetLockoutEnabledAsync(user, input.LockoutEnabled)).CheckErrors(); user.Name = input.Name; user.Surname = input.Surname; if (input.RoleNames != null) { - (await _userManager.SetRolesAsync(user, input.RoleNames)).CheckErrors(); + (await UserManager.SetRolesAsync(user, input.RoleNames)).CheckErrors(); } } } diff --git a/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/ProfileAppService.cs b/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/ProfileAppService.cs index 0b8712b93d..7501108dec 100644 --- a/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/ProfileAppService.cs +++ b/modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/ProfileAppService.cs @@ -10,40 +10,40 @@ namespace Volo.Abp.Identity [Authorize] public class ProfileAppService : IdentityAppServiceBase, IProfileAppService { - private readonly IdentityUserManager _userManager; + protected IdentityUserManager UserManager { get; } public ProfileAppService(IdentityUserManager userManager) { - _userManager = userManager; + UserManager = userManager; } public virtual async Task GetAsync() { return ObjectMapper.Map( - await _userManager.GetByIdAsync(CurrentUser.GetId()) + await UserManager.GetByIdAsync(CurrentUser.GetId()) ); } public virtual async Task UpdateAsync(UpdateProfileDto input) { - var user = await _userManager.GetByIdAsync(CurrentUser.GetId()); + var user = await UserManager.GetByIdAsync(CurrentUser.GetId()); if (await SettingProvider.IsTrueAsync(IdentitySettingNames.User.IsUserNameUpdateEnabled)) { - (await _userManager.SetUserNameAsync(user, input.UserName)).CheckErrors(); + (await UserManager.SetUserNameAsync(user, input.UserName)).CheckErrors(); } if (await SettingProvider.IsTrueAsync(IdentitySettingNames.User.IsEmailUpdateEnabled)) { - (await _userManager.SetEmailAsync(user, input.Email)).CheckErrors(); + (await UserManager.SetEmailAsync(user, input.Email)).CheckErrors(); } - (await _userManager.SetPhoneNumberAsync(user, input.PhoneNumber)).CheckErrors(); + (await UserManager.SetPhoneNumberAsync(user, input.PhoneNumber)).CheckErrors(); user.Name = input.Name; user.Surname = input.Surname; - (await _userManager.UpdateAsync(user)).CheckErrors(); + (await UserManager.UpdateAsync(user)).CheckErrors(); await CurrentUnitOfWork.SaveChangesAsync(); @@ -52,8 +52,8 @@ namespace Volo.Abp.Identity public virtual async Task ChangePasswordAsync(ChangePasswordInput input) { - var currentUser = await _userManager.GetByIdAsync(CurrentUser.GetId()); - (await _userManager.ChangePasswordAsync(currentUser, input.CurrentPassword, input.NewPassword)).CheckErrors(); + var currentUser = await UserManager.GetByIdAsync(CurrentUser.GetId()); + (await UserManager.ChangePasswordAsync(currentUser, input.CurrentPassword, input.NewPassword)).CheckErrors(); } } } diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/AbpIdentityOptionsFactory.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/AbpIdentityOptionsFactory.cs index 89f2b11bc2..ef383ac0ad 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/AbpIdentityOptionsFactory.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/AbpIdentityOptionsFactory.cs @@ -12,7 +12,7 @@ namespace Volo.Abp.Identity { public class AbpIdentityOptionsFactory : AbpOptionsFactory { - private readonly ISettingProvider _settingProvider; + protected ISettingProvider SettingProvider { get; } public AbpIdentityOptionsFactory( IEnumerable> setups, @@ -20,7 +20,7 @@ namespace Volo.Abp.Identity ISettingProvider settingProvider) : base(setups, postConfigures) { - _settingProvider = settingProvider; + SettingProvider = settingProvider; } public override IdentityOptions Create(string name) @@ -39,19 +39,19 @@ namespace Volo.Abp.Identity protected virtual async Task OverrideOptionsAsync(IdentityOptions options) { - options.Password.RequiredLength = await _settingProvider.GetAsync(IdentitySettingNames.Password.RequiredLength, options.Password.RequiredLength); - options.Password.RequiredUniqueChars = await _settingProvider.GetAsync(IdentitySettingNames.Password.RequiredUniqueChars, options.Password.RequiredUniqueChars); - options.Password.RequireNonAlphanumeric = await _settingProvider.GetAsync(IdentitySettingNames.Password.RequireNonAlphanumeric, options.Password.RequireNonAlphanumeric); - options.Password.RequireLowercase = await _settingProvider.GetAsync(IdentitySettingNames.Password.RequireLowercase, options.Password.RequireLowercase); - options.Password.RequireUppercase = await _settingProvider.GetAsync(IdentitySettingNames.Password.RequireUppercase, options.Password.RequireUppercase); - options.Password.RequireDigit = await _settingProvider.GetAsync(IdentitySettingNames.Password.RequireDigit, options.Password.RequireDigit); - - options.Lockout.AllowedForNewUsers = await _settingProvider.GetAsync(IdentitySettingNames.Lockout.AllowedForNewUsers, options.Lockout.AllowedForNewUsers); - options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromSeconds(await _settingProvider.GetAsync(IdentitySettingNames.Lockout.LockoutDuration, options.Lockout.DefaultLockoutTimeSpan.TotalSeconds.To())); - options.Lockout.MaxFailedAccessAttempts = await _settingProvider.GetAsync(IdentitySettingNames.Lockout.MaxFailedAccessAttempts, options.Lockout.MaxFailedAccessAttempts); - - options.SignIn.RequireConfirmedEmail = await _settingProvider.GetAsync(IdentitySettingNames.SignIn.RequireConfirmedEmail, options.SignIn.RequireConfirmedEmail); - options.SignIn.RequireConfirmedPhoneNumber = await _settingProvider.GetAsync(IdentitySettingNames.SignIn.RequireConfirmedPhoneNumber, options.SignIn.RequireConfirmedPhoneNumber); + options.Password.RequiredLength = await SettingProvider.GetAsync(IdentitySettingNames.Password.RequiredLength, options.Password.RequiredLength); + options.Password.RequiredUniqueChars = await SettingProvider.GetAsync(IdentitySettingNames.Password.RequiredUniqueChars, options.Password.RequiredUniqueChars); + options.Password.RequireNonAlphanumeric = await SettingProvider.GetAsync(IdentitySettingNames.Password.RequireNonAlphanumeric, options.Password.RequireNonAlphanumeric); + options.Password.RequireLowercase = await SettingProvider.GetAsync(IdentitySettingNames.Password.RequireLowercase, options.Password.RequireLowercase); + options.Password.RequireUppercase = await SettingProvider.GetAsync(IdentitySettingNames.Password.RequireUppercase, options.Password.RequireUppercase); + options.Password.RequireDigit = await SettingProvider.GetAsync(IdentitySettingNames.Password.RequireDigit, options.Password.RequireDigit); + + options.Lockout.AllowedForNewUsers = await SettingProvider.GetAsync(IdentitySettingNames.Lockout.AllowedForNewUsers, options.Lockout.AllowedForNewUsers); + options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromSeconds(await SettingProvider.GetAsync(IdentitySettingNames.Lockout.LockoutDuration, options.Lockout.DefaultLockoutTimeSpan.TotalSeconds.To())); + options.Lockout.MaxFailedAccessAttempts = await SettingProvider.GetAsync(IdentitySettingNames.Lockout.MaxFailedAccessAttempts, options.Lockout.MaxFailedAccessAttempts); + + options.SignIn.RequireConfirmedEmail = await SettingProvider.GetAsync(IdentitySettingNames.SignIn.RequireConfirmedEmail, options.SignIn.RequireConfirmedEmail); + options.SignIn.RequireConfirmedPhoneNumber = await SettingProvider.GetAsync(IdentitySettingNames.SignIn.RequireConfirmedPhoneNumber, options.SignIn.RequireConfirmedPhoneNumber); } } diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/AbpIdentityResultException.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/AbpIdentityResultException.cs index eb0aaccbcc..de02081a1d 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/AbpIdentityResultException.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/AbpIdentityResultException.cs @@ -30,7 +30,7 @@ namespace Volo.Abp.Identity } - public string LocalizeMessage(LocalizationContext context) + public virtual string LocalizeMessage(LocalizationContext context) { return IdentityResult.LocalizeErrors(context.LocalizerFactory.Create()); } diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityClaimTypeManager.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityClaimTypeManager.cs index 6e79b29d98..f7286b53d2 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityClaimTypeManager.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityClaimTypeManager.cs @@ -6,26 +6,26 @@ namespace Volo.Abp.Identity //TODO: Rename to IdentityClaimTypeManager in v2.0! public class IdenityClaimTypeManager : DomainService { - private readonly IIdentityClaimTypeRepository _identityClaimTypeRepository; + protected IIdentityClaimTypeRepository IdentityClaimTypeRepository { get; } public IdenityClaimTypeManager(IIdentityClaimTypeRepository identityClaimTypeRepository) { - _identityClaimTypeRepository = identityClaimTypeRepository; + IdentityClaimTypeRepository = identityClaimTypeRepository; } public virtual async Task CreateAsync(IdentityClaimType claimType) { - if (await _identityClaimTypeRepository.AnyAsync(claimType.Name)) + if (await IdentityClaimTypeRepository.AnyAsync(claimType.Name)) { throw new AbpException($"Name Exist: {claimType.Name}"); } - return await _identityClaimTypeRepository.InsertAsync(claimType); + return await IdentityClaimTypeRepository.InsertAsync(claimType); } public virtual async Task UpdateAsync(IdentityClaimType claimType) { - if (await _identityClaimTypeRepository.AnyAsync(claimType.Name, claimType.Id)) + if (await IdentityClaimTypeRepository.AnyAsync(claimType.Name, claimType.Id)) { throw new AbpException($"Name Exist: {claimType.Name}"); } @@ -36,7 +36,7 @@ namespace Volo.Abp.Identity } - return await _identityClaimTypeRepository.UpdateAsync(claimType); + return await IdentityClaimTypeRepository.UpdateAsync(claimType); } } } diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityDataSeedContributor.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityDataSeedContributor.cs index 21cda46613..9dd44f1fca 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityDataSeedContributor.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityDataSeedContributor.cs @@ -6,16 +6,16 @@ namespace Volo.Abp.Identity { public class IdentityDataSeedContributor : IDataSeedContributor, ITransientDependency { - private readonly IIdentityDataSeeder _identityDataSeeder; + protected IIdentityDataSeeder IdentityDataSeeder { get; } public IdentityDataSeedContributor(IIdentityDataSeeder identityDataSeeder) { - _identityDataSeeder = identityDataSeeder; + IdentityDataSeeder = identityDataSeeder; } - public Task SeedAsync(DataSeedContext context) + public virtual Task SeedAsync(DataSeedContext context) { - return _identityDataSeeder.SeedAsync( + return IdentityDataSeeder.SeedAsync( context["AdminEmail"] as string ?? "admin@abp.io", context["AdminPassword"] as string ?? "1q2w3E*", context.TenantId diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityDataSeeder.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityDataSeeder.cs index 70945c2546..6e32ed877a 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityDataSeeder.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityDataSeeder.cs @@ -9,12 +9,12 @@ namespace Volo.Abp.Identity { public class IdentityDataSeeder : ITransientDependency, IIdentityDataSeeder { - private readonly IGuidGenerator _guidGenerator; - private readonly IIdentityRoleRepository _roleRepository; - private readonly IIdentityUserRepository _userRepository; - private readonly ILookupNormalizer _lookupNormalizer; - private readonly IdentityUserManager _userManager; - private readonly IdentityRoleManager _roleManager; + protected IGuidGenerator GuidGenerator { get; } + protected IIdentityRoleRepository RoleRepository { get; } + protected IIdentityUserRepository UserRepository { get; } + protected ILookupNormalizer LookupNormalizer { get; } + protected IdentityUserManager UserManager { get; } + protected IdentityRoleManager RoleManager { get; } public IdentityDataSeeder( IGuidGenerator guidGenerator, @@ -24,12 +24,12 @@ namespace Volo.Abp.Identity IdentityUserManager userManager, IdentityRoleManager roleManager) { - _guidGenerator = guidGenerator; - _roleRepository = roleRepository; - _userRepository = userRepository; - _lookupNormalizer = lookupNormalizer; - _userManager = userManager; - _roleManager = roleManager; + GuidGenerator = guidGenerator; + RoleRepository = roleRepository; + UserRepository = userRepository; + LookupNormalizer = lookupNormalizer; + UserManager = userManager; + RoleManager = roleManager; } [UnitOfWork] @@ -45,8 +45,8 @@ namespace Volo.Abp.Identity //"admin" user const string adminUserName = "admin"; - var adminUser = await _userRepository.FindByNormalizedUserNameAsync( - _lookupNormalizer.NormalizeName(adminUserName) + var adminUser = await UserRepository.FindByNormalizedUserNameAsync( + LookupNormalizer.NormalizeName(adminUserName) ); if (adminUser != null) @@ -55,7 +55,7 @@ namespace Volo.Abp.Identity } adminUser = new IdentityUser( - _guidGenerator.Create(), + GuidGenerator.Create(), adminUserName, adminEmail, tenantId @@ -64,16 +64,16 @@ namespace Volo.Abp.Identity Name = adminUserName }; - (await _userManager.CreateAsync(adminUser, adminPassword)).CheckErrors(); + (await UserManager.CreateAsync(adminUser, adminPassword)).CheckErrors(); result.CreatedAdminUser = true; //"admin" role const string adminRoleName = "admin"; - var adminRole = await _roleRepository.FindByNormalizedNameAsync(_lookupNormalizer.NormalizeName(adminRoleName)); + var adminRole = await RoleRepository.FindByNormalizedNameAsync(LookupNormalizer.NormalizeName(adminRoleName)); if (adminRole == null) { adminRole = new IdentityRole( - _guidGenerator.Create(), + GuidGenerator.Create(), adminRoleName, tenantId ) @@ -82,11 +82,11 @@ namespace Volo.Abp.Identity IsPublic = true }; - (await _roleManager.CreateAsync(adminRole)).CheckErrors(); + (await RoleManager.CreateAsync(adminRole)).CheckErrors(); result.CreatedAdminRole = true; } - (await _userManager.AddToRoleAsync(adminUser, adminRoleName)).CheckErrors(); + (await UserManager.AddToRoleAsync(adminUser, adminRoleName)).CheckErrors(); return result; } diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityRoleManager.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityRoleManager.cs index 0a64d64aad..9c2a80a807 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityRoleManager.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityRoleManager.cs @@ -15,10 +15,10 @@ namespace Volo.Abp.Identity { public class IdentityRoleManager : RoleManager, IDomainService { - protected override CancellationToken CancellationToken => _cancellationTokenProvider.Token; + protected override CancellationToken CancellationToken => CancellationTokenProvider.Token; - private readonly IStringLocalizer _localizer; - private readonly ICancellationTokenProvider _cancellationTokenProvider; + protected IStringLocalizer Localizer { get; } + protected ICancellationTokenProvider CancellationTokenProvider { get; } public IdentityRoleManager( IdentityRoleStore store, @@ -35,8 +35,8 @@ namespace Volo.Abp.Identity errors, logger) { - _localizer = localizer; - _cancellationTokenProvider = cancellationTokenProvider; + Localizer = localizer; + CancellationTokenProvider = cancellationTokenProvider; } public virtual async Task GetByIdAsync(Guid id) @@ -54,7 +54,7 @@ namespace Volo.Abp.Identity { if (role.IsStatic && role.Name != name) { - throw new BusinessException(_localizer["Identity.StaticRoleRenamingErrorMessage"]); // TODO: localize & change exception type + throw new BusinessException(Localizer["Identity.StaticRoleRenamingErrorMessage"]); // TODO: localize & change exception type } return await base.SetRoleNameAsync(role, name); @@ -64,7 +64,7 @@ namespace Volo.Abp.Identity { if (role.IsStatic) { - throw new BusinessException(_localizer["Identity.StaticRoleDeletionErrorMessage"]); // TODO: localize & change exception type + throw new BusinessException(Localizer["Identity.StaticRoleDeletionErrorMessage"]); // TODO: localize & change exception type } return await base.DeleteAsync(role); diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityRoleStore.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityRoleStore.cs index ddff3ae844..c21b839b00 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityRoleStore.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityRoleStore.cs @@ -22,9 +22,9 @@ namespace Volo.Abp.Identity IRoleClaimStore, ITransientDependency { - private readonly IIdentityRoleRepository _roleRepository; - private readonly ILogger _logger; - private readonly IGuidGenerator _guidGenerator; + protected IIdentityRoleRepository RoleRepository { get; } + protected ILogger Logger { get; } + protected IGuidGenerator GuidGenerator { get; } /// /// Constructs a new instance of . @@ -35,9 +35,9 @@ namespace Volo.Abp.Identity IGuidGenerator guidGenerator, IdentityErrorDescriber describer = null) { - _roleRepository = roleRepository; - _logger = logger; - _guidGenerator = guidGenerator; + RoleRepository = roleRepository; + Logger = logger; + GuidGenerator = guidGenerator; ErrorDescriber = describer ?? new IdentityErrorDescriber(); } @@ -67,7 +67,7 @@ namespace Volo.Abp.Identity Check.NotNull(role, nameof(role)); - await _roleRepository.InsertAsync(role, AutoSaveChanges, cancellationToken); + await RoleRepository.InsertAsync(role, AutoSaveChanges, cancellationToken); return IdentityResult.Success; } @@ -86,11 +86,11 @@ namespace Volo.Abp.Identity try { - await _roleRepository.UpdateAsync(role, AutoSaveChanges, cancellationToken); + await RoleRepository.UpdateAsync(role, AutoSaveChanges, cancellationToken); } catch (AbpDbConcurrencyException ex) { - _logger.LogWarning(ex.ToString()); //Trigger some AbpHandledException event + Logger.LogWarning(ex.ToString()); //Trigger some AbpHandledException event return IdentityResult.Failed(ErrorDescriber.ConcurrencyFailure()); } @@ -111,11 +111,11 @@ namespace Volo.Abp.Identity try { - await _roleRepository.DeleteAsync(role, AutoSaveChanges, cancellationToken); + await RoleRepository.DeleteAsync(role, AutoSaveChanges, cancellationToken); } catch (AbpDbConcurrencyException ex) { - _logger.LogWarning(ex.ToString()); //Trigger some AbpHandledException event + Logger.LogWarning(ex.ToString()); //Trigger some AbpHandledException event return IdentityResult.Failed(ErrorDescriber.ConcurrencyFailure()); } @@ -128,7 +128,7 @@ namespace Volo.Abp.Identity /// The role whose ID should be returned. /// The used to propagate notifications that the operation should be canceled. /// A that contains the ID of the role. - public Task GetRoleIdAsync([NotNull] IdentityRole role, CancellationToken cancellationToken = default) + public virtual Task GetRoleIdAsync([NotNull] IdentityRole role, CancellationToken cancellationToken = default) { cancellationToken.ThrowIfCancellationRequested(); @@ -143,7 +143,7 @@ namespace Volo.Abp.Identity /// The role whose name should be returned. /// The used to propagate notifications that the operation should be canceled. /// A that contains the name of the role. - public Task GetRoleNameAsync([NotNull] IdentityRole role, CancellationToken cancellationToken = default) + public virtual Task GetRoleNameAsync([NotNull] IdentityRole role, CancellationToken cancellationToken = default) { cancellationToken.ThrowIfCancellationRequested(); @@ -159,7 +159,7 @@ namespace Volo.Abp.Identity /// The name of the role. /// The used to propagate notifications that the operation should be canceled. /// The that represents the asynchronous operation. - public Task SetRoleNameAsync([NotNull] IdentityRole role, string roleName, CancellationToken cancellationToken = default) + public virtual Task SetRoleNameAsync([NotNull] IdentityRole role, string roleName, CancellationToken cancellationToken = default) { cancellationToken.ThrowIfCancellationRequested(); @@ -179,7 +179,7 @@ namespace Volo.Abp.Identity { cancellationToken.ThrowIfCancellationRequested(); - return _roleRepository.FindAsync(Guid.Parse(id), cancellationToken: cancellationToken); + return RoleRepository.FindAsync(Guid.Parse(id), cancellationToken: cancellationToken); } /// @@ -194,7 +194,7 @@ namespace Volo.Abp.Identity Check.NotNull(normalizedName, nameof(normalizedName)); - return _roleRepository.FindByNormalizedNameAsync(normalizedName, cancellationToken: cancellationToken); + return RoleRepository.FindByNormalizedNameAsync(normalizedName, cancellationToken: cancellationToken); } /// @@ -233,7 +233,7 @@ namespace Volo.Abp.Identity /// /// Dispose the stores /// - public void Dispose() + public virtual void Dispose() { } @@ -243,13 +243,13 @@ namespace Volo.Abp.Identity /// The role whose claims should be retrieved. /// The used to propagate notifications that the operation should be canceled. /// A that contains the claims granted to a role. - public async Task> GetClaimsAsync([NotNull] IdentityRole role, CancellationToken cancellationToken = default) + public virtual async Task> GetClaimsAsync([NotNull] IdentityRole role, CancellationToken cancellationToken = default) { cancellationToken.ThrowIfCancellationRequested(); Check.NotNull(role, nameof(role)); - await _roleRepository.EnsureCollectionLoadedAsync(role, r => r.Claims, cancellationToken); + await RoleRepository.EnsureCollectionLoadedAsync(role, r => r.Claims, cancellationToken); return role.Claims.Select(c => c.ToClaim()).ToList(); } @@ -261,16 +261,16 @@ namespace Volo.Abp.Identity /// The claim to add to the role. /// The used to propagate notifications that the operation should be canceled. /// The that represents the asynchronous operation. - public async Task AddClaimAsync([NotNull] IdentityRole role, [NotNull] Claim claim, CancellationToken cancellationToken = default) + public virtual async Task AddClaimAsync([NotNull] IdentityRole role, [NotNull] Claim claim, CancellationToken cancellationToken = default) { cancellationToken.ThrowIfCancellationRequested(); Check.NotNull(role, nameof(role)); Check.NotNull(claim, nameof(claim)); - await _roleRepository.EnsureCollectionLoadedAsync(role, r => r.Claims, cancellationToken); + await RoleRepository.EnsureCollectionLoadedAsync(role, r => r.Claims, cancellationToken); - role.AddClaim(_guidGenerator, claim); + role.AddClaim(GuidGenerator, claim); } /// @@ -280,12 +280,12 @@ namespace Volo.Abp.Identity /// The claim to remove from the role. /// The used to propagate notifications that the operation should be canceled. /// The that represents the asynchronous operation. - public async Task RemoveClaimAsync([NotNull] IdentityRole role, [NotNull] Claim claim, CancellationToken cancellationToken = default) + public virtual async Task RemoveClaimAsync([NotNull] IdentityRole role, [NotNull] Claim claim, CancellationToken cancellationToken = default) { Check.NotNull(role, nameof(role)); Check.NotNull(claim, nameof(claim)); - await _roleRepository.EnsureCollectionLoadedAsync(role, r => r.Claims, cancellationToken); + await RoleRepository.EnsureCollectionLoadedAsync(role, r => r.Claims, cancellationToken); role.RemoveClaim(claim); } diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserLogin.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserLogin.cs index c9e76ff97d..8cfbf08879 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserLogin.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserLogin.cs @@ -68,7 +68,7 @@ namespace Volo.Abp.Identity { } - public UserLoginInfo ToUserLoginInfo() + public virtual UserLoginInfo ToUserLoginInfo() { return new UserLoginInfo(LoginProvider, ProviderKey, ProviderDisplayName); } diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserManager.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserManager.cs index b15d765a0c..430a4822b4 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserManager.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserManager.cs @@ -19,9 +19,9 @@ namespace Volo.Abp.Identity protected IIdentityRoleRepository RoleRepository { get; } protected IIdentityUserRepository UserRepository { get; } - protected override CancellationToken CancellationToken => _cancellationTokenProvider.Token; + protected override CancellationToken CancellationToken => CancellationTokenProvider.Token; - private readonly ICancellationTokenProvider _cancellationTokenProvider; + protected ICancellationTokenProvider CancellationTokenProvider { get; } public IdentityUserManager( IdentityUserStore store, @@ -49,7 +49,7 @@ namespace Volo.Abp.Identity { RoleRepository = roleRepository; UserRepository = userRepository; - _cancellationTokenProvider = cancellationTokenProvider; + CancellationTokenProvider = cancellationTokenProvider; } public virtual async Task GetByIdAsync(Guid id) diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserRepositoryExternalUserLookupServiceProvider.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserRepositoryExternalUserLookupServiceProvider.cs index 75c2ef53a7..7fe729b325 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserRepositoryExternalUserLookupServiceProvider.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserRepositoryExternalUserLookupServiceProvider.cs @@ -9,15 +9,15 @@ namespace Volo.Abp.Identity { public class IdentityUserRepositoryExternalUserLookupServiceProvider : IExternalUserLookupServiceProvider, ITransientDependency { - private readonly IIdentityUserRepository _userRepository; - private readonly ILookupNormalizer _lookupNormalizer; + protected IIdentityUserRepository UserRepository { get; } + protected ILookupNormalizer LookupNormalizer { get; } public IdentityUserRepositoryExternalUserLookupServiceProvider( IIdentityUserRepository userRepository, ILookupNormalizer lookupNormalizer) { - _userRepository = userRepository; - _lookupNormalizer = lookupNormalizer; + UserRepository = userRepository; + LookupNormalizer = lookupNormalizer; } public virtual async Task FindByIdAsync( @@ -25,12 +25,12 @@ namespace Volo.Abp.Identity CancellationToken cancellationToken = default) { return ( - await _userRepository.FindAsync( - id, - includeDetails: false, - cancellationToken: cancellationToken - ) -)?.ToAbpUserData(); + await UserRepository.FindAsync( + id, + includeDetails: false, + cancellationToken: cancellationToken + ) + )?.ToAbpUserData(); } public virtual async Task FindByUserNameAsync( @@ -38,12 +38,12 @@ namespace Volo.Abp.Identity CancellationToken cancellationToken = default) { return ( - await _userRepository.FindByNormalizedUserNameAsync( - _lookupNormalizer.NormalizeName(userName), - includeDetails: false, - cancellationToken: cancellationToken - ) -)?.ToAbpUserData(); + await UserRepository.FindByNormalizedUserNameAsync( + LookupNormalizer.NormalizeName(userName), + includeDetails: false, + cancellationToken: cancellationToken + ) + )?.ToAbpUserData(); } } } diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserStore.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserStore.cs index e92f31797d..ddf2dd4f4b 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserStore.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserStore.cs @@ -50,10 +50,10 @@ namespace Volo.Abp.Identity /// public bool AutoSaveChanges { get; set; } = true; - private readonly IIdentityRoleRepository _roleRepository; - private readonly IGuidGenerator _guidGenerator; - private readonly ILogger _logger; - private readonly IIdentityUserRepository _userRepository; + protected IIdentityRoleRepository RoleRepository { get; } + protected IGuidGenerator GuidGenerator { get; } + protected ILogger Logger { get; } + protected IIdentityUserRepository UserRepository { get; } public IdentityUserStore( IIdentityUserRepository userRepository, @@ -62,10 +62,10 @@ namespace Volo.Abp.Identity ILogger logger, IdentityErrorDescriber describer = null) { - _userRepository = userRepository; - _roleRepository = roleRepository; - _guidGenerator = guidGenerator; - _logger = logger; + UserRepository = userRepository; + RoleRepository = roleRepository; + GuidGenerator = guidGenerator; + Logger = logger; ErrorDescriber = describer ?? new IdentityErrorDescriber(); } @@ -163,7 +163,7 @@ namespace Volo.Abp.Identity Check.NotNull(user, nameof(user)); - await _userRepository.InsertAsync(user, AutoSaveChanges, cancellationToken); + await UserRepository.InsertAsync(user, AutoSaveChanges, cancellationToken); return IdentityResult.Success; } @@ -182,11 +182,11 @@ namespace Volo.Abp.Identity try { - await _userRepository.UpdateAsync(user, AutoSaveChanges, cancellationToken); + await UserRepository.UpdateAsync(user, AutoSaveChanges, cancellationToken); } catch (AbpDbConcurrencyException ex) { - _logger.LogWarning(ex.ToString()); //Trigger some AbpHandledException event + Logger.LogWarning(ex.ToString()); //Trigger some AbpHandledException event return IdentityResult.Failed(ErrorDescriber.ConcurrencyFailure()); } @@ -207,11 +207,11 @@ namespace Volo.Abp.Identity try { - await _userRepository.DeleteAsync(user, AutoSaveChanges, cancellationToken); + await UserRepository.DeleteAsync(user, AutoSaveChanges, cancellationToken); } catch (AbpDbConcurrencyException ex) { - _logger.LogWarning(ex.ToString()); //Trigger some AbpHandledException event + Logger.LogWarning(ex.ToString()); //Trigger some AbpHandledException event return IdentityResult.Failed(ErrorDescriber.ConcurrencyFailure()); } @@ -230,7 +230,7 @@ namespace Volo.Abp.Identity { cancellationToken.ThrowIfCancellationRequested(); - return _userRepository.FindAsync(Guid.Parse(userId), cancellationToken: cancellationToken); + return UserRepository.FindAsync(Guid.Parse(userId), cancellationToken: cancellationToken); } /// @@ -247,7 +247,7 @@ namespace Volo.Abp.Identity Check.NotNull(normalizedUserName, nameof(normalizedUserName)); - return _userRepository.FindByNormalizedUserNameAsync(normalizedUserName, includeDetails: false, cancellationToken: cancellationToken); + return UserRepository.FindByNormalizedUserNameAsync(normalizedUserName, includeDetails: false, cancellationToken: cancellationToken); } /// @@ -313,14 +313,14 @@ namespace Volo.Abp.Identity Check.NotNull(user, nameof(user)); Check.NotNull(normalizedRoleName, nameof(normalizedRoleName)); - var role = await _roleRepository.FindByNormalizedNameAsync(normalizedRoleName, cancellationToken: cancellationToken); + var role = await RoleRepository.FindByNormalizedNameAsync(normalizedRoleName, cancellationToken: cancellationToken); if (role == null) { throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, "Role {0} does not exist!", normalizedRoleName)); } - await _userRepository.EnsureCollectionLoadedAsync(user, u => u.Roles, cancellationToken); + await UserRepository.EnsureCollectionLoadedAsync(user, u => u.Roles, cancellationToken); user.AddRole(role.Id); } @@ -343,13 +343,13 @@ namespace Volo.Abp.Identity throw new ArgumentException(nameof(normalizedRoleName) + " can not be null or whitespace"); } - var role = await _roleRepository.FindByNormalizedNameAsync(normalizedRoleName, cancellationToken: cancellationToken); + var role = await RoleRepository.FindByNormalizedNameAsync(normalizedRoleName, cancellationToken: cancellationToken); if (role == null) { return; } - await _userRepository.EnsureCollectionLoadedAsync(user, u => u.Roles, cancellationToken); + await UserRepository.EnsureCollectionLoadedAsync(user, u => u.Roles, cancellationToken); user.RemoveRole(role.Id); } @@ -366,7 +366,7 @@ namespace Volo.Abp.Identity Check.NotNull(user, nameof(user)); - return await _userRepository.GetRoleNamesAsync(user.Id, cancellationToken: cancellationToken); + return await UserRepository.GetRoleNamesAsync(user.Id, cancellationToken: cancellationToken); } /// @@ -388,13 +388,13 @@ namespace Volo.Abp.Identity throw new ArgumentException(nameof(normalizedRoleName) + " can not be null or whitespace"); } - var role = await _roleRepository.FindByNormalizedNameAsync(normalizedRoleName, cancellationToken: cancellationToken); + var role = await RoleRepository.FindByNormalizedNameAsync(normalizedRoleName, cancellationToken: cancellationToken); if (role == null) { return false; } - await _userRepository.EnsureCollectionLoadedAsync(user, u => u.Roles, cancellationToken); + await UserRepository.EnsureCollectionLoadedAsync(user, u => u.Roles, cancellationToken); return user.IsInRole(role.Id); } @@ -411,7 +411,7 @@ namespace Volo.Abp.Identity Check.NotNull(user, nameof(user)); - await _userRepository.EnsureCollectionLoadedAsync(user, u => u.Claims, cancellationToken); + await UserRepository.EnsureCollectionLoadedAsync(user, u => u.Claims, cancellationToken); return user.Claims.Select(c => c.ToClaim()).ToList(); } @@ -430,9 +430,9 @@ namespace Volo.Abp.Identity Check.NotNull(user, nameof(user)); Check.NotNull(claims, nameof(claims)); - await _userRepository.EnsureCollectionLoadedAsync(user, u => u.Claims, cancellationToken); + await UserRepository.EnsureCollectionLoadedAsync(user, u => u.Claims, cancellationToken); - user.AddClaims(_guidGenerator, claims); + user.AddClaims(GuidGenerator, claims); } /// @@ -451,7 +451,7 @@ namespace Volo.Abp.Identity Check.NotNull(claim, nameof(claim)); Check.NotNull(newClaim, nameof(newClaim)); - await _userRepository.EnsureCollectionLoadedAsync(user, u => u.Claims, cancellationToken); + await UserRepository.EnsureCollectionLoadedAsync(user, u => u.Claims, cancellationToken); user.ReplaceClaim(claim, newClaim); } @@ -470,7 +470,7 @@ namespace Volo.Abp.Identity Check.NotNull(user, nameof(user)); Check.NotNull(claims, nameof(claims)); - await _userRepository.EnsureCollectionLoadedAsync(user, u => u.Claims, cancellationToken); + await UserRepository.EnsureCollectionLoadedAsync(user, u => u.Claims, cancellationToken); user.RemoveClaims(claims); } @@ -489,7 +489,7 @@ namespace Volo.Abp.Identity Check.NotNull(user, nameof(user)); Check.NotNull(login, nameof(login)); - await _userRepository.EnsureCollectionLoadedAsync(user, u => u.Logins, cancellationToken); + await UserRepository.EnsureCollectionLoadedAsync(user, u => u.Logins, cancellationToken); user.AddLogin(login); } @@ -510,7 +510,7 @@ namespace Volo.Abp.Identity Check.NotNull(loginProvider, nameof(loginProvider)); Check.NotNull(providerKey, nameof(providerKey)); - await _userRepository.EnsureCollectionLoadedAsync(user, u => u.Logins, cancellationToken); + await UserRepository.EnsureCollectionLoadedAsync(user, u => u.Logins, cancellationToken); user.RemoveLogin(loginProvider, providerKey); } @@ -529,7 +529,7 @@ namespace Volo.Abp.Identity Check.NotNull(user, nameof(user)); - await _userRepository.EnsureCollectionLoadedAsync(user, u => u.Logins, cancellationToken); + await UserRepository.EnsureCollectionLoadedAsync(user, u => u.Logins, cancellationToken); return user.Logins.Select(l => l.ToUserLoginInfo()).ToList(); } @@ -550,7 +550,7 @@ namespace Volo.Abp.Identity Check.NotNull(loginProvider, nameof(loginProvider)); Check.NotNull(providerKey, nameof(providerKey)); - return _userRepository.FindByLoginAsync(loginProvider, providerKey, cancellationToken: cancellationToken); + return UserRepository.FindByLoginAsync(loginProvider, providerKey, cancellationToken: cancellationToken); } /// @@ -671,7 +671,7 @@ namespace Volo.Abp.Identity { cancellationToken.ThrowIfCancellationRequested(); - return _userRepository.FindByNormalizedEmailAsync(normalizedEmail, includeDetails: false, cancellationToken: cancellationToken); + return UserRepository.FindByNormalizedEmailAsync(normalizedEmail, includeDetails: false, cancellationToken: cancellationToken); } /// @@ -950,7 +950,7 @@ namespace Volo.Abp.Identity Check.NotNull(claim, nameof(claim)); - return await _userRepository.GetListByClaimAsync(claim, cancellationToken: cancellationToken); + return await UserRepository.GetListByClaimAsync(claim, cancellationToken: cancellationToken); } /// @@ -970,7 +970,7 @@ namespace Volo.Abp.Identity throw new ArgumentNullException(nameof(normalizedRoleName)); } - return await _userRepository.GetListByNormalizedRoleNameAsync(normalizedRoleName, cancellationToken: cancellationToken); + return await UserRepository.GetListByNormalizedRoleNameAsync(normalizedRoleName, cancellationToken: cancellationToken); } /// @@ -988,7 +988,7 @@ namespace Volo.Abp.Identity Check.NotNull(user, nameof(user)); - await _userRepository.EnsureCollectionLoadedAsync(user, u => u.Tokens, cancellationToken); + await UserRepository.EnsureCollectionLoadedAsync(user, u => u.Tokens, cancellationToken); user.SetToken(loginProvider, name, value); } @@ -1001,13 +1001,13 @@ namespace Volo.Abp.Identity /// The name of the token. /// The used to propagate notifications that the operation should be canceled. /// The that represents the asynchronous operation. - public async Task RemoveTokenAsync(IdentityUser user, string loginProvider, string name, CancellationToken cancellationToken = default) + public virtual async Task RemoveTokenAsync(IdentityUser user, string loginProvider, string name, CancellationToken cancellationToken = default) { cancellationToken.ThrowIfCancellationRequested(); Check.NotNull(user, nameof(user)); - await _userRepository.EnsureCollectionLoadedAsync(user, u => u.Tokens, cancellationToken); + await UserRepository.EnsureCollectionLoadedAsync(user, u => u.Tokens, cancellationToken); user.RemoveToken(loginProvider, name); } @@ -1020,23 +1020,23 @@ namespace Volo.Abp.Identity /// The name of the token. /// The used to propagate notifications that the operation should be canceled. /// The that represents the asynchronous operation. - public async Task GetTokenAsync(IdentityUser user, string loginProvider, string name, CancellationToken cancellationToken = default) + public virtual async Task GetTokenAsync(IdentityUser user, string loginProvider, string name, CancellationToken cancellationToken = default) { cancellationToken.ThrowIfCancellationRequested(); Check.NotNull(user, nameof(user)); - await _userRepository.EnsureCollectionLoadedAsync(user, u => u.Tokens, cancellationToken); + await UserRepository.EnsureCollectionLoadedAsync(user, u => u.Tokens, cancellationToken); return user.FindToken(loginProvider, name)?.Value; } - public Task SetAuthenticatorKeyAsync(IdentityUser user, string key, CancellationToken cancellationToken = default) + public virtual Task SetAuthenticatorKeyAsync(IdentityUser user, string key, CancellationToken cancellationToken = default) { return SetTokenAsync(user, InternalLoginProvider, AuthenticatorKeyTokenName, key, cancellationToken); } - public Task GetAuthenticatorKeyAsync(IdentityUser user, CancellationToken cancellationToken = default) + public virtual Task GetAuthenticatorKeyAsync(IdentityUser user, CancellationToken cancellationToken = default) { return GetTokenAsync(user, InternalLoginProvider, AuthenticatorKeyTokenName, cancellationToken); } @@ -1101,7 +1101,7 @@ namespace Volo.Abp.Identity return false; } - public void Dispose() + public virtual void Dispose() { } 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 d2de24a568..7886865369 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 @@ -6,16 +6,16 @@ namespace Volo.Abp.Identity { public class UserRoleFinder : IUserRoleFinder, ITransientDependency { - private readonly IIdentityUserRepository _identityUserRepository; + protected IIdentityUserRepository IdentityUserRepository { get; } public UserRoleFinder(IIdentityUserRepository identityUserRepository) { - _identityUserRepository = identityUserRepository; + IdentityUserRepository = identityUserRepository; } public virtual async Task GetRolesAsync(Guid userId) { - return (await _identityUserRepository.GetRoleNamesAsync(userId)).ToArray(); + return (await IdentityUserRepository.GetRoleNamesAsync(userId)).ToArray(); } } } diff --git a/modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentityClaimTypeRepository.cs b/modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentityClaimTypeRepository.cs index 95b7a7fe42..6d6dcf3d50 100644 --- a/modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentityClaimTypeRepository.cs +++ b/modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentityClaimTypeRepository.cs @@ -17,14 +17,14 @@ namespace Volo.Abp.Identity.EntityFrameworkCore } - public async Task AnyAsync(string name, Guid? ignoredId = null) + public virtual async Task AnyAsync(string name, Guid? ignoredId = null) { return await DbSet .WhereIf(ignoredId != null, ct => ct.Id != ignoredId) .CountAsync(ct => ct.Name == name) > 0; } - public async Task> GetListAsync(string sorting, int maxResultCount, int skipCount, string filter) + public virtual async Task> GetListAsync(string sorting, int maxResultCount, int skipCount, string filter) { var identityClaimTypes = await DbSet .WhereIf( diff --git a/modules/identity/src/Volo.Abp.Identity.HttpApi.Client/Volo/Abp/Identity/HttpClientIdentityUserLookupService.cs b/modules/identity/src/Volo.Abp.Identity.HttpApi.Client/Volo/Abp/Identity/HttpClientIdentityUserLookupService.cs index 53eb6a1af1..ec1dca264f 100644 --- a/modules/identity/src/Volo.Abp.Identity.HttpApi.Client/Volo/Abp/Identity/HttpClientIdentityUserLookupService.cs +++ b/modules/identity/src/Volo.Abp.Identity.HttpApi.Client/Volo/Abp/Identity/HttpClientIdentityUserLookupService.cs @@ -9,21 +9,21 @@ namespace Volo.Abp.Identity [Dependency(TryRegister = true)] public class HttpClientExternalUserLookupServiceProvider : IExternalUserLookupServiceProvider, ITransientDependency { - private readonly IIdentityUserLookupAppService _userLookupAppService; + protected IIdentityUserLookupAppService UserLookupAppService { get; } public HttpClientExternalUserLookupServiceProvider(IIdentityUserLookupAppService userLookupAppService) { - _userLookupAppService = userLookupAppService; + UserLookupAppService = userLookupAppService; } - public async Task FindByIdAsync(Guid id, CancellationToken cancellationToken = default) + public virtual async Task FindByIdAsync(Guid id, CancellationToken cancellationToken = default) { - return await _userLookupAppService.FindByIdAsync(id); + return await UserLookupAppService.FindByIdAsync(id); } - public async Task FindByUserNameAsync(string userName, CancellationToken cancellationToken = default) + public virtual async Task FindByUserNameAsync(string userName, CancellationToken cancellationToken = default) { - return await _userLookupAppService.FindByUserNameAsync(userName); + return await UserLookupAppService.FindByUserNameAsync(userName); } } } 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 a5fffe9848..61e35f4d35 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 @@ -8,14 +8,14 @@ namespace Volo.Abp.Identity [Dependency(TryRegister = true)] public class HttpClientUserRoleFinder : IUserRoleFinder, ITransientDependency { - private readonly IIdentityUserAppService _userAppService; + protected IIdentityUserAppService _userAppService { get; } public HttpClientUserRoleFinder(IIdentityUserAppService userAppService) { _userAppService = userAppService; } - public async Task GetRolesAsync(Guid userId) + public virtual async Task GetRolesAsync(Guid userId) { var output = await _userAppService.GetRolesAsync(userId); return output.Items.Select(r => r.Name).ToArray(); diff --git a/modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/IdentityRoleController.cs b/modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/IdentityRoleController.cs index 9925d18abb..451e4d49f7 100644 --- a/modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/IdentityRoleController.cs +++ b/modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/IdentityRoleController.cs @@ -13,51 +13,51 @@ namespace Volo.Abp.Identity [Route("api/identity/roles")] public class IdentityRoleController : AbpController, IIdentityRoleAppService { - private readonly IIdentityRoleAppService _roleAppService; + protected IIdentityRoleAppService RoleAppService { get; } public IdentityRoleController(IIdentityRoleAppService roleAppService) { - _roleAppService = roleAppService; + RoleAppService = roleAppService; } [HttpGet] [Route("all")] public virtual Task> GetAllListAsync() { - return _roleAppService.GetAllListAsync(); + return RoleAppService.GetAllListAsync(); } [HttpGet] public virtual Task> GetListAsync(PagedAndSortedResultRequestDto input) { - return _roleAppService.GetListAsync(input); + return RoleAppService.GetListAsync(input); } [HttpGet] [Route("{id}")] public virtual Task GetAsync(Guid id) { - return _roleAppService.GetAsync(id); + return RoleAppService.GetAsync(id); } [HttpPost] public virtual Task CreateAsync(IdentityRoleCreateDto input) { - return _roleAppService.CreateAsync(input); + return RoleAppService.CreateAsync(input); } [HttpPut] [Route("{id}")] public virtual Task UpdateAsync(Guid id, IdentityRoleUpdateDto input) { - return _roleAppService.UpdateAsync(id, input); + return RoleAppService.UpdateAsync(id, input); } [HttpDelete] [Route("{id}")] public virtual Task DeleteAsync(Guid id) { - return _roleAppService.DeleteAsync(id); + return RoleAppService.DeleteAsync(id); } } } diff --git a/modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/IdentityUserController.cs b/modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/IdentityUserController.cs index 02e8176a1e..43bdf844d7 100644 --- a/modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/IdentityUserController.cs +++ b/modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/IdentityUserController.cs @@ -12,72 +12,72 @@ namespace Volo.Abp.Identity [Route("api/identity/users")] public class IdentityUserController : AbpController, IIdentityUserAppService { - private readonly IIdentityUserAppService _userAppService; + protected IIdentityUserAppService UserAppService { get; } public IdentityUserController(IIdentityUserAppService userAppService) { - _userAppService = userAppService; + UserAppService = userAppService; } [HttpGet] [Route("{id}")] public virtual Task GetAsync(Guid id) { - return _userAppService.GetAsync(id); + return UserAppService.GetAsync(id); } [HttpGet] public virtual Task> GetListAsync(GetIdentityUsersInput input) { - return _userAppService.GetListAsync(input); + return UserAppService.GetListAsync(input); } [HttpPost] public virtual Task CreateAsync(IdentityUserCreateDto input) { - return _userAppService.CreateAsync(input); + return UserAppService.CreateAsync(input); } [HttpPut] [Route("{id}")] public virtual Task UpdateAsync(Guid id, IdentityUserUpdateDto input) { - return _userAppService.UpdateAsync(id, input); + return UserAppService.UpdateAsync(id, input); } [HttpDelete] [Route("{id}")] public virtual Task DeleteAsync(Guid id) { - return _userAppService.DeleteAsync(id); + return UserAppService.DeleteAsync(id); } [HttpGet] [Route("{id}/roles")] public virtual Task> GetRolesAsync(Guid id) { - return _userAppService.GetRolesAsync(id); + return UserAppService.GetRolesAsync(id); } [HttpPut] [Route("{id}/roles")] public virtual Task UpdateRolesAsync(Guid id, IdentityUserUpdateRolesDto input) { - return _userAppService.UpdateRolesAsync(id, input); + return UserAppService.UpdateRolesAsync(id, input); } [HttpGet] [Route("by-username/{userName}")] public virtual Task FindByUsernameAsync(string username) { - return _userAppService.FindByUsernameAsync(username); + return UserAppService.FindByUsernameAsync(username); } [HttpGet] [Route("by-email/{email}")] public virtual Task FindByEmailAsync(string email) { - return _userAppService.FindByEmailAsync(email); + return UserAppService.FindByEmailAsync(email); } } } diff --git a/modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/IdentityUserLookupController.cs b/modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/IdentityUserLookupController.cs index 0c29f36ceb..6bd3bec020 100644 --- a/modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/IdentityUserLookupController.cs +++ b/modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/IdentityUserLookupController.cs @@ -21,14 +21,14 @@ namespace Volo.Abp.Identity [HttpGet] [Route("{id}")] - public Task FindByIdAsync(Guid id) + public virtual Task FindByIdAsync(Guid id) { return LookupAppService.FindByIdAsync(id); } [HttpGet] [Route("by-username/{userName}")] - public Task FindByUserNameAsync(string userName) + public virtual Task FindByUserNameAsync(string userName) { return LookupAppService.FindByUserNameAsync(userName); } diff --git a/modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/ProfileController.cs b/modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/ProfileController.cs index a87af4eef6..d6ed67a7b8 100644 --- a/modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/ProfileController.cs +++ b/modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/ProfileController.cs @@ -10,30 +10,30 @@ namespace Volo.Abp.Identity [Route("/api/identity/my-profile")] public class ProfileController : AbpController, IProfileAppService { - private readonly IProfileAppService _profileAppService; + protected IProfileAppService ProfileAppService { get; } public ProfileController(IProfileAppService profileAppService) { - _profileAppService = profileAppService; + ProfileAppService = profileAppService; } [HttpGet] - public Task GetAsync() + public virtual Task GetAsync() { - return _profileAppService.GetAsync(); + return ProfileAppService.GetAsync(); } [HttpPut] - public Task UpdateAsync(UpdateProfileDto input) + public virtual Task UpdateAsync(UpdateProfileDto input) { - return _profileAppService.UpdateAsync(input); + return ProfileAppService.UpdateAsync(input); } [HttpPost] [Route("change-password")] - public Task ChangePasswordAsync(ChangePasswordInput input) + public virtual Task ChangePasswordAsync(ChangePasswordInput input) { - return _profileAppService.ChangePasswordAsync(input); + return ProfileAppService.ChangePasswordAsync(input); } } } diff --git a/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityClaimTypeRepository.cs b/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityClaimTypeRepository.cs index 16ba528412..8880bcaf1c 100644 --- a/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityClaimTypeRepository.cs +++ b/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityClaimTypeRepository.cs @@ -16,7 +16,7 @@ namespace Volo.Abp.Identity.MongoDB { } - public async Task AnyAsync(string name, Guid? ignoredId = null) + public virtual async Task AnyAsync(string name, Guid? ignoredId = null) { if (ignoredId == null) { @@ -32,7 +32,7 @@ namespace Volo.Abp.Identity.MongoDB } } - public async Task> GetListAsync(string sorting, int maxResultCount, int skipCount, string filter) + public virtual async Task> GetListAsync(string sorting, int maxResultCount, int skipCount, string filter) { return await GetMongoQueryable() .WhereIf>( diff --git a/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityRoleRepository.cs b/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityRoleRepository.cs index 10f77836c9..7acb9b4e4b 100644 --- a/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityRoleRepository.cs +++ b/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityRoleRepository.cs @@ -14,12 +14,9 @@ namespace Volo.Abp.Identity.MongoDB { public class MongoIdentityRoleRepository : MongoDbRepository, IIdentityRoleRepository { - private readonly IGuidGenerator _guidGenerator; - - public MongoIdentityRoleRepository(IMongoDbContextProvider dbContextProvider, IGuidGenerator guidGenerator) + public MongoIdentityRoleRepository(IMongoDbContextProvider dbContextProvider) : base(dbContextProvider) { - _guidGenerator = guidGenerator; } public async Task FindByNormalizedNameAsync( diff --git a/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityUserRepository.cs b/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityUserRepository.cs index 218c2e59e7..9eb1664bd5 100644 --- a/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityUserRepository.cs +++ b/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityUserRepository.cs @@ -15,15 +15,12 @@ namespace Volo.Abp.Identity.MongoDB { public class MongoIdentityUserRepository : MongoDbRepository, IIdentityUserRepository { - private readonly IGuidGenerator _guidGenerator; - - public MongoIdentityUserRepository(IMongoDbContextProvider dbContextProvider, IGuidGenerator guidGenerator) + public MongoIdentityUserRepository(IMongoDbContextProvider dbContextProvider) : base(dbContextProvider) { - _guidGenerator = guidGenerator; } - public async Task FindByNormalizedUserNameAsync( + public virtual async Task FindByNormalizedUserNameAsync( string normalizedUserName, bool includeDetails = true, CancellationToken cancellationToken = default) @@ -35,7 +32,7 @@ namespace Volo.Abp.Identity.MongoDB ); } - public async Task> GetRoleNamesAsync( + public virtual async Task> GetRoleNamesAsync( Guid id, CancellationToken cancellationToken = default) { @@ -44,7 +41,7 @@ namespace Volo.Abp.Identity.MongoDB return await DbContext.Roles.AsQueryable().Where(r => roleIds.Contains(r.Id)).Select(r => r.Name).ToListAsync(GetCancellationToken(cancellationToken)); } - public async Task FindByLoginAsync( + public virtual async Task FindByLoginAsync( string loginProvider, string providerKey, bool includeDetails = true, @@ -55,7 +52,7 @@ namespace Volo.Abp.Identity.MongoDB .FirstOrDefaultAsync(GetCancellationToken(cancellationToken)); } - public async Task FindByNormalizedEmailAsync( + public virtual async Task FindByNormalizedEmailAsync( string normalizedEmail, bool includeDetails = true, CancellationToken cancellationToken = default) @@ -63,7 +60,7 @@ namespace Volo.Abp.Identity.MongoDB return await GetMongoQueryable().FirstOrDefaultAsync(u => u.NormalizedEmail == normalizedEmail, GetCancellationToken(cancellationToken)); } - public async Task> GetListByClaimAsync( + public virtual async Task> GetListByClaimAsync( Claim claim, bool includeDetails = false, CancellationToken cancellationToken = default) @@ -73,7 +70,7 @@ namespace Volo.Abp.Identity.MongoDB .ToListAsync(GetCancellationToken(cancellationToken)); } - public async Task> GetListByNormalizedRoleNameAsync( + public virtual async Task> GetListByNormalizedRoleNameAsync( string normalizedRoleName, bool includeDetails = false, CancellationToken cancellationToken = default) @@ -90,7 +87,7 @@ namespace Volo.Abp.Identity.MongoDB .ToListAsync(GetCancellationToken(cancellationToken)); } - public async Task> GetListAsync( + public virtual async Task> GetListAsync( string sorting = null, int maxResultCount = int.MaxValue, int skipCount = 0, @@ -111,7 +108,7 @@ namespace Volo.Abp.Identity.MongoDB .ToListAsync(GetCancellationToken(cancellationToken)); } - public async Task> GetRolesAsync( + public virtual async Task> GetRolesAsync( Guid id, bool includeDetails = false, CancellationToken cancellationToken = default) @@ -121,7 +118,7 @@ namespace Volo.Abp.Identity.MongoDB return await DbContext.Roles.AsQueryable().Where(r => roleIds.Contains(r.Id)).ToListAsync(GetCancellationToken(cancellationToken)); } - public async Task GetCountAsync( + public virtual async Task GetCountAsync( string filter = null, CancellationToken cancellationToken = default) { diff --git a/modules/identity/src/Volo.Abp.Identity.Web/Navigation/AbpIdentityWebMainMenuContributor.cs b/modules/identity/src/Volo.Abp.Identity.Web/Navigation/AbpIdentityWebMainMenuContributor.cs index 34dc3dd4cd..b06f590066 100644 --- a/modules/identity/src/Volo.Abp.Identity.Web/Navigation/AbpIdentityWebMainMenuContributor.cs +++ b/modules/identity/src/Volo.Abp.Identity.Web/Navigation/AbpIdentityWebMainMenuContributor.cs @@ -9,7 +9,7 @@ namespace Volo.Abp.Identity.Web.Navigation { public class AbpIdentityWebMainMenuContributor : IMenuContributor { - public async Task ConfigureMenuAsync(MenuConfigurationContext context) + public virtual async Task ConfigureMenuAsync(MenuConfigurationContext context) { if (context.Menu.Name != StandardMenus.Main) { 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 09fb389163..74aa138b5e 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 @@ -11,7 +11,7 @@ namespace Volo.Abp.PermissionManagement.Identity { public override string Name => RolePermissionValueProvider.ProviderName; - private readonly IUserRoleFinder _userRoleFinder; + protected IUserRoleFinder UserRoleFinder { get; } public RolePermissionManagementProvider( IPermissionGrantRepository permissionGrantRepository, @@ -23,7 +23,7 @@ namespace Volo.Abp.PermissionManagement.Identity guidGenerator, currentTenant) { - _userRoleFinder = userRoleFinder; + UserRoleFinder = userRoleFinder; } public override async Task CheckAsync(string name, string providerName, string providerKey) @@ -39,7 +39,7 @@ namespace Volo.Abp.PermissionManagement.Identity if (providerName == UserPermissionValueProvider.ProviderName) { var userId = Guid.Parse(providerKey); - var roleNames = await _userRoleFinder.GetRolesAsync(userId); + var roleNames = await UserRoleFinder.GetRolesAsync(userId); foreach (var roleName in roleNames) { diff --git a/modules/identity/src/Volo.Abp.PermissionManagement.Domain.Identity/Volo/Abp/PermissionManagement/Identity/RoleUpdateEventHandler.cs b/modules/identity/src/Volo.Abp.PermissionManagement.Domain.Identity/Volo/Abp/PermissionManagement/Identity/RoleUpdateEventHandler.cs index ca2695aaf5..5a95d515c4 100644 --- a/modules/identity/src/Volo.Abp.PermissionManagement.Domain.Identity/Volo/Abp/PermissionManagement/Identity/RoleUpdateEventHandler.cs +++ b/modules/identity/src/Volo.Abp.PermissionManagement.Domain.Identity/Volo/Abp/PermissionManagement/Identity/RoleUpdateEventHandler.cs @@ -25,7 +25,7 @@ namespace Volo.Abp.PermissionManagement.Identity PermissionGrantRepository = permissionGrantRepository; } - public async Task HandleEventAsync(IdentityRoleNameChangedEvent eventData) + public virtual async Task HandleEventAsync(IdentityRoleNameChangedEvent eventData) { var role = await RoleRepository.FindAsync(eventData.IdentityRole.Id, false); if (role == null) From d2d5d79be4d09e2c3787d1ae53ce3a95e4a3c3e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20=C3=87otur?= Date: Wed, 18 Mar 2020 12:16:11 +0300 Subject: [PATCH 2/2] mapping is also virtualized --- .../Volo.Abp.Identity.Web/AbpIdentityWebAutoMapperProfile.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/identity/src/Volo.Abp.Identity.Web/AbpIdentityWebAutoMapperProfile.cs b/modules/identity/src/Volo.Abp.Identity.Web/AbpIdentityWebAutoMapperProfile.cs index 7419a6f668..f29659efe6 100644 --- a/modules/identity/src/Volo.Abp.Identity.Web/AbpIdentityWebAutoMapperProfile.cs +++ b/modules/identity/src/Volo.Abp.Identity.Web/AbpIdentityWebAutoMapperProfile.cs @@ -14,7 +14,7 @@ namespace Volo.Abp.Identity.Web CreateRoleMappings(); } - private void CreateUserMappings() + protected virtual void CreateUserMappings() { //List CreateMap() @@ -35,7 +35,7 @@ namespace Volo.Abp.Identity.Web .ForMember(dest => dest.IsAssigned, opt => opt.Ignore()); } - private void CreateRoleMappings() + protected virtual void CreateRoleMappings() { //List CreateMap();