mirror of https://github.com/abpframework/abp.git
11 changed files with 82 additions and 76 deletions
@ -1,14 +0,0 @@ |
|||
using Volo.Abp.Collections; |
|||
|
|||
namespace Volo.Abp.Security.Claims |
|||
{ |
|||
public class AbpClaimOptions |
|||
{ |
|||
public ITypeList<IClaimsIdentityContributor> ClaimsIdentityContributors { get; set; } |
|||
|
|||
public AbpClaimOptions() |
|||
{ |
|||
ClaimsIdentityContributors = new TypeList<IClaimsIdentityContributor>(); |
|||
} |
|||
} |
|||
} |
|||
@ -1,36 +0,0 @@ |
|||
using System.Security.Claims; |
|||
using System.Threading.Tasks; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Microsoft.Extensions.Options; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace Volo.Abp.Security.Claims |
|||
{ |
|||
public class AbpClaimsIdentityService : IAbpClaimsIdentityService, ITransientDependency |
|||
{ |
|||
protected AbpClaimOptions Options { get; } |
|||
protected IServiceScopeFactory ServiceScopeFactory { get; } |
|||
|
|||
public AbpClaimsIdentityService( |
|||
IServiceScopeFactory serviceScopeFactory, |
|||
IOptions<AbpClaimOptions> abpClaimOptions) |
|||
{ |
|||
ServiceScopeFactory = serviceScopeFactory; |
|||
Options = abpClaimOptions.Value; |
|||
} |
|||
|
|||
public async Task AddClaimsAsync(ClaimsIdentity identity) |
|||
{ |
|||
using (var scope = ServiceScopeFactory.CreateScope()) |
|||
{ |
|||
var context = new ClaimsIdentityContext(identity, scope.ServiceProvider); |
|||
|
|||
foreach (var contributorType in Options.ClaimsIdentityContributors) |
|||
{ |
|||
var contributor = (IClaimsIdentityContributor) scope.ServiceProvider.GetRequiredService(contributorType); |
|||
await contributor.AddClaimsAsync(context); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,40 @@ |
|||
using System.Security.Claims; |
|||
using System.Threading.Tasks; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Microsoft.Extensions.Options; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace Volo.Abp.Security.Claims |
|||
{ |
|||
public class AbpClaimsPrincipalFactory : IAbpClaimsPrincipalFactory, ITransientDependency |
|||
{ |
|||
protected IServiceScopeFactory ServiceScopeFactory { get; } |
|||
protected AbpClaimsPrincipalFactoryOptions Options { get; } |
|||
|
|||
public AbpClaimsPrincipalFactory( |
|||
IServiceScopeFactory serviceScopeFactory, |
|||
IOptions<AbpClaimsPrincipalFactoryOptions> abpClaimOptions) |
|||
{ |
|||
ServiceScopeFactory = serviceScopeFactory; |
|||
Options = abpClaimOptions.Value; |
|||
} |
|||
|
|||
public virtual async Task<ClaimsPrincipal> CreateAsync() |
|||
{ |
|||
using (var scope = ServiceScopeFactory.CreateScope()) |
|||
{ |
|||
var claimsPrincipal = new ClaimsPrincipal(new ClaimsIdentity()); |
|||
|
|||
var context = new AbpClaimsPrincipalContributorContext(claimsPrincipal, scope.ServiceProvider); |
|||
|
|||
foreach (var contributorType in Options.Contributors) |
|||
{ |
|||
var contributor = (IAbpClaimsPrincipalContributor) scope.ServiceProvider.GetRequiredService(contributorType); |
|||
await contributor.ContributeAsync(context); |
|||
} |
|||
|
|||
return claimsPrincipal; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,14 @@ |
|||
using Volo.Abp.Collections; |
|||
|
|||
namespace Volo.Abp.Security.Claims |
|||
{ |
|||
public class AbpClaimsPrincipalFactoryOptions |
|||
{ |
|||
public ITypeList<IAbpClaimsPrincipalContributor> Contributors { get; } |
|||
|
|||
public AbpClaimsPrincipalFactoryOptions() |
|||
{ |
|||
Contributors = new TypeList<IAbpClaimsPrincipalContributor>(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,9 @@ |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace Volo.Abp.Security.Claims |
|||
{ |
|||
public interface IAbpClaimsPrincipalContributor |
|||
{ |
|||
Task ContributeAsync(AbpClaimsPrincipalContributorContext context); |
|||
} |
|||
} |
|||
@ -1,9 +0,0 @@ |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace Volo.Abp.Security.Claims |
|||
{ |
|||
public interface IClaimsIdentityContributor |
|||
{ |
|||
Task AddClaimsAsync(ClaimsIdentityContext context); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue