我如何配置一个用户具有只读访问权限,而另一用户具有对Hangfire仪表板的完全访问权限?

问题描述 投票:0回答:1

如何配置一个用户具有只读访问权限,而另一用户具有对仪表板的完全访问权限?

hangfire
1个回答
0
投票

您可以使用DashboardOptions和AuthorizationFilter设置只读和编辑访问权限。 See Documentation from Hangfire

public class HangFireAuthorizationFilter : IDashboardAuthorizationFilter
{
    public bool Authorize([NotNull] DashboardContext context)
    {
        string user = HttpContext.Current.User.Identity.Name;
        var adminAuthz = InternalMethod.lookup_db_for_user_access(user, "View");

        return adminAuthz != null;
    }

    public bool IsUserAuthorizedToEditHangfireDashboard([NotNull] DashboardContext context)
    {
        string user = HttpContext.Current.User.Identity.Name;
        var adminAuthz = InternalMethod.lookup_db_for_user_access(user, "Edit");

        return adminAuthz != null;
    }
}

在Hangfire仪表板初始化中使用上述过滤器

public void Configuration(IAppBuilder app)
{
    var hangfireAuthz = new HangFireAuthorizationFilter();
    var dashboardOptions = new DashboardOptions
    {
        Authorization = new[] { hangfireAuthz },
        IsReadOnlyFunc = (DashboardContext context) => !hangfireAuthz.IsUserAuthorizedToEditHangfireDashboard(context)
    };

    app.UseHangfireDashboard("/hangfire", dashboardOptions);
}
© www.soinside.com 2019 - 2024. All rights reserved.