Browse Source

virtualized

pull/3178/head
Ahmet Çotur 7 years ago
parent
commit
0dea196761
  1. 28
      modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityRoleAppService.cs
  2. 54
      modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityUserAppService.cs
  3. 20
      modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/ProfileAppService.cs
  4. 30
      modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/AbpIdentityOptionsFactory.cs
  5. 2
      modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/AbpIdentityResultException.cs
  6. 12
      modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityClaimTypeManager.cs
  7. 8
      modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityDataSeedContributor.cs
  8. 40
      modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityDataSeeder.cs
  9. 14
      modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityRoleManager.cs
  10. 48
      modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityRoleStore.cs
  11. 2
      modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserLogin.cs
  12. 6
      modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserManager.cs
  13. 32
      modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserRepositoryExternalUserLookupServiceProvider.cs
  14. 84
      modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserStore.cs
  15. 6
      modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/UserRoleFinder.cs
  16. 4
      modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentityClaimTypeRepository.cs
  17. 12
      modules/identity/src/Volo.Abp.Identity.HttpApi.Client/Volo/Abp/Identity/HttpClientIdentityUserLookupService.cs
  18. 4
      modules/identity/src/Volo.Abp.Identity.HttpApi.Client/Volo/Abp/Identity/HttpClientUserRoleFinder.cs
  19. 16
      modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/IdentityRoleController.cs
  20. 22
      modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/IdentityUserController.cs
  21. 4
      modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/IdentityUserLookupController.cs
  22. 16
      modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/ProfileController.cs
  23. 4
      modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityClaimTypeRepository.cs
  24. 5
      modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityRoleRepository.cs
  25. 23
      modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityUserRepository.cs
  26. 2
      modules/identity/src/Volo.Abp.Identity.Web/Navigation/AbpIdentityWebMainMenuContributor.cs
  27. 6
      modules/identity/src/Volo.Abp.PermissionManagement.Domain.Identity/Volo/Abp/PermissionManagement/Identity/RolePermissionManagementProvider.cs
  28. 2
      modules/identity/src/Volo.Abp.PermissionManagement.Domain.Identity/Volo/Abp/PermissionManagement/Identity/RoleUpdateEventHandler.cs

28
modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityRoleAppService.cs

@ -10,34 +10,34 @@ namespace Volo.Abp.Identity
[Authorize(IdentityPermissions.Roles.Default)] [Authorize(IdentityPermissions.Roles.Default)]
public class IdentityRoleAppService : IdentityAppServiceBase, IIdentityRoleAppService public class IdentityRoleAppService : IdentityAppServiceBase, IIdentityRoleAppService
{ {
private readonly IdentityRoleManager _roleManager; protected IdentityRoleManager RoleManager { get; }
private readonly IIdentityRoleRepository _roleRepository; protected IIdentityRoleRepository RoleRepository { get; }
public IdentityRoleAppService( public IdentityRoleAppService(
IdentityRoleManager roleManager, IdentityRoleManager roleManager,
IIdentityRoleRepository roleRepository) IIdentityRoleRepository roleRepository)
{ {
_roleManager = roleManager; RoleManager = roleManager;
_roleRepository = roleRepository; RoleRepository = roleRepository;
} }
public virtual async Task<IdentityRoleDto> GetAsync(Guid id) public virtual async Task<IdentityRoleDto> GetAsync(Guid id)
{ {
return ObjectMapper.Map<IdentityRole, IdentityRoleDto>( return ObjectMapper.Map<IdentityRole, IdentityRoleDto>(
await _roleManager.GetByIdAsync(id)); await RoleManager.GetByIdAsync(id));
} }
public virtual async Task<ListResultDto<IdentityRoleDto>> GetAllListAsync() public virtual async Task<ListResultDto<IdentityRoleDto>> GetAllListAsync()
{ {
var list = await _roleRepository.GetListAsync(); var list = await RoleRepository.GetListAsync();
return new ListResultDto<IdentityRoleDto>( return new ListResultDto<IdentityRoleDto>(
ObjectMapper.Map<List<IdentityRole>, List<IdentityRoleDto>>(list)); ObjectMapper.Map<List<IdentityRole>, List<IdentityRoleDto>>(list));
} }
public virtual async Task<PagedResultDto<IdentityRoleDto>> GetListAsync(PagedAndSortedResultRequestDto input) public virtual async Task<PagedResultDto<IdentityRoleDto>> GetListAsync(PagedAndSortedResultRequestDto input)
{ {
var list = await _roleRepository.GetListAsync(input.Sorting, input.MaxResultCount, input.SkipCount); var list = await RoleRepository.GetListAsync(input.Sorting, input.MaxResultCount, input.SkipCount);
var totalCount = await _roleRepository.GetCountAsync(); var totalCount = await RoleRepository.GetCountAsync();
return new PagedResultDto<IdentityRoleDto>( return new PagedResultDto<IdentityRoleDto>(
totalCount, totalCount,
@ -53,7 +53,7 @@ namespace Volo.Abp.Identity
role.IsDefault = input.IsDefault; role.IsDefault = input.IsDefault;
role.IsPublic = input.IsPublic; role.IsPublic = input.IsPublic;
(await _roleManager.CreateAsync(role)).CheckErrors(); (await RoleManager.CreateAsync(role)).CheckErrors();
await CurrentUnitOfWork.SaveChangesAsync(); await CurrentUnitOfWork.SaveChangesAsync();
return ObjectMapper.Map<IdentityRole, IdentityRoleDto>(role); return ObjectMapper.Map<IdentityRole, IdentityRoleDto>(role);
@ -62,15 +62,15 @@ namespace Volo.Abp.Identity
[Authorize(IdentityPermissions.Roles.Update)] [Authorize(IdentityPermissions.Roles.Update)]
public virtual async Task<IdentityRoleDto> UpdateAsync(Guid id, IdentityRoleUpdateDto input) public virtual async Task<IdentityRoleDto> UpdateAsync(Guid id, IdentityRoleUpdateDto input)
{ {
var role = await _roleManager.GetByIdAsync(id); var role = await RoleManager.GetByIdAsync(id);
role.ConcurrencyStamp = input.ConcurrencyStamp; role.ConcurrencyStamp = input.ConcurrencyStamp;
(await _roleManager.SetRoleNameAsync(role, input.Name)).CheckErrors(); (await RoleManager.SetRoleNameAsync(role, input.Name)).CheckErrors();
role.IsDefault = input.IsDefault; role.IsDefault = input.IsDefault;
role.IsPublic = input.IsPublic; role.IsPublic = input.IsPublic;
(await _roleManager.UpdateAsync(role)).CheckErrors(); (await RoleManager.UpdateAsync(role)).CheckErrors();
await CurrentUnitOfWork.SaveChangesAsync(); await CurrentUnitOfWork.SaveChangesAsync();
return ObjectMapper.Map<IdentityRole, IdentityRoleDto>(role); return ObjectMapper.Map<IdentityRole, IdentityRoleDto>(role);
@ -79,13 +79,13 @@ namespace Volo.Abp.Identity
[Authorize(IdentityPermissions.Roles.Delete)] [Authorize(IdentityPermissions.Roles.Delete)]
public virtual async Task DeleteAsync(Guid id) public virtual async Task DeleteAsync(Guid id)
{ {
var role = await _roleManager.FindByIdAsync(id.ToString()); var role = await RoleManager.FindByIdAsync(id.ToString());
if (role == null) if (role == null)
{ {
return; return;
} }
(await _roleManager.DeleteAsync(role)).CheckErrors(); (await RoleManager.DeleteAsync(role)).CheckErrors();
} }
} }
} }

54
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 public class IdentityUserAppService : IdentityAppServiceBase, IIdentityUserAppService
{ {
private readonly IdentityUserManager _userManager; protected IdentityUserManager UserManager { get; }
private readonly IIdentityUserRepository _userRepository; protected IIdentityUserRepository UserRepository { get; }
public IdentityUserAppService( public IdentityUserAppService(
IdentityUserManager userManager, IdentityUserManager userManager,
IIdentityUserRepository userRepository) IIdentityUserRepository userRepository)
{ {
_userManager = userManager; UserManager = userManager;
_userRepository = userRepository; UserRepository = userRepository;
} }
//TODO: [Authorize(IdentityPermissions.Users.Default)] should go the IdentityUserAppService class. //TODO: [Authorize(IdentityPermissions.Users.Default)] should go the IdentityUserAppService class.
@ -25,15 +25,15 @@ namespace Volo.Abp.Identity
public virtual async Task<IdentityUserDto> GetAsync(Guid id) public virtual async Task<IdentityUserDto> GetAsync(Guid id)
{ {
return ObjectMapper.Map<IdentityUser, IdentityUserDto>( return ObjectMapper.Map<IdentityUser, IdentityUserDto>(
await _userManager.GetByIdAsync(id) await UserManager.GetByIdAsync(id)
); );
} }
[Authorize(IdentityPermissions.Users.Default)] [Authorize(IdentityPermissions.Users.Default)]
public virtual async Task<PagedResultDto<IdentityUserDto>> GetListAsync(GetIdentityUsersInput input) public virtual async Task<PagedResultDto<IdentityUserDto>> GetListAsync(GetIdentityUsersInput input)
{ {
var count = await _userRepository.GetCountAsync(input.Filter); var count = await UserRepository.GetCountAsync(input.Filter);
var list = await _userRepository.GetListAsync(input.Sorting, input.MaxResultCount, input.SkipCount, input.Filter); var list = await UserRepository.GetListAsync(input.Sorting, input.MaxResultCount, input.SkipCount, input.Filter);
return new PagedResultDto<IdentityUserDto>( return new PagedResultDto<IdentityUserDto>(
count, count,
@ -44,7 +44,7 @@ namespace Volo.Abp.Identity
[Authorize(IdentityPermissions.Users.Default)] [Authorize(IdentityPermissions.Users.Default)]
public virtual async Task<ListResultDto<IdentityRoleDto>> GetRolesAsync(Guid id) public virtual async Task<ListResultDto<IdentityRoleDto>> GetRolesAsync(Guid id)
{ {
var roles = await _userRepository.GetRolesAsync(id); var roles = await UserRepository.GetRolesAsync(id);
return new ListResultDto<IdentityRoleDto>( return new ListResultDto<IdentityRoleDto>(
ObjectMapper.Map<List<IdentityRole>, List<IdentityRoleDto>>(roles) ObjectMapper.Map<List<IdentityRole>, List<IdentityRoleDto>>(roles)
); );
@ -55,7 +55,7 @@ namespace Volo.Abp.Identity
{ {
var user = new IdentityUser(GuidGenerator.Create(), input.UserName, input.Email, CurrentTenant.Id); 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 UpdateUserByInput(user, input);
await CurrentUnitOfWork.SaveChangesAsync(); await CurrentUnitOfWork.SaveChangesAsync();
@ -66,17 +66,17 @@ namespace Volo.Abp.Identity
[Authorize(IdentityPermissions.Users.Update)] [Authorize(IdentityPermissions.Users.Update)]
public virtual async Task<IdentityUserDto> UpdateAsync(Guid id, IdentityUserUpdateDto input) public virtual async Task<IdentityUserDto> UpdateAsync(Guid id, IdentityUserUpdateDto input)
{ {
var user = await _userManager.GetByIdAsync(id); var user = await UserManager.GetByIdAsync(id);
user.ConcurrencyStamp = input.ConcurrencyStamp; user.ConcurrencyStamp = input.ConcurrencyStamp;
(await _userManager.SetUserNameAsync(user, input.UserName)).CheckErrors(); (await UserManager.SetUserNameAsync(user, input.UserName)).CheckErrors();
await UpdateUserByInput(user, input); await UpdateUserByInput(user, input);
(await _userManager.UpdateAsync(user)).CheckErrors(); (await UserManager.UpdateAsync(user)).CheckErrors();
if (!input.Password.IsNullOrEmpty()) if (!input.Password.IsNullOrEmpty())
{ {
(await _userManager.RemovePasswordAsync(user)).CheckErrors(); (await UserManager.RemovePasswordAsync(user)).CheckErrors();
(await _userManager.AddPasswordAsync(user, input.Password)).CheckErrors(); (await UserManager.AddPasswordAsync(user, input.Password)).CheckErrors();
} }
await CurrentUnitOfWork.SaveChangesAsync(); await CurrentUnitOfWork.SaveChangesAsync();
@ -92,28 +92,28 @@ namespace Volo.Abp.Identity
throw new BusinessException(code: IdentityErrorCodes.UserSelfDeletion); throw new BusinessException(code: IdentityErrorCodes.UserSelfDeletion);
} }
var user = await _userManager.FindByIdAsync(id.ToString()); var user = await UserManager.FindByIdAsync(id.ToString());
if (user == null) if (user == null)
{ {
return; return;
} }
(await _userManager.DeleteAsync(user)).CheckErrors(); (await UserManager.DeleteAsync(user)).CheckErrors();
} }
[Authorize(IdentityPermissions.Users.Update)] [Authorize(IdentityPermissions.Users.Update)]
public virtual async Task UpdateRolesAsync(Guid id, IdentityUserUpdateRolesDto input) public virtual async Task UpdateRolesAsync(Guid id, IdentityUserUpdateRolesDto input)
{ {
var user = await _userManager.GetByIdAsync(id); var user = await UserManager.GetByIdAsync(id);
(await _userManager.SetRolesAsync(user, input.RoleNames)).CheckErrors(); (await UserManager.SetRolesAsync(user, input.RoleNames)).CheckErrors();
await _userRepository.UpdateAsync(user); await UserRepository.UpdateAsync(user);
} }
[Authorize(IdentityPermissions.Users.Default)] [Authorize(IdentityPermissions.Users.Default)]
public virtual async Task<IdentityUserDto> FindByUsernameAsync(string username) public virtual async Task<IdentityUserDto> FindByUsernameAsync(string username)
{ {
return ObjectMapper.Map<IdentityUser, IdentityUserDto>( return ObjectMapper.Map<IdentityUser, IdentityUserDto>(
await _userManager.FindByNameAsync(username) await UserManager.FindByNameAsync(username)
); );
} }
@ -121,31 +121,31 @@ namespace Volo.Abp.Identity
public virtual async Task<IdentityUserDto> FindByEmailAsync(string email) public virtual async Task<IdentityUserDto> FindByEmailAsync(string email)
{ {
return ObjectMapper.Map<IdentityUser, IdentityUserDto>( return ObjectMapper.Map<IdentityUser, IdentityUserDto>(
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)) 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)) 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.SetTwoFactorEnabledAsync(user, input.TwoFactorEnabled)).CheckErrors();
(await _userManager.SetLockoutEnabledAsync(user, input.LockoutEnabled)).CheckErrors(); (await UserManager.SetLockoutEnabledAsync(user, input.LockoutEnabled)).CheckErrors();
user.Name = input.Name; user.Name = input.Name;
user.Surname = input.Surname; user.Surname = input.Surname;
if (input.RoleNames != null) if (input.RoleNames != null)
{ {
(await _userManager.SetRolesAsync(user, input.RoleNames)).CheckErrors(); (await UserManager.SetRolesAsync(user, input.RoleNames)).CheckErrors();
} }
} }
} }

20
modules/identity/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/ProfileAppService.cs

@ -10,40 +10,40 @@ namespace Volo.Abp.Identity
[Authorize] [Authorize]
public class ProfileAppService : IdentityAppServiceBase, IProfileAppService public class ProfileAppService : IdentityAppServiceBase, IProfileAppService
{ {
private readonly IdentityUserManager _userManager; protected IdentityUserManager UserManager { get; }
public ProfileAppService(IdentityUserManager userManager) public ProfileAppService(IdentityUserManager userManager)
{ {
_userManager = userManager; UserManager = userManager;
} }
public virtual async Task<ProfileDto> GetAsync() public virtual async Task<ProfileDto> GetAsync()
{ {
return ObjectMapper.Map<IdentityUser, ProfileDto>( return ObjectMapper.Map<IdentityUser, ProfileDto>(
await _userManager.GetByIdAsync(CurrentUser.GetId()) await UserManager.GetByIdAsync(CurrentUser.GetId())
); );
} }
public virtual async Task<ProfileDto> UpdateAsync(UpdateProfileDto input) public virtual async Task<ProfileDto> UpdateAsync(UpdateProfileDto input)
{ {
var user = await _userManager.GetByIdAsync(CurrentUser.GetId()); var user = await UserManager.GetByIdAsync(CurrentUser.GetId());
if (await SettingProvider.IsTrueAsync(IdentitySettingNames.User.IsUserNameUpdateEnabled)) 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)) 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.Name = input.Name;
user.Surname = input.Surname; user.Surname = input.Surname;
(await _userManager.UpdateAsync(user)).CheckErrors(); (await UserManager.UpdateAsync(user)).CheckErrors();
await CurrentUnitOfWork.SaveChangesAsync(); await CurrentUnitOfWork.SaveChangesAsync();
@ -52,8 +52,8 @@ namespace Volo.Abp.Identity
public virtual async Task ChangePasswordAsync(ChangePasswordInput input) public virtual async Task ChangePasswordAsync(ChangePasswordInput input)
{ {
var currentUser = await _userManager.GetByIdAsync(CurrentUser.GetId()); var currentUser = await UserManager.GetByIdAsync(CurrentUser.GetId());
(await _userManager.ChangePasswordAsync(currentUser, input.CurrentPassword, input.NewPassword)).CheckErrors(); (await UserManager.ChangePasswordAsync(currentUser, input.CurrentPassword, input.NewPassword)).CheckErrors();
} }
} }
} }

30
modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/AbpIdentityOptionsFactory.cs

@ -12,7 +12,7 @@ namespace Volo.Abp.Identity
{ {
public class AbpIdentityOptionsFactory : AbpOptionsFactory<IdentityOptions> public class AbpIdentityOptionsFactory : AbpOptionsFactory<IdentityOptions>
{ {
private readonly ISettingProvider _settingProvider; protected ISettingProvider SettingProvider { get; }
public AbpIdentityOptionsFactory( public AbpIdentityOptionsFactory(
IEnumerable<IConfigureOptions<IdentityOptions>> setups, IEnumerable<IConfigureOptions<IdentityOptions>> setups,
@ -20,7 +20,7 @@ namespace Volo.Abp.Identity
ISettingProvider settingProvider) ISettingProvider settingProvider)
: base(setups, postConfigures) : base(setups, postConfigures)
{ {
_settingProvider = settingProvider; SettingProvider = settingProvider;
} }
public override IdentityOptions Create(string name) public override IdentityOptions Create(string name)
@ -39,19 +39,19 @@ namespace Volo.Abp.Identity
protected virtual async Task OverrideOptionsAsync(IdentityOptions options) protected virtual async Task OverrideOptionsAsync(IdentityOptions options)
{ {
options.Password.RequiredLength = await _settingProvider.GetAsync(IdentitySettingNames.Password.RequiredLength, options.Password.RequiredLength); 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.RequiredUniqueChars = await SettingProvider.GetAsync(IdentitySettingNames.Password.RequiredUniqueChars, options.Password.RequiredUniqueChars);
options.Password.RequireNonAlphanumeric = await _settingProvider.GetAsync(IdentitySettingNames.Password.RequireNonAlphanumeric, options.Password.RequireNonAlphanumeric); 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.RequireLowercase = await SettingProvider.GetAsync(IdentitySettingNames.Password.RequireLowercase, options.Password.RequireLowercase);
options.Password.RequireUppercase = await _settingProvider.GetAsync(IdentitySettingNames.Password.RequireUppercase, options.Password.RequireUppercase); 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.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.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<int>())); options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromSeconds(await SettingProvider.GetAsync(IdentitySettingNames.Lockout.LockoutDuration, options.Lockout.DefaultLockoutTimeSpan.TotalSeconds.To<int>()));
options.Lockout.MaxFailedAccessAttempts = await _settingProvider.GetAsync(IdentitySettingNames.Lockout.MaxFailedAccessAttempts, options.Lockout.MaxFailedAccessAttempts); 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.RequireConfirmedEmail = await SettingProvider.GetAsync(IdentitySettingNames.SignIn.RequireConfirmedEmail, options.SignIn.RequireConfirmedEmail);
options.SignIn.RequireConfirmedPhoneNumber = await _settingProvider.GetAsync(IdentitySettingNames.SignIn.RequireConfirmedPhoneNumber, options.SignIn.RequireConfirmedPhoneNumber); options.SignIn.RequireConfirmedPhoneNumber = await SettingProvider.GetAsync(IdentitySettingNames.SignIn.RequireConfirmedPhoneNumber, options.SignIn.RequireConfirmedPhoneNumber);
} }
} }

2
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<IdentityResource>()); return IdentityResult.LocalizeErrors(context.LocalizerFactory.Create<IdentityResource>());
} }

12
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! //TODO: Rename to IdentityClaimTypeManager in v2.0!
public class IdenityClaimTypeManager : DomainService public class IdenityClaimTypeManager : DomainService
{ {
private readonly IIdentityClaimTypeRepository _identityClaimTypeRepository; protected IIdentityClaimTypeRepository IdentityClaimTypeRepository { get; }
public IdenityClaimTypeManager(IIdentityClaimTypeRepository identityClaimTypeRepository) public IdenityClaimTypeManager(IIdentityClaimTypeRepository identityClaimTypeRepository)
{ {
_identityClaimTypeRepository = identityClaimTypeRepository; IdentityClaimTypeRepository = identityClaimTypeRepository;
} }
public virtual async Task<IdentityClaimType> CreateAsync(IdentityClaimType claimType) public virtual async Task<IdentityClaimType> CreateAsync(IdentityClaimType claimType)
{ {
if (await _identityClaimTypeRepository.AnyAsync(claimType.Name)) if (await IdentityClaimTypeRepository.AnyAsync(claimType.Name))
{ {
throw new AbpException($"Name Exist: {claimType.Name}"); throw new AbpException($"Name Exist: {claimType.Name}");
} }
return await _identityClaimTypeRepository.InsertAsync(claimType); return await IdentityClaimTypeRepository.InsertAsync(claimType);
} }
public virtual async Task<IdentityClaimType> UpdateAsync(IdentityClaimType claimType) public virtual async Task<IdentityClaimType> 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}"); 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);
} }
} }
} }

8
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 public class IdentityDataSeedContributor : IDataSeedContributor, ITransientDependency
{ {
private readonly IIdentityDataSeeder _identityDataSeeder; protected IIdentityDataSeeder IdentityDataSeeder { get; }
public IdentityDataSeedContributor(IIdentityDataSeeder identityDataSeeder) 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["AdminEmail"] as string ?? "admin@abp.io",
context["AdminPassword"] as string ?? "1q2w3E*", context["AdminPassword"] as string ?? "1q2w3E*",
context.TenantId context.TenantId

40
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 public class IdentityDataSeeder : ITransientDependency, IIdentityDataSeeder
{ {
private readonly IGuidGenerator _guidGenerator; protected IGuidGenerator GuidGenerator { get; }
private readonly IIdentityRoleRepository _roleRepository; protected IIdentityRoleRepository RoleRepository { get; }
private readonly IIdentityUserRepository _userRepository; protected IIdentityUserRepository UserRepository { get; }
private readonly ILookupNormalizer _lookupNormalizer; protected ILookupNormalizer LookupNormalizer { get; }
private readonly IdentityUserManager _userManager; protected IdentityUserManager UserManager { get; }
private readonly IdentityRoleManager _roleManager; protected IdentityRoleManager RoleManager { get; }
public IdentityDataSeeder( public IdentityDataSeeder(
IGuidGenerator guidGenerator, IGuidGenerator guidGenerator,
@ -24,12 +24,12 @@ namespace Volo.Abp.Identity
IdentityUserManager userManager, IdentityUserManager userManager,
IdentityRoleManager roleManager) IdentityRoleManager roleManager)
{ {
_guidGenerator = guidGenerator; GuidGenerator = guidGenerator;
_roleRepository = roleRepository; RoleRepository = roleRepository;
_userRepository = userRepository; UserRepository = userRepository;
_lookupNormalizer = lookupNormalizer; LookupNormalizer = lookupNormalizer;
_userManager = userManager; UserManager = userManager;
_roleManager = roleManager; RoleManager = roleManager;
} }
[UnitOfWork] [UnitOfWork]
@ -45,8 +45,8 @@ namespace Volo.Abp.Identity
//"admin" user //"admin" user
const string adminUserName = "admin"; const string adminUserName = "admin";
var adminUser = await _userRepository.FindByNormalizedUserNameAsync( var adminUser = await UserRepository.FindByNormalizedUserNameAsync(
_lookupNormalizer.NormalizeName(adminUserName) LookupNormalizer.NormalizeName(adminUserName)
); );
if (adminUser != null) if (adminUser != null)
@ -55,7 +55,7 @@ namespace Volo.Abp.Identity
} }
adminUser = new IdentityUser( adminUser = new IdentityUser(
_guidGenerator.Create(), GuidGenerator.Create(),
adminUserName, adminUserName,
adminEmail, adminEmail,
tenantId tenantId
@ -64,16 +64,16 @@ namespace Volo.Abp.Identity
Name = adminUserName Name = adminUserName
}; };
(await _userManager.CreateAsync(adminUser, adminPassword)).CheckErrors(); (await UserManager.CreateAsync(adminUser, adminPassword)).CheckErrors();
result.CreatedAdminUser = true; result.CreatedAdminUser = true;
//"admin" role //"admin" role
const string adminRoleName = "admin"; const string adminRoleName = "admin";
var adminRole = await _roleRepository.FindByNormalizedNameAsync(_lookupNormalizer.NormalizeName(adminRoleName)); var adminRole = await RoleRepository.FindByNormalizedNameAsync(LookupNormalizer.NormalizeName(adminRoleName));
if (adminRole == null) if (adminRole == null)
{ {
adminRole = new IdentityRole( adminRole = new IdentityRole(
_guidGenerator.Create(), GuidGenerator.Create(),
adminRoleName, adminRoleName,
tenantId tenantId
) )
@ -82,11 +82,11 @@ namespace Volo.Abp.Identity
IsPublic = true IsPublic = true
}; };
(await _roleManager.CreateAsync(adminRole)).CheckErrors(); (await RoleManager.CreateAsync(adminRole)).CheckErrors();
result.CreatedAdminRole = true; result.CreatedAdminRole = true;
} }
(await _userManager.AddToRoleAsync(adminUser, adminRoleName)).CheckErrors(); (await UserManager.AddToRoleAsync(adminUser, adminRoleName)).CheckErrors();
return result; return result;
} }

14
modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityRoleManager.cs

@ -15,10 +15,10 @@ namespace Volo.Abp.Identity
{ {
public class IdentityRoleManager : RoleManager<IdentityRole>, IDomainService public class IdentityRoleManager : RoleManager<IdentityRole>, IDomainService
{ {
protected override CancellationToken CancellationToken => _cancellationTokenProvider.Token; protected override CancellationToken CancellationToken => CancellationTokenProvider.Token;
private readonly IStringLocalizer<IdentityResource> _localizer; protected IStringLocalizer<IdentityResource> Localizer { get; }
private readonly ICancellationTokenProvider _cancellationTokenProvider; protected ICancellationTokenProvider CancellationTokenProvider { get; }
public IdentityRoleManager( public IdentityRoleManager(
IdentityRoleStore store, IdentityRoleStore store,
@ -35,8 +35,8 @@ namespace Volo.Abp.Identity
errors, errors,
logger) logger)
{ {
_localizer = localizer; Localizer = localizer;
_cancellationTokenProvider = cancellationTokenProvider; CancellationTokenProvider = cancellationTokenProvider;
} }
public virtual async Task<IdentityRole> GetByIdAsync(Guid id) public virtual async Task<IdentityRole> GetByIdAsync(Guid id)
@ -54,7 +54,7 @@ namespace Volo.Abp.Identity
{ {
if (role.IsStatic && role.Name != name) 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); return await base.SetRoleNameAsync(role, name);
@ -64,7 +64,7 @@ namespace Volo.Abp.Identity
{ {
if (role.IsStatic) 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); return await base.DeleteAsync(role);

48
modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityRoleStore.cs

@ -22,9 +22,9 @@ namespace Volo.Abp.Identity
IRoleClaimStore<IdentityRole>, IRoleClaimStore<IdentityRole>,
ITransientDependency ITransientDependency
{ {
private readonly IIdentityRoleRepository _roleRepository; protected IIdentityRoleRepository RoleRepository { get; }
private readonly ILogger<IdentityRoleStore> _logger; protected ILogger<IdentityRoleStore> Logger { get; }
private readonly IGuidGenerator _guidGenerator; protected IGuidGenerator GuidGenerator { get; }
/// <summary> /// <summary>
/// Constructs a new instance of <see cref="IdentityRoleStore"/>. /// Constructs a new instance of <see cref="IdentityRoleStore"/>.
@ -35,9 +35,9 @@ namespace Volo.Abp.Identity
IGuidGenerator guidGenerator, IGuidGenerator guidGenerator,
IdentityErrorDescriber describer = null) IdentityErrorDescriber describer = null)
{ {
_roleRepository = roleRepository; RoleRepository = roleRepository;
_logger = logger; Logger = logger;
_guidGenerator = guidGenerator; GuidGenerator = guidGenerator;
ErrorDescriber = describer ?? new IdentityErrorDescriber(); ErrorDescriber = describer ?? new IdentityErrorDescriber();
} }
@ -67,7 +67,7 @@ namespace Volo.Abp.Identity
Check.NotNull(role, nameof(role)); Check.NotNull(role, nameof(role));
await _roleRepository.InsertAsync(role, AutoSaveChanges, cancellationToken); await RoleRepository.InsertAsync(role, AutoSaveChanges, cancellationToken);
return IdentityResult.Success; return IdentityResult.Success;
} }
@ -86,11 +86,11 @@ namespace Volo.Abp.Identity
try try
{ {
await _roleRepository.UpdateAsync(role, AutoSaveChanges, cancellationToken); await RoleRepository.UpdateAsync(role, AutoSaveChanges, cancellationToken);
} }
catch (AbpDbConcurrencyException ex) catch (AbpDbConcurrencyException ex)
{ {
_logger.LogWarning(ex.ToString()); //Trigger some AbpHandledException event Logger.LogWarning(ex.ToString()); //Trigger some AbpHandledException event
return IdentityResult.Failed(ErrorDescriber.ConcurrencyFailure()); return IdentityResult.Failed(ErrorDescriber.ConcurrencyFailure());
} }
@ -111,11 +111,11 @@ namespace Volo.Abp.Identity
try try
{ {
await _roleRepository.DeleteAsync(role, AutoSaveChanges, cancellationToken); await RoleRepository.DeleteAsync(role, AutoSaveChanges, cancellationToken);
} }
catch (AbpDbConcurrencyException ex) catch (AbpDbConcurrencyException ex)
{ {
_logger.LogWarning(ex.ToString()); //Trigger some AbpHandledException event Logger.LogWarning(ex.ToString()); //Trigger some AbpHandledException event
return IdentityResult.Failed(ErrorDescriber.ConcurrencyFailure()); return IdentityResult.Failed(ErrorDescriber.ConcurrencyFailure());
} }
@ -128,7 +128,7 @@ namespace Volo.Abp.Identity
/// <param name="role">The role whose ID should be returned.</param> /// <param name="role">The role whose ID should be returned.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> used to propagate notifications that the operation should be canceled.</param> /// <param name="cancellationToken">The <see cref="CancellationToken"/> used to propagate notifications that the operation should be canceled.</param>
/// <returns>A <see cref="Task{TResult}"/> that contains the ID of the role.</returns> /// <returns>A <see cref="Task{TResult}"/> that contains the ID of the role.</returns>
public Task<string> GetRoleIdAsync([NotNull] IdentityRole role, CancellationToken cancellationToken = default) public virtual Task<string> GetRoleIdAsync([NotNull] IdentityRole role, CancellationToken cancellationToken = default)
{ {
cancellationToken.ThrowIfCancellationRequested(); cancellationToken.ThrowIfCancellationRequested();
@ -143,7 +143,7 @@ namespace Volo.Abp.Identity
/// <param name="role">The role whose name should be returned.</param> /// <param name="role">The role whose name should be returned.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> used to propagate notifications that the operation should be canceled.</param> /// <param name="cancellationToken">The <see cref="CancellationToken"/> used to propagate notifications that the operation should be canceled.</param>
/// <returns>A <see cref="Task{TResult}"/> that contains the name of the role.</returns> /// <returns>A <see cref="Task{TResult}"/> that contains the name of the role.</returns>
public Task<string> GetRoleNameAsync([NotNull] IdentityRole role, CancellationToken cancellationToken = default) public virtual Task<string> GetRoleNameAsync([NotNull] IdentityRole role, CancellationToken cancellationToken = default)
{ {
cancellationToken.ThrowIfCancellationRequested(); cancellationToken.ThrowIfCancellationRequested();
@ -159,7 +159,7 @@ namespace Volo.Abp.Identity
/// <param name="roleName">The name of the role.</param> /// <param name="roleName">The name of the role.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> used to propagate notifications that the operation should be canceled.</param> /// <param name="cancellationToken">The <see cref="CancellationToken"/> used to propagate notifications that the operation should be canceled.</param>
/// <returns>The <see cref="Task"/> that represents the asynchronous operation.</returns> /// <returns>The <see cref="Task"/> that represents the asynchronous operation.</returns>
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(); cancellationToken.ThrowIfCancellationRequested();
@ -179,7 +179,7 @@ namespace Volo.Abp.Identity
{ {
cancellationToken.ThrowIfCancellationRequested(); cancellationToken.ThrowIfCancellationRequested();
return _roleRepository.FindAsync(Guid.Parse(id), cancellationToken: cancellationToken); return RoleRepository.FindAsync(Guid.Parse(id), cancellationToken: cancellationToken);
} }
/// <summary> /// <summary>
@ -194,7 +194,7 @@ namespace Volo.Abp.Identity
Check.NotNull(normalizedName, nameof(normalizedName)); Check.NotNull(normalizedName, nameof(normalizedName));
return _roleRepository.FindByNormalizedNameAsync(normalizedName, cancellationToken: cancellationToken); return RoleRepository.FindByNormalizedNameAsync(normalizedName, cancellationToken: cancellationToken);
} }
/// <summary> /// <summary>
@ -233,7 +233,7 @@ namespace Volo.Abp.Identity
/// <summary> /// <summary>
/// Dispose the stores /// Dispose the stores
/// </summary> /// </summary>
public void Dispose() public virtual void Dispose()
{ {
} }
@ -243,13 +243,13 @@ namespace Volo.Abp.Identity
/// <param name="role">The role whose claims should be retrieved.</param> /// <param name="role">The role whose claims should be retrieved.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> used to propagate notifications that the operation should be canceled.</param> /// <param name="cancellationToken">The <see cref="CancellationToken"/> used to propagate notifications that the operation should be canceled.</param>
/// <returns>A <see cref="Task{TResult}"/> that contains the claims granted to a role.</returns> /// <returns>A <see cref="Task{TResult}"/> that contains the claims granted to a role.</returns>
public async Task<IList<Claim>> GetClaimsAsync([NotNull] IdentityRole role, CancellationToken cancellationToken = default) public virtual async Task<IList<Claim>> GetClaimsAsync([NotNull] IdentityRole role, CancellationToken cancellationToken = default)
{ {
cancellationToken.ThrowIfCancellationRequested(); cancellationToken.ThrowIfCancellationRequested();
Check.NotNull(role, nameof(role)); 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(); return role.Claims.Select(c => c.ToClaim()).ToList();
} }
@ -261,16 +261,16 @@ namespace Volo.Abp.Identity
/// <param name="claim">The claim to add to the role.</param> /// <param name="claim">The claim to add to the role.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> used to propagate notifications that the operation should be canceled.</param> /// <param name="cancellationToken">The <see cref="CancellationToken"/> used to propagate notifications that the operation should be canceled.</param>
/// <returns>The <see cref="Task"/> that represents the asynchronous operation.</returns> /// <returns>The <see cref="Task"/> that represents the asynchronous operation.</returns>
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(); cancellationToken.ThrowIfCancellationRequested();
Check.NotNull(role, nameof(role)); Check.NotNull(role, nameof(role));
Check.NotNull(claim, nameof(claim)); 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);
} }
/// <summary> /// <summary>
@ -280,12 +280,12 @@ namespace Volo.Abp.Identity
/// <param name="claim">The claim to remove from the role.</param> /// <param name="claim">The claim to remove from the role.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> used to propagate notifications that the operation should be canceled.</param> /// <param name="cancellationToken">The <see cref="CancellationToken"/> used to propagate notifications that the operation should be canceled.</param>
/// <returns>The <see cref="Task"/> that represents the asynchronous operation.</returns> /// <returns>The <see cref="Task"/> that represents the asynchronous operation.</returns>
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(role, nameof(role));
Check.NotNull(claim, nameof(claim)); Check.NotNull(claim, nameof(claim));
await _roleRepository.EnsureCollectionLoadedAsync(role, r => r.Claims, cancellationToken); await RoleRepository.EnsureCollectionLoadedAsync(role, r => r.Claims, cancellationToken);
role.RemoveClaim(claim); role.RemoveClaim(claim);
} }

2
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); return new UserLoginInfo(LoginProvider, ProviderKey, ProviderDisplayName);
} }

6
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 IIdentityRoleRepository RoleRepository { get; }
protected IIdentityUserRepository UserRepository { 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( public IdentityUserManager(
IdentityUserStore store, IdentityUserStore store,
@ -49,7 +49,7 @@ namespace Volo.Abp.Identity
{ {
RoleRepository = roleRepository; RoleRepository = roleRepository;
UserRepository = userRepository; UserRepository = userRepository;
_cancellationTokenProvider = cancellationTokenProvider; CancellationTokenProvider = cancellationTokenProvider;
} }
public virtual async Task<IdentityUser> GetByIdAsync(Guid id) public virtual async Task<IdentityUser> GetByIdAsync(Guid id)

32
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 public class IdentityUserRepositoryExternalUserLookupServiceProvider : IExternalUserLookupServiceProvider, ITransientDependency
{ {
private readonly IIdentityUserRepository _userRepository; protected IIdentityUserRepository UserRepository { get; }
private readonly ILookupNormalizer _lookupNormalizer; protected ILookupNormalizer LookupNormalizer { get; }
public IdentityUserRepositoryExternalUserLookupServiceProvider( public IdentityUserRepositoryExternalUserLookupServiceProvider(
IIdentityUserRepository userRepository, IIdentityUserRepository userRepository,
ILookupNormalizer lookupNormalizer) ILookupNormalizer lookupNormalizer)
{ {
_userRepository = userRepository; UserRepository = userRepository;
_lookupNormalizer = lookupNormalizer; LookupNormalizer = lookupNormalizer;
} }
public virtual async Task<IUserData> FindByIdAsync( public virtual async Task<IUserData> FindByIdAsync(
@ -25,12 +25,12 @@ namespace Volo.Abp.Identity
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return ( return (
await _userRepository.FindAsync( await UserRepository.FindAsync(
id, id,
includeDetails: false, includeDetails: false,
cancellationToken: cancellationToken cancellationToken: cancellationToken
) )
)?.ToAbpUserData(); )?.ToAbpUserData();
} }
public virtual async Task<IUserData> FindByUserNameAsync( public virtual async Task<IUserData> FindByUserNameAsync(
@ -38,12 +38,12 @@ namespace Volo.Abp.Identity
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return ( return (
await _userRepository.FindByNormalizedUserNameAsync( await UserRepository.FindByNormalizedUserNameAsync(
_lookupNormalizer.NormalizeName(userName), LookupNormalizer.NormalizeName(userName),
includeDetails: false, includeDetails: false,
cancellationToken: cancellationToken cancellationToken: cancellationToken
) )
)?.ToAbpUserData(); )?.ToAbpUserData();
} }
} }
} }

84
modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserStore.cs

@ -50,10 +50,10 @@ namespace Volo.Abp.Identity
/// </value> /// </value>
public bool AutoSaveChanges { get; set; } = true; public bool AutoSaveChanges { get; set; } = true;
private readonly IIdentityRoleRepository _roleRepository; protected IIdentityRoleRepository RoleRepository { get; }
private readonly IGuidGenerator _guidGenerator; protected IGuidGenerator GuidGenerator { get; }
private readonly ILogger<IdentityRoleStore> _logger; protected ILogger<IdentityRoleStore> Logger { get; }
private readonly IIdentityUserRepository _userRepository; protected IIdentityUserRepository UserRepository { get; }
public IdentityUserStore( public IdentityUserStore(
IIdentityUserRepository userRepository, IIdentityUserRepository userRepository,
@ -62,10 +62,10 @@ namespace Volo.Abp.Identity
ILogger<IdentityRoleStore> logger, ILogger<IdentityRoleStore> logger,
IdentityErrorDescriber describer = null) IdentityErrorDescriber describer = null)
{ {
_userRepository = userRepository; UserRepository = userRepository;
_roleRepository = roleRepository; RoleRepository = roleRepository;
_guidGenerator = guidGenerator; GuidGenerator = guidGenerator;
_logger = logger; Logger = logger;
ErrorDescriber = describer ?? new IdentityErrorDescriber(); ErrorDescriber = describer ?? new IdentityErrorDescriber();
} }
@ -163,7 +163,7 @@ namespace Volo.Abp.Identity
Check.NotNull(user, nameof(user)); Check.NotNull(user, nameof(user));
await _userRepository.InsertAsync(user, AutoSaveChanges, cancellationToken); await UserRepository.InsertAsync(user, AutoSaveChanges, cancellationToken);
return IdentityResult.Success; return IdentityResult.Success;
} }
@ -182,11 +182,11 @@ namespace Volo.Abp.Identity
try try
{ {
await _userRepository.UpdateAsync(user, AutoSaveChanges, cancellationToken); await UserRepository.UpdateAsync(user, AutoSaveChanges, cancellationToken);
} }
catch (AbpDbConcurrencyException ex) catch (AbpDbConcurrencyException ex)
{ {
_logger.LogWarning(ex.ToString()); //Trigger some AbpHandledException event Logger.LogWarning(ex.ToString()); //Trigger some AbpHandledException event
return IdentityResult.Failed(ErrorDescriber.ConcurrencyFailure()); return IdentityResult.Failed(ErrorDescriber.ConcurrencyFailure());
} }
@ -207,11 +207,11 @@ namespace Volo.Abp.Identity
try try
{ {
await _userRepository.DeleteAsync(user, AutoSaveChanges, cancellationToken); await UserRepository.DeleteAsync(user, AutoSaveChanges, cancellationToken);
} }
catch (AbpDbConcurrencyException ex) catch (AbpDbConcurrencyException ex)
{ {
_logger.LogWarning(ex.ToString()); //Trigger some AbpHandledException event Logger.LogWarning(ex.ToString()); //Trigger some AbpHandledException event
return IdentityResult.Failed(ErrorDescriber.ConcurrencyFailure()); return IdentityResult.Failed(ErrorDescriber.ConcurrencyFailure());
} }
@ -230,7 +230,7 @@ namespace Volo.Abp.Identity
{ {
cancellationToken.ThrowIfCancellationRequested(); cancellationToken.ThrowIfCancellationRequested();
return _userRepository.FindAsync(Guid.Parse(userId), cancellationToken: cancellationToken); return UserRepository.FindAsync(Guid.Parse(userId), cancellationToken: cancellationToken);
} }
/// <summary> /// <summary>
@ -247,7 +247,7 @@ namespace Volo.Abp.Identity
Check.NotNull(normalizedUserName, nameof(normalizedUserName)); Check.NotNull(normalizedUserName, nameof(normalizedUserName));
return _userRepository.FindByNormalizedUserNameAsync(normalizedUserName, includeDetails: false, cancellationToken: cancellationToken); return UserRepository.FindByNormalizedUserNameAsync(normalizedUserName, includeDetails: false, cancellationToken: cancellationToken);
} }
/// <summary> /// <summary>
@ -313,14 +313,14 @@ namespace Volo.Abp.Identity
Check.NotNull(user, nameof(user)); Check.NotNull(user, nameof(user));
Check.NotNull(normalizedRoleName, nameof(normalizedRoleName)); Check.NotNull(normalizedRoleName, nameof(normalizedRoleName));
var role = await _roleRepository.FindByNormalizedNameAsync(normalizedRoleName, cancellationToken: cancellationToken); var role = await RoleRepository.FindByNormalizedNameAsync(normalizedRoleName, cancellationToken: cancellationToken);
if (role == null) if (role == null)
{ {
throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, "Role {0} does not exist!", normalizedRoleName)); 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); user.AddRole(role.Id);
} }
@ -343,13 +343,13 @@ namespace Volo.Abp.Identity
throw new ArgumentException(nameof(normalizedRoleName) + " can not be null or whitespace"); 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) if (role == null)
{ {
return; return;
} }
await _userRepository.EnsureCollectionLoadedAsync(user, u => u.Roles, cancellationToken); await UserRepository.EnsureCollectionLoadedAsync(user, u => u.Roles, cancellationToken);
user.RemoveRole(role.Id); user.RemoveRole(role.Id);
} }
@ -366,7 +366,7 @@ namespace Volo.Abp.Identity
Check.NotNull(user, nameof(user)); Check.NotNull(user, nameof(user));
return await _userRepository.GetRoleNamesAsync(user.Id, cancellationToken: cancellationToken); return await UserRepository.GetRoleNamesAsync(user.Id, cancellationToken: cancellationToken);
} }
/// <summary> /// <summary>
@ -388,13 +388,13 @@ namespace Volo.Abp.Identity
throw new ArgumentException(nameof(normalizedRoleName) + " can not be null or whitespace"); 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) if (role == null)
{ {
return false; return false;
} }
await _userRepository.EnsureCollectionLoadedAsync(user, u => u.Roles, cancellationToken); await UserRepository.EnsureCollectionLoadedAsync(user, u => u.Roles, cancellationToken);
return user.IsInRole(role.Id); return user.IsInRole(role.Id);
} }
@ -411,7 +411,7 @@ namespace Volo.Abp.Identity
Check.NotNull(user, nameof(user)); 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(); return user.Claims.Select(c => c.ToClaim()).ToList();
} }
@ -430,9 +430,9 @@ namespace Volo.Abp.Identity
Check.NotNull(user, nameof(user)); Check.NotNull(user, nameof(user));
Check.NotNull(claims, nameof(claims)); 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);
} }
/// <summary> /// <summary>
@ -451,7 +451,7 @@ namespace Volo.Abp.Identity
Check.NotNull(claim, nameof(claim)); Check.NotNull(claim, nameof(claim));
Check.NotNull(newClaim, nameof(newClaim)); 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); user.ReplaceClaim(claim, newClaim);
} }
@ -470,7 +470,7 @@ namespace Volo.Abp.Identity
Check.NotNull(user, nameof(user)); Check.NotNull(user, nameof(user));
Check.NotNull(claims, nameof(claims)); Check.NotNull(claims, nameof(claims));
await _userRepository.EnsureCollectionLoadedAsync(user, u => u.Claims, cancellationToken); await UserRepository.EnsureCollectionLoadedAsync(user, u => u.Claims, cancellationToken);
user.RemoveClaims(claims); user.RemoveClaims(claims);
} }
@ -489,7 +489,7 @@ namespace Volo.Abp.Identity
Check.NotNull(user, nameof(user)); Check.NotNull(user, nameof(user));
Check.NotNull(login, nameof(login)); Check.NotNull(login, nameof(login));
await _userRepository.EnsureCollectionLoadedAsync(user, u => u.Logins, cancellationToken); await UserRepository.EnsureCollectionLoadedAsync(user, u => u.Logins, cancellationToken);
user.AddLogin(login); user.AddLogin(login);
} }
@ -510,7 +510,7 @@ namespace Volo.Abp.Identity
Check.NotNull(loginProvider, nameof(loginProvider)); Check.NotNull(loginProvider, nameof(loginProvider));
Check.NotNull(providerKey, nameof(providerKey)); 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); user.RemoveLogin(loginProvider, providerKey);
} }
@ -529,7 +529,7 @@ namespace Volo.Abp.Identity
Check.NotNull(user, nameof(user)); 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(); return user.Logins.Select(l => l.ToUserLoginInfo()).ToList();
} }
@ -550,7 +550,7 @@ namespace Volo.Abp.Identity
Check.NotNull(loginProvider, nameof(loginProvider)); Check.NotNull(loginProvider, nameof(loginProvider));
Check.NotNull(providerKey, nameof(providerKey)); Check.NotNull(providerKey, nameof(providerKey));
return _userRepository.FindByLoginAsync(loginProvider, providerKey, cancellationToken: cancellationToken); return UserRepository.FindByLoginAsync(loginProvider, providerKey, cancellationToken: cancellationToken);
} }
/// <summary> /// <summary>
@ -671,7 +671,7 @@ namespace Volo.Abp.Identity
{ {
cancellationToken.ThrowIfCancellationRequested(); cancellationToken.ThrowIfCancellationRequested();
return _userRepository.FindByNormalizedEmailAsync(normalizedEmail, includeDetails: false, cancellationToken: cancellationToken); return UserRepository.FindByNormalizedEmailAsync(normalizedEmail, includeDetails: false, cancellationToken: cancellationToken);
} }
/// <summary> /// <summary>
@ -950,7 +950,7 @@ namespace Volo.Abp.Identity
Check.NotNull(claim, nameof(claim)); Check.NotNull(claim, nameof(claim));
return await _userRepository.GetListByClaimAsync(claim, cancellationToken: cancellationToken); return await UserRepository.GetListByClaimAsync(claim, cancellationToken: cancellationToken);
} }
/// <summary> /// <summary>
@ -970,7 +970,7 @@ namespace Volo.Abp.Identity
throw new ArgumentNullException(nameof(normalizedRoleName)); throw new ArgumentNullException(nameof(normalizedRoleName));
} }
return await _userRepository.GetListByNormalizedRoleNameAsync(normalizedRoleName, cancellationToken: cancellationToken); return await UserRepository.GetListByNormalizedRoleNameAsync(normalizedRoleName, cancellationToken: cancellationToken);
} }
/// <summary> /// <summary>
@ -988,7 +988,7 @@ namespace Volo.Abp.Identity
Check.NotNull(user, nameof(user)); 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); user.SetToken(loginProvider, name, value);
} }
@ -1001,13 +1001,13 @@ namespace Volo.Abp.Identity
/// <param name="name">The name of the token.</param> /// <param name="name">The name of the token.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> used to propagate notifications that the operation should be canceled.</param> /// <param name="cancellationToken">The <see cref="CancellationToken"/> used to propagate notifications that the operation should be canceled.</param>
/// <returns>The <see cref="Task"/> that represents the asynchronous operation.</returns> /// <returns>The <see cref="Task"/> that represents the asynchronous operation.</returns>
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(); cancellationToken.ThrowIfCancellationRequested();
Check.NotNull(user, nameof(user)); 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); user.RemoveToken(loginProvider, name);
} }
@ -1020,23 +1020,23 @@ namespace Volo.Abp.Identity
/// <param name="name">The name of the token.</param> /// <param name="name">The name of the token.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> used to propagate notifications that the operation should be canceled.</param> /// <param name="cancellationToken">The <see cref="CancellationToken"/> used to propagate notifications that the operation should be canceled.</param>
/// <returns>The <see cref="Task"/> that represents the asynchronous operation.</returns> /// <returns>The <see cref="Task"/> that represents the asynchronous operation.</returns>
public async Task<string> GetTokenAsync(IdentityUser user, string loginProvider, string name, CancellationToken cancellationToken = default) public virtual async Task<string> GetTokenAsync(IdentityUser user, string loginProvider, string name, CancellationToken cancellationToken = default)
{ {
cancellationToken.ThrowIfCancellationRequested(); cancellationToken.ThrowIfCancellationRequested();
Check.NotNull(user, nameof(user)); 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; 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); return SetTokenAsync(user, InternalLoginProvider, AuthenticatorKeyTokenName, key, cancellationToken);
} }
public Task<string> GetAuthenticatorKeyAsync(IdentityUser user, CancellationToken cancellationToken = default) public virtual Task<string> GetAuthenticatorKeyAsync(IdentityUser user, CancellationToken cancellationToken = default)
{ {
return GetTokenAsync(user, InternalLoginProvider, AuthenticatorKeyTokenName, cancellationToken); return GetTokenAsync(user, InternalLoginProvider, AuthenticatorKeyTokenName, cancellationToken);
} }
@ -1101,7 +1101,7 @@ namespace Volo.Abp.Identity
return false; return false;
} }
public void Dispose() public virtual void Dispose()
{ {
} }

6
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 public class UserRoleFinder : IUserRoleFinder, ITransientDependency
{ {
private readonly IIdentityUserRepository _identityUserRepository; protected IIdentityUserRepository IdentityUserRepository { get; }
public UserRoleFinder(IIdentityUserRepository identityUserRepository) public UserRoleFinder(IIdentityUserRepository identityUserRepository)
{ {
_identityUserRepository = identityUserRepository; IdentityUserRepository = identityUserRepository;
} }
public virtual async Task<string[]> GetRolesAsync(Guid userId) public virtual async Task<string[]> GetRolesAsync(Guid userId)
{ {
return (await _identityUserRepository.GetRoleNamesAsync(userId)).ToArray(); return (await IdentityUserRepository.GetRoleNamesAsync(userId)).ToArray();
} }
} }
} }

4
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<bool> AnyAsync(string name, Guid? ignoredId = null) public virtual async Task<bool> AnyAsync(string name, Guid? ignoredId = null)
{ {
return await DbSet return await DbSet
.WhereIf(ignoredId != null, ct => ct.Id != ignoredId) .WhereIf(ignoredId != null, ct => ct.Id != ignoredId)
.CountAsync(ct => ct.Name == name) > 0; .CountAsync(ct => ct.Name == name) > 0;
} }
public async Task<List<IdentityClaimType>> GetListAsync(string sorting, int maxResultCount, int skipCount, string filter) public virtual async Task<List<IdentityClaimType>> GetListAsync(string sorting, int maxResultCount, int skipCount, string filter)
{ {
var identityClaimTypes = await DbSet var identityClaimTypes = await DbSet
.WhereIf( .WhereIf(

12
modules/identity/src/Volo.Abp.Identity.HttpApi.Client/Volo/Abp/Identity/HttpClientIdentityUserLookupService.cs

@ -9,21 +9,21 @@ namespace Volo.Abp.Identity
[Dependency(TryRegister = true)] [Dependency(TryRegister = true)]
public class HttpClientExternalUserLookupServiceProvider : IExternalUserLookupServiceProvider, ITransientDependency public class HttpClientExternalUserLookupServiceProvider : IExternalUserLookupServiceProvider, ITransientDependency
{ {
private readonly IIdentityUserLookupAppService _userLookupAppService; protected IIdentityUserLookupAppService UserLookupAppService { get; }
public HttpClientExternalUserLookupServiceProvider(IIdentityUserLookupAppService userLookupAppService) public HttpClientExternalUserLookupServiceProvider(IIdentityUserLookupAppService userLookupAppService)
{ {
_userLookupAppService = userLookupAppService; UserLookupAppService = userLookupAppService;
} }
public async Task<IUserData> FindByIdAsync(Guid id, CancellationToken cancellationToken = default) public virtual async Task<IUserData> FindByIdAsync(Guid id, CancellationToken cancellationToken = default)
{ {
return await _userLookupAppService.FindByIdAsync(id); return await UserLookupAppService.FindByIdAsync(id);
} }
public async Task<IUserData> FindByUserNameAsync(string userName, CancellationToken cancellationToken = default) public virtual async Task<IUserData> FindByUserNameAsync(string userName, CancellationToken cancellationToken = default)
{ {
return await _userLookupAppService.FindByUserNameAsync(userName); return await UserLookupAppService.FindByUserNameAsync(userName);
} }
} }
} }

4
modules/identity/src/Volo.Abp.Identity.HttpApi.Client/Volo/Abp/Identity/HttpClientUserRoleFinder.cs

@ -8,14 +8,14 @@ namespace Volo.Abp.Identity
[Dependency(TryRegister = true)] [Dependency(TryRegister = true)]
public class HttpClientUserRoleFinder : IUserRoleFinder, ITransientDependency public class HttpClientUserRoleFinder : IUserRoleFinder, ITransientDependency
{ {
private readonly IIdentityUserAppService _userAppService; protected IIdentityUserAppService _userAppService { get; }
public HttpClientUserRoleFinder(IIdentityUserAppService userAppService) public HttpClientUserRoleFinder(IIdentityUserAppService userAppService)
{ {
_userAppService = userAppService; _userAppService = userAppService;
} }
public async Task<string[]> GetRolesAsync(Guid userId) public virtual async Task<string[]> GetRolesAsync(Guid userId)
{ {
var output = await _userAppService.GetRolesAsync(userId); var output = await _userAppService.GetRolesAsync(userId);
return output.Items.Select(r => r.Name).ToArray(); return output.Items.Select(r => r.Name).ToArray();

16
modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/IdentityRoleController.cs

@ -13,51 +13,51 @@ namespace Volo.Abp.Identity
[Route("api/identity/roles")] [Route("api/identity/roles")]
public class IdentityRoleController : AbpController, IIdentityRoleAppService public class IdentityRoleController : AbpController, IIdentityRoleAppService
{ {
private readonly IIdentityRoleAppService _roleAppService; protected IIdentityRoleAppService RoleAppService { get; }
public IdentityRoleController(IIdentityRoleAppService roleAppService) public IdentityRoleController(IIdentityRoleAppService roleAppService)
{ {
_roleAppService = roleAppService; RoleAppService = roleAppService;
} }
[HttpGet] [HttpGet]
[Route("all")] [Route("all")]
public virtual Task<ListResultDto<IdentityRoleDto>> GetAllListAsync() public virtual Task<ListResultDto<IdentityRoleDto>> GetAllListAsync()
{ {
return _roleAppService.GetAllListAsync(); return RoleAppService.GetAllListAsync();
} }
[HttpGet] [HttpGet]
public virtual Task<PagedResultDto<IdentityRoleDto>> GetListAsync(PagedAndSortedResultRequestDto input) public virtual Task<PagedResultDto<IdentityRoleDto>> GetListAsync(PagedAndSortedResultRequestDto input)
{ {
return _roleAppService.GetListAsync(input); return RoleAppService.GetListAsync(input);
} }
[HttpGet] [HttpGet]
[Route("{id}")] [Route("{id}")]
public virtual Task<IdentityRoleDto> GetAsync(Guid id) public virtual Task<IdentityRoleDto> GetAsync(Guid id)
{ {
return _roleAppService.GetAsync(id); return RoleAppService.GetAsync(id);
} }
[HttpPost] [HttpPost]
public virtual Task<IdentityRoleDto> CreateAsync(IdentityRoleCreateDto input) public virtual Task<IdentityRoleDto> CreateAsync(IdentityRoleCreateDto input)
{ {
return _roleAppService.CreateAsync(input); return RoleAppService.CreateAsync(input);
} }
[HttpPut] [HttpPut]
[Route("{id}")] [Route("{id}")]
public virtual Task<IdentityRoleDto> UpdateAsync(Guid id, IdentityRoleUpdateDto input) public virtual Task<IdentityRoleDto> UpdateAsync(Guid id, IdentityRoleUpdateDto input)
{ {
return _roleAppService.UpdateAsync(id, input); return RoleAppService.UpdateAsync(id, input);
} }
[HttpDelete] [HttpDelete]
[Route("{id}")] [Route("{id}")]
public virtual Task DeleteAsync(Guid id) public virtual Task DeleteAsync(Guid id)
{ {
return _roleAppService.DeleteAsync(id); return RoleAppService.DeleteAsync(id);
} }
} }
} }

22
modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/IdentityUserController.cs

@ -12,72 +12,72 @@ namespace Volo.Abp.Identity
[Route("api/identity/users")] [Route("api/identity/users")]
public class IdentityUserController : AbpController, IIdentityUserAppService public class IdentityUserController : AbpController, IIdentityUserAppService
{ {
private readonly IIdentityUserAppService _userAppService; protected IIdentityUserAppService UserAppService { get; }
public IdentityUserController(IIdentityUserAppService userAppService) public IdentityUserController(IIdentityUserAppService userAppService)
{ {
_userAppService = userAppService; UserAppService = userAppService;
} }
[HttpGet] [HttpGet]
[Route("{id}")] [Route("{id}")]
public virtual Task<IdentityUserDto> GetAsync(Guid id) public virtual Task<IdentityUserDto> GetAsync(Guid id)
{ {
return _userAppService.GetAsync(id); return UserAppService.GetAsync(id);
} }
[HttpGet] [HttpGet]
public virtual Task<PagedResultDto<IdentityUserDto>> GetListAsync(GetIdentityUsersInput input) public virtual Task<PagedResultDto<IdentityUserDto>> GetListAsync(GetIdentityUsersInput input)
{ {
return _userAppService.GetListAsync(input); return UserAppService.GetListAsync(input);
} }
[HttpPost] [HttpPost]
public virtual Task<IdentityUserDto> CreateAsync(IdentityUserCreateDto input) public virtual Task<IdentityUserDto> CreateAsync(IdentityUserCreateDto input)
{ {
return _userAppService.CreateAsync(input); return UserAppService.CreateAsync(input);
} }
[HttpPut] [HttpPut]
[Route("{id}")] [Route("{id}")]
public virtual Task<IdentityUserDto> UpdateAsync(Guid id, IdentityUserUpdateDto input) public virtual Task<IdentityUserDto> UpdateAsync(Guid id, IdentityUserUpdateDto input)
{ {
return _userAppService.UpdateAsync(id, input); return UserAppService.UpdateAsync(id, input);
} }
[HttpDelete] [HttpDelete]
[Route("{id}")] [Route("{id}")]
public virtual Task DeleteAsync(Guid id) public virtual Task DeleteAsync(Guid id)
{ {
return _userAppService.DeleteAsync(id); return UserAppService.DeleteAsync(id);
} }
[HttpGet] [HttpGet]
[Route("{id}/roles")] [Route("{id}/roles")]
public virtual Task<ListResultDto<IdentityRoleDto>> GetRolesAsync(Guid id) public virtual Task<ListResultDto<IdentityRoleDto>> GetRolesAsync(Guid id)
{ {
return _userAppService.GetRolesAsync(id); return UserAppService.GetRolesAsync(id);
} }
[HttpPut] [HttpPut]
[Route("{id}/roles")] [Route("{id}/roles")]
public virtual Task UpdateRolesAsync(Guid id, IdentityUserUpdateRolesDto input) public virtual Task UpdateRolesAsync(Guid id, IdentityUserUpdateRolesDto input)
{ {
return _userAppService.UpdateRolesAsync(id, input); return UserAppService.UpdateRolesAsync(id, input);
} }
[HttpGet] [HttpGet]
[Route("by-username/{userName}")] [Route("by-username/{userName}")]
public virtual Task<IdentityUserDto> FindByUsernameAsync(string username) public virtual Task<IdentityUserDto> FindByUsernameAsync(string username)
{ {
return _userAppService.FindByUsernameAsync(username); return UserAppService.FindByUsernameAsync(username);
} }
[HttpGet] [HttpGet]
[Route("by-email/{email}")] [Route("by-email/{email}")]
public virtual Task<IdentityUserDto> FindByEmailAsync(string email) public virtual Task<IdentityUserDto> FindByEmailAsync(string email)
{ {
return _userAppService.FindByEmailAsync(email); return UserAppService.FindByEmailAsync(email);
} }
} }
} }

4
modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/IdentityUserLookupController.cs

@ -21,14 +21,14 @@ namespace Volo.Abp.Identity
[HttpGet] [HttpGet]
[Route("{id}")] [Route("{id}")]
public Task<UserData> FindByIdAsync(Guid id) public virtual Task<UserData> FindByIdAsync(Guid id)
{ {
return LookupAppService.FindByIdAsync(id); return LookupAppService.FindByIdAsync(id);
} }
[HttpGet] [HttpGet]
[Route("by-username/{userName}")] [Route("by-username/{userName}")]
public Task<UserData> FindByUserNameAsync(string userName) public virtual Task<UserData> FindByUserNameAsync(string userName)
{ {
return LookupAppService.FindByUserNameAsync(userName); return LookupAppService.FindByUserNameAsync(userName);
} }

16
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")] [Route("/api/identity/my-profile")]
public class ProfileController : AbpController, IProfileAppService public class ProfileController : AbpController, IProfileAppService
{ {
private readonly IProfileAppService _profileAppService; protected IProfileAppService ProfileAppService { get; }
public ProfileController(IProfileAppService profileAppService) public ProfileController(IProfileAppService profileAppService)
{ {
_profileAppService = profileAppService; ProfileAppService = profileAppService;
} }
[HttpGet] [HttpGet]
public Task<ProfileDto> GetAsync() public virtual Task<ProfileDto> GetAsync()
{ {
return _profileAppService.GetAsync(); return ProfileAppService.GetAsync();
} }
[HttpPut] [HttpPut]
public Task<ProfileDto> UpdateAsync(UpdateProfileDto input) public virtual Task<ProfileDto> UpdateAsync(UpdateProfileDto input)
{ {
return _profileAppService.UpdateAsync(input); return ProfileAppService.UpdateAsync(input);
} }
[HttpPost] [HttpPost]
[Route("change-password")] [Route("change-password")]
public Task ChangePasswordAsync(ChangePasswordInput input) public virtual Task ChangePasswordAsync(ChangePasswordInput input)
{ {
return _profileAppService.ChangePasswordAsync(input); return ProfileAppService.ChangePasswordAsync(input);
} }
} }
} }

4
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<bool> AnyAsync(string name, Guid? ignoredId = null) public virtual async Task<bool> AnyAsync(string name, Guid? ignoredId = null)
{ {
if (ignoredId == null) if (ignoredId == null)
{ {
@ -32,7 +32,7 @@ namespace Volo.Abp.Identity.MongoDB
} }
} }
public async Task<List<IdentityClaimType>> GetListAsync(string sorting, int maxResultCount, int skipCount, string filter) public virtual async Task<List<IdentityClaimType>> GetListAsync(string sorting, int maxResultCount, int skipCount, string filter)
{ {
return await GetMongoQueryable() return await GetMongoQueryable()
.WhereIf<IdentityClaimType, IMongoQueryable<IdentityClaimType>>( .WhereIf<IdentityClaimType, IMongoQueryable<IdentityClaimType>>(

5
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<IAbpIdentityMongoDbContext, IdentityRole, Guid>, IIdentityRoleRepository public class MongoIdentityRoleRepository : MongoDbRepository<IAbpIdentityMongoDbContext, IdentityRole, Guid>, IIdentityRoleRepository
{ {
private readonly IGuidGenerator _guidGenerator; public MongoIdentityRoleRepository(IMongoDbContextProvider<IAbpIdentityMongoDbContext> dbContextProvider)
public MongoIdentityRoleRepository(IMongoDbContextProvider<IAbpIdentityMongoDbContext> dbContextProvider, IGuidGenerator guidGenerator)
: base(dbContextProvider) : base(dbContextProvider)
{ {
_guidGenerator = guidGenerator;
} }
public async Task<IdentityRole> FindByNormalizedNameAsync( public async Task<IdentityRole> FindByNormalizedNameAsync(

23
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<IAbpIdentityMongoDbContext, IdentityUser, Guid>, IIdentityUserRepository public class MongoIdentityUserRepository : MongoDbRepository<IAbpIdentityMongoDbContext, IdentityUser, Guid>, IIdentityUserRepository
{ {
private readonly IGuidGenerator _guidGenerator; public MongoIdentityUserRepository(IMongoDbContextProvider<IAbpIdentityMongoDbContext> dbContextProvider)
public MongoIdentityUserRepository(IMongoDbContextProvider<IAbpIdentityMongoDbContext> dbContextProvider, IGuidGenerator guidGenerator)
: base(dbContextProvider) : base(dbContextProvider)
{ {
_guidGenerator = guidGenerator;
} }
public async Task<IdentityUser> FindByNormalizedUserNameAsync( public virtual async Task<IdentityUser> FindByNormalizedUserNameAsync(
string normalizedUserName, string normalizedUserName,
bool includeDetails = true, bool includeDetails = true,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
@ -35,7 +32,7 @@ namespace Volo.Abp.Identity.MongoDB
); );
} }
public async Task<List<string>> GetRoleNamesAsync( public virtual async Task<List<string>> GetRoleNamesAsync(
Guid id, Guid id,
CancellationToken cancellationToken = default) 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)); return await DbContext.Roles.AsQueryable().Where(r => roleIds.Contains(r.Id)).Select(r => r.Name).ToListAsync(GetCancellationToken(cancellationToken));
} }
public async Task<IdentityUser> FindByLoginAsync( public virtual async Task<IdentityUser> FindByLoginAsync(
string loginProvider, string loginProvider,
string providerKey, string providerKey,
bool includeDetails = true, bool includeDetails = true,
@ -55,7 +52,7 @@ namespace Volo.Abp.Identity.MongoDB
.FirstOrDefaultAsync(GetCancellationToken(cancellationToken)); .FirstOrDefaultAsync(GetCancellationToken(cancellationToken));
} }
public async Task<IdentityUser> FindByNormalizedEmailAsync( public virtual async Task<IdentityUser> FindByNormalizedEmailAsync(
string normalizedEmail, string normalizedEmail,
bool includeDetails = true, bool includeDetails = true,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
@ -63,7 +60,7 @@ namespace Volo.Abp.Identity.MongoDB
return await GetMongoQueryable().FirstOrDefaultAsync(u => u.NormalizedEmail == normalizedEmail, GetCancellationToken(cancellationToken)); return await GetMongoQueryable().FirstOrDefaultAsync(u => u.NormalizedEmail == normalizedEmail, GetCancellationToken(cancellationToken));
} }
public async Task<List<IdentityUser>> GetListByClaimAsync( public virtual async Task<List<IdentityUser>> GetListByClaimAsync(
Claim claim, Claim claim,
bool includeDetails = false, bool includeDetails = false,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
@ -73,7 +70,7 @@ namespace Volo.Abp.Identity.MongoDB
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }
public async Task<List<IdentityUser>> GetListByNormalizedRoleNameAsync( public virtual async Task<List<IdentityUser>> GetListByNormalizedRoleNameAsync(
string normalizedRoleName, string normalizedRoleName,
bool includeDetails = false, bool includeDetails = false,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
@ -90,7 +87,7 @@ namespace Volo.Abp.Identity.MongoDB
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }
public async Task<List<IdentityUser>> GetListAsync( public virtual async Task<List<IdentityUser>> GetListAsync(
string sorting = null, string sorting = null,
int maxResultCount = int.MaxValue, int maxResultCount = int.MaxValue,
int skipCount = 0, int skipCount = 0,
@ -111,7 +108,7 @@ namespace Volo.Abp.Identity.MongoDB
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }
public async Task<List<IdentityRole>> GetRolesAsync( public virtual async Task<List<IdentityRole>> GetRolesAsync(
Guid id, Guid id,
bool includeDetails = false, bool includeDetails = false,
CancellationToken cancellationToken = default) 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)); return await DbContext.Roles.AsQueryable().Where(r => roleIds.Contains(r.Id)).ToListAsync(GetCancellationToken(cancellationToken));
} }
public async Task<long> GetCountAsync( public virtual async Task<long> GetCountAsync(
string filter = null, string filter = null,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {

2
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 class AbpIdentityWebMainMenuContributor : IMenuContributor
{ {
public async Task ConfigureMenuAsync(MenuConfigurationContext context) public virtual async Task ConfigureMenuAsync(MenuConfigurationContext context)
{ {
if (context.Menu.Name != StandardMenus.Main) if (context.Menu.Name != StandardMenus.Main)
{ {

6
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; public override string Name => RolePermissionValueProvider.ProviderName;
private readonly IUserRoleFinder _userRoleFinder; protected IUserRoleFinder UserRoleFinder { get; }
public RolePermissionManagementProvider( public RolePermissionManagementProvider(
IPermissionGrantRepository permissionGrantRepository, IPermissionGrantRepository permissionGrantRepository,
@ -23,7 +23,7 @@ namespace Volo.Abp.PermissionManagement.Identity
guidGenerator, guidGenerator,
currentTenant) currentTenant)
{ {
_userRoleFinder = userRoleFinder; UserRoleFinder = userRoleFinder;
} }
public override async Task<PermissionValueProviderGrantInfo> CheckAsync(string name, string providerName, string providerKey) public override async Task<PermissionValueProviderGrantInfo> CheckAsync(string name, string providerName, string providerKey)
@ -39,7 +39,7 @@ namespace Volo.Abp.PermissionManagement.Identity
if (providerName == UserPermissionValueProvider.ProviderName) if (providerName == UserPermissionValueProvider.ProviderName)
{ {
var userId = Guid.Parse(providerKey); var userId = Guid.Parse(providerKey);
var roleNames = await _userRoleFinder.GetRolesAsync(userId); var roleNames = await UserRoleFinder.GetRolesAsync(userId);
foreach (var roleName in roleNames) foreach (var roleName in roleNames)
{ {

2
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; PermissionGrantRepository = permissionGrantRepository;
} }
public async Task HandleEventAsync(IdentityRoleNameChangedEvent eventData) public virtual async Task HandleEventAsync(IdentityRoleNameChangedEvent eventData)
{ {
var role = await RoleRepository.FindAsync(eventData.IdentityRole.Id, false); var role = await RoleRepository.FindAsync(eventData.IdentityRole.Id, false);
if (role == null) if (role == null)

Loading…
Cancel
Save