You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
abp/modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/CmsKitAdminAppServiceBase.cs

39 lines
1.2 KiB

using JetBrains.Annotations;
using Microsoft.AspNetCore.Authorization;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices.ComTypes;
using System.Threading.Tasks;
using Volo.Abp;
using Volo.Abp.Authorization;
namespace Volo.CmsKit.Admin;
public abstract class CmsKitAdminAppServiceBase : CmsKitAppServiceBase
{
protected CmsKitAdminAppServiceBase()
{
ObjectMapperContext = typeof(CmsKitAdminApplicationModule);
}
/// <summary>
/// Checks given policies until finding granted policy. If none of them is granted, throws <see cref="AbpAuthorizationException"/>
/// </summary>
/// <param name="policies">Policies to be checked.</param>
/// <exception cref="AbpAuthorizationException">Thrown when none of policies is granted.</exception>
protected async Task CheckAnyOfPoliciesAsync([NotNull] IEnumerable<string> policies)
{
Check.NotNull(policies, nameof(policies));
foreach (var policy in policies)
{
if (await AuthorizationService.IsGrantedAsync(policy))
{
return;
}
}
throw new AbpAuthorizationException();
}
}