|
|
|
@ -1,20 +1,24 @@ |
|
|
|
using System.Threading.Tasks; |
|
|
|
using Volo.Abp.DependencyInjection; |
|
|
|
using Volo.Abp.Guids; |
|
|
|
using Volo.Abp.Identity; |
|
|
|
|
|
|
|
namespace Volo.Abp.IdentityServer.IdentityResources |
|
|
|
{ |
|
|
|
public class IdentityResourceDataSeeder : IIdentityResourceDataSeeder, ITransientDependency |
|
|
|
{ |
|
|
|
protected IIdentityClaimTypeRepository ClaimTypeRepository { get; } |
|
|
|
protected IIdentityResourceRepository IdentityResourceRepository { get; } |
|
|
|
protected IGuidGenerator GuidGenerator { get; } |
|
|
|
|
|
|
|
public IdentityResourceDataSeeder( |
|
|
|
IIdentityResourceRepository identityResourceRepository, |
|
|
|
IGuidGenerator guidGenerator) |
|
|
|
IGuidGenerator guidGenerator, |
|
|
|
IIdentityClaimTypeRepository claimTypeRepository) |
|
|
|
{ |
|
|
|
IdentityResourceRepository = identityResourceRepository; |
|
|
|
GuidGenerator = guidGenerator; |
|
|
|
ClaimTypeRepository = claimTypeRepository; |
|
|
|
} |
|
|
|
|
|
|
|
public virtual async Task CreateStandardResourcesAsync() |
|
|
|
@ -30,11 +34,16 @@ namespace Volo.Abp.IdentityServer.IdentityResources |
|
|
|
|
|
|
|
foreach (var resource in resources) |
|
|
|
{ |
|
|
|
await AddIfNotExistsAsync(resource); |
|
|
|
foreach (var claimType in resource.UserClaims) |
|
|
|
{ |
|
|
|
await AddClaimTypeIfNotExistsAsync(claimType); |
|
|
|
} |
|
|
|
|
|
|
|
await AddIdentityResourceIfNotExistsAsync(resource); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
protected virtual async Task AddIfNotExistsAsync(IdentityServer4.Models.IdentityResource resource) |
|
|
|
|
|
|
|
protected virtual async Task AddIdentityResourceIfNotExistsAsync(IdentityServer4.Models.IdentityResource resource) |
|
|
|
{ |
|
|
|
if (await IdentityResourceRepository.FindByNameAsync(resource.Name) != null) |
|
|
|
{ |
|
|
|
@ -48,5 +57,21 @@ namespace Volo.Abp.IdentityServer.IdentityResources |
|
|
|
) |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
protected virtual async Task AddClaimTypeIfNotExistsAsync(string claimType) |
|
|
|
{ |
|
|
|
if (await ClaimTypeRepository.AnyAsync(claimType)) |
|
|
|
{ |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
await ClaimTypeRepository.InsertAsync( |
|
|
|
new IdentityClaimType( |
|
|
|
GuidGenerator.Create(), |
|
|
|
claimType, |
|
|
|
isStatic: true |
|
|
|
) |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|