private static void Checker() { /// Define the expected service certificate. It is required to establish communication using certificates. /// ALWAYS SERVER string srvCertCN = "Dalibor"; List <ProcessModel> blackList = new List <ProcessModel>(); List <ProcessModel> unauthorizedProcesses = new List <ProcessModel>(); NetTcpBinding binding = new NetTcpBinding(); binding.Security.Transport.ClientCredentialType = TcpClientCredentialType.Certificate; X509Certificate2 srvCert = CertManager.GetCertificateFromStorage(StoreName.TrustedPeople, StoreLocation.LocalMachine, srvCertCN); EndpointAddress address = new EndpointAddress(new Uri("net.tcp://10.1.212.105:9519/IntrusionService"), new X509CertificateEndpointIdentity(srvCert)); int timer = 5000; Int32.TryParse(_timer, out timer); while (true) { blackList = ConvertJson.Deserialize($"..\\..\\BlacklistConfig.json"); unauthorizedProcesses = ProcessManager.CheckIfUnauthorizedExists(blackList); if (unauthorizedProcesses.Count > 0) { using (IDSProxy client = new IDSProxy(binding, address)) { client.AddIntrusion(unauthorizedProcesses); } } Thread.Sleep(timer); } }
public IActionResult Update(ApiSettings apiSettings) { VMAward vMAward = ConvertJson.Deserialize <VMAward>(apiSettings.Obj.ToString()); bool result = _awardService.Update(vMAward).Result; return(Ok(result)); }
public override async Task <User> GetUserSocialNetworkByTokenAsync(string token) { RequestInfo requestInfo = new RequestInfo { UrlBase = $"{QueryString}{token}" }; var responseData = await RequestAPI.ConnectRestAPI(requestInfo, MethodType.GET); var user = new User(); if (responseData.Code == ApiStatusCode.Ok && !string.IsNullOrEmpty(responseData.Data)) { var userGooogle = ConvertJson.Deserialize <UserGoogleInfo>(responseData.Data); user.FullName = ($"{userGooogle.GivenName} {userGooogle.FamilyName}").Trim(); user.UserName = userGooogle.Name; user.SocialNetworkId = userGooogle.Sub; user.Email = userGooogle.Email; //user.Gender user.Avatar = userGooogle.Picture; } return(user); }
public IActionResult AddLessonList(ApiSettings apiSettings) { List <VMLesson> lesson = ConvertJson.Deserialize <List <VMLesson> >(apiSettings.Obj.ToString()); _lessonService.AddLessonList(lesson); return(Ok("Success")); }
public override async Task <User> GetUserSocialNetworkByTokenAsync(string token) { RequestInfo requestInfo = new RequestInfo { UrlBase = $"{QueryString}{token}" }; var responseData = await RequestAPI.ConnectRestAPI(requestInfo, MethodType.GET); var user = new User(); if (responseData.Code == ApiStatusCode.Ok && !string.IsNullOrEmpty(responseData.Data)) { var userFacebook = ConvertJson.Deserialize <UserFacebookInfo>(responseData.Data); user.FullName = userFacebook.Name; user.UserName = userFacebook.Email; user.SocialNetworkId = userFacebook.Id; user.Email = userFacebook.Email; //user.Gender = userFacebook.Gender; user.Avatar = userFacebook.Picture?.data?.url ?? string.Empty; } return(user); }
public IActionResult GetByName([FromBody] ApiSettings apiSettings) { VMStudent std = ConvertJson.Deserialize <VMStudent>(apiSettings.Obj.ToString()); List <VMStudent> vmStd = _studentService.GetByName(std); return(Json(vmStd)); }
public IActionResult AddStudent(ApiSettings apiSettings) { VMStudent std = ConvertJson.Deserialize <VMStudent>(apiSettings.Obj.ToString()); _studentService.AddStudent(std); return(Ok("Success")); }
private IEnumerable <Tuple <string, string, int> > GetIntrusions() { if (!File.Exists(_path)) { throw new Exception($"File:{_path} doesnt exsist"); } var jsonObjects = File.ReadAllText(_path); List <ProcessModel> processModels = new List <ProcessModel>(ConvertJson.Deserialize(_path)); //tuple that cointains: process name, username, count IEnumerable <Tuple <string, string, int> > ProcessUserCount = processModels.GroupBy(p => new { p.Name, p.User }) .Select(t => new Tuple <string, string, int>(t.Key.Name, t.Key.User, t.Count())); return(ProcessUserCount); }
public override async Task OnActionExecutionAsync(ActionExecutingContext actionContext, ActionExecutionDelegate next) { var isAuthHeader = actionContext.HttpContext.Request.Headers.TryGetValue("Authorization", out _authorizationToken); if (!isAuthHeader) { actionContext.Result = new ContentResult { Content = "UnAuthorized - Bạn không có quyền truy cập chức năng này", StatusCode = ApiStatusCode.UnAuthorized }; return; } string token = _authorizationToken.ToString().Substring("Bearer ".Length); JwtSecurityToken secToken = new JwtSecurityToken(token); var user = new UserProfile(); try { string userInfoJson = secToken.Claims.First(claim => claim.Type == JwtClaimTypes.Subject)?.Value; if (!string.IsNullOrEmpty(userInfoJson)) { user = ConvertJson.Deserialize <UserProfile>(userInfoJson); } } catch { } if (string.IsNullOrEmpty(user?.FullName)) { actionContext.Result = new ContentResult { Content = "UnAuthorized - Bạn không có quyền truy cập chức năng này", StatusCode = ApiStatusCode.UnAuthorized }; return; } actionContext.HttpContext.Items[Constant.USER_INFO] = user; await next(); }
private static void ConfigurationCheck() { string validHash = string.Empty; string path = $"..\\Debug\\validHash.txt"; List <ProcessModel> blackList = ConvertJson.Deserialize($"..\\..\\BlacklistConfig.json"); if (!File.Exists(path)) { using (StreamWriter sw = File.CreateText(path)) { } } validHash = File.ReadAllText(path); ConfigCheck cc = new ConfigCheck(); if (validHash.Equals(cc.ReadConfigHash())) { Console.WriteLine("Configuration file checksum is valid!"); } else { Console.WriteLine("Configuration file checksum is NOT valid!"); } }
public static async Task <ResponseData> ConnectRestAPI(RequestInfo requestInfor, MethodType type) { ResponseData responseData = new ResponseData(); try { using (HttpClient client = new HttpClient()) { if (requestInfor.HeaderValue != null && requestInfor.HeaderValue.AuthorizationType != null && requestInfor.HeaderValue.AuthorizationValue != null) { client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(requestInfor.HeaderValue.AuthorizationType, requestInfor.HeaderValue.AuthorizationValue); } if (requestInfor.HeaderValue != null && requestInfor.HeaderValue.ListHeader != null && requestInfor.HeaderValue.ListHeader.Any()) { foreach (var item in requestInfor.HeaderValue.ListHeader) { client.DefaultRequestHeaders.Add(item.Key, item.Value); } } var request = new HttpResponseMessage(); switch (type) { case MethodType.GET: request = await client.GetAsync(requestInfor.UrlBase); break; case MethodType.POST: request = await client.PostAsync(requestInfor.UrlBase, new FormUrlEncodedContent(requestInfor.FormValue)); break; case MethodType.PUT: request = await client.PutAsync(requestInfor.UrlBase, new FormUrlEncodedContent(requestInfor.FormValue)); break; case MethodType.DELETE: request = await client.DeleteAsync(requestInfor.UrlBase); break; default: break; } if (request.StatusCode == HttpStatusCode.OK) { string resultData = request.Content.ReadAsStringAsync().Result; responseData = new ResponseData() { Code = (int)HttpStatusCode.OK, Data = resultData }; } else if (request.StatusCode == HttpStatusCode.NoContent) { responseData = new ResponseData() { Code = (int)HttpStatusCode.NoContent, Message = "NoContent", }; } else { var errorData = ConvertJson.Deserialize <ErrorData>(request.Content.ReadAsStringAsync().Result); if (errorData != null) { responseData = new ResponseData() { Code = (int)request.StatusCode, Message = errorData.error + " - " + errorData.error_description }; } else { responseData = new ResponseData() { Code = (int)request.StatusCode, Message = "Unknown Error: " + request.Content.ReadAsStringAsync().Result }; } } } } catch (Exception ex) { } return(responseData); }