|
|
|
|
@ -0,0 +1,43 @@
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using Microsoft.Extensions.Options;
|
|
|
|
|
using Volo.Abp.DependencyInjection;
|
|
|
|
|
using Volo.Abp.Security.Claims;
|
|
|
|
|
|
|
|
|
|
namespace Volo.Abp.Authorization
|
|
|
|
|
{
|
|
|
|
|
[Dependency(ReplaceServices = true)]
|
|
|
|
|
public class AbpAuthorizationService : DefaultAuthorizationService, IAbpAuthorizationService, ITransientDependency
|
|
|
|
|
{
|
|
|
|
|
private readonly ICurrentPrincipalAccessor _currentPrincipalAccessor;
|
|
|
|
|
|
|
|
|
|
public AbpAuthorizationService(
|
|
|
|
|
IAuthorizationPolicyProvider policyProvider,
|
|
|
|
|
IAuthorizationHandlerProvider handlers,
|
|
|
|
|
ILogger<DefaultAuthorizationService> logger,
|
|
|
|
|
IAuthorizationHandlerContextFactory contextFactory,
|
|
|
|
|
IAuthorizationEvaluator evaluator,
|
|
|
|
|
IOptions<AuthorizationOptions> options,
|
|
|
|
|
ICurrentPrincipalAccessor currentPrincipalAccessor)
|
|
|
|
|
: base(
|
|
|
|
|
policyProvider,
|
|
|
|
|
handlers,
|
|
|
|
|
logger,
|
|
|
|
|
contextFactory,
|
|
|
|
|
evaluator,
|
|
|
|
|
options)
|
|
|
|
|
{
|
|
|
|
|
_currentPrincipalAccessor = currentPrincipalAccessor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task CheckAsync(string policyName)
|
|
|
|
|
{
|
|
|
|
|
var result = await AuthorizeAsync(_currentPrincipalAccessor.Principal, null, policyName);
|
|
|
|
|
if (!result.Succeeded)
|
|
|
|
|
{
|
|
|
|
|
throw new AbpAuthorizationException("Authorization failed! Given policy has not granted: " + policyName);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|