|
|
|
@ -50,10 +50,10 @@ namespace Volo.Abp.Identity |
|
|
|
/// </value>
|
|
|
|
public bool AutoSaveChanges { get; set; } = true; |
|
|
|
|
|
|
|
private readonly IIdentityRoleRepository _roleRepository; |
|
|
|
private readonly IGuidGenerator _guidGenerator; |
|
|
|
private readonly ILogger<IdentityRoleStore> _logger; |
|
|
|
private readonly IIdentityUserRepository _userRepository; |
|
|
|
protected IIdentityRoleRepository RoleRepository { get; } |
|
|
|
protected IGuidGenerator GuidGenerator { get; } |
|
|
|
protected ILogger<IdentityRoleStore> Logger { get; } |
|
|
|
protected IIdentityUserRepository UserRepository { get; } |
|
|
|
|
|
|
|
public IdentityUserStore( |
|
|
|
IIdentityUserRepository userRepository, |
|
|
|
@ -62,10 +62,10 @@ namespace Volo.Abp.Identity |
|
|
|
ILogger<IdentityRoleStore> 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); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -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); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -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); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -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); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -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); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -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); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -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); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -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); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -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 |
|
|
|
/// <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>
|
|
|
|
/// <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(); |
|
|
|
|
|
|
|
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 |
|
|
|
/// <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>
|
|
|
|
/// <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(); |
|
|
|
|
|
|
|
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<string> GetAuthenticatorKeyAsync(IdentityUser user, CancellationToken cancellationToken = default) |
|
|
|
public virtual Task<string> 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() |
|
|
|
{ |
|
|
|
|
|
|
|
} |
|
|
|
|