Browse Source

Merge pull request #3181 from abpframework/Cotur-Virtualization-IdentityServer

Make IdentityServer module services easily overridable by inheritance
pull/3205/head
Halil İbrahim Kalkan 6 years ago
committed by GitHub
parent
commit
026b072da0
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpCorsPolicyService.cs
  2. 4
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AllowedCorsOriginsCacheItemInvalidator.cs
  3. 8
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AspNetIdentity/AbpProfileService.cs
  4. 58
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AspNetIdentity/AbpResourceOwnerPasswordValidator.cs
  5. 12
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientStore.cs
  6. 2
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Devices/DeviceFlowCodes.cs
  7. 12
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Devices/DeviceFlowStore.cs
  8. 40
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Grants/PersistedGrantStore.cs
  9. 32
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ResourceStore.cs
  10. 2
      modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/ApiResources/ApiResourceRepository.cs
  11. 4
      modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/Clients/ClientRepository.cs
  12. 6
      modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/Devices/DeviceFlowCodesRepository.cs
  13. 10
      modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/Grants/PersistedGrantRepository.cs
  14. 4
      modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/IdentityResources/IdentityResourceRepository.cs
  15. 2
      modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoApiResourceRepository.cs
  16. 4
      modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoClientRepository.cs
  17. 6
      modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoDeviceFlowCodesRepository.cs
  18. 6
      modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoIdentityResourceRepository.cs
  19. 10
      modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoPersistedGrantRepository.cs

2
modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpCorsPolicyService.cs

@ -26,7 +26,7 @@ namespace Volo.Abp.IdentityServer
Logger = NullLogger<AbpCorsPolicyService>.Instance; Logger = NullLogger<AbpCorsPolicyService>.Instance;
} }
public async Task<bool> IsOriginAllowedAsync(string origin) public virtual async Task<bool> IsOriginAllowedAsync(string origin)
{ {
var cacheItem = await Cache.GetOrAddAsync(AllowedCorsOriginsCacheItem.AllOrigins, CreateCacheItemAsync); var cacheItem = await Cache.GetOrAddAsync(AllowedCorsOriginsCacheItem.AllOrigins, CreateCacheItemAsync);

4
modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AllowedCorsOriginsCacheItemInvalidator.cs

@ -19,12 +19,12 @@ namespace Volo.Abp.IdentityServer
Cache = cache; Cache = cache;
} }
public async Task HandleEventAsync(EntityChangedEventData<Client> eventData) public virtual async Task HandleEventAsync(EntityChangedEventData<Client> eventData)
{ {
await Cache.RemoveAsync(AllowedCorsOriginsCacheItem.AllOrigins); await Cache.RemoveAsync(AllowedCorsOriginsCacheItem.AllOrigins);
} }
public async Task HandleEventAsync(EntityChangedEventData<ClientCorsOrigin> eventData) public virtual async Task HandleEventAsync(EntityChangedEventData<ClientCorsOrigin> eventData)
{ {
await Cache.RemoveAsync(AllowedCorsOriginsCacheItem.AllOrigins); await Cache.RemoveAsync(AllowedCorsOriginsCacheItem.AllOrigins);
} }

8
modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AspNetIdentity/AbpProfileService.cs

@ -12,7 +12,7 @@ namespace Volo.Abp.IdentityServer.AspNetIdentity
{ {
public class AbpProfileService : ProfileService<IdentityUser> public class AbpProfileService : ProfileService<IdentityUser>
{ {
private readonly ICurrentTenant _currentTenant; protected ICurrentTenant CurrentTenant { get; }
public AbpProfileService( public AbpProfileService(
IdentityUserManager userManager, IdentityUserManager userManager,
@ -20,13 +20,13 @@ namespace Volo.Abp.IdentityServer.AspNetIdentity
ICurrentTenant currentTenant) ICurrentTenant currentTenant)
: base(userManager, claimsFactory) : base(userManager, claimsFactory)
{ {
_currentTenant = currentTenant; CurrentTenant = currentTenant;
} }
[UnitOfWork] [UnitOfWork]
public override async Task GetProfileDataAsync(ProfileDataRequestContext context) public override async Task GetProfileDataAsync(ProfileDataRequestContext context)
{ {
using (_currentTenant.Change(context.Subject.FindTenantId())) using (CurrentTenant.Change(context.Subject.FindTenantId()))
{ {
await base.GetProfileDataAsync(context); await base.GetProfileDataAsync(context);
} }
@ -35,7 +35,7 @@ namespace Volo.Abp.IdentityServer.AspNetIdentity
[UnitOfWork] [UnitOfWork]
public override async Task IsActiveAsync(IsActiveContext context) public override async Task IsActiveAsync(IsActiveContext context)
{ {
using (_currentTenant.Change(context.Subject.FindTenantId())) using (CurrentTenant.Change(context.Subject.FindTenantId()))
{ {
await base.IsActiveAsync(context); await base.IsActiveAsync(context);
} }

58
modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AspNetIdentity/AbpResourceOwnerPasswordValidator.cs

@ -20,11 +20,11 @@ namespace Volo.Abp.IdentityServer.AspNetIdentity
{ {
public class AbpResourceOwnerPasswordValidator : IResourceOwnerPasswordValidator public class AbpResourceOwnerPasswordValidator : IResourceOwnerPasswordValidator
{ {
private readonly SignInManager<IdentityUser> _signInManager; protected SignInManager<IdentityUser> SignInManager { get; }
private readonly IEventService _events; protected IEventService Events { get; }
private readonly UserManager<IdentityUser> _userManager; protected UserManager<IdentityUser> UserManager { get; }
private readonly ILogger<ResourceOwnerPasswordValidator<IdentityUser>> _logger; protected ILogger<ResourceOwnerPasswordValidator<IdentityUser>> Logger { get; }
private readonly IStringLocalizer<AbpIdentityServerResource> _localizer; protected IStringLocalizer<AbpIdentityServerResource> Localizer { get; }
public AbpResourceOwnerPasswordValidator( public AbpResourceOwnerPasswordValidator(
UserManager<IdentityUser> userManager, UserManager<IdentityUser> userManager,
@ -33,11 +33,11 @@ namespace Volo.Abp.IdentityServer.AspNetIdentity
ILogger<ResourceOwnerPasswordValidator<IdentityUser>> logger, ILogger<ResourceOwnerPasswordValidator<IdentityUser>> logger,
IStringLocalizer<AbpIdentityServerResource> localizer) IStringLocalizer<AbpIdentityServerResource> localizer)
{ {
_userManager = userManager; UserManager = userManager;
_signInManager = signInManager; SignInManager = signInManager;
_events = events; Events = events;
_logger = logger; Logger = logger;
_localizer = localizer; Localizer = localizer;
} }
/// <summary> /// <summary>
@ -49,17 +49,17 @@ namespace Volo.Abp.IdentityServer.AspNetIdentity
public virtual async Task ValidateAsync(ResourceOwnerPasswordValidationContext context) public virtual async Task ValidateAsync(ResourceOwnerPasswordValidationContext context)
{ {
await ReplaceEmailToUsernameOfInputIfNeeds(context); await ReplaceEmailToUsernameOfInputIfNeeds(context);
var user = await _userManager.FindByNameAsync(context.UserName); var user = await UserManager.FindByNameAsync(context.UserName);
string errorDescription; string errorDescription;
if (user != null) if (user != null)
{ {
var result = await _signInManager.CheckPasswordSignInAsync(user, context.Password, true); var result = await SignInManager.CheckPasswordSignInAsync(user, context.Password, true);
if (result.Succeeded) if (result.Succeeded)
{ {
var sub = await _userManager.GetUserIdAsync(user); var sub = await UserManager.GetUserIdAsync(user);
_logger.LogInformation("Credentials validated for username: {username}", context.UserName); Logger.LogInformation("Credentials validated for username: {username}", context.UserName);
await _events.RaiseAsync(new UserLoginSuccessEvent(context.UserName, sub, context.UserName, interactive: false)); await Events.RaiseAsync(new UserLoginSuccessEvent(context.UserName, sub, context.UserName, interactive: false));
var additionalClaims = new List<Claim>(); var additionalClaims = new List<Claim>();
@ -75,28 +75,28 @@ namespace Volo.Abp.IdentityServer.AspNetIdentity
} }
else if (result.IsLockedOut) else if (result.IsLockedOut)
{ {
_logger.LogInformation("Authentication failed for username: {username}, reason: locked out", context.UserName); Logger.LogInformation("Authentication failed for username: {username}, reason: locked out", context.UserName);
await _events.RaiseAsync(new UserLoginFailureEvent(context.UserName, "locked out", interactive: false)); await Events.RaiseAsync(new UserLoginFailureEvent(context.UserName, "locked out", interactive: false));
errorDescription = _localizer["UserLockedOut"]; errorDescription = Localizer["UserLockedOut"];
} }
else if (result.IsNotAllowed) else if (result.IsNotAllowed)
{ {
_logger.LogInformation("Authentication failed for username: {username}, reason: not allowed", context.UserName); Logger.LogInformation("Authentication failed for username: {username}, reason: not allowed", context.UserName);
await _events.RaiseAsync(new UserLoginFailureEvent(context.UserName, "not allowed", interactive: false)); await Events.RaiseAsync(new UserLoginFailureEvent(context.UserName, "not allowed", interactive: false));
errorDescription = _localizer["LoginIsNotAllowed"]; errorDescription = Localizer["LoginIsNotAllowed"];
} }
else else
{ {
_logger.LogInformation("Authentication failed for username: {username}, reason: invalid credentials", context.UserName); Logger.LogInformation("Authentication failed for username: {username}, reason: invalid credentials", context.UserName);
await _events.RaiseAsync(new UserLoginFailureEvent(context.UserName, "invalid credentials", interactive: false)); await Events.RaiseAsync(new UserLoginFailureEvent(context.UserName, "invalid credentials", interactive: false));
errorDescription = _localizer["InvalidUserNameOrPassword"]; errorDescription = Localizer["InvalidUserNameOrPassword"];
} }
} }
else else
{ {
_logger.LogInformation("No user found matching username: {username}", context.UserName); Logger.LogInformation("No user found matching username: {username}", context.UserName);
await _events.RaiseAsync(new UserLoginFailureEvent(context.UserName, "invalid username", interactive: false)); await Events.RaiseAsync(new UserLoginFailureEvent(context.UserName, "invalid username", interactive: false));
errorDescription = _localizer["InvalidUsername"]; errorDescription = Localizer["InvalidUsername"];
} }
context.Result = new GrantValidationResult(TokenRequestErrors.InvalidGrant, errorDescription); context.Result = new GrantValidationResult(TokenRequestErrors.InvalidGrant, errorDescription);
@ -109,13 +109,13 @@ namespace Volo.Abp.IdentityServer.AspNetIdentity
return; return;
} }
var userByUsername = await _userManager.FindByNameAsync(context.UserName); var userByUsername = await UserManager.FindByNameAsync(context.UserName);
if (userByUsername != null) if (userByUsername != null)
{ {
return; return;
} }
var userByEmail = await _userManager.FindByEmailAsync(context.UserName); var userByEmail = await UserManager.FindByEmailAsync(context.UserName);
if (userByEmail == null) if (userByEmail == null)
{ {
return; return;

12
modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientStore.cs

@ -6,19 +6,19 @@ namespace Volo.Abp.IdentityServer.Clients
{ {
public class ClientStore : IClientStore public class ClientStore : IClientStore
{ {
private readonly IClientRepository _clientRepository; protected IClientRepository ClientRepository { get; }
private readonly IObjectMapper<AbpIdentityServerDomainModule> _objectMapper; protected IObjectMapper<AbpIdentityServerDomainModule> ObjectMapper { get; }
public ClientStore(IClientRepository clientRepository, IObjectMapper<AbpIdentityServerDomainModule> objectMapper) public ClientStore(IClientRepository clientRepository, IObjectMapper<AbpIdentityServerDomainModule> objectMapper)
{ {
_clientRepository = clientRepository; ClientRepository = clientRepository;
_objectMapper = objectMapper; ObjectMapper = objectMapper;
} }
public virtual async Task<IdentityServer4.Models.Client> FindClientByIdAsync(string clientId) public virtual async Task<IdentityServer4.Models.Client> FindClientByIdAsync(string clientId)
{ {
var client = await _clientRepository.FindByCliendIdAsync(clientId); var client = await ClientRepository.FindByCliendIdAsync(clientId);
return _objectMapper.Map<Client, IdentityServer4.Models.Client>(client); return ObjectMapper.Map<Client, IdentityServer4.Models.Client>(client);
} }
} }
} }

2
modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Devices/DeviceFlowCodes.cs

@ -17,7 +17,7 @@ namespace Volo.Abp.IdentityServer.Devices
public virtual string Data { get; set; } public virtual string Data { get; set; }
private DeviceFlowCodes() protected DeviceFlowCodes()
{ {
} }

12
modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Devices/DeviceFlowStore.cs

@ -26,7 +26,7 @@ namespace Volo.Abp.IdentityServer.Devices
PersistentGrantSerializer = persistentGrantSerializer; PersistentGrantSerializer = persistentGrantSerializer;
} }
public async Task StoreDeviceAuthorizationAsync(string deviceCode, string userCode, DeviceCode data) public virtual async Task StoreDeviceAuthorizationAsync(string deviceCode, string userCode, DeviceCode data)
{ {
Check.NotNull(deviceCode, nameof(deviceCode)); Check.NotNull(deviceCode, nameof(deviceCode));
Check.NotNull(userCode, nameof(userCode)); Check.NotNull(userCode, nameof(userCode));
@ -47,7 +47,7 @@ namespace Volo.Abp.IdentityServer.Devices
); );
} }
public async Task<DeviceCode> FindByUserCodeAsync(string userCode) public virtual async Task<DeviceCode> FindByUserCodeAsync(string userCode)
{ {
Check.NotNull(userCode, nameof(userCode)); Check.NotNull(userCode, nameof(userCode));
@ -63,7 +63,7 @@ namespace Volo.Abp.IdentityServer.Devices
return DeserializeToDeviceCode(deviceCodes.Data); return DeserializeToDeviceCode(deviceCodes.Data);
} }
public async Task<DeviceCode> FindByDeviceCodeAsync(string deviceCode) public virtual async Task<DeviceCode> FindByDeviceCodeAsync(string deviceCode)
{ {
Check.NotNull(deviceCode, nameof(deviceCode)); Check.NotNull(deviceCode, nameof(deviceCode));
@ -79,7 +79,7 @@ namespace Volo.Abp.IdentityServer.Devices
return DeserializeToDeviceCode(deviceCodes.Data); return DeserializeToDeviceCode(deviceCodes.Data);
} }
public async Task UpdateByUserCodeAsync(string userCode, DeviceCode data) public virtual async Task UpdateByUserCodeAsync(string userCode, DeviceCode data)
{ {
Check.NotNull(userCode, nameof(userCode)); Check.NotNull(userCode, nameof(userCode));
Check.NotNull(data, nameof(data)); Check.NotNull(data, nameof(data));
@ -102,7 +102,7 @@ namespace Volo.Abp.IdentityServer.Devices
; ;
} }
public async Task RemoveByDeviceCodeAsync(string deviceCode) public virtual async Task RemoveByDeviceCodeAsync(string deviceCode)
{ {
Check.NotNull(deviceCode, nameof(deviceCode)); Check.NotNull(deviceCode, nameof(deviceCode));
@ -120,7 +120,7 @@ namespace Volo.Abp.IdentityServer.Devices
; ;
} }
private string Serialize([CanBeNull] DeviceCode deviceCode) protected virtual string Serialize([CanBeNull] DeviceCode deviceCode)
{ {
if (deviceCode == null) if (deviceCode == null)
{ {

40
modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Grants/PersistedGrantStore.cs

@ -10,65 +10,65 @@ namespace Volo.Abp.IdentityServer.Grants
{ {
public class PersistedGrantStore : IPersistedGrantStore public class PersistedGrantStore : IPersistedGrantStore
{ {
private readonly IPersistentGrantRepository _persistentGrantRepository; protected IPersistentGrantRepository PersistentGrantRepository { get; }
private readonly IObjectMapper<AbpIdentityServerDomainModule> _objectMapper; protected IObjectMapper<AbpIdentityServerDomainModule> ObjectMapper { get; }
private readonly IGuidGenerator _guidGenerator; protected IGuidGenerator GuidGenerator { get; }
public PersistedGrantStore(IPersistentGrantRepository persistentGrantRepository, public PersistedGrantStore(IPersistentGrantRepository persistentGrantRepository,
IObjectMapper<AbpIdentityServerDomainModule> objectMapper, IGuidGenerator guidGenerator) IObjectMapper<AbpIdentityServerDomainModule> objectMapper, IGuidGenerator guidGenerator)
{ {
_persistentGrantRepository = persistentGrantRepository; PersistentGrantRepository = persistentGrantRepository;
_objectMapper = objectMapper; ObjectMapper = objectMapper;
_guidGenerator = guidGenerator; GuidGenerator = guidGenerator;
} }
public virtual async Task StoreAsync(IdentityServer4.Models.PersistedGrant grant) public virtual async Task StoreAsync(IdentityServer4.Models.PersistedGrant grant)
{ {
var entity = await _persistentGrantRepository.FindByKeyAsync(grant.Key); var entity = await PersistentGrantRepository.FindByKeyAsync(grant.Key);
if (entity == null) if (entity == null)
{ {
entity = _objectMapper.Map<IdentityServer4.Models.PersistedGrant, PersistedGrant>(grant); entity = ObjectMapper.Map<IdentityServer4.Models.PersistedGrant, PersistedGrant>(grant);
EntityHelper.TrySetId(entity, () => _guidGenerator.Create()); EntityHelper.TrySetId(entity, () => GuidGenerator.Create());
await _persistentGrantRepository.InsertAsync(entity); await PersistentGrantRepository.InsertAsync(entity);
} }
else else
{ {
_objectMapper.Map(grant, entity); ObjectMapper.Map(grant, entity);
await _persistentGrantRepository.UpdateAsync(entity); await PersistentGrantRepository.UpdateAsync(entity);
} }
} }
public virtual async Task<IdentityServer4.Models.PersistedGrant> GetAsync(string key) public virtual async Task<IdentityServer4.Models.PersistedGrant> GetAsync(string key)
{ {
var persistedGrant = await _persistentGrantRepository.FindByKeyAsync(key); var persistedGrant = await PersistentGrantRepository.FindByKeyAsync(key);
return _objectMapper.Map<PersistedGrant, IdentityServer4.Models.PersistedGrant>(persistedGrant); return ObjectMapper.Map<PersistedGrant, IdentityServer4.Models.PersistedGrant>(persistedGrant);
} }
public virtual async Task<IEnumerable<IdentityServer4.Models.PersistedGrant>> GetAllAsync(string subjectId) public virtual async Task<IEnumerable<IdentityServer4.Models.PersistedGrant>> GetAllAsync(string subjectId)
{ {
var persistedGrants = await _persistentGrantRepository.GetListBySubjectIdAsync(subjectId); var persistedGrants = await PersistentGrantRepository.GetListBySubjectIdAsync(subjectId);
return persistedGrants.Select(x => _objectMapper.Map<PersistedGrant, IdentityServer4.Models.PersistedGrant>(x)); return persistedGrants.Select(x => ObjectMapper.Map<PersistedGrant, IdentityServer4.Models.PersistedGrant>(x));
} }
public virtual async Task RemoveAsync(string key) public virtual async Task RemoveAsync(string key)
{ {
var persistedGrant = await _persistentGrantRepository.FindByKeyAsync(key); var persistedGrant = await PersistentGrantRepository.FindByKeyAsync(key);
if (persistedGrant == null) if (persistedGrant == null)
{ {
return; return;
} }
await _persistentGrantRepository.DeleteAsync(persistedGrant); await PersistentGrantRepository.DeleteAsync(persistedGrant);
} }
public virtual async Task RemoveAllAsync(string subjectId, string clientId) public virtual async Task RemoveAllAsync(string subjectId, string clientId)
{ {
await _persistentGrantRepository.DeleteAsync(subjectId, clientId); await PersistentGrantRepository.DeleteAsync(subjectId, clientId);
} }
public virtual async Task RemoveAllAsync(string subjectId, string clientId, string type) public virtual async Task RemoveAllAsync(string subjectId, string clientId, string type)
{ {
await _persistentGrantRepository.DeleteAsync(subjectId, clientId, type); await PersistentGrantRepository.DeleteAsync(subjectId, clientId, type);
} }
} }
} }

32
modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ResourceStore.cs

@ -13,46 +13,46 @@ namespace Volo.Abp.IdentityServer
{ {
public class ResourceStore : IResourceStore public class ResourceStore : IResourceStore
{ {
private readonly IIdentityResourceRepository _identityResourceRepository; protected IIdentityResourceRepository IdentityResourceRepository { get; }
private readonly IApiResourceRepository _apiResourceRepository; protected IApiResourceRepository ApiResourceRepository { get; }
private readonly IObjectMapper<AbpIdentityServerDomainModule> _objectMapper; protected IObjectMapper<AbpIdentityServerDomainModule> ObjectMapper { get; }
public ResourceStore( public ResourceStore(
IIdentityResourceRepository identityResourceRepository, IIdentityResourceRepository identityResourceRepository,
IObjectMapper<AbpIdentityServerDomainModule> objectMapper, IObjectMapper<AbpIdentityServerDomainModule> objectMapper,
IApiResourceRepository apiResourceRepository) IApiResourceRepository apiResourceRepository)
{ {
_identityResourceRepository = identityResourceRepository; IdentityResourceRepository = identityResourceRepository;
_objectMapper = objectMapper; ObjectMapper = objectMapper;
_apiResourceRepository = apiResourceRepository; ApiResourceRepository = apiResourceRepository;
} }
public virtual async Task<IEnumerable<IdentityServer4.Models.IdentityResource>> FindIdentityResourcesByScopeAsync(IEnumerable<string> scopeNames) public virtual async Task<IEnumerable<IdentityServer4.Models.IdentityResource>> FindIdentityResourcesByScopeAsync(IEnumerable<string> scopeNames)
{ {
var resource = await _identityResourceRepository.GetListByScopesAsync(scopeNames.ToArray(), includeDetails: true); var resource = await IdentityResourceRepository.GetListByScopesAsync(scopeNames.ToArray(), includeDetails: true);
return _objectMapper.Map<List<IdentityResource>, List<IdentityServer4.Models.IdentityResource>>(resource); return ObjectMapper.Map<List<IdentityResource>, List<IdentityServer4.Models.IdentityResource>>(resource);
} }
public virtual async Task<IEnumerable<ApiResource>> FindApiResourcesByScopeAsync(IEnumerable<string> scopeNames) public virtual async Task<IEnumerable<ApiResource>> FindApiResourcesByScopeAsync(IEnumerable<string> scopeNames)
{ {
var resources = await _apiResourceRepository.GetListByScopesAsync(scopeNames.ToArray(), includeDetails: true); var resources = await ApiResourceRepository.GetListByScopesAsync(scopeNames.ToArray(), includeDetails: true);
return resources.Select(x => _objectMapper.Map<ApiResources.ApiResource, ApiResource>(x)); return resources.Select(x => ObjectMapper.Map<ApiResources.ApiResource, ApiResource>(x));
} }
public virtual async Task<ApiResource> FindApiResourceAsync(string name) public virtual async Task<ApiResource> FindApiResourceAsync(string name)
{ {
var resource = await _apiResourceRepository.FindByNameAsync(name); var resource = await ApiResourceRepository.FindByNameAsync(name);
return _objectMapper.Map<ApiResources.ApiResource, ApiResource>(resource); return ObjectMapper.Map<ApiResources.ApiResource, ApiResource>(resource);
} }
public virtual async Task<Resources> GetAllResourcesAsync() public virtual async Task<Resources> GetAllResourcesAsync()
{ {
var identityResources = await _identityResourceRepository.GetListAsync(includeDetails: true); var identityResources = await IdentityResourceRepository.GetListAsync(includeDetails: true);
var apiResources = await _apiResourceRepository.GetListAsync(includeDetails: true); var apiResources = await ApiResourceRepository.GetListAsync(includeDetails: true);
return new Resources( return new Resources(
_objectMapper.Map<List<IdentityResource>, IdentityServer4.Models.IdentityResource[]>(identityResources), ObjectMapper.Map<List<IdentityResource>, IdentityServer4.Models.IdentityResource[]>(identityResources),
_objectMapper.Map<List<ApiResources.ApiResource>, ApiResource[]>(apiResources) ObjectMapper.Map<List<ApiResources.ApiResource>, ApiResource[]>(apiResources)
); );
} }
} }

2
modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/ApiResources/ApiResourceRepository.cs

@ -61,7 +61,7 @@ namespace Volo.Abp.IdentityServer.ApiResources
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }
public async Task<bool> CheckNameExistAsync(string name, Guid? expectedId = null, CancellationToken cancellationToken = default) public virtual async Task<bool> CheckNameExistAsync(string name, Guid? expectedId = null, CancellationToken cancellationToken = default)
{ {
return await DbSet.AnyAsync(ar => ar.Id != expectedId && ar.Name == name, cancellationToken: cancellationToken); return await DbSet.AnyAsync(ar => ar.Id != expectedId && ar.Name == name, cancellationToken: cancellationToken);
} }

4
modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/Clients/ClientRepository.cs

@ -37,7 +37,7 @@ namespace Volo.Abp.IdentityServer.Clients
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }
public async Task<List<string>> GetAllDistinctAllowedCorsOriginsAsync(CancellationToken cancellationToken = default) public virtual async Task<List<string>> GetAllDistinctAllowedCorsOriginsAsync(CancellationToken cancellationToken = default)
{ {
return await DbContext.ClientCorsOrigins return await DbContext.ClientCorsOrigins
.Select(x => x.Origin) .Select(x => x.Origin)
@ -45,7 +45,7 @@ namespace Volo.Abp.IdentityServer.Clients
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }
public async Task<bool> CheckClientIdExistAsync(string clientId, Guid? expectedId = null, CancellationToken cancellationToken = default) public virtual async Task<bool> CheckClientIdExistAsync(string clientId, Guid? expectedId = null, CancellationToken cancellationToken = default)
{ {
return await DbSet.AnyAsync(c => c.Id != expectedId && c.ClientId == clientId, cancellationToken: cancellationToken); return await DbSet.AnyAsync(c => c.Id != expectedId && c.ClientId == clientId, cancellationToken: cancellationToken);
} }

6
modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/Devices/DeviceFlowCodesRepository.cs

@ -19,7 +19,7 @@ namespace Volo.Abp.IdentityServer.Devices
} }
public async Task<DeviceFlowCodes> FindByUserCodeAsync( public virtual async Task<DeviceFlowCodes> FindByUserCodeAsync(
string userCode, string userCode,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
@ -28,7 +28,7 @@ namespace Volo.Abp.IdentityServer.Devices
; ;
} }
public async Task<DeviceFlowCodes> FindByDeviceCodeAsync( public virtual async Task<DeviceFlowCodes> FindByDeviceCodeAsync(
string deviceCode, string deviceCode,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
@ -36,7 +36,7 @@ namespace Volo.Abp.IdentityServer.Devices
.FirstOrDefaultAsync(d => d.DeviceCode == deviceCode, GetCancellationToken(cancellationToken)); .FirstOrDefaultAsync(d => d.DeviceCode == deviceCode, GetCancellationToken(cancellationToken));
} }
public async Task<List<DeviceFlowCodes>> GetListByExpirationAsync(DateTime maxExpirationDate, int maxResultCount, public virtual async Task<List<DeviceFlowCodes>> GetListByExpirationAsync(DateTime maxExpirationDate, int maxResultCount,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return await DbSet return await DbSet

10
modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/Grants/PersistedGrantRepository.cs

@ -18,7 +18,7 @@ namespace Volo.Abp.IdentityServer.Grants
} }
public async Task<PersistedGrant> FindByKeyAsync( public virtual async Task<PersistedGrant> FindByKeyAsync(
string key, string key,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
@ -27,7 +27,7 @@ namespace Volo.Abp.IdentityServer.Grants
; ;
} }
public async Task<List<PersistedGrant>> GetListBySubjectIdAsync( public virtual async Task<List<PersistedGrant>> GetListBySubjectIdAsync(
string subjectId, string subjectId,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
@ -36,7 +36,7 @@ namespace Volo.Abp.IdentityServer.Grants
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }
public async Task<List<PersistedGrant>> GetListByExpirationAsync( public virtual async Task<List<PersistedGrant>> GetListByExpirationAsync(
DateTime maxExpirationDate, DateTime maxExpirationDate,
int maxResultCount, int maxResultCount,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
@ -48,7 +48,7 @@ namespace Volo.Abp.IdentityServer.Grants
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }
public async Task DeleteAsync( public virtual async Task DeleteAsync(
string subjectId, string subjectId,
string clientId, string clientId,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
@ -59,7 +59,7 @@ namespace Volo.Abp.IdentityServer.Grants
); );
} }
public async Task DeleteAsync( public virtual async Task DeleteAsync(
string subjectId, string subjectId,
string clientId, string clientId,
string type, string type,

4
modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/IdentityResources/IdentityResourceRepository.cs

@ -46,7 +46,7 @@ namespace Volo.Abp.IdentityServer.IdentityResources
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }
public async Task<IdentityResource> FindByNameAsync( public virtual async Task<IdentityResource> FindByNameAsync(
string name, string name,
bool includeDetails = true, bool includeDetails = true,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
@ -57,7 +57,7 @@ namespace Volo.Abp.IdentityServer.IdentityResources
.FirstOrDefaultAsync(GetCancellationToken(cancellationToken)); .FirstOrDefaultAsync(GetCancellationToken(cancellationToken));
} }
public async Task<bool> CheckNameExistAsync(string name, Guid? expectedId = null, CancellationToken cancellationToken = default) public virtual async Task<bool> CheckNameExistAsync(string name, Guid? expectedId = null, CancellationToken cancellationToken = default)
{ {
return await DbSet.AnyAsync(ir => ir.Id != expectedId && ir.Name == name, cancellationToken: cancellationToken); return await DbSet.AnyAsync(ir => ir.Id != expectedId && ir.Name == name, cancellationToken: cancellationToken);
} }

2
modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoApiResourceRepository.cs

@ -48,7 +48,7 @@ namespace Volo.Abp.IdentityServer.MongoDB
return await GetCountAsync(); return await GetCountAsync();
} }
public async Task<bool> CheckNameExistAsync(string name, Guid? expectedId = null, CancellationToken cancellationToken = default) public virtual async Task<bool> CheckNameExistAsync(string name, Guid? expectedId = null, CancellationToken cancellationToken = default)
{ {
return await GetMongoQueryable().AnyAsync(ar => ar.Id != expectedId && ar.Name == name, cancellationToken: cancellationToken); return await GetMongoQueryable().AnyAsync(ar => ar.Id != expectedId && ar.Name == name, cancellationToken: cancellationToken);
} }

4
modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoClientRepository.cs

@ -43,7 +43,7 @@ namespace Volo.Abp.IdentityServer.MongoDB
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }
public async Task<List<string>> GetAllDistinctAllowedCorsOriginsAsync( public virtual async Task<List<string>> GetAllDistinctAllowedCorsOriginsAsync(
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return await GetMongoQueryable() return await GetMongoQueryable()
@ -53,7 +53,7 @@ namespace Volo.Abp.IdentityServer.MongoDB
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }
public async Task<bool> CheckClientIdExistAsync(string clientId, Guid? expectedId = null, CancellationToken cancellationToken = default) public virtual async Task<bool> CheckClientIdExistAsync(string clientId, Guid? expectedId = null, CancellationToken cancellationToken = default)
{ {
return await GetMongoQueryable().AnyAsync(c => c.Id != expectedId && c.ClientId == clientId, cancellationToken: cancellationToken); return await GetMongoQueryable().AnyAsync(c => c.Id != expectedId && c.ClientId == clientId, cancellationToken: cancellationToken);
} }

6
modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoDeviceFlowCodesRepository.cs

@ -19,7 +19,7 @@ namespace Volo.Abp.IdentityServer.MongoDB
} }
public async Task<DeviceFlowCodes> FindByUserCodeAsync( public virtual async Task<DeviceFlowCodes> FindByUserCodeAsync(
string userCode, string userCode,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
@ -28,13 +28,13 @@ namespace Volo.Abp.IdentityServer.MongoDB
; ;
} }
public async Task<DeviceFlowCodes> FindByDeviceCodeAsync(string deviceCode, CancellationToken cancellationToken = default) public virtual async Task<DeviceFlowCodes> FindByDeviceCodeAsync(string deviceCode, CancellationToken cancellationToken = default)
{ {
return await GetMongoQueryable() return await GetMongoQueryable()
.FirstOrDefaultAsync(d => d.DeviceCode == deviceCode, GetCancellationToken(cancellationToken)); .FirstOrDefaultAsync(d => d.DeviceCode == deviceCode, GetCancellationToken(cancellationToken));
} }
public async Task<List<DeviceFlowCodes>> GetListByExpirationAsync( public virtual async Task<List<DeviceFlowCodes>> GetListByExpirationAsync(
DateTime maxExpirationDate, DateTime maxExpirationDate,
int maxResultCount, int maxResultCount,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)

6
modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoIdentityResourceRepository.cs

@ -27,7 +27,7 @@ namespace Volo.Abp.IdentityServer.MongoDB
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }
public async Task<IdentityResource> FindByNameAsync( public virtual async Task<IdentityResource> FindByNameAsync(
string name, string name,
bool includeDetails = true, bool includeDetails = true,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
@ -37,7 +37,7 @@ namespace Volo.Abp.IdentityServer.MongoDB
.FirstOrDefaultAsync(GetCancellationToken(cancellationToken)); .FirstOrDefaultAsync(GetCancellationToken(cancellationToken));
} }
public async Task<List<IdentityResource>> GetListByScopesAsync(string[] scopeNames, bool includeDetails = false, public virtual async Task<List<IdentityResource>> GetListByScopesAsync(string[] scopeNames, bool includeDetails = false,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return await GetMongoQueryable() return await GetMongoQueryable()
@ -50,7 +50,7 @@ namespace Volo.Abp.IdentityServer.MongoDB
return await GetCountAsync(); return await GetCountAsync();
} }
public async Task<bool> CheckNameExistAsync(string name, Guid? expectedId = null, CancellationToken cancellationToken = default) public virtual async Task<bool> CheckNameExistAsync(string name, Guid? expectedId = null, CancellationToken cancellationToken = default)
{ {
return await GetMongoQueryable().AnyAsync(ir => ir.Id != expectedId && ir.Name == name, cancellationToken: cancellationToken); return await GetMongoQueryable().AnyAsync(ir => ir.Id != expectedId && ir.Name == name, cancellationToken: cancellationToken);
} }

10
modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoPersistedGrantRepository.cs

@ -16,14 +16,14 @@ namespace Volo.Abp.IdentityServer.MongoDB
{ {
} }
public async Task<PersistedGrant> FindByKeyAsync(string key, CancellationToken cancellationToken = default) public virtual async Task<PersistedGrant> FindByKeyAsync(string key, CancellationToken cancellationToken = default)
{ {
return await GetMongoQueryable() return await GetMongoQueryable()
.FirstOrDefaultAsync(x => x.Key == key, GetCancellationToken(cancellationToken)); .FirstOrDefaultAsync(x => x.Key == key, GetCancellationToken(cancellationToken));
} }
public async Task<List<PersistedGrant>> GetListBySubjectIdAsync(string subjectId, CancellationToken cancellationToken = default) public virtual async Task<List<PersistedGrant>> GetListBySubjectIdAsync(string subjectId, CancellationToken cancellationToken = default)
{ {
return await GetMongoQueryable() return await GetMongoQueryable()
.Where(x => x.SubjectId == subjectId) .Where(x => x.SubjectId == subjectId)
@ -31,7 +31,7 @@ namespace Volo.Abp.IdentityServer.MongoDB
; ;
} }
public async Task<List<PersistedGrant>> GetListByExpirationAsync(DateTime maxExpirationDate, int maxResultCount, public virtual async Task<List<PersistedGrant>> GetListByExpirationAsync(DateTime maxExpirationDate, int maxResultCount,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return await GetMongoQueryable() return await GetMongoQueryable()
@ -41,7 +41,7 @@ namespace Volo.Abp.IdentityServer.MongoDB
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }
public async Task DeleteAsync(string subjectId, string clientId, CancellationToken cancellationToken = default) public virtual async Task DeleteAsync(string subjectId, string clientId, CancellationToken cancellationToken = default)
{ {
await DeleteAsync( await DeleteAsync(
x => x.SubjectId == subjectId && x.ClientId == clientId, x => x.SubjectId == subjectId && x.ClientId == clientId,
@ -49,7 +49,7 @@ namespace Volo.Abp.IdentityServer.MongoDB
); );
} }
public async Task DeleteAsync(string subjectId, string clientId, string type, CancellationToken cancellationToken = default) public virtual async Task DeleteAsync(string subjectId, string clientId, string type, CancellationToken cancellationToken = default)
{ {
await DeleteAsync( await DeleteAsync(
x => x.SubjectId == subjectId && x.ClientId == clientId && x.Type == type, x => x.SubjectId == subjectId && x.ClientId == clientId && x.Type == type,

Loading…
Cancel
Save