Пример #1
0
        /// <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();
            }
        }
Пример #2
0
        /// <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);
        }
Пример #3
0
 private void AdjustSignInTimeout(ISignInInfo signInInfo)
 {
     if (PassportSignInSettings.GetConfig().HasSlidingExpiration)
     {
         signInInfo.SignInTime = SNTPClient.AdjustedTime;
     }
 }
Пример #4
0
 private void AdjustSignInTimeout(ISignInInfo signInInfo)
 {
     if (PassportSignInSettings.GetConfig().HasSlidingExpiration)
     {
         signInInfo.SignInTime = DateTime.Now;
     }
 }
Пример #5
0
        /// <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();
            }
        }
Пример #6
0
        private static string PrepareTicket()
        {
            ISignInInfo signInInfo = SignInInfo.Create("SinoOceanLand\\liumh");

            ITicket ticket = Ticket.Create(signInInfo);

            return(ticket.ToEncryptString());
        }
Пример #7
0
        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);
        }
Пример #8
0
        private bool IsSignInInfoInvalid(ISignInInfo signInInfo)
        {
            bool invalid = true;

            if (signInInfo != null)
            {
                invalid = signInInfo.IsValid() == false;
            }

            return(invalid);
        }
Пример #9
0
        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)));
        }
Пример #10
0
        /// <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));
            }
        }
Пример #11
0
        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);
        }
Пример #12
0
        /// <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)));
        }
Пример #13
0
        /// <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;
            }
        }
Пример #14
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");
        }
Пример #15
0
        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);
        }
Пример #16
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");
        }
Пример #17
0
		/// <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;
		}
Пример #18
0
 /// <summary>
 /// 创建票据
 /// </summary>
 /// <param name="signInInfo"></param>
 /// <returns></returns>
 public static ITicket Create(ISignInInfo signInInfo)
 {
     return Create(signInInfo, string.Empty);
 }
Пример #19
0
 /// <summary>
 /// 创建票据
 /// </summary>
 /// <param name="signInInfo"></param>
 /// <returns></returns>
 public static ITicket Create(ISignInInfo signInInfo)
 {
     return(Create(signInInfo, string.Empty));
 }
Пример #20
0
        /// <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));
        }