public TcpInputConnector(string ipAddressAndPort, IProtocolFormatter protocolFormatter, ISecurityFactory securityFactory, int sendTimeout, int receiveTimeout, int sendBuffer, int receiveBuffer, bool reuseAddressFlag, int maxAmountOfConnections) { using (EneterTrace.Entering()) { Uri aUri; try { aUri = new Uri(ipAddressAndPort); } catch (Exception err) { EneterTrace.Error(ipAddressAndPort + ErrorHandler.InvalidUriAddress, err); throw; } int aPort = (aUri.Port < 0) ? 0 : aUri.Port; myTcpListenerProvider = new TcpListenerProvider(IPAddress.Parse(aUri.Host), aPort, reuseAddressFlag, maxAmountOfConnections); myProtocolFormatter = protocolFormatter; mySecurityStreamFactory = securityFactory; mySendTimeout = sendTimeout; myReceiveTimeout = receiveTimeout; mySendBuffer = sendBuffer; myReceiveBuffer = receiveBuffer; // Check if protocol encodes open and close messages. myProtocolUsesOpenConnectionMessage = myProtocolFormatter.EncodeOpenConnectionMessage("test") != null; } }
public JsonResult DeletePage(int id) { try { Dictionary <int, CheckSessionData> dictionary = CheckSessionData.GetSessionValues(); int userGroupId = Convert.ToInt32(dictionary[6].Id == "" ? 0 : Convert.ToInt32(dictionary[6].Id)); if (userGroupId != 0) { ISecurityFactory _securityLogInFactory = new SecurityFactorys(); PagePermissionVM tblUserActionMapping = _securityLogInFactory.GetCrudPermission(userGroupId, "Page"); if (tblUserActionMapping.Delete) { securityFactory = new SecurityFactorys(); result = securityFactory.DeleteUiPage(id); if (result.isSucess) { return(Json(result, JsonRequestBehavior.AllowGet)); } return(Json(new { isSucess = false, message = "You cant delete this another one use this User Group" }, JsonRequestBehavior.AllowGet)); } return(Json(new { isSucess = false, message = "You are not permitted for this action" }, JsonRequestBehavior.AllowGet)); } return(Json(new { isSucess = false, message = "LogOut" }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(new { isSucess = false, message = ex.Message }, JsonRequestBehavior.AllowGet)); } }
public JsonResult UserGroupSave(SEC_UserGroup userGroup) { try { Dictionary <int, CheckSessionData> dictionary = CheckSessionData.GetSessionValues(); int userId = Convert.ToInt32(dictionary[3].Id); int empId = Convert.ToInt32(dictionary[1].Id); if (userId != 0) { _securityFactory = new SecurityFactorys(); if (userGroup.ID < 1) { userGroup.CreatedBy = empId; userGroup.CreatedDate = DateTime.Now; } result = _securityFactory.SaveUserGroupWithPageMapping(userGroup); if (result.isSucess) { return(Json(result)); } return(Json(result)); } Session["logInSession"] = null; return(Json(new { success = false, message = "LogOut" }, JsonRequestBehavior.AllowGet)); } catch (Exception exception) { return(Json(new { success = false, message = exception.Message }, JsonRequestBehavior.AllowGet)); } }
public TcpOutputConnector(string ipAddressAndPort, string outputConnectorAddress, IProtocolFormatter protocolFormatter, ISecurityFactory clientSecurityFactory, int connectTimeout, int sendTimeout, int receiveTimeout, int sendBuffer, int receiveBuffer, bool reuseAddressFlag, int responseReceivingPort) { using (EneterTrace.Entering()) { try { myUri = new Uri(ipAddressAndPort, UriKind.Absolute); } catch (Exception err) { EneterTrace.Error(ipAddressAndPort + ErrorHandler.InvalidUriAddress, err); throw; } myOutputConnectorAddress = outputConnectorAddress; myClientSecurityFactory = clientSecurityFactory; myProtocolFormatter = protocolFormatter; myConnectTimeout = (connectTimeout != 0) ? connectTimeout : -1; mySendTimeout = sendTimeout; myReceiveTimeout = receiveTimeout; mySendBuffer = sendBuffer; myReceiveBuffer = receiveBuffer; myReuseAddressFlag = reuseAddressFlag; myResponseReceivingPort = responseReceivingPort; } }
public HostListenerBase CreateHostListener(IPEndPoint address, ISecurityFactory securityFactory) { using (EneterTrace.Entering()) { WebSocketHostListener aPathListener = new WebSocketHostListener(address, securityFactory, myReuseAddressFlag, myMaxAmountOfConnections); return(aPathListener); } }
public PathListenerProviderBase(IHostListenerFactory hostListenerFactory, Uri uri, ISecurityFactory securityFactory) { using (EneterTrace.Entering()) { myHostListenerFactory = hostListenerFactory; Address = uri; mySecurityFactory = securityFactory; } }
/// <summary> /// Starts listening for the given URI path. /// </summary> /// <remarks> /// The listening consists of two parts: /// => Host listener - TCP listening on an address and port. /// => Path listener - based on the above protocol (HTTP or WebSocket) listening to the path. /// /// If the URI contains hostname instead of the IP address then it resolves the host name. /// But the result can be multiple addresses. E.g. for localhost it can return IPV4: 127.0.0.1 and IPV6: [::1]. /// In sach case it will try to start listening to all addresses associated with the host name. /// If start listening fails for one of those addresses then StartListening throws exception. /// /// </remarks> /// <param name="address"></param> /// <param name="hostListenerFactory"></param> /// <param name="connectionHandler"></param> /// <param name="serverSecurityFactory"></param> public static void StartListening(Uri address, IHostListenerFactory hostListenerFactory, object connectionHandler, ISecurityFactory serverSecurityFactory) { using (EneterTrace.Entering()) { try { using (ThreadLock.Lock(myListeners)) { // Get all possible end points for the given hostname/address. IEnumerable <IPEndPoint> anEndPoints = GetEndPoints(address); foreach (IPEndPoint anEndPoint in anEndPoints) { // Try to get existing host listener for the endpoint. HostListenerBase aHostListener = GetHostListener(anEndPoint); if (aHostListener == null) { // The host listener does not exist so create it. aHostListener = hostListenerFactory.CreateHostListener(anEndPoint, serverSecurityFactory); // Register the path listener. aHostListener.RegisterListener(address, connectionHandler); myListeners.Add(aHostListener); } else { // If found listener is listening to another protocol. // e.g. if I want to start listening to http but websocket listener is listening on // the given IP address and port. if (aHostListener.GetType() != hostListenerFactory.ListenerType) { string anErrorMessage = TracedObject + "failed to start " + hostListenerFactory.ListenerType + " because " + aHostListener.GetType() + " is already listening on IP address and port."; EneterTrace.Error(anErrorMessage); throw new InvalidOperationException(anErrorMessage); } // Register the path listener. aHostListener.RegisterListener(address, connectionHandler); } } } } catch (Exception err) { EneterTrace.Error(TracedObject + "failed to start listening.", err); throw; } } }
public WebSocketInputConnectorFactory(IProtocolFormatter protocolFormatter, ISecurityFactory serverSecurityFactory, int sendTimeout, int receiveTimeout, bool reuseAddressFlag, int maxAmountOfConnections) { using (EneterTrace.Entering()) { myProtocolFormatter = protocolFormatter; myServerSecurityFactory = serverSecurityFactory; mySendTimeout = sendTimeout; myReceiveTimeout = receiveTimeout; myReuseAddressFlag = reuseAddressFlag; myMaxAmountOfConnections = maxAmountOfConnections; } }
public ActionResult GetPage() { try { Dictionary <int, CheckSessionData> dictionary = CheckSessionData.GetSessionValues(); int companyId = Convert.ToInt32(dictionary[1].Id == "" ? 0 : Convert.ToInt32(dictionary[1].Id)); _securityFactory = new SecurityFactorys(); //var menu = _securityFactory.GetPageList(Convert.ToInt32(companyId)); //Page are Common For all the Application var menu = _securityFactory.GetPageList(); return(Json(new { data = menu }, JsonRequestBehavior.AllowGet)); } catch (Exception) { return(Json(new { success = false, message = "Error occured" }, JsonRequestBehavior.AllowGet)); } }
public WebSocketOutputConnectorFactory(IProtocolFormatter protocolFormatter, ISecurityFactory clientSecurityFactory, int connectionTimeout, int sendTimeout, int receiveTimeout, int pingFrequency, int responseReceivingPort) { using (EneterTrace.Entering()) { myProtocolFormatter = protocolFormatter; myClientSecurityFactory = clientSecurityFactory; myConnectionTimeout = connectionTimeout; mySendTimeout = sendTimeout; myReceiveTimeout = receiveTimeout; myPingFrequency = pingFrequency; myResponseReceivingPort = responseReceivingPort; } }
public TcpOutputConnectorFactory(IProtocolFormatter protocolFormatter, ISecurityFactory securityFactory, int connectionTimeout, int sendTimeout, int receiveTimeout, int sendBuffer, int receiveBuffer, bool reuseAddressFlag, int responseReceivingPort) { using (EneterTrace.Entering()) { myProtocolFormatter = protocolFormatter; mySecurityFactory = securityFactory; myConnectionTimeout = connectionTimeout; mySendTimeout = sendTimeout; myReceiveTimeout = receiveTimeout; mySendBuffer = sendBuffer; myReceiveBuffer = receiveBuffer; myReuseAddressFlag = reuseAddressFlag; myResponseReceivingPort = responseReceivingPort; } }
/// <summary> /// Constructs the websocket client. /// </summary> /// <param name="uri">websocket uri address. Provide port number too. e.g. ws://127.0.0.1:8055/myservice/<br/> /// You can also specify the query that can be used to pass some open connection related parameters. /// e.g. ws://127.0.0.1:8055/myservice/?param1=10&param2=20 /// </param> /// <param name="clientSecurityFactory"> /// Factory allowing SSL communication. <see cref="ClientSslFactory"/> /// </param> public WebSocketClient(Uri uri, ISecurityFactory clientSecurityFactory) { using (EneterTrace.Entering()) { Uri = uri; mySecurityFactory = clientSecurityFactory; HeaderFields = new Dictionary <string, string>(); HeaderFields["Host"] = Uri.Authority; HeaderFields["Upgrade"] = "websocket"; HeaderFields["Connection"] = "Upgrade"; HeaderFields["Sec-WebSocket-Version"] = "13"; ConnectTimeout = 30000; SendTimeout = 30000; ResponseReceivingPort = -1; } }
public JsonResult LoadMappingDataForEdit(int id) { try { Dictionary <int, CheckSessionData> dictionary = CheckSessionData.GetSessionValues(); int userId = Convert.ToInt32(dictionary[3].Id); if (userId != 0) { _securityFactory = new SecurityFactorys(); var userPagemapping = _securityFactory.GetEditPageList(id); return(Json(userPagemapping)); } return(Json(new { success = false, message = "LogOut" }, JsonRequestBehavior.AllowGet)); } catch (Exception exception) { return(Json(new { success = false, message = exception.Message }, JsonRequestBehavior.AllowGet)); } }
public JsonResult GetModuleData(int?moduleID) { try { Dictionary <int, CheckSessionData> dictionary = CheckSessionData.GetSessionValues(); int userGroupId = Convert.ToInt32(dictionary[6].Id == "" ? 0 : Convert.ToInt32(dictionary[6].Id)); if (userGroupId > 0) { securityFactory = new SecurityFactorys(); List <SEC_UIModule> list = securityFactory.SearchUiModule(moduleID); var pageList = list.Select(x => new { x.ID, x.Name }); return(Json(pageList, JsonRequestBehavior.AllowGet)); } return(Json(new { success = false, message = "LogOut" }, JsonRequestBehavior.AllowGet)); } catch (Exception exception) { return(Json(new { success = false, message = exception.Message }, JsonRequestBehavior.AllowGet)); } }
public JsonResult EditUserGroupSave(SEC_UserGroup userGroup, List <MenuItemVM> userMappingVm = null) { try { _securityFactory = new SecurityFactorys(); Dictionary <int, CheckSessionData> dictionary = CheckSessionData.GetSessionValues(); int userId = Convert.ToInt32(dictionary[3].Id); if (userId != 0) { result = _securityFactory.EditUserGroupPagePermission(userGroup, userMappingVm); if (result.isSucess) { return(Json(result, JsonRequestBehavior.AllowGet)); } return(Json(result, JsonRequestBehavior.AllowGet)); } Session["logInSession"] = null; return(Json(new { success = false, message = "LogOut" }, JsonRequestBehavior.AllowGet)); } catch (Exception exception) { return(Json(new { success = false, message = exception.Message }, JsonRequestBehavior.AllowGet)); } }
public JsonResult PageSave(SEC_UIPage page) { try { Dictionary <int, CheckSessionData> dictionary = CheckSessionData.GetSessionValues(); int userId = Convert.ToInt32(dictionary[3].Id); if (userId != 0) { securityFactory = new SecurityFactorys(); result = securityFactory.UiPageSave(page); if (result.isSucess) { return(Json(result)); } return(Json(result)); } Session["logInSession"] = null; return(Json(result)); } catch (Exception exception) { return(Json(new { isSucess = false, message = exception.Message }, JsonRequestBehavior.AllowGet)); } }
public SecurityService(ISecurityRepository Repository, IUserRepository UserRepository, ISecurityFactory SecurityFactory) { this.Repository = Repository; this.UserRepository = UserRepository; this.SecurityFactory = SecurityFactory; }
public HostListenerBase(IPEndPoint address, ISecurityFactory securityFactory, bool reuseAddressFlag, int maxAmountOfConnections) { Address = address; myTcpListener = new TcpListenerProvider(address, reuseAddressFlag, maxAmountOfConnections); SecurityFactory = securityFactory; }
public WebSocketInputConnector(string wsUriAddress, IProtocolFormatter protocolFormatter, ISecurityFactory securityFactory, int sendTimeout, int receiveTimeout, bool reuseAddressFlag, int maxAmountOfConnections) { using (EneterTrace.Entering()) { Uri aUri; try { aUri = new Uri(wsUriAddress); } catch (Exception err) { EneterTrace.Error(wsUriAddress + ErrorHandler.InvalidUriAddress, err); throw; } myProtocolFormatter = protocolFormatter; myListener = new WebSocketListener(aUri, securityFactory); myListener.ReuseAddress = reuseAddressFlag; myListener.MaxAmountOfClients = maxAmountOfConnections; mySendTimeout = sendTimeout; myReceiveTimeout = receiveTimeout; // Check if protocol encodes open and close messages. myProtocolUsesOpenConnectionMessage = myProtocolFormatter.EncodeOpenConnectionMessage("test") != null; } }
public WebSocketListenerImpl(Uri uri, ISecurityFactory securityFactory, bool reuseAddressFlag, int maxAmountOfConnections) : base(new WebSocketHostListenerFactory(reuseAddressFlag, maxAmountOfConnections), uri, securityFactory) { }
/// <summary> /// Construct websocket service. /// </summary> /// <param name="webSocketUri">service address. Provide port number too.</param> /// <param name="securityFactory"> /// Factory allowing SSL communication. <see cref="ServerSslFactory"/> /// </param> public WebSocketListener(Uri webSocketUri, ISecurityFactory securityFactory) { MaxAmountOfClients = -1; myListenerFactoryMethod = () => new WebSocketListenerImpl(webSocketUri, securityFactory, ReuseAddress, MaxAmountOfClients); }
public ActionResult Login(LogOnModel model) { try { if (ModelState.IsValid) { bool getLan = false; string visitorIpAddress = System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]; if (String.IsNullOrEmpty(visitorIpAddress)) { visitorIpAddress = System.Web.HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]; } if (string.IsNullOrEmpty(visitorIpAddress)) { visitorIpAddress = System.Web.HttpContext.Current.Request.UserHostAddress; } if (string.IsNullOrEmpty(visitorIpAddress) || visitorIpAddress.Trim() == "::1") { getLan = true; visitorIpAddress = string.Empty; } if (getLan && string.IsNullOrEmpty(visitorIpAddress)) { //This is for Local(LAN) Connected ID Address string stringHostName = Dns.GetHostName(); //Get Ip Host Entry IPHostEntry ipHostEntries = Dns.GetHostEntry(stringHostName); ipHostEntries = System.Net.Dns.GetHostEntry(Request.ServerVariables["REMOTE_HOST"]); //Get Ip Address From The Ip Host Entry Address List IPAddress[] arrIpAddress = ipHostEntries.AddressList; try { visitorIpAddress = arrIpAddress[arrIpAddress.Length - 2].ToString(); } catch { try { visitorIpAddress = arrIpAddress[0].ToString(); } catch { try { arrIpAddress = Dns.GetHostAddresses(stringHostName); visitorIpAddress = arrIpAddress[0].ToString(); } catch { visitorIpAddress = "127.0.0.1"; } } } } //////////////////////////////////// _securityFactory = new SecurityFactorys(); _userInformationFactory = new UserFactory(); _employeeFactory = new EmployeeFactory(); model.UserName = model.UserName.ToLower().Trim(); var logInStatus = _securityFactory.CheckLogIn(new LogOnModel { CompanyID = model.CompanyID, BranchID = model.BranchID, UserName = model.UserName, Password = model.Password }); if (logInStatus.IsAllowed) { var aSecurityUser = _userInformationFactory.FindBy(x => x.UserName.Contains(model.UserName)).FirstOrDefault(); var aCompanyUser = _employeeFactory.FindBy(x => x.EmployeeID == aSecurityUser.EmployeeID).FirstOrDefault(); if (aSecurityUser != null) { System.Web.HttpContext.Current.Session["LoginEmployee"] = aSecurityUser.EmployeeID; System.Web.HttpContext.Current.Session["LoginCompanyID"] = aCompanyUser.CompanyID; System.Web.HttpContext.Current.Session["LoginBranchID"] = aCompanyUser.BranchID; System.Web.HttpContext.Current.Session["LoginUserID"] = aSecurityUser.ID; System.Web.HttpContext.Current.Session["LoginUserName"] = aSecurityUser.UserName; System.Web.HttpContext.Current.Session["LoginUserFullName"] = aSecurityUser.Employee.EmpName; System.Web.HttpContext.Current.Session["UserGroupID"] = aSecurityUser.UserGroupID; System.Web.HttpContext.Current.Session["IPAddress"] = visitorIpAddress; System.Web.HttpContext.Current.Session["LoginPhoto"] = GetLoginPhoto(aSecurityUser.EmployeeID); string[] computerName = null; //try //{ // computerName = Dns.GetHostEntry(Request.ServerVariables["REMOTE_ADDR"]).HostName.Split(new Char[] { '.' }); //} //catch (Exception) //{ //} if (computerName != null) { System.Web.HttpContext.Current.Session["PCName"] = computerName[0]; } else { System.Web.HttpContext.Current.Session["PCName"] = "N/A"; } if (!String.IsNullOrEmpty(model.UserName)) { if (!aSecurityUser.UserName.Equals(model.UserName, StringComparison.Ordinal)) { return(Json(new { success = false, message = "Incorrect User Name or Password." }, JsonRequestBehavior.AllowGet)); } } else { System.Web.HttpContext.Current.Session["LoginUserID"] = 0; } if (!logInStatus.IsAllowed) { return(Json(new { success = false, message = logInStatus.Message }, JsonRequestBehavior.AllowGet)); } //if (String.IsNullOrEmpty(model.UserName)) throw new ArgumentException("Value cannot be null or empty.", "userName"); //FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe); SEC_LoginStatus tblLogInStatus = new SEC_LoginStatus(); _loginStatusFactory = new LoginStatusFactory(); tblLogInStatus.UserID = aSecurityUser.ID; tblLogInStatus.PresentLogInStatus = true; tblLogInStatus.LogInTime = DateTime.Now; tblLogInStatus.LogOutTime = DateTime.Now; tblLogInStatus.ForcedLogOutStatus = false; _loginStatusFactory.Add(tblLogInStatus); _loginStatusFactory.Save(); Session["logInSession"] = "true"; return(Json(new { success = true, message = "Success" }, JsonRequestBehavior.AllowGet)); // } return(Json(new { success = false, message = "The user name or password provided is incorrect." }, JsonRequestBehavior.AllowGet)); } return(Json(new { success = false, message = logInStatus.Message }, JsonRequestBehavior.AllowGet)); } return(Json(new { success = false, message = "The user name or password provided is incorrect." }, JsonRequestBehavior.AllowGet)); } catch (Exception e) { //Route(); return(Json(new { success = false, message = e.Message }, JsonRequestBehavior.AllowGet)); } //return Json(new { success = false, message = "The user name or password provided is incorrect. 4" }, JsonRequestBehavior.AllowGet); }
/// <summary> /// 构造函数。 /// </summary> public SecurityFactoryProviderService() { this.factory = new SecurityFactoryProvider(); }
public WebSocketHostListener(IPEndPoint address, ISecurityFactory securityFactory, bool reuseAddressFlag, int maxAmountOfConnections) : base(address, securityFactory, reuseAddressFlag, maxAmountOfConnections) { }
/// <summary> /// 构造函数。 /// </summary> public UserPickerEntity() { this.orgFactory = ModuleConfiguration.ModuleConfig.OrgFacotry; this.securityFacotry = ModuleConfiguration.ModuleConfig.SecurityFactory; }
public WebSocketOutputConnector(string inputConnectorAddress, string outputConnectorAddress, IProtocolFormatter protocolFormatter, ISecurityFactory clientSecurityFactory, int connectTimeout, int sendTimeout, int receiveTimeout, int pingFrequency, int responseReceivingPort) { using (EneterTrace.Entering()) { Uri aUri; try { aUri = new Uri(inputConnectorAddress, UriKind.Absolute); } catch (Exception err) { EneterTrace.Error(inputConnectorAddress + ErrorHandler.InvalidUriAddress, err); throw; } myClient = new WebSocketClient(aUri, clientSecurityFactory); myClient.ResponseReceivingPort = responseReceivingPort; myOutputConnectorAddress = outputConnectorAddress; myProtocolFormatter = protocolFormatter; myClient.ConnectTimeout = connectTimeout; myClient.SendTimeout = sendTimeout; myClient.ReceiveTimeout = receiveTimeout; myPingFrequency = pingFrequency; myTimer = new Timer(OnPing, null, -1, -1); } }