Exemple #1
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            //摸拟用户登录验证(帐号、密码于web.config中)
            //真实环境此处应通过数据库进行验证

            string strAccount     = this.txtAccount.Text;
            string strPassport    = this.txtPassport.Text;
            string strWebSiteName = String.Empty;


            JosonOAuth.OUser Entity = null;

            if (OAuthByLDAP)
            {
                if (OAuthDefault)
                {
                    OAuthLDAP   = System.Configuration.ConfigurationManager.AppSettings["OAuthLDAP"];
                    isValidUser = ADHelper.TryAuthenticate(OAuthLDAP, strAccount, strPassport);
                }
                else
                {
                    JosonOAuth.WebServiceSoapClient O = new JosonOAuth.WebServiceSoapClient();

                    isValidUser = O.OAuth(out Entity, strAccount, strPassport);
                }

                //IdentityImpersonation Login = new IdentityImpersonation(strAccount, strPassport, OAuthLDAP);
                //Login.BeginImpersonate();
            }
            else
            {
                isValidUser = this.txtAccount.Text == System.Configuration.ConfigurationManager.AppSettings["Acount"] &&
                              this.txtPassport.Text == System.Configuration.ConfigurationManager.AppSettings["PassWord"];
            }

            //JScript.Alert(this, OAuthDefaultURL);
            //JScript.Alert(this, isValidUser.ToStrings());

            //JScript.Alert(this, Request.QueryString["BackURL"]);
            //JScript.Alert(this, OAuthDefaultURL);

            if (isValidUser)
            {
                //产生令牌
                string     tokenValue  = Guid.NewGuid().ToString().ToUpper(); //产生绝对唯一字符串,用于令牌
                HttpCookie tokenCookie = new HttpCookie("Token");
                tokenCookie.Values.Add("Value", tokenValue);
                //获取验证站点域名 "www.passport.com";
                tokenCookie.Domain = strCookieDomain ?? Net.Common.GetRequest.GetCurrentDomain();
                Response.AppendCookie(tokenCookie);

                //HttpCookie AccountCookie = new HttpCookie("AccountID");
                //AccountCookie.Values.Add("Value", strAccount);
                //Response.AppendCookie(AccountCookie);

                //HttpCookie PassportCookie = new HttpCookie("Passport");
                //PassportCookie.Values.Add("Value", strPassport);
                //Response.AppendCookie(PassportCookie);

                LabMsg.Text = String.Empty;

                OAuthToken OAuth = new OAuthToken
                {
                    ID          = 0,
                    UserAgent   = Request.UserAgent,
                    isLocked    = false,
                    AccountID   = strAccount,
                    AccountName = strAccount,

                    //sn = Entity?.SN,
                    //givenName = Entity?.GivenName,
                    //displayName = Entity?.DisplayName,
                    //initials = Entity?.initials,
                    //title = Entity?.Title,
                    //company = Entity?.Company,
                    //mail = Entity?.Mail,
                    //otherMailBox = Entity?.OtherMailBox,
                    //homePhone = Entity?.HomePhone,
                    //mobile = Entity?.Mobile,
                    //otherMobile = Entity?.OtherMobile,
                    //whenCreated = Entity.WhenCreated,
                    //whenChanged = Entity.WhenChanged,
                    //department = Entity?.Department,
                    //manager = Entity?.Manager,
                    //streetAddress=Entity?.streetAddress,
                    //physicalDeliveryOfficeName= Entity?.physicalDeliveryOfficeName,


                    sn            = Entity.SN,
                    givenName     = Entity.GivenName,
                    displayName   = Entity.DisplayName,
                    initials      = Entity.initials,
                    title         = Entity.Title,
                    company       = Entity.Company,
                    mail          = Entity.Mail,
                    otherMailBox  = Entity.OtherMailBox,
                    homePhone     = Entity.HomePhone,
                    mobile        = Entity.Mobile,
                    otherMobile   = Entity.OtherMobile,
                    whenCreated   = Entity.WhenCreated,
                    whenChanged   = Entity.WhenChanged,
                    department    = Entity.Department,
                    manager       = Entity.Manager,
                    streetAddress = Entity.streetAddress,
                    physicalDeliveryOfficeName = Entity.physicalDeliveryOfficeName,


                    PassWords   = strPassport,
                    TokenVal    = tokenValue,
                    WebSiteName = strWebSiteName,
                    RedirectURL = "",
                    ReturnURL   = "",
                    LogInDtime  = DateTime.Now.ToStrings(),
                    LogOutDtime = DateTime.Now.AddMinutes(1).ToStrings(),
                    LogInIP     = GetRequest.GetClientIP() // "172.0.0.1" + Request.UserAgent
                };

                //产生主站凭证
                object info = true;

                TokenCache.Insert(tokenValue, OAuth.Serializer(), DateTime.Now.AddMinutes(double.Parse(System.Configuration.ConfigurationManager.AppSettings["Timeout"])));


                //跳转回分站
                if (Request.QueryString["BackURL"] != null)
                {
                    String RedirectURL = Server.UrlDecode(Request.QueryString["BackURL"]);
                    Response.Redirect(RedirectURL);
                }
                else
                {
                    if (OAuthDefaultURL.NotIsNullOrEmpty())
                    {
                        Response.Redirect(OAuthDefaultURL);
                    }
                }
            }
            else
            {
                LabMsg.Text = "抱歉,帐号或密码有误!";
            }
        }
Exemple #2
0
        public OAuthToken SSOLogin(String strAccount, String strPassport)
        {
            //摸拟用户登录验证(帐号、密码于web.config中)
            //真实环境此处应通过数据库进行验证


            string strWebSiteName = String.Empty;

            OAuthDefault = String.IsNullOrWhiteSpace(System.Configuration.ConfigurationManager.AppSettings["OAuthDefault"]);
            //非常重要的配置 如果要配置请保证其正确性!建议不要配置 默认读取域名
            strCookieDomain = System.Configuration.ConfigurationManager.AppSettings["OAuthURL"];

            //是否使用域验证
            OAuthByLDAP = System.Configuration.ConfigurationManager.AppSettings["OAuthByLDAP"] == "true";

            //验证通过后跳转页面 SSO 登录中心导向页面
            OAuthDefaultURL = System.Configuration.ConfigurationManager.AppSettings["OAuthSucessfulURL"];


            JosonOAuth.OUser Entity = null;

            if (OAuthByLDAP)
            {
                if (OAuthDefault)
                {
                    OAuthLDAP = System.Configuration.ConfigurationManager.AppSettings["OAuthLDAP"];
                    isValidUser = ADHelper.TryAuthenticate(OAuthLDAP, strAccount, strPassport);

                }
                else
                {

                    JosonOAuth.WebServiceSoapClient O = new JosonOAuth.WebServiceSoapClient();

                    isValidUser = O.OAuth(out Entity, strAccount, strPassport);

                }

            }
            else
            {

                isValidUser = strAccount == System.Configuration.ConfigurationManager.AppSettings["Acount"]
                              && strPassport == System.Configuration.ConfigurationManager.AppSettings["PassWord"];

            }

            OAuthToken OAuth = new OAuthToken();

            if (isValidUser)
            {
                //产生令牌
                string tokenValue = Guid.NewGuid().ToString().ToUpper(); //产生绝对唯一字符串,用于令牌
                HttpCookie tokenCookie = new HttpCookie("Token");
                tokenCookie.Values.Add("Value", tokenValue);

                tokenCookie.Domain = strCookieDomain ?? Net.Common.GetRequest.GetCurrentDomain();
                HttpContext.Current.Response.AppendCookie(tokenCookie);

                OAuth = new OAuthToken
                {
                    ID = 0,
                    UserAgent = HttpContext.Current.Request.UserAgent,
                    isLocked = false,
                    AccountID = strAccount,
                    AccountName = strAccount,

                    //sn = Entity?.SN,
                    //givenName = Entity?.GivenName,
                    //displayName = Entity?.DisplayName,
                    //initials = Entity?.initials,
                    //title = Entity?.Title,
                    //company = Entity?.Company,
                    //mail = Entity?.Mail,
                    //otherMailBox = Entity?.OtherMailBox,
                    //homePhone = Entity?.HomePhone,
                    //mobile = Entity?.Mobile,
                    //otherMobile = Entity?.OtherMobile,
                    //whenCreated = Entity.WhenCreated,
                    //whenChanged = Entity.WhenChanged,
                    //department = Entity?.Department,
                    //manager = Entity?.Manager,
                    //streetAddress=Entity?.streetAddress,
                    //physicalDeliveryOfficeName= Entity?.physicalDeliveryOfficeName,


                    sn = Entity.SN,
                    givenName = Entity.GivenName,
                    displayName = Entity.DisplayName,
                    initials = Entity.initials,
                    title = Entity.Title,
                    company = Entity.Company,
                    mail = Entity.Mail,
                    otherMailBox = Entity.OtherMailBox,
                    homePhone = Entity.HomePhone,
                    mobile = Entity.Mobile,
                    otherMobile = Entity.OtherMobile,
                    whenCreated = Entity.WhenCreated,
                    whenChanged = Entity.WhenChanged,
                    department = Entity.Department,
                    manager = Entity.Manager,
                    streetAddress = Entity.streetAddress,
                    physicalDeliveryOfficeName = Entity.physicalDeliveryOfficeName,



                    PassWords = strPassport,
                    TokenVal = tokenValue,
                    WebSiteName = strWebSiteName,
                    RedirectURL = "",
                    ReturnURL = "",
                    LogInDtime = DateTime.Now.ToStrings(),
                    LogOutDtime = DateTime.Now.AddMinutes(1).ToStrings(),
                    LogInIP = GetRequest.GetClientIP() // "172.0.0.1" + Request.UserAgent

                };

                //产生主站凭证
                object info = true;

                TokenCache.Insert(tokenValue, OAuth.Serializer(), DateTime.Now.AddMinutes(double.Parse(System.Configuration.ConfigurationManager.AppSettings["Timeout"])));

            }


            return OAuth;

        }