如何配置一个用户具有只读权限,而另一个用户具有对仪表板的完全访问权限?
答案 0 :(得分: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);
}