private string InternalGetLogOnName(out ITicket ticket) { string userID = string.Empty; ticket = null; if (ImpersonateSettings.GetConfig().EnableTestUser) { //是否使用测试帐户 userID = HttpContext.Current.Request.Headers["testUserID"]; if (userID.IsNotEmpty()) { HttpContext.Current.Response.AppendHeader("testUserID", userID); } else { userID = ImpersonateSettings.GetConfig().TestUserID; } } if (userID.IsNullOrEmpty()) { userID = GetLogOnName(out ticket); } return(userID); }
private void DoAuthentication() { ITicket ticket; string logonName = InternalGetLogOnName(out ticket); if (logonName.IsNotEmpty()) { logonName = ImpersonateSettings.GetConfig().Impersonation[logonName]; LogOnIdentity loi = new LogOnIdentity(logonName); if (ticket != null) { ticket.SignInInfo.UserID = loi.LogOnNameWithDomain; } SetTenantContext(ticket); SetPrincipal(loi.LogOnNameWithDomain, ticket); } }
/// <summary> /// 生成SignInInfo的Xml格式数据 /// </summary> /// <param name="userInfo">用户登录信息</param> /// <param name="bDontSaveUserID">是否保存用户名</param> /// <param name="bAutoSignIn">是否自动登录</param> /// <returns>SignInfo的xml格式数据</returns> public static XmlDocument GenerateSignInInfo(ISignInUserInfo userInfo, bool bDontSaveUserID, bool bAutoSignIn) { string userID = ImpersonateSettings.GetConfig().Impersonation[userInfo.UserID]; HttpContext context = HttpContext.Current; HttpRequest request = context.Request; XmlDocument xmlDoc = XmlHelper.CreateDomDocument("<SignInInfo/>"); XmlHelper.AppendNode(xmlDoc.DocumentElement, "SSID", Guid.NewGuid().ToString()); XmlHelper.AppendNode(xmlDoc.DocumentElement, "UID", userID); XmlHelper.AppendNode(xmlDoc.DocumentElement, "OUID", userInfo.OriginalUserID); XmlHelper.AppendNode(xmlDoc.DocumentElement, "DO", userInfo.Domain); object windowsIntegrated; if (true == userInfo.Properties.TryGetValue("WindowsIntegrated", out windowsIntegrated)) { XmlHelper.AppendNode(xmlDoc.DocumentElement, "WI", true); } XmlHelper.AppendNode(xmlDoc.DocumentElement, "DSUID", bDontSaveUserID); XmlHelper.AppendNode(xmlDoc.DocumentElement, "ASI", bAutoSignIn); XmlHelper.AppendNode(xmlDoc.DocumentElement, "STime", DateTimeStandardFormat(SNTPClient.AdjustedTime)); XmlHelper.AppendNode(xmlDoc.DocumentElement, "AS", request.Url.Host + ":" + request.Url.Port); if (userInfo.Properties.Count > 0) { XmlNode nodeProps = XmlHelper.AppendNode(xmlDoc.DocumentElement, Resource.SignInInfoExtraProperties); foreach (KeyValuePair <string, object> kp in userInfo.Properties) { XmlNode nodeProp = XmlHelper.AppendNode(nodeProps, "add"); XmlHelper.AppendAttr(nodeProp, "key", kp.Key); XmlHelper.AppendAttr(nodeProp, "value", kp.Value.ToString()); } } DateTime dtExpireTime = DateTime.MaxValue; PassportSignInSettings settings = PassportSignInSettings.GetConfig(); if (settings.DefaultTimeout >= TimeSpan.Zero) { dtExpireTime = DateTime.Now.Add(settings.DefaultTimeout); } else if (settings.DefaultTimeout < TimeSpan.FromSeconds(-1)) { dtExpireTime = DateTime.MinValue; } else if (settings.DefaultTimeout == TimeSpan.FromSeconds(-1)) { dtExpireTime = DateTime.MaxValue; } XmlHelper.AppendNode(xmlDoc.DocumentElement, "STimeout", DateTimeStandardFormat(dtExpireTime)); return(xmlDoc); }