using System.Linq;
using System.Threading.Tasks;
using Dpz.Core.EnumLibrary;
using Hangfire.Dashboard;
using Microsoft.AspNetCore.Authentication;
namespace Dpz.Core.Web.Library;
public class HangfireFilter: IDashboardAuthorizationFilter
{
public bool Authorize(DashboardContext context)
{
var authenticateResult = Task.Run(() => context.GetHttpContext().AuthenticateAsync(Program.AuthorizeCookieName)).Result;
if (authenticateResult is { Succeeded: true, Principal.Identity.IsAuthenticated: true })
{
var userInfo = authenticateResult.Principal.GetIdentity();
var permissible = (userInfo.Permissions?.ToString() ?? "").Split(",").Select(x => x.Trim()).ToList();
return permissible.Contains(Permissions.System.ToString());
}
return false;
}
}