/// <summary>
		/// 认证
		/// </summary>
		/// <param name="strUserID"></param>
		/// <param name="strPassword"></param>
		/// <param name="context">一些额外的参数</param>
		/// <returns></returns>
		public ISignInUserInfo Authenticate(string strUserID, string strPassword, Dictionary<string, object> context)
		{
			LogOnIdentity loi = new LogOnIdentity(strUserID, strPassword);

			DefaultSignInUserInfo signInUserInfo = new DefaultSignInUserInfo();

			string authCode = context.GetValue("AuthenticationCode", string.Empty);

			//是否使用验证码认证
			if (authCode.IsNotEmpty())
			{
				AuthenticationCodeAdapter.Instance.CheckAuthenticationCode(authCode, strPassword);
			}
			else
			{
				if (AuthenticateUser(loi) == false)
				{
					IEnumerable<string> alternativeUserIDs = context.GetValue("AlternativeUserIDs", (IEnumerable<string>)null);

					if (AuthenticateAlternativeUserIDs(alternativeUserIDs, strPassword, context) == false)
						AuthenticateException.ThrowAuthenticateException(loi.LogOnNameWithoutDomain);
				}
			}

			signInUserInfo.UserID = loi.LogOnNameWithoutDomain;
			signInUserInfo.Domain = loi.Domain;

			return signInUserInfo;
		}
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Cache.SetCacheability(HttpCacheability.NoCache);

            string lastUserID = Request.QueryString["lastUserID"];

            string returnUrl = Request.QueryString["ru"];

            if (string.IsNullOrEmpty(returnUrl) == false)
            {
                string logonUserID = Request.ServerVariables["LOGON_USER"];

                ExceptionHelper.FalseThrow(string.IsNullOrEmpty(logonUserID) == false, "不能取到LOGON_USER,该页面应该设置为禁止匿名访问");

                LogOnIdentity loi = new LogOnIdentity(logonUserID);

                if (string.Compare(loi.LogOnNameWithoutDomain, lastUserID, true) == 0)
                {
                    Response.StatusCode = (int)HttpStatusCode.Unauthorized;
                    Response.AddHeader("WWW-Authenticate", "NTLM");
                }
                else
                {
                    Response.Redirect(PassportManager.GetSignInPageUrl(returnUrl, logonUserID));
                }
            }
        }
		private static ITicket BuildTicket()
		{
			HttpRequest request = HttpContext.Current.Request;

			string appID = HttpUtility.UrlDecode(request.QueryString["appID"]);
			string ip = request.QueryString["ip"];

			if (string.IsNullOrEmpty(ip))
				ip = request.UserHostAddress;

			string logonName = request.ServerVariables["LOGON_USER"];
			LogOnIdentity loi = new LogOnIdentity(logonName);

			XmlDocument xmlDoc = XmlHelper.CreateDomDocument("<Ticket/>");
			XmlElement root = xmlDoc.DocumentElement;

			DateTime now = DateTime.Now;

			XmlHelper.AppendNode(root, "AppSSID", Guid.NewGuid().ToString());
			XmlHelper.AppendNode(root, "AppID", appID);
			XmlHelper.AppendNode(root, "AppSTime", now.ToString("yyyy-MM-dd HH:mm:ss"));
			XmlHelper.AppendNode(root, "IP", ip);

			XmlElement signInInfoNode = (XmlElement)XmlHelper.AppendNode(root, "SignInInfo");

			XmlHelper.AppendNode(signInInfoNode, "SSID", Guid.NewGuid().ToString());
			XmlHelper.AppendNode(signInInfoNode, "STime", now.ToString("yyyy-MM-dd HH:mm:ss"));
			XmlHelper.AppendNode(signInInfoNode, "UID", loi.LogOnNameWithoutDomain);
			XmlHelper.AppendNode(signInInfoNode, "WI", "True");
			XmlHelper.AppendNode(signInInfoNode, "DO", loi.Domain);
			XmlHelper.AppendNode(signInInfoNode, "AS", request.Url.Host + ":" + request.Url.Port);

			return new Ticket(xmlDoc.OuterXml);
		}
        public static void AreEqual(this WfNetworkCredential actual, LogOnIdentity identity)
        {
            if (actual == null && identity == null)
                return;

            Assert.AreEqual(actual.LogOnNameWithoutDomain, identity.LogOnNameWithoutDomain);
            Assert.AreEqual(actual.Password, identity.Password);
            Assert.AreEqual(actual.Domain, identity.Domain);
        }
		private bool AuthenticateUser(LogOnIdentity loi)
		{
			const int LOGON32_PROVIDER_DEFAULT = 0; //使用默认的Windows 2000/NT NTLM验证方式
			const int LOGON32_LOGON_NETWORK = 3;
			IntPtr tokenHandle = new IntPtr(0);
			tokenHandle = IntPtr.Zero;

			return LogonUser(loi.LogOnNameWithoutDomain, loi.Domain, loi.Password, LOGON32_LOGON_NETWORK, LOGON32_PROVIDER_DEFAULT, ref tokenHandle);
		}
		/// <summary>
		/// 认证
		/// </summary>
		/// <param name="strUserID"></param>
		/// <param name="strPassword"></param>
		/// <returns></returns>
		public ISignInUserInfo Authenticate(string strUserID, string strPassword)
		{
			LogOnIdentity loi = new LogOnIdentity(strUserID, strPassword);

			DefaultSignInUserInfo signInUserInfo = new DefaultSignInUserInfo();

			if (AuthenticateUser(loi) == false)
				AuthenticateException.ThrowAuthenticateException(loi.LogOnNameWithoutDomain);

			signInUserInfo.UserID = loi.LogOnNameWithoutDomain;
			signInUserInfo.Domain = loi.Domain;

			return signInUserInfo;
		}
        /// <summary>
        /// 获取登录票据
        /// </summary>
        /// <param name="ticket">ticket</param>
        /// <returns>用户ID</returns>
        protected override string GetLogOnName(out ITicket ticket)
        {
            ticket = null;

            HttpRequest request = HttpContext.Current.Request;

            string logonName = request.ServerVariables["LOGON_USER"];

			ExceptionHelper.TrueThrow<AuthenticateException>(string.IsNullOrEmpty(logonName),
			    Resource.PageMustForbidAnonymousAccess);

            LogOnIdentity loi = new LogOnIdentity(logonName);

			DomainMappingSettings section = DomainMappingSettings.GetConfig();

			string domainName = section.Mappings[loi.Domain];

			if (section.CheckDomainName)
                CheckDomainName(domainName);

            return logonName;
        }
		protected void SignInControl_BeforeAuthenticate(LogOnIdentity loi)
		{
			//如果需要验证码认证,将AuthenticationCode放在loi中即可
			//loi.Context["AuthenticationCode"] = UuidHelper.NewUuidString();
		}
		private bool AuthenticateUser(LogOnIdentity loi)
		{
			bool result = false;

			try
			{
				result = OguMechanismFactory.GetMechanism().AuthenticateUser(loi);
			}
			catch (System.Exception)
			{
			}

			return result;
		}
		private bool AuthenticateAlternativeUserIDs(IEnumerable<string> alternativeUserIDs, string password, Dictionary<string, object> context)
		{
			bool result = false;

			if (alternativeUserIDs != null)
			{
				foreach (string userID in alternativeUserIDs)
				{
					LogOnIdentity loi = new LogOnIdentity(userID, password);

					result = AuthenticateUser(loi);

					if (result)
						break;
				}
			}

			return result;
		}
		/// <summary>
		/// 根据登录名得到用户不变的ID
		/// </summary>
		/// <param name="logonName"></param>
		/// <returns></returns>
		public string GetUserConsistentID(string logonName)
		{
			logonName.CheckStringIsNullOrEmpty("logonName");

			LogOnIdentity loi = new LogOnIdentity(logonName, string.Empty);

			OguObjectCollection<IUser> users = OguMechanismFactory.GetMechanism().GetObjects<IUser>(SearchOUIDType.LogOnName, loi.LogOnNameWithoutDomain);

			string result = string.Empty;

			if (users.Count > 0)
				result = users[0].ID;

			return result;
		}
Beispiel #12
0
        /// <summary>
        /// 根据UserID创建SignInInfo
        /// </summary>
        /// <param name="userID"></param>
        /// <param name="bDontSaveUserID"></param>
        /// <param name="bAutoSignIn"></param>
        /// <returns></returns>
        public static ISignInInfo Create(string userID, bool bDontSaveUserID, bool bAutoSignIn)
        {
            LogOnIdentity loi = new LogOnIdentity(userID);

            DefaultSignInUserInfo userInfo = new DefaultSignInUserInfo();

            userInfo.UserID = loi.LogOnNameWithoutDomain;
            userInfo.Domain = loi.Domain;

            return Create(userInfo, bDontSaveUserID, bAutoSignIn);
        }
Beispiel #13
0
        /// <summary>
        /// 登录名称是否合法
        /// </summary>
        /// <param name="logonName">登录名称</param>
        /// <returns></returns>
        public bool IsLogOnNameValid(string logonName)
        {
            LogOnIdentity identity = new LogOnIdentity(logonName);

            ExceptionHelper.FalseThrow(string.Compare(identity.Domain, DomainShortName, true) == 0,
                string.Format("帐号“{0}”的域名与当前域“{1}”不匹配", identity.LogOnName, DomainShortName));

            using (DirectoryEntry root = GetRootEntry())
            {
                return ExecuteSearch(root,
                                ADSearchConditions.GetFilterByMask(ADSchemaType.Users,
                                    new ExtraFilter(string.Empty,
                                                    string.Format("(samAccountName={0})", EscapeString(identity.LogOnNameWithoutDomain)),
                                                    string.Empty)),
                                new ADSearchConditions(SearchScope.Subtree), "samAccountName").Count > 0;
            }
        }
		private SendMailParameters CollectInfo()
		{
			SendMailParameters result = new SendMailParameters();

			SmtpParameters sp = new SmtpParameters();

			LogOnIdentity identity = new LogOnIdentity(textBoxLogOnName.Text, textBoxPassword.Text);

			ServerInfo serverInfo = new ServerInfo(textBoxServer.Text, identity);

			int port = 0;

			if (int.TryParse(textBoxPort.Text, out port))
				serverInfo.Port = port;

			serverInfo.AuthenticateType = (AuthenticateType)Enum.Parse(typeof(AuthenticateType), (string)comboBoxAuthenticateType.SelectedValue);

			sp.ServerInfo = serverInfo;
			sp.UseDefaultCredentials = serverInfo.AuthenticateType == AuthenticateType.Anonymous;

			if (textBoxSignInAddress.Text.IsNotEmpty())
				sp.DefaultSender = EmailAddress.FromDescription(textBoxSignInAddress.Text);

			sp.AfterSentOP = EmailMessageAfterSentOP.NotPersisted;

			result.SmtpParams = sp;
			result.DefaultEmailSubject = textBoxMessage.Text;
			result.ToAddress = EmailAddress.FromDescription(textBoxDest.Text);

			return result;
		}
Beispiel #15
0
		private void buttonOK_Click(object sender, EventArgs e)
		{
			this.identity = new LogOnIdentity(this.textBoxUser.Text, this.textBoxPassword.Text, this.textBoxDC.Text);
		}
Beispiel #16
0
 protected void signInControl_BeforeAuthenticate(MCS.Library.Core.LogOnIdentity loi)
 {
     //如果需要验证码认证,将AuthenticationCode放在loi中即可
     //loi.Context["AuthenticationCode"] = UuidHelper.NewUuidString();
     //loi.Context["AlternativeUserIDs"] = new string[] { "fanhy" };
 }
Beispiel #17
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="serverName"></param>
 /// <param name="identity"></param>
 public ServerInfo(string serverName, LogOnIdentity identity)
 {
     this.serverName = serverName;
     this.identity   = identity;
 }
 internal void FireBeforeAuthenticate(LogOnIdentity loi)
 {
     if (BeforeAuthenticate != null)
         BeforeAuthenticate(loi);
 }