/// <summary> /// 保持SignInInfo信息 /// </summary> /// <param name="signInInfo">SignInInfo信息</param> /// <remarks> /// <code source="..\Framework\TestProjects\DeluxeWorks.Library.Passport.Test\DataObjectsTest.cs" region="SignInInfoPersistTest" lang="cs" title="保存SignInInfo对象" /> /// </remarks> public void SaveSignInInfo(ISignInInfo signInInfo) { ORMappingItemCollection mapping = LoadMappingFromResource("MCS.Library.Passport.DataObjects.SignInInfoMapping.xml", typeof(ISignInInfo)); string sql = string.Format("UPDATE PASSPORT_SIGNIN_INFO SET {0} WHERE {1}", ORMapping.GetUpdateSqlClauseBuilder(signInInfo, mapping).ToSqlString(TSqlBuilder.Instance), ORMapping.GetWhereSqlClauseBuilderByPrimaryKey(signInInfo, mapping).ToSqlString(TSqlBuilder.Instance)); using (TransactionScope scope = TransactionScopeFactory.Create()) { using (DbContext context = DbContext.GetContext(DataAdapter.DBConnectionName)) { Database db = DatabaseFactory.Create(DataAdapter.DBConnectionName); if (db.ExecuteNonQuery(CommandType.Text, sql) == 0) { sql = string.Format("INSERT INTO PASSPORT_SIGNIN_INFO {0}", ORMapping.GetInsertSqlClauseBuilder(signInInfo, mapping).ToSqlString(TSqlBuilder.Instance)); db.ExecuteNonQuery(CommandType.Text, sql); } } scope.Complete(); } }
/// <summary> /// 生成Ticket的字符串 /// </summary> /// <param name="signInInfo">登录信息</param> /// <param name="strIP">客户端ip</param> /// <returns>Ticket的字符串</returns> public static string GenerateTicketString(ISignInInfo signInInfo, string strIP) { HttpContext context = HttpContext.Current; HttpRequest request = context.Request; XmlDocument xmlDoc = XmlHelper.CreateDomDocument("<Ticket/>"); XmlDocument xmlSignInInfo = signInInfo.SaveToXml(); XmlNode SignInNode = XmlHelper.AppendNode(xmlDoc.DocumentElement, "SignInInfo"); SignInNode.InnerXml = xmlSignInInfo.DocumentElement.InnerXml; string strTimeout = request.QueryString["to"]; int nTimeout = -1; if (strTimeout != null) { try { nTimeout = int.Parse(strTimeout); } catch (System.Exception) { } } else { nTimeout = (int)(PassportSignInSettings.GetConfig().DefaultTimeout.TotalSeconds); } string strAppID = request.QueryString["aid"]; XmlHelper.AppendNode(xmlDoc.DocumentElement, "AppSSID", Guid.NewGuid().ToString()); XmlHelper.AppendNode(xmlDoc.DocumentElement, "AppID", strAppID); XmlHelper.AppendNode(xmlDoc.DocumentElement, "AppSTime", DateTimeStandardFormat(SNTPClient.AdjustedTime)); XmlHelper.AppendNode(xmlDoc.DocumentElement, "IP", strIP); DateTime dtExpireTime = DateTime.MaxValue; if (nTimeout >= 0) { dtExpireTime = SNTPClient.AdjustedTime.AddSeconds(nTimeout); } else if (nTimeout < -1) { dtExpireTime = DateTime.MinValue; } else if (nTimeout == -1) { dtExpireTime = DateTime.MaxValue; } XmlHelper.AppendNode(xmlDoc.DocumentElement, "AppSTimeout", DateTimeStandardFormat(dtExpireTime)); return(xmlDoc.OuterXml); }
private void AdjustSignInTimeout(ISignInInfo signInInfo) { if (PassportSignInSettings.GetConfig().HasSlidingExpiration) { signInInfo.SignInTime = SNTPClient.AdjustedTime; } }
private void AdjustSignInTimeout(ISignInInfo signInInfo) { if (PassportSignInSettings.GetConfig().HasSlidingExpiration) { signInInfo.SignInTime = DateTime.Now; } }
private static string PrepareTicket() { ISignInInfo signInInfo = SignInInfo.Create("SinoOceanLand\\liumh"); ITicket ticket = Ticket.Create(signInInfo); return(ticket.ToEncryptString()); }
internal SignInContext(SignInResultType resultType, string userID, ISignInInfo signInInfo, SignInPageData pageData, string clientInfo, System.Exception ex) { this.resultType = resultType; this.userID = userID; this.signInInfo = signInInfo; this.pageData = pageData; this.exception = ex; this.clientInfo = new SignInClientInfo(clientInfo); }
private bool IsSignInInfoInvalid(ISignInInfo signInInfo) { bool invalid = true; if (signInInfo != null) { invalid = signInInfo.IsValid() == false; } return(invalid); }
private ITicket GenerateTicket(ISignInInfo signInInfo) { HttpRequest request = HttpContext.Current.Request; string strIP = request.QueryString["ip"]; if (strIP == null || strIP == string.Empty) { strIP = request.UserHostAddress; } return(new Ticket(Common.GenerateTicketString(signInInfo, strIP))); }
/// <summary> /// 如果登录信息依然有效,可以自动转到应用页面 /// </summary> /// <param name="signInInfo">登录信息</param> private void AutoSignIn(ISignInInfo signInInfo) { #if DELUXEWORKSTEST Debug.WriteLine("Timeout Datetime: " + signInInfo.SignInTimeout.ToString("yyyy-MM-dd HH:mm:ss"), "SignInPage Check"); #endif if (IsSignInInfoInvalid(signInInfo) == false) { AdjustSignInTimeout(signInInfo); PassportSignInSettings.GetConfig().PersistSignInInfo.SaveSignInInfo(signInInfo); signInInfo.SaveToCookie(); RedirectToAppUrl(GenerateTicket(signInInfo)); } }
private SignInContext DoPostAuthenticateOP(ISignInInfo signInInfo) { SignInContext result = new SignInContext( SignInResultType.Success, signInInfo.UserID, signInInfo, CollectPageData(), (string)PassportWebControlHelper.GetControlValue(this.TemplateControl, "clientEnv", "Value", string.Empty), null); OnSignInComplete(result); PassportSignInSettings.GetConfig().PersistSignInInfo.SaveSignInInfo(signInInfo); signInInfo.SaveToCookie(); return(result); }
/// <summary> /// 创建票据 /// </summary> /// <param name="signInInfo"></param> /// <param name="clientIP"></param> /// <returns></returns> public static ITicket Create(ISignInInfo signInInfo, string clientIP) { signInInfo.NullCheck("signInInfo"); string strIP = clientIP; if (string.IsNullOrEmpty(strIP)) { if (HttpContext.Current != null) { HttpRequest request = HttpContext.Current.Request; strIP = request.UserHostAddress; } } return(new Ticket(Common.GenerateTicketString(signInInfo, strIP))); }
/// <summary> /// 判断SignInInfo状态,如果在SignInInfo合法情况下,基于Session的Cookie,或者用户选择自动登录的进行自动登录。 /// </summary> private void Initialize() { Control signInBtn = PassportWebControlHelper.FindControlRecursively(this.TemplateControl, "SignInButton"); if (signInBtn != null && signInBtn is IButtonControl) { ((IButtonControl)signInBtn).Click += new EventHandler(SignInButton_Click); } if (Page.IsPostBack == false) { //从Cookie中得到登录信息 ISignInInfo signInInfo = SignInInfo.LoadFromCookie(); if (signInInfo != null) { Trace.WriteLine(string.Format("认证服务,从cookie中得到用户{0}的认证信息", signInInfo.UserID), "PassportSDK"); } this._PageData.LoadFromCookie(); PassportSignInSettings settings = PassportSignInSettings.GetConfig(); if (IsSignInInfoInvalid(signInInfo) == false) //SignIn Info非法 { if (settings.IsSessionBased || this.PageData.AutoSignIn) { if (IsSelfAuthenticate == false) { AutoSignIn(signInInfo); //May be execute Response.End when redirect to app's url } } } if (Page.IsPostBack == false) { InitForm(this.PageData); } Page.Response.Expires = 0; } }
private void InitFromXml(string strXml) { XmlDocument xmlDoc = XmlHelper.CreateDomDocument(strXml); XmlElement root = xmlDoc.DocumentElement; XmlNode nodeSignInInfo = root.SelectSingleNode("SignInInfo"); if (nodeSignInInfo != null) { this.signInInfo = new SignInInfo(nodeSignInInfo.OuterXml); } this.appSignInSessionID = XmlHelper.GetSingleNodeText(root, "AppSSID"); this.appID = XmlHelper.GetSingleNodeText(root, "AppID"); this.appSignInTime = XmlHelper.GetSingleNodeValue(root, "AppSTime", DateTime.MinValue); this.appSignInTimeout = XmlHelper.GetSingleNodeValue(root, "AppSTimeout", DateTime.MinValue); this.appSignInIP = XmlHelper.GetSingleNodeText(root, "IP"); }
private ITicket AuthenticateUser() { HttpRequest request = HttpContext.Current.Request; string strSignInName = (string)PassportWebControlHelper.GetControlValue(this.TemplateControl, "signInName", "Text", string.Empty); string strPassword = (string)PassportWebControlHelper.GetControlValue(this.TemplateControl, "password", "value", string.Empty); ISignInUserInfo userInfo = DefaultAuthenticate(strSignInName, strPassword); ISignInInfo signInInfo = SignInInfo.Create(userInfo, (bool)PassportWebControlHelper.GetControlValue(this.TemplateControl, "dontSaveUserName", "Checked", false), (bool)PassportWebControlHelper.GetControlValue(this.TemplateControl, "autoSignIn", "Checked", false)); SignInContext signInContext = DoPostAuthenticateOP(signInInfo); ITicket ticket = Ticket.Create(signInInfo, request.QueryString["ip"]); SaveFormStatus(signInContext.PageData); return(ticket); }
private void InitFromXml(string strXml) { XmlDocument xmlDoc = XmlHelper.CreateDomDocument(strXml); XmlElement root = xmlDoc.DocumentElement; XmlNode nodeSignInInfo = root.SelectSingleNode("SignInInfo"); if (nodeSignInInfo != null) this.signInInfo = new SignInInfo(nodeSignInInfo.OuterXml); this.appSignInSessionID = XmlHelper.GetSingleNodeText(root, "AppSSID"); this.appID = XmlHelper.GetSingleNodeText(root, "AppID"); this.appSignInTime = XmlHelper.GetSingleNodeValue(root, "AppSTime", DateTime.MinValue); this.appSignInTimeout = XmlHelper.GetSingleNodeValue(root, "AppSTimeout", DateTime.MinValue); this.appSignInIP = XmlHelper.GetSingleNodeText(root, "IP"); }
/// <summary> /// 生成Ticket的字符串 /// </summary> /// <param name="signInInfo">登录信息</param> /// <param name="strIP">客户端ip</param> /// <returns>Ticket的字符串</returns> public static string GenerateTicketString(ISignInInfo signInInfo, string strIP) { HttpContext context = HttpContext.Current; HttpRequest request = context.Request; XmlDocument xmlDoc = XmlHelper.CreateDomDocument("<Ticket/>"); XmlDocument xmlSignInInfo = signInInfo.SaveToXml(); XmlNode SignInNode = XmlHelper.AppendNode(xmlDoc.DocumentElement, "SignInInfo"); SignInNode.InnerXml = xmlSignInInfo.DocumentElement.InnerXml; string strTimeout = request.QueryString["to"]; int nTimeout = -1; if (strTimeout != null) { try { nTimeout = int.Parse(strTimeout); } catch (System.Exception) { } } else nTimeout = (int)(PassportSignInSettings.GetConfig().DefaultTimeout.TotalSeconds); string strAppID = request.QueryString["aid"]; XmlHelper.AppendNode(xmlDoc.DocumentElement, "AppSSID", Guid.NewGuid().ToString()); XmlHelper.AppendNode(xmlDoc.DocumentElement, "AppID", strAppID); XmlHelper.AppendNode(xmlDoc.DocumentElement, "AppSTime", DateTimeStandardFormat(DateTime.Now)); XmlHelper.AppendNode(xmlDoc.DocumentElement, "IP", strIP); DateTime dtExpireTime = DateTime.MaxValue; if (nTimeout >= 0) dtExpireTime = DateTime.Now.AddSeconds(nTimeout); else if (nTimeout < -1) dtExpireTime = DateTime.MinValue; else if (nTimeout == -1) dtExpireTime = DateTime.MaxValue; XmlHelper.AppendNode(xmlDoc.DocumentElement, "AppSTimeout", DateTimeStandardFormat(dtExpireTime)); return xmlDoc.OuterXml; }
/// <summary> /// 创建票据 /// </summary> /// <param name="signInInfo"></param> /// <returns></returns> public static ITicket Create(ISignInInfo signInInfo) { return Create(signInInfo, string.Empty); }
/// <summary> /// 创建票据 /// </summary> /// <param name="signInInfo"></param> /// <returns></returns> public static ITicket Create(ISignInInfo signInInfo) { return(Create(signInInfo, string.Empty)); }
/// <summary> /// 创建票据 /// </summary> /// <param name="signInInfo"></param> /// <param name="clientIP"></param> /// <returns></returns> public static ITicket Create(ISignInInfo signInInfo, string clientIP) { signInInfo.NullCheck("signInInfo"); string strIP = clientIP; if (string.IsNullOrEmpty(strIP)) { if (HttpContext.Current != null) { HttpRequest request = HttpContext.Current.Request; strIP = request.UserHostAddress; } } return new Ticket(Common.GenerateTicketString(signInInfo, strIP)); }