public DashboardRepository(IUnitOfWork<DashboardContext> uow, ICurrentUser currentUser) { _context = uow.Context; this._dbSet = _context.Set<Dashboard>(); _uow = uow; this._currentUser = currentUser; }
/// <summary> /// //The authentication process that decides if a user can access the dashboard. /// </summary> /// <param name="context"></param> /// <returns></returns> public bool Authorize(DashboardContext context) { return(true); }
public bool Authorize([NotNull] DashboardContext context) { return(true); }
/// <summary> /// 通用的检查并获取jobItem /// </summary> /// <param name="context"></param> /// <returns></returns> private async Task <(HttpJobItem, string)> GetCheckedJobItem(DashboardContext context) { var jobItemBody = await GetRequestBody <HttpJobItem>(context); var jobItem = jobItemBody.Item1; if (jobItem == null) { return(null, $"get job data fail:{jobItemBody.Item2}"); } string CheckHttpJobItem(HttpJobItem item, bool isParent) { if (string.IsNullOrEmpty(item.Url) || item.Url.ToLower().Equals("http://")) { return("Url invaild"); } if (string.IsNullOrEmpty(item.ContentType)) { return("ContentType invaild"); } if (isParent) { if (string.IsNullOrEmpty(item.JobName)) { var jobName = item.Url.Split('/').LastOrDefault() ?? string.Empty; item.JobName = jobName; } if (string.IsNullOrEmpty(item.JobName)) { return("JobName invaild"); } } return(string.Empty); } var list = new List <HttpJobItem>(); void AddAllJobItem(HttpJobItem item, List <HttpJobItem> listOut) { listOut.Add(item); if (item.Success != null) { AddAllJobItem(item.Success, listOut); } if (item.Fail != null) { AddAllJobItem(item.Fail, listOut); } } AddAllJobItem(jobItem, list); for (int i = 0; i < list.Count; i++) { var checkResult = CheckHttpJobItem(list[i], i == 0); if (!string.IsNullOrEmpty(checkResult)) { return(null, checkResult); } } return(jobItem, null); }
/// <summary> /// 获取jobAgent类型的JobInfo /// </summary> /// <param name="context"></param> /// <returns></returns> private async Task <JobDetailInfo> GetBackGroundJobDetail(DashboardContext context) { var result = new JobDetailInfo(); var jobName = string.Empty; var jobItemBody = await GetRequestBody <HttpJobItem>(context); var jobItem = jobItemBody.Item1; if (jobItem == null || string.IsNullOrEmpty(jobItem.JobName)) { result.Info = "GetJobDetail Error:can not found job by id:" + jobItemBody.Item2; return(result); } try { using (var connection = JobStorage.Current.GetConnection()) { Job job = null; if (string.IsNullOrEmpty(jobItem.Cron)) { var jobData = connection.GetJobData(jobItem.JobName); if (jobData == null) { result.Info = "GetJobDetail Error:can not found job by id:" + jobItem.JobName; return(result); } job = jobData.Job; } else { Dictionary <string, string> dictionary = connection.GetAllEntriesFromHash("recurring-job:" + jobItem.JobName); if (dictionary == null || dictionary.Count == 0) { result.Info = "GetJobDetail Error:can not found job by id:" + jobItem.JobName; return(result); } if (!dictionary.TryGetValue(nameof(Job), out var jobDetail)) { result.Info = "GetJobDetail Error:can not found job by id:" + jobItem.JobName; return(result); } job = InvocationData.DeserializePayload(jobDetail).DeserializeJob(); } var jobItem2 = job.Args.FirstOrDefault(); var httpJobItem = jobItem2 as HttpJobItem; if (httpJobItem == null) { result.Info = $"GetJobDetail Error:jobData can not found job by id:" + jobItem.JobName; return(result); } result.JobName = jobName = httpJobItem.JobName; if (string.IsNullOrEmpty(httpJobItem.AgentClass)) { result.Info = $"{(!string.IsNullOrEmpty(jobName) ? "【" + jobName + "】" : string.Empty)} Error:is not AgentJob! "; return(result); } var jobInfo = HttpJob.GetAgentJobDetail(httpJobItem); if (string.IsNullOrEmpty(jobInfo)) { result.Info = $"{(!string.IsNullOrEmpty(jobName) ? "【" + jobName + "】" : string.Empty)} Error:get null info! "; return(result); } jobInfo = jobInfo.Replace("\r\n", "<br/>"); result.Info = jobInfo; return(result); } } catch (Exception ex) { Logger.ErrorException("HttpJobDispatcher.GetBackGroundJobDetail", ex); result.Info = $"{(!string.IsNullOrEmpty(jobName) ? "【" + jobName + "】" : string.Empty)} GetJobDetail Error:" + ex.ToString(); return(result); } }
public async 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; } var jobIds = await context.Request.GetFormValuesAsync("jobid").ConfigureAwait(false); var jobId = jobIds.FirstOrDefault()?.Trim(); var urlHelper = new UrlHelper(context); string link = null; if (!String.IsNullOrEmpty(jobId)) { try { var monitoringApi = context.Storage.GetMonitoringApi(); var normalizedId = jobId.StartsWith("#") ? jobId.Substring(1) : jobId; var jobDetails = monitoringApi.JobDetails(normalizedId); if (jobDetails != null) { link = urlHelper.JobDetails(normalizedId); } } catch { // } if (link == null) { using (var connection = context.Storage.GetConnection()) { var recurringJob = connection.GetAllEntriesFromHash($"recurring-job:{jobId}"); if (recurringJob != null && recurringJob.Count != 0) { link = urlHelper.To("/recurring/details/" + jobId); } } } if (link == null) { using (var connection = context.Storage.GetConnection()) { var batch = connection.GetAllEntriesFromHash($"batch:{jobId}"); if (batch != null && batch.Count != 0) { link = urlHelper.To("/batches/" + jobId); } } } } response.StatusCode = link != null ? 200 : 404; #pragma warning disable 618 await response.WriteAsync(JobHelper.ToJson(new Dictionary <string, string> #pragma warning restore 618 { { "location", link } })); }
private static bool IsLoggedIn(DashboardContext context) { var currentUser = context.GetHttpContext().RequestServices.GetRequiredService <ICurrentUser>(); return(currentUser.IsAuthenticated); }
public TeamRepository(DashboardContext context) : base(context) { }
public bool Authorize([NotNull] DashboardContext context) => context.GetHttpContext().User?.IsInRole(AuthorizationConstants.AdminRole) ?? false;
public FuncionarioRepository(DashboardContext db) : base(db) { }
public ProdutoRepository(DashboardContext db) : base(db) { }
public bool Authorize(DashboardContext context) { var admin = context.GetHttpContext().User.IsInRole("admin"); return(context.Request.LocalIpAddress == "127.0.0.1" || context.Request.LocalIpAddress == "::1" || admin); }
public bool Authorize([NotNull] DashboardContext context) { //Code auth logic if this service will have external ip address and port return(true); }
public bool Authorize(DashboardContext context) { return(true); //I am returning true for simplicity }
public bool Authorize(DashboardContext context) { return true; }
public bool Authorize([NotNull] DashboardContext context) { //return context.GetHttpContext().User.Identity.IsAuthenticated; return(true); }
public Task Dispatch(DashboardContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } try { if (!"POST".Equals(context.Request.Method, StringComparison.OrdinalIgnoreCase)) { context.Response.StatusCode = (int)HttpStatusCode.MethodNotAllowed; return(Task.FromResult(false)); } var op = context.Request.GetQuery("op"); if (string.IsNullOrEmpty(op)) { context.Response.StatusCode = (int)HttpStatusCode.BadRequest; return(Task.FromResult(false)); } if (op.ToLower() == "getjoblist") { var joblist = GetRecurringJobs(); context.Response.ContentType = "application/json"; context.Response.StatusCode = (int)HttpStatusCode.OK; context.Response.WriteAsync(JsonConvert.SerializeObject(joblist)); return(Task.FromResult(true)); } var jobItem = GetJobItem(context); if (jobItem == null) { context.Response.StatusCode = (int)HttpStatusCode.BadRequest; return(Task.FromResult(false)); } if (op.ToLower() == "getrecurringjob") { var strdata = GetJobdata(jobItem.JobName); if (!string.IsNullOrEmpty(strdata)) { context.Response.ContentType = "application/json"; context.Response.StatusCode = (int)HttpStatusCode.OK; context.Response.WriteAsync(strdata); return(Task.FromResult(true)); } else { context.Response.ContentType = "application/json"; context.Response.StatusCode = (int)HttpStatusCode.NotFound; return(Task.FromResult(false)); } } else if (op.ToLower() == "getbackgroundjobdetail") { var jobDetail = GetBackGroundJobDetail(jobItem); context.Response.ContentType = "application/json"; context.Response.StatusCode = (int)HttpStatusCode.OK; context.Response.WriteAsync(JsonConvert.SerializeObject(jobDetail)); return(Task.FromResult(true)); } if (string.IsNullOrEmpty(jobItem.Url) || string.IsNullOrEmpty(jobItem.ContentType) || jobItem.Url.ToLower().Equals("http://")) { context.Response.StatusCode = (int)HttpStatusCode.BadRequest; return(Task.FromResult(false)); } if (string.IsNullOrEmpty(jobItem.JobName)) { var jobName = context.Request.Path.Split('/').LastOrDefault() ?? string.Empty; jobItem.JobName = jobName; } if (string.IsNullOrEmpty(jobItem.JobName)) { context.Response.StatusCode = (int)HttpStatusCode.BadRequest; return(Task.FromResult(false)); } var result = false; switch (op.ToLower()) { case "backgroundjob": if (jobItem.DelayFromMinutes < -1) { context.Response.StatusCode = (int)HttpStatusCode.BadRequest; return(Task.FromResult(false)); } result = AddHttpbackgroundjob(jobItem); break; case "recurringjob": if (string.IsNullOrEmpty(jobItem.Cron)) { context.Response.StatusCode = (int)HttpStatusCode.BadRequest; return(Task.FromResult(false)); } result = AddHttprecurringjob(jobItem); break; case "editrecurringjob": if (string.IsNullOrEmpty(jobItem.Cron)) { context.Response.StatusCode = (int)HttpStatusCode.BadRequest; return(Task.FromResult(false)); } result = AddHttprecurringjob(jobItem); break; case "pausejob": result = PauseOrRestartJob(jobItem.JobName); break; case "startbackgroudjob": result = StartBackgroudJob(jobItem); break; case "stopbackgroudjob": result = StopBackgroudJob(jobItem); break; default: context.Response.StatusCode = (int)HttpStatusCode.MethodNotAllowed; return(Task.FromResult(false)); } if (result) { context.Response.ContentType = "application/json"; context.Response.StatusCode = (int)HttpStatusCode.NoContent; return(Task.FromResult(true)); } else { context.Response.ContentType = "application/json"; context.Response.StatusCode = (int)HttpStatusCode.InternalServerError; return(Task.FromResult(false)); } } catch (Exception ex) { Logger.ErrorException("HttpJobDispatcher.Dispatch", ex); context.Response.ContentType = "application/json"; context.Response.StatusCode = (int)HttpStatusCode.InternalServerError; return(Task.FromResult(false)); } }
public bool Authorize(DashboardContext context) { return(true); // open for now, wait until 1.7 }
/// <summary> /// hangfire dashboard授权 /// </summary> /// <param name="context"></param> /// <returns></returns> public bool Authorize(DashboardContext context) { return(ExternalAuthorizationHelper.IsGranted(context.GetHttpContext(), _authenticateApiUrl, PermissionNames.Tools_HangfireDashboard)); }
private static async Task <bool> IsPermissionGrantedAsync(DashboardContext context, string requiredPermissionName) { var permissionChecker = context.GetHttpContext().RequestServices.GetRequiredService <IPermissionChecker>(); return(await permissionChecker.IsGrantedAsync(requiredPermissionName)); }
public bool Authorize(DashboardContext context) { var httpContext = context.GetHttpContext(); return(httpContext.User.IsInRole(Constants.AdminRole)); }
public bool Authorize(DashboardContext context) { var httpContext = context.GetHttpContext(); return(httpContext.User.IsInRole(GlobalConstants.AdministratorRoleName)); }
public LookupService(DashboardContext context) { this.context = context; }
public async Task Dispatch(DashboardContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } try { if (!"POST".Equals(context.Request.Method, StringComparison.OrdinalIgnoreCase)) { context.Response.StatusCode = (int)HttpStatusCode.MethodNotAllowed; return; } //操作类型 var op = context.Request.GetQuery("op"); if (string.IsNullOrEmpty(op)) { context.Response.StatusCode = (int)HttpStatusCode.BadRequest; return; } op = op.ToLower(); switch (op) { // dashbord 上获取周期性job详情 case "getrecurringjob": await GetRecurringJobDetail(context); return; // dashbord 上获取Agent job详情 case "getbackgroundjobdetail": await DoGetBackGroundJobDetail(context); return; // 删除job case "deljob": await DelJob(context); return; // 暂停或开始job case "pausejob": await DoPauseOrRestartJob(context); return; //新增后台任务job case "backgroundjob": await AddBackgroundjob(context); return; //新增周期性任务job 只新增有重复的话报错 case "addrecurringjob": await AddRecurringJob(context); return; case "recurringjob": //新增或修改周期性任务job case "editrecurringjob": await AddOrUpdateRecurringJob(context); return; //启动job case "startbackgroundjob": await StartBackgroudJob(context); return; //暂停job case "stopbackgroundjob": await StopBackgroudJob(context); return; //获取全局配置 case "getglobalsetting": await GetGlobalSetting(context); return; //保存全局配置 case "saveglobalsetting": await SaveGlobalSetting(context); return; //获取agentserver列表 case "getagentserver": await GetAgentServer(context); return; //导出 case "exportjobs": await ExportJobsAsync(context); return; //导入 case "importjobs": await ImportJobsAsync(context); return; default: context.Response.StatusCode = (int)HttpStatusCode.MethodNotAllowed; break; } } catch (Exception ex) { Logger.ErrorException("HttpJobDispatcher.Dispatch", ex); context.Response.ContentType = "application/json"; context.Response.StatusCode = (int)HttpStatusCode.InternalServerError; return; } }
public bool Authorize([NotNull] DashboardContext context) { return(authStrategy.IsRequestAuthorized(context.GetHttpContext())); }
/// <summary> /// 获取jobDetail /// </summary> /// <param name="_context"></param> /// <returns></returns> public async Task <Tuple <T, string> > GetRequestBody <T>(DashboardContext _context) { try { Stream body = null; if (_context is AspNetCoreDashboardContext) { var context = _context.GetHttpContext(); body = context.Request.Body; } else { //兼容netframework var contextType = _context.Request.GetType(); //private readonly IOwinContext _context; var owinContext = contextType.GetField("_context", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(_context.Request); if (owinContext == null) { Logger.Warn($"HttpJobDispatcher.GetJobItem:: get data from DashbordContext err,DashboardContext:{contextType.FullName}"); return(new Tuple <T, string>(default(T), $"HttpJobDispatcher.GetJobItem:: get data from DashbordContext err,DashboardContext:{contextType.FullName}")); } var request = owinContext.GetType().GetProperty("Request")?.GetValue(owinContext); if (request == null) { Logger.Warn($"HttpJobDispatcher.GetJobItem:: get data from DashbordContext err,OwinContext:{owinContext.GetType().FullName}"); return(new Tuple <T, string>(default(T), $"HttpJobDispatcher.GetJobItem:: get data from DashbordContext err,OwinContext:{owinContext.GetType().FullName}")); } body = request.GetType().GetProperty("Body")?.GetValue(request) as Stream; if (body == null) { Logger.Warn($"HttpJobDispatcher.GetJobItem:: get data from DashbordContext err,Request:{request.GetType().FullName}"); return(new Tuple <T, string>(default(T), $"HttpJobDispatcher.GetJobItem:: get data from DashbordContext err,Request:{request.GetType().FullName}")); } } if (body == null) { return(new Tuple <T, string>(default(T), $"get body stream from request fail")); } using (MemoryStream ms = new MemoryStream()) { await body.CopyToAsync(ms); await ms.FlushAsync(); ms.Seek(0, SeekOrigin.Begin); var sr = new StreamReader(ms); var requestBody = await sr.ReadToEndAsync(); if (typeof(T) == typeof(String)) { return(new Tuple <T, string>((T)(object)requestBody, null)); } return(new Tuple <T, string>(Newtonsoft.Json.JsonConvert.DeserializeObject <T>(requestBody), null)); } } catch (Exception ex) { return(new Tuple <T, string>(default(T), ex.Message)); } }
public bool Authorize(DashboardContext context) { return(true); // 任何人都可以直接觀看 }
public bool Authorize([NotNull] DashboardContext context) { var httpcontext = context.GetHttpContext(); return(httpcontext.User.Identity.IsAuthenticated); }
public Task Dispatch(DashboardContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } try { if (!"POST".Equals(context.Request.Method, StringComparison.OrdinalIgnoreCase)) { context.Response.StatusCode = (int)HttpStatusCode.MethodNotAllowed; return(Task.FromResult(false)); } var op = context.Request.GetQuery("op"); if (string.IsNullOrEmpty(op)) { context.Response.StatusCode = (int)HttpStatusCode.MethodNotAllowed; return(Task.FromResult(false)); } var detailKey = context.Request.GetQuery("key"); HttpJobItem jobItem = null; if (string.IsNullOrEmpty(detailKey)) { jobItem = GetJobItem(context); if (jobItem == null || string.IsNullOrEmpty(jobItem.Url) || string.IsNullOrEmpty(jobItem.ContentType)) { context.Response.StatusCode = (int)HttpStatusCode.MethodNotAllowed; return(Task.FromResult(false)); } if (string.IsNullOrEmpty(jobItem.JobName)) { var jobName = context.Request.Path.Split('/').LastOrDefault() ?? string.Empty; jobItem.JobName = jobName; } if (string.IsNullOrEmpty(jobItem.JobName)) { context.Response.StatusCode = (int)HttpStatusCode.MethodNotAllowed; return(Task.FromResult(false)); } } var result = false; var jobDetailSet = string.Empty; switch (op.ToLower()) { case "backgroundjob": result = AddHttpbackgroundjob(jobItem); break; case "recurringjob": if (string.IsNullOrEmpty(jobItem.Corn)) { context.Response.StatusCode = (int)HttpStatusCode.MethodNotAllowed; return(Task.FromResult(false)); } result = AddHttprecurringjob(jobItem); break; case "getdetailjobset": if (string.IsNullOrEmpty(detailKey)) { context.Response.StatusCode = (int)HttpStatusCode.MethodNotAllowed; return(Task.FromResult(false)); } jobDetailSet = GetJobDetailSet(detailKey); break; default: context.Response.StatusCode = (int)HttpStatusCode.MethodNotAllowed; return(Task.FromResult(false)); } if (result) { context.Response.ContentType = "application/json"; context.Response.StatusCode = (int)HttpStatusCode.NoContent; return(Task.FromResult(true)); } else { if (jobDetailSet != string.Empty) { context.Response.ContentType = "application/json"; context.Response.WriteAsync(jobDetailSet); return(Task.FromResult(true)); } context.Response.ContentType = "application/json"; context.Response.StatusCode = (int)HttpStatusCode.InternalServerError; return(Task.FromResult(false)); } } catch (Exception ex) { Logger.ErrorException("HttpJobDispatcher.Dispatch", ex); context.Response.ContentType = "application/json"; context.Response.StatusCode = (int)HttpStatusCode.InternalServerError; return(Task.FromResult(false)); } }
public bool Authorize(DashboardContext context) => true;
public bool Authorize(DashboardContext context, ITaskParameters taskParameters) { return(new Random().Next(1) == 1); }
public DashboardUserRepository(IUnitOfWork<DashboardContext> uow) { _context = uow.Context; this._dbSet = _context.Set<DashboardUser>(); _uow = uow; }
public bool Authorize(DashboardContext context) { //var httpcontext = context.GetHttpContext(); //return httpcontext.User.Identity.IsAuthenticated;//Use this for actual authorization for HangFire return(true); //Bypassing the authorizzation as its all internal as of now. }