private static async Task <bool> SessionHasAllRolesAsync(IRequest req, IAuthSession session, IAuthRepositoryAsync authRepo, ICollection <string> requiredRoles) { if (await session.HasRoleAsync(RoleNames.Admin, authRepo).ConfigAwait()) { return(true); } if (await requiredRoles.AllAsync(x => session.HasRoleAsync(x, authRepo)).ConfigAwait()) { return(true); } await session.UpdateFromUserAuthRepoAsync(req, authRepo).ConfigAwait(); if (await requiredRoles.AllAsync(x => session.HasRoleAsync(x, authRepo)).ConfigAwait()) { await req.SaveSessionAsync(session).ConfigAwait(); return(true); } return(false); }
private static async Task <bool> SessionHasAllPermissionsAsync(IRequest req, IAuthSession session, IAuthRepositoryAsync authRepo, ICollection <string> requiredPermissions, CancellationToken token = default) { if (await session.HasRoleAsync(RoleNames.Admin, authRepo, token).ConfigAwait()) { return(true); } if (await requiredPermissions.AllAsync(x => session.HasPermissionAsync(x, authRepo, token)).ConfigAwait()) { return(true); } await session.UpdateFromUserAuthRepoAsync(req, authRepo).ConfigAwait(); if (await requiredPermissions.AllAsync(x => session.HasPermissionAsync(x, authRepo, token)).ConfigAwait()) { await req.SaveSessionAsync(session, token : token).ConfigAwait(); return(true); } return(false); }
public virtual async Task <bool> HasAnyRolesAsync(IAuthSession session, IAuthRepositoryAsync authRepo) { return(session != null && await this.RequiredRoles .AnyAsync(requiredRole => session.HasRoleAsync(requiredRole, authRepo)).ConfigAwait()); }