public BaseService() { string token = this.GetToken(); if (!string.IsNullOrEmpty(token)) { try { //检查令牌,这里需要动态调用服务 //节点中心安全检查服务 //string FrameNodeSecurityService = this.GetNodeBaseAddr(this.GetNodeCenterAddr(), ServiceType.NodeCenter) + // APPConfig.GetAPPConfig().GetConfigValue(SSY_ServiceHost.FrameNodeSecurityService, "").TrimStart('/'); DataRow drServ = this.GetServiceConfigOne("framenodesecu", "1.0", "normal", "frameNode", this.serviceConfig); //string FrameNodeSecurityService = base.envirObj.BizNodeAddr + "/" + drServ["servcodename"].ToString().TrimStart('/'); string FrameNodeSecurityService = drServ["url_addr"].ToString().TrimStart('/') + "/" + drServ["servcodename"].ToString().TrimStart('/'); //初始化完整框架环境 base.GetAllSysEnvironment(); SSY_DYNAMICTOKEN tokenModel = new SSY_DYNAMICTOKEN(); tokenModel.Dynamictoken = envirObj.TokenEncrpValue; this.reqdata = new ReqData(); this.reqdata.reqdata = json.Serialize(tokenModel); //检查令牌 string resCheckToken = DynamicInvokeWCF.Create <IFrameNodeSecurity>(FrameNodeSecurityService).CheckToken(json.Serialize(this.reqdata)); this.resdata = json.Deserialize <RespData>(resCheckToken); if (this.resdata.respflag == "0") { throw new Exception(this.resdata.resptoolstr); } } catch (Exception ex) { throw new Exception(this.GetI18nLangItem("ana2CheckTokenErr", this.i18nCommonCurrLang) + ex.Message); } } else { throw new Exception(this.GetI18nLangItem("noFindTokenErr", this.i18nCommonCurrLang)); } }
/// <summary> /// 装载数据节点 /// </summary> /// <returns></returns> public DistributeDataNodeManagerParams GetDistributeDataNodeManagerParams() { DistributeDataNodeManagerParams distManagerParam = new DistributeDataNodeManagerParams(); //分布式管理参数 //调用节点中心服务获取数据节点 DataRow drServ = this.GetServiceConfigOne("framenodesecu", "1.0", "normal", "frameNode", this.serviceConfig); string FramenodeSecurity = drServ["url_addr"].ToString().TrimStart('/') + "/" + drServ["servcodename"].ToString().TrimStart('/'); this.reqdata = new ReqData(); this.reqdata.reqdata = "1"; string resdatanode = DynamicInvokeWCF.Create <IFrameNodeSecurity>(FramenodeSecurity).GetDataNodeCollection(json.Serialize(this.reqdata)); this.resdata = json.Deserialize <RespData>(resdatanode); if (this.resdata.respflag == "1") { distManagerParam = json.Deserialize <DistributeDataNodeManagerParams>(this.resdata.respdata); } return(distManagerParam); }
/// <summary> /// 报告节点异常,包括节点中心服务、业务节点服务、业务节点数据库 /// </summary> /// <param name="servType"></param> /// <param name="node_addr"></param> /// <param name="errStr"></param> private void ReportNodeError(ServiceType servType, string node_addr, string errStr) { //报告节点异常 string FrameManagerNodeService = this.GetNodeBaseAddr(this.GetNodeCenterAddr(), servType) + APPConfig.GetAPPConfig().GetConfigValue(SSY_ServiceHost.FrameManagerNodeService, "").TrimStart('/'); List <SSY_NODE_ERRORS> model = new List <SSY_NODE_ERRORS>(); SSY_NODE_ERRORS modelOne = new SSY_NODE_ERRORS(); string timestr = DateTime.Now.ToString("yyyyMMddHHmmss"); modelOne.ID = timestr + Utility.GetRandNum(3); modelOne.Node_typs = servType.ToString(); modelOne.Url_addr = node_addr; modelOne.Error_desc = errStr; modelOne.Remarks = ""; modelOne.Timestampss = timestr; model.Add(modelOne); //报告节点异常 var res = DynamicInvokeWCF.Create <IFrameManagerNode>(FrameManagerNodeService).RecordNodeErrorLogN(this.json.Serialize(model)); }
/// <summary> /// 获取用户信息 /// </summary> /// <param name="model"></param> /// <returns></returns>d public string GetUserForLoginN(string req) { try { //解析参数实体 reqdata = this.AnaRequestData(req); SSY_USER_DICT model = this.json.Deserialize <SSY_USER_DICT>(reqdata.reqdata); StringBuilder toolStr = new StringBuilder(); //准备日志参数实例 List <SSY_LOGENTITY> ListBizLog = new List <SSY_LOGENTITY>(); if (model.USERID.ToString().ToUpper() == "super".ToUpper()) { base.envirObj.distManagerParam.DistributeActionIden = DistributeActionIden.Query; } else { base.envirObj.distManagerParam.DistributeActionIden = DistributeActionIden.TransAction; } //this.permitMaxLoginFailtCnt = APPConfig.GetAPPConfig().GetConfigValue("permitMaxLoginFailtCnt", "5"); //允许最大错误登录次数, 默认5次 //解密口令, 客户端已经加密,这里无需解密,直接比较密码串 //string iv128str = APPConfig.GetAPPConfig().GetConfigValue("ivpwd", "5CRc851hRywf7W3m"); //string key256str = APPConfig.GetAPPConfig().GetConfigValue("keypwd", "nW8FnftasWp7AVZrmgr9sdaGNXsjMWiw"); //byte[] key256 = Security.CreateKeyByte(key256str); //byte[] iv128 = Security.CreateKeyByte(iv128str); //model.PASSWORD = Security.DeAES(model.PASSWORD.ToString(), key256, iv128); List <SSY_USER_DICT> uds = this._comBiz.GetUserForLogin(model, base.envirObj.distManagerParam, ListBizLog); if (uds.Count > 0) { if (model.PASSWORD.ToString() == uds[0].PASSWORD.ToString()) { if (uds[0].ISUSE.ToString() == "0") { //判断是否禁用 resdata = this.MakeResponseData("0", this.GetI18nLangItem("loginerr_Enabled", this.i18nModuleCurrLang), string.Empty, string.Empty); } else if (uds[0].LOCKED.ToString() == "1") { //判断是否锁定 resdata = this.MakeResponseData("0", this.GetI18nLangItem("loginerr_Locked", this.i18nModuleCurrLang), string.Empty, string.Empty); } else { #region 允许登录后,正常验证处理 //判断是否登录 bool alreadyLonin = false; if (Utility.ObjHasData(uds[0].ISLONIN) && Utility.ObjHasData(uds[0].FROMPLAT)) { if (uds[0].ISLONIN == "Y" && uds[0].FROMPLAT.ToUpper() == base.envirObj.distManagerParam.DistributeDataNodes[0].Systemname.ToUpper()) { alreadyLonin = true; } } if (alreadyLonin) { //检查密码安全补存提示信息 //resdata = BaseWebPage.MakeResponseData("0", string.Format(BaseUI.GetNoticeCfg("com0008", "CommonNoticeCfg"), uds[0].FROMPLAT.ToUpper()), string.Empty); resdata = this.MakeResponseData("0", this.GetI18nLangItem("loginok_exist", this.i18nModuleCurrLang), string.Empty, string.Empty); } else { //检查是否启用密码安全策略 检查首次登陆 检查超过时间间隔 if (base.envirObj.distManagerParam.DistributeDataNodes[0].Isusepwdsecuritycheck == "Y") { if (base.envirObj.distManagerParam.DistributeDataNodes[0].Pwdfirstcheck == "Y" && uds[0].ISFIRSTLOGIN == "Y") { //首次登陆提示 toolStr.AppendLine(this.GetI18nLangItem("loginok_firstlogin", this.i18nModuleCurrLang)); } //这里取服务器时间即可 //Frame.ServiceLibs.FrameManagerService tmpop = new FrameManagerService(); //string currTime = string.Empty; //currTime = tmpop.GetSystemDateTimesN(string.Empty); string currTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); if ((!string.IsNullOrEmpty(currTime)) && (!string.IsNullOrEmpty(uds[0].LASTLOGINTIME.ToString()))) { TimeSpan ts = Convert.ToDateTime(currTime) - Convert.ToDateTime(uds[0].LASTLOGINTIME.ToString()); if (ts.TotalHours >= int.Parse(base.envirObj.distManagerParam.DistributeDataNodes[0].Pwdintervalhours)) { //超过时间提示 toolStr.AppendLine(string.Format(this.GetI18nLangItem("loginok_oversecuritytime", this.i18nModuleCurrLang), base.envirObj.distManagerParam.DistributeDataNodes[0].Pwdintervalhours)); } } } #region 获取令牌 //节点中心安全服务 //string FrameNodeSecurity = APPConfig.GetAPPConfig().GetConfigValue("NodeCenterMaster", "") + // APPConfig.GetAPPConfig().GetConfigValue(SSY_ServiceHost.FrameNodeSecurityService, "").TrimStart('/'); //调用普通节点中心服务获取令牌 DataRow drServ = this.GetServiceConfigOne("framenodesecu", "1.0", "normal", "frameNode", this.serviceConfig); //string FrameNodeSecurity = base.envirObj.BizNodeAddr + "/" + drServ["servcodename"].ToString().TrimStart('/'); string FrameNodeSecurity = drServ["url_addr"].ToString().TrimStart('/') + "/" + drServ["servcodename"].ToString().TrimStart('/'); SSY_DYNAMICTOKEN tokenModel = new SSY_DYNAMICTOKEN(); tokenModel.Dynamictoken = ""; tokenModel.ID = ""; tokenModel.Remarks = model.USERID.ToString(); //暂存用户账户,用于节点中心获取令牌时重新验证 tokenModel.Timestampss = model.PASSWORD.ToString(); //暂存用户口令,用于节点中心获取令牌时重新验证 this.reqdata = new ReqData(); this.reqdata.reqdata = json.Serialize(tokenModel); //动态调用服务获取令牌 string tokenstr = DynamicInvokeWCF.Create <IFrameNodeSecurity>(FrameNodeSecurity).GetToken(this.json.Serialize(this.reqdata)); //返回执行结果 if (string.IsNullOrEmpty(tokenstr)) { resdata = this.MakeResponseData("0", this.GetI18nLangItem("loginok_notoken", this.i18nModuleCurrLang), string.Empty, string.Empty); } else { //解析令牌 RespData tmpToken = json.Deserialize <RespData>(tokenstr); if (tmpToken.respflag == "1") { //赋值当前登录用户数据 base.envirObj.SysUserDict = uds[0]; RespData tmpresdata = json.Deserialize <RespData>(tokenstr); //直接返回环境参数,去除口令和数据节点 base.envirObj.TokenEncrpValue = tmpresdata.respdata; SysEnvironmentSerialize resTmp = new SysEnvironmentSerialize(); resTmp = json.Deserialize <SysEnvironmentSerialize>(json.Serialize(base.envirObj)); resTmp.SysUserDict.PASSWORD = ""; //不返回密码 resTmp.distManagerParam = null; //不返回数据节点 //赋值用户数据到框架环境变量 ManagerSysEnvironment.GetSysEnvironmentSerialize2SysEnvironment(base.envirObj); if (string.IsNullOrEmpty(toolStr.ToString())) { resdata = this.MakeResponseData("1", this.GetI18nLangItem("loginok", this.i18nModuleCurrLang), json.Serialize(resTmp), string.Empty); } else { resdata = this.MakeResponseData("2", this.GetI18nLangItem("loginok", this.i18nModuleCurrLang), json.Serialize(resTmp), string.Empty); } } else { resdata = this.MakeResponseData("0", this.GetI18nLangItem("loginok_gettokenerr", this.i18nModuleCurrLang), string.Empty, string.Empty); } } #endregion } #endregion } } else { resdata = this.MakeResponseData("0", this.GetI18nLangItem("loginerr_userNotPassword", this.i18nModuleCurrLang), string.Empty, string.Empty); } } else { resdata = this.MakeResponseData("0", this.GetI18nLangItem("loginerr_nocurruser", this.i18nModuleCurrLang), string.Empty, string.Empty); } } catch (Exception ex) { resdata = this.MakeResponseData("0", this.GetI18nLangItem("loginerr_findexception", this.i18nModuleCurrLang) + ex.Message, string.Empty, string.Empty); } return(json.Serialize(resdata)); }
/// <summary> /// 启动更新数据缓存 /// </summary> /// <param name="obj"></param> public void ExecUpdateCacheData(object obj) { System.Web.Caching.Cache currCache = HttpRuntime.Cache; int cacheMinute = 50; //加载缓存服务配置 DataTable dtservconfig = BaseServiceUtility.GetServiceConfig(APPConfig.GetAPPConfig().GetConfigValue("ServiceConfigPath", "")); currCache.Insert("serviceConfig", dtservconfig, null, System.Web.Caching.Cache.NoAbsoluteExpiration, new TimeSpan(0, cacheMinute, 0)); //缓存默认公共语言包 string defaultlang = APPConfig.GetAPPConfig().GetConfigValue("currlang", ""); string commoni18nLangPath = string.Format(APPConfig.GetAPPConfig().GetConfigValue("Commoni18nLang", ""), defaultlang); DataTable i18nCommonCurrLang = BaseServiceUtility.GetI18nLang(commoni18nLangPath); currCache.Insert("i18nCommonCurrLang", i18nCommonCurrLang, null, System.Web.Caching.Cache.NoAbsoluteExpiration, new TimeSpan(0, cacheMinute, 0)); //当前模块语言包 string Xxxi18nLang = string.Format(this.baseXmlPath + APPConfig.GetAPPConfig().GetConfigValue("XxxManageri18nLang", ""), defaultlang); DataTable i18nXxxi18nLang = BaseServiceUtility.GetI18nLang(Xxxi18nLang); currCache.Insert("i18nXxxi18nLang", i18nXxxi18nLang, null, System.Web.Caching.Cache.NoAbsoluteExpiration, new TimeSpan(0, cacheMinute, 0)); //加载缓存数据节点 //调用普通节点中心服务加载数据节点 DataRow drServ = BaseServiceUtility.GetServiceConfigOne("framenodesecu", "1.0", "normal", "frameNode", dtservconfig); string FrameNodeSecurity = drServ["url_addr"].ToString().TrimStart('/') + "/" + drServ["servcodename"].ToString().TrimStart('/'); JavaScriptSerializer json = new JavaScriptSerializer(); ReqData reqdata = new ReqData(); reqdata.reqdata = "1"; RespData resdata = new RespData(); //获取节点中心数据节点, string datanodes = DynamicInvokeWCF.Create <IFrameNodeSecurity>(FrameNodeSecurity).GetDataNodeCollection(json.Serialize(reqdata)); DistributeDataNodeManagerParams distManagerParam = new DistributeDataNodeManagerParams(); //分布式管理参数 resdata = json.Deserialize <RespData>(datanodes); if (resdata.respflag == "1") { distManagerParam = json.Deserialize <DistributeDataNodeManagerParams>(resdata.respdata); if (distManagerParam.DistributeDataNodes.Count > 0) { currCache.Insert("dataNodes", distManagerParam, null, System.Web.Caching.Cache.NoAbsoluteExpiration, new TimeSpan(0, cacheMinute, 0)); } } //获取业务模块节点 string nodelists = DynamicInvokeWCF.Create <IFrameNodeSecurity>(FrameNodeSecurity).GetNodeCollection(json.Serialize(reqdata)); UseNodeCollection nodes = new UseNodeCollection(); //节点集合 resdata = json.Deserialize <RespData>(nodelists); if (resdata.respflag == "1") { nodes = json.Deserialize <UseNodeCollection>(resdata.respdata); if (nodes.BizNodeList.Count > 0) { currCache.Insert("bizNodes", nodes.BizNodeList, null, System.Web.Caching.Cache.NoAbsoluteExpiration, new TimeSpan(0, cacheMinute, 0)); } } Common.Utility.RecordLog("完成Somebiz模块配置缓存!", this.logpathForDebug, this.isLogpathForDebug); }
/// <summary> /// 启动更新数据缓存 /// </summary> /// <param name="obj"></param> public void ExecUpdateCacheData() { System.Web.Caching.Cache currCache = HttpRuntime.Cache; int cacheMinute = 50; bool executeFlag = true; while (executeFlag) { executeFlag = false; try { #region 缓存处理 //加载缓存服务配置 DataTable dtservconfig = BaseServiceUtility.GetServiceConfig(APPConfig.GetAPPConfig().GetConfigValue("ServiceConfigPath", "")); currCache.Insert("serviceConfig", dtservconfig, null, System.Web.Caching.Cache.NoAbsoluteExpiration, new TimeSpan(0, cacheMinute, 0)); //缓存默认公共语言包 string defaultlang = APPConfig.GetAPPConfig().GetConfigValue("currlang", ""); string commoni18nLangPath = string.Format(APPConfig.GetAPPConfig().GetConfigValue("Commoni18nLang", ""), defaultlang); DataTable i18nCommonCurrLang = BaseServiceUtility.GetI18nLang(commoni18nLangPath); currCache.Insert("i18nCommonCurrLang", i18nCommonCurrLang, null, System.Web.Caching.Cache.NoAbsoluteExpiration, new TimeSpan(0, cacheMinute, 0)); //缓存默认各模块语言包,多个模块独立累加 //框架安全语言包 string FrameSecurityi18nLang = string.Format(APPConfig.GetAPPConfig().GetConfigValue("FrameSecurityi18nLang", ""), defaultlang); DataTable i18nFrameSecurityi18nLang = BaseServiceUtility.GetI18nLang(FrameSecurityi18nLang); currCache.Insert("i18nFrameSecurityi18nLang", i18nFrameSecurityi18nLang, null, System.Web.Caching.Cache.NoAbsoluteExpiration, new TimeSpan(0, cacheMinute, 0)); //框架管理语言包 string FrameManageri18nLang = string.Format(APPConfig.GetAPPConfig().GetConfigValue("FrameManageri18nLang", ""), defaultlang); DataTable i18nFrameManageri18nLang = BaseServiceUtility.GetI18nLang(FrameManageri18nLang); currCache.Insert("i18nFrameManageri18nLang", i18nFrameManageri18nLang, null, System.Web.Caching.Cache.NoAbsoluteExpiration, new TimeSpan(0, cacheMinute, 0)); //加载缓存数据节点 //调用普通节点中心服务加载数据节点 DataRow drServ = BaseServiceUtility.GetServiceConfigOne("framenodesecu", "1.0", "normal", "frameNode", dtservconfig); string FrameNodeSecurity = drServ["url_addr"].ToString().TrimStart('/') + "/" + drServ["servcodename"].ToString().TrimStart('/'); JavaScriptSerializer json = new JavaScriptSerializer(); ReqData reqdata = new ReqData(); reqdata.reqdata = "1"; RespData resdata = new RespData(); //获取节点中心数据节点, string datanodes = DynamicInvokeWCF.Create <IFrameNodeSecurity>(FrameNodeSecurity).GetDataNodeCollection(json.Serialize(reqdata)); DistributeDataNodeManagerParams distManagerParam = new DistributeDataNodeManagerParams(); //分布式管理参数 resdata = json.Deserialize <RespData>(datanodes); if (resdata.respflag == "1") { distManagerParam = json.Deserialize <DistributeDataNodeManagerParams>(resdata.respdata); if (distManagerParam.DistributeDataNodes.Count > 0) { currCache.Insert("dataNodes", distManagerParam, null, System.Web.Caching.Cache.NoAbsoluteExpiration, new TimeSpan(0, cacheMinute, 0)); } } //获取业务模块节点 string nodelists = DynamicInvokeWCF.Create <IFrameNodeSecurity>(FrameNodeSecurity).GetNodeCollection(json.Serialize(reqdata)); UseNodeCollection nodes = new UseNodeCollection(); //节点集合 resdata = json.Deserialize <RespData>(nodelists); if (resdata.respflag == "1") { nodes = json.Deserialize <UseNodeCollection>(resdata.respdata); if (nodes.BizNodeList.Count > 0) { currCache.Insert("bizNodes", nodes.BizNodeList, null, System.Web.Caching.Cache.NoAbsoluteExpiration, new TimeSpan(0, cacheMinute, 0)); } } Common.Utility.RecordLog("完成框架管理配置缓存!", this.logpathForDebug, this.isLogpathForDebug); #endregion } catch (Exception ex) { Common.Utility.RecordLog("配置框架管理缓存,发生异常!原因:" + ex.Message, this.logpathForDebug, this.isLogpathForDebug); } Thread.Sleep(this.internalTime * 60000);//延迟秒级别 executeFlag = true; } }
/// <summary> /// 获取令牌 /// </summary> /// <param name="req"></param> /// <returns></returns> public string GetToken(string req) { try { //解析参数实体 reqdata = this.AnaRequestData(req); SSY_DYNAMICTOKEN model = this.json.Deserialize <SSY_DYNAMICTOKEN>(reqdata.reqdata); string bizErrStr = ""; //具体失败的业务提示 string FrameSecurity = ""; //获取业务可用节点 UseNodeCollection unc = new UseNodeCollection(); SSY_ResponseResult <UseNodeCollection> res = this.GetUseNodeCollection("1"); if (res.IsCompleted) { unc = res.Result; //获取业务节点地址 List <string> bizNodes = new List <string>(); for (int i = 0; i < unc.BizNodeList.Count; i++) { bizNodes.Add(unc.BizNodeList[i].Url_addr); } //获取业务服务 //string bizSvcName = this._GetSingleBizSvc(SSY_ServiceHost.Frame_FrameSecurityService); //FrameSecurity = this.GetNodeBaseAddr(bizNodes, ServiceType.BizDueWith) + bizSvcName.TrimStart('/'); //调用普通登陆验证服务 DataRow drServ = this.GetServiceConfigOne("framesecurity", "1.0", "normal", "frameMgt", this.serviceConfig); //FrameSecurity = base.envirObj.BizNodeAddr + "/" + drServ["servcodename"].ToString().TrimStart('/'); //获取本地配置业务节点 List <SSY_BIZNODE_ADDR> tmpBizNode = base.json.Deserialize <List <SSY_BIZNODE_ADDR> >(this._GetBizNodeAddr()); for (int i = 0; i < tmpBizNode.Count; i++) { if (tmpBizNode[i].Moudiden.ToUpper() == "FrameMgt".ToUpper()) { FrameSecurity = tmpBizNode[i].Url_addr + "/" + drServ["servcodename"].ToString().TrimStart('/'); break; } } //二次登陆验证 SSY_USER_DICT ud = new SSY_USER_DICT(); ud.USERID = model.Remarks; ud.PASSWORD = model.Timestampss; this.reqdata = new ReqData(); this.reqdata.reqdata = json.Serialize(ud); string reslogin = DynamicInvokeWCF.Create <IFrameSecurity>(FrameSecurity).GetUserForLogin2N(json.Serialize(this.reqdata)); List <SSY_USER_DICT> resuds = new List <SSY_USER_DICT>(); this.resdata = json.Deserialize <RespData>(reslogin); if (this.resdata.respflag == "1") { #region 登陆成功 string cols = "id|dynamictoken|remarks|timestampss"; string colTypes = "String|String|String|String"; string tokenFilePath = APPConfig.GetAPPConfig().GetConfigValue("XmldataPath", "") + "\\SSY_DYNAMICTOKEN.xml"; System.Data.DataTable dtToken = Common.Utility.GetTableFromXml(cols, colTypes, tokenFilePath); if (Utility.DtHasData(dtToken)) { //随机获取令牌 model.Dynamictoken = dtToken.Rows[Utility.GetRandNum(1, 99)]["dynamictoken"].ToString(); if (string.IsNullOrEmpty(model.Dynamictoken)) { bizErrStr = this.GetI18nLangItem("noFoundTokenText", this.i18nModuleCurrLang); } else { resdata = this.MakeResponseData("1", base.successStr, model.Dynamictoken, string.Empty); } } else { bizErrStr = this.GetI18nLangItem("noFoundTokens", this.i18nModuleCurrLang); } #endregion } else { bizErrStr = this.resdata.resptoolstr; } } else { bizErrStr = res.Exception; } if (!string.IsNullOrEmpty(bizErrStr)) { resdata = this.MakeResponseData("0", base.errorStr + bizErrStr, string.Empty, string.Empty); } } catch (Exception ex) { resdata = this.MakeResponseData("0", this.GetI18nLangItem("GetTokenErr", this.i18nModuleCurrLang) + ex.Message, string.Empty, string.Empty); } return(json.Serialize(resdata)); }