Configure hangfire dashboard to use umbraco authorization

This commit is contained in:
2016-12-13 14:41:30 -05:00
parent 0086743882
commit 0d9bd7260c
3 changed files with 36 additions and 3 deletions
+34 -2
View File
@@ -1,9 +1,13 @@
using System.Web.Hosting;
using System.Linq;
using System.Web;
using System.Web.Hosting;
using Hangfire;
using Hangfire.Dashboard;
using LeafWeb.WebCms.App_Start;
using LeafWeb.WebCms.Services.PiscalQueue;
using Microsoft.Owin;
using Owin;
using Umbraco.Core.Security;
using Umbraco.Web;
using ConfigurationManager = System.Configuration.ConfigurationManager;
@@ -27,7 +31,15 @@ namespace LeafWeb.WebCms.App_Start
public void Configuration(IAppBuilder app)
{
app.UseHangfireDashboard();
app.UseHangfireDashboard("/hangfire",
new DashboardOptions
{
Authorization = new IDashboardAuthorizationFilter[]
{
//new LocalRequestsOnlyAuthorizationFilter(),
new UmbracoAuthorizationFilter()
}
});
SetupRecurringJobs();
}
@@ -45,6 +57,26 @@ namespace LeafWeb.WebCms.App_Start
}
}
public class UmbracoAuthorizationFilter : IDashboardAuthorizationFilter
{
public bool Authorize(DashboardContext context)
{
// Ensure umbraco user if possible.
var http = new HttpContextWrapper(HttpContext.Current);
var ticket = http.GetUmbracoAuthTicket();
http.AuthenticateCurrentRequest(ticket, true);
var user = UmbracoContext.Current.Security.CurrentUser;
if (user != null && user.AllowedSections.Contains("developer"))
{
return true;
}
return false;
}
}
// http://docs.hangfire.io/en/latest/deployment-to-production/making-aspnet-app-always-running.html
public class ApplicationPreload : IProcessHostPreloadClient
{