/// <summary> /// 授权 /// </summary> /// <param name = "id" > 用户编号 </ param > /// < param name="token">用户token</param> /// <param name = "actionContext" ></ param > /// < returns ></ returns > public static bool Authorize(string authorization, string agents, Func <TokenAuthIdentity, HttpClientType, bool> checkToken) { try { if (!authorization.StartsWith(AuthConst.AuthPrefix)) { return(false); } var auth = AuthReader.Read(authorization); if (auth == null) { return(false); } else { if (auth.Id == 0 || !StringValid.IsEmpty(auth.Token)) { return(false); } else { return(checkToken(auth, HttpClientReader.Read(agents))); } } } catch { return(false); } }
public GeneralSiteCrawler(SiteParameter siteParameter) { IItemReader itemReader = new RegexItemReader(siteParameter); IHtmlReader htmlReader = new HttpClientReader(); this.pageReader = new SequentialPageReader(siteParameter, htmlReader, itemReader); this.pageParser = new RegexPageParser(siteParameter, htmlReader); }
public GeneralSiteCrawler(SiteParameter siteParameter) { this.dataService = new DbDataService(CrawlerDbHelper.GetContext()); IItemReader itemReader = new RegexItemReader(siteParameter); IHtmlReader htmlReader = new HttpClientReader(); this.pageReader = new SequentialPageReader(siteParameter, htmlReader, itemReader); this.pageParser = new RegexPageParser(siteParameter, htmlReader); this.pageParser.SetErrorHandler((url, exception) => this.dataService.AddLog(new CrawlerLog { Url = url, LogTime = DateTime.Now, Message = exception.Message })); }
public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) { if (AuthConst.AuthType == AuthType.Internal) { if (context.HttpContext.Request.Headers.ContainsKey(AuthConst.AuthKey) || context.HttpContext.Request.Cookies.ContainsKey(AuthConst.AuthKey)) { var agents = context.HttpContext.Request.Headers[AuthConst.UserAgentKey].ToString(); string authorization = context.HttpContext.Request.Headers[AuthConst.AuthKey].ToString(); if (authorization.IsEmpty()) { //如果header中没有读到尝试从cookie中读取 authorization = context.HttpContext.Request.Cookies[AuthConst.AuthKey]; } if (!authorization.StartsWith(AuthConst.AuthPrefix)) { context.Result = new RedirectResult(AuthConst.LoginUrl); } var identity = AuthReader.Read(authorization); if (identity.NotNull() && await AuthConst.CheckAuth(identity, HttpClientReader.Read(agents))) { await next(); } else { context.Result = new RedirectResult(AuthConst.LoginUrl); } } else { context.Result = new RedirectResult(AuthConst.LoginUrl); } } else { throw new NotImplementedException(); } }
public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) { if (context.HttpContext.Request.Headers.ContainsKey(AuthConst.AuthKey) || context.HttpContext.Request.Cookies.ContainsKey(AuthConst.AuthKey)) { var agents = context.HttpContext.Request.Headers[AuthConst.UserAgentKey].ToString(); string authorization = context.HttpContext.Request.Headers[AuthConst.AuthKey].ToString(); if (authorization.IsEmpty()) { //如果header中没有读到尝试从cookie中读取 authorization = context.HttpContext.Request.Cookies[AuthConst.AuthKey]; } if (!authorization.StartsWith(AuthConst.AuthPrefix)) { context.Result = new RedirectResult(AuthConst.LoginUrl); } var identity = AuthReader.Read(authorization); var descriptor = context.ActionDescriptor as ControllerActionDescriptor; var permissionActionContext = new PermissionActionContext() { ActionName = descriptor.ActionName, ControllerName = descriptor.ControllerName, ControllerTypeInfo = descriptor.ControllerTypeInfo, DisplayName = descriptor.DisplayName, MethodInfo = descriptor.MethodInfo, Path = context.HttpContext.Request.Path }; if (identity.NotNull() && await AuthConst.CheckPermission(permissionActionContext, identity, HttpClientReader.Read(agents))) { await next(); } else { context.Result = new StatusCodeResult(403); } } else { context.Result = new RedirectResult(AuthConst.LoginUrl); } }