private async Task <bool> IsGrantedAsync(IInvocationAuthorizationContext authorizationContext) { if (authorizationContext.Permissions.IsNullOrEmpty()) { return(true); } if (authorizationContext.RequireAllPermissions) { return(await authorizationContext.Permissions.AllAsync(p => _permissionChecker.CheckAsync(p))); } else { return(await authorizationContext.Permissions.AnyAsync(p => _permissionChecker.CheckAsync(p))); } }
/// <summary> /// /// </summary> /// <param name="context"></param> /// <param name="requirement"></param> /// <returns></returns> protected override async Task HandleRequirementAsync( AuthorizationHandlerContext context, PermissionRequirement requirement) { try { if (await _permissionChecker.CheckAsync(context.User, requirement.PermissionName)) { context.Succeed(requirement); } } catch (PermissionNotFondException) { context.Fail(); } }
public void CheckAsync() { _permissionChecker.CheckAsync("Permission_Test_1").Result.ShouldBeTrue(); _permissionChecker.CheckAsync("Permission_Test_2").Result.ShouldBeFalse(); Should.Throw <PermissionNotFondException>(() => _permissionChecker.CheckAsync("Permission_Test_3")); }
public static async Task <bool> IsGrantedAsync(this IPermissionChecker permissionChecker, string name) { return((await permissionChecker.CheckAsync(name)).IsGranted); }
public static async Task <bool> IsGrantedAsync(this IPermissionChecker permissionChecker, ClaimsPrincipal principal, string name) { return((await permissionChecker.CheckAsync(principal, name)).IsGranted); }