mirror of https://github.com/abpframework/abp.git
committed by
GitHub
11 changed files with 153 additions and 20 deletions
@ -0,0 +1,23 @@ |
|||||
|
using System; |
||||
|
using System.Security.Claims; |
||||
|
using JetBrains.Annotations; |
||||
|
|
||||
|
namespace Volo.Abp.Security.Claims |
||||
|
{ |
||||
|
public class AbpClaimsPrincipalContributorContext |
||||
|
{ |
||||
|
[NotNull] |
||||
|
public ClaimsPrincipal ClaimsPrincipal { get; } |
||||
|
|
||||
|
[NotNull] |
||||
|
public IServiceProvider ServiceProvider { get; } |
||||
|
|
||||
|
public AbpClaimsPrincipalContributorContext( |
||||
|
[NotNull] ClaimsPrincipal claimsIdentity, |
||||
|
[NotNull] IServiceProvider serviceProvider) |
||||
|
{ |
||||
|
ClaimsPrincipal = claimsIdentity; |
||||
|
ServiceProvider = serviceProvider; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -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); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,10 @@ |
|||||
|
using System.Security.Claims; |
||||
|
using System.Threading.Tasks; |
||||
|
|
||||
|
namespace Volo.Abp.Security.Claims |
||||
|
{ |
||||
|
public interface IAbpClaimsPrincipalFactory |
||||
|
{ |
||||
|
Task<ClaimsPrincipal> CreateAsync(); |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue