public bool Authorize(Hangfire.Dashboard.DashboardContext context)
        {
            var httpContext = context.GetHttpContext();

            return(httpContext.User.Identity.IsAuthenticated &&
                   httpContext.User.IsInRole("admin"));
        }
Beispiel #2
0
        public async Task Dispatch(DashboardContext context)
        {
            var requestedMetrics = await context.Request.GetFormValuesAsync("metrics[]");
            var page = new StubPage();
            page.Assign(context);

            var metrics = DashboardMetrics.GetMetrics().Where(x => requestedMetrics.Contains(x.Name));
            var result = new Dictionary<string, Metric>();

            foreach (var metric in metrics)
            {
                var value = metric.Func(page);
                result.Add(metric.Name, value);
            }

            var settings = new JsonSerializerSettings
            {
                ContractResolver = new CamelCasePropertyNamesContractResolver(),
                Converters = new JsonConverter[]{ new StringEnumConverter { CamelCaseText = true } }
            };
            var serialized = JsonConvert.SerializeObject(result, settings);

            context.Response.ContentType = "application/json";
            await context.Response.WriteAsync(serialized);
        }
        public Task Dispatch(DashboardContext context)
        {
            context.Response.ContentType = "text/html";

            var page = _pageFunc(context.UriMatch);
            page.Assign(context);

            return context.Response.WriteAsync(page.ToString());
        }
        public Task Dispatch(DashboardContext context)
        {
            context.Response.ContentType = _contentType;
            context.Response.SetExpire(DateTimeOffset.Now.AddYears(1));

            WriteResponse(context.Response);

            return Task.FromResult(true);
        }
 /// <summary>
 /// Authorizes access to the hangfire dashboard.
 /// </summary>
 public bool Authorize(DashboardContext context)
 {
     using (var lifetimeScope = _container.BeginLifetimeScope())
     {
         return lifetimeScope
             .Resolve<IUserProvider>()
             .GetCurrentIdentityStateAsync()
             .Result == IdentityState.SuperUser;
     }
 }
        public bool Authorize(DashboardContext context)
        {
            if (!IsLoggedIn())
            {
                return false;
            }

            if (!_requiredPermissionName.IsNullOrEmpty() && !IsPermissionGranted(_requiredPermissionName))
            {
                return false;
            }

            return true;
        }
        public bool Authorize(DashboardContext context)
        {
            // if unknown, assume not local
            if (String.IsNullOrEmpty(context.Request.RemoteIpAddress))
                return false;

            // check if localhost
            if (context.Request.RemoteIpAddress == "127.0.0.1" || context.Request.RemoteIpAddress == "::1")
                return true;

            // compare with local address
            if (context.Request.RemoteIpAddress == context.Request.LocalIpAddress)
                return true;

            return false;
        }
        public Task Dispatch(DashboardContext context)
        {
            var request = context.Request;
            var response = context.Response;

            if (!"POST".Equals(request.Method, StringComparison.OrdinalIgnoreCase))
            {
                response.StatusCode = (int)HttpStatusCode.MethodNotAllowed;
                return Task.FromResult(false);
            }

            if (_command(context))
            {
                response.StatusCode = (int)HttpStatusCode.NoContent;
            }
            else
            {
                response.StatusCode = 422;
            }

            return Task.FromResult(true);
        }
 public Task Dispatch(DashboardContext context)
 {
     return _dispatcher.Dispatch(RequestDispatcherContext.FromDashboardContext(context));
 }
Beispiel #10
0
 public bool Authorize([NotNull] Hangfire.Dashboard.DashboardContext context)
 {
     //var httpcontext = context.GetHttpContext();
     // return httpcontext.User.Identity.IsAuthenticated;
     return(true);
 }
 public bool Authorize(DashboardContext context)
 {
     var httpContext = context.GetHttpContext();
     return httpContext.User.IsUserType(UserType.SiteAdmin);
 }
Beispiel #12
0
        internal void Assign(DashboardContext context)
        {
            Request = context.Request;
            Response = context.Response;

            Storage = context.Storage;
            AppPath = context.Options.AppPath;
            StatsPollingInterval = context.Options.StatsPollingInterval;
            Url = new UrlHelper(context);

            _statisticsLazy = new Lazy<StatisticsDto>(() =>
            {
                var monitoring = Storage.GetMonitoringApi();
                return monitoring.GetStatistics();
            });
        }
Beispiel #13
0
 public UrlHelper([NotNull] DashboardContext context)
 {
     if (context == null) throw new ArgumentNullException(nameof(context));
     _context = context;
 }
 public bool Authorize(DashboardContext dashboardContext)
 {
     return(Authorize(dashboardContext.GetOwinEnvironment()));
 }
Beispiel #15
0
 public bool Authorize([NotNull] Hangfire.Dashboard.DashboardContext context)
 {
     throw new NotImplementedException();
 }
Beispiel #16
0
 public Task Dispatch(DashboardContext context)
 {
     return(_dispatcher.Dispatch(RequestDispatcherContext.FromDashboardContext(context)));
 }