Ejemplo n.º 1
0
        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="userData"></param>
        /// <param name="token"></param>
        public void SignIn(SortedList <string, string> userData, out string token)
        {
            token = null;
            var data = NHHIdentity.BuildString(userData);
            var type = ParamManager.GetStringValue("auth:type").ToUpper();

            switch (type)
            {
            case "NHH":
            {
                HttpContext.Current.Response.Headers[NHHAuthentication.NHHAuthHeaderName] = token = NHHAuthentication.Encrypt(data);
                this.User = new NHHPrincipal(new NHHIdentity("NHH", userData));
                break;
            }

            case "FROMS":
            {
                if (FormsAuthentication.IsEnabled)
                {
                    var ticket = new FormsAuthenticationTicket(1, userData["UserName"] ?? userData["UserID"], DateTime.Now, DateTime.Now.AddMinutes(120), false, data);
                    HttpContext.Current.Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(ticket)));
                    this.User = new NHHPrincipal(new NHHIdentity("Froms", userData));
                }
                break;
            }

            case "NONE":
            default:
            {
                break;
            }
            }
        }
Ejemplo n.º 2
0
        protected void context_AuthenticateRequest(object sender, EventArgs e)
        {
            var type = ParamManager.GetStringValue("auth:type").ToUpper();

            switch (type)
            {
            case "NHH":
            {
                var head = HttpContext.Current.Request.Headers[NHHAuthentication.NHHAuthHeaderName];
                if (head != null)
                {
                    var ticket   = NHHAuthentication.Decrypt(head);
                    var identity = new NHHIdentity("NHH", ticket);
                    this.LoadUserConfig(identity.UserID);
                    var principal = new NHHPrincipal(identity, GetUserPermissions(identity.UserID));
                    NHHWebContext.Current.User = principal;
                }
                break;
            }

            case "FROMS":
            {
                if (FormsAuthentication.IsEnabled)
                {
                    var cookie = HttpContext.Current.Request.Cookies[FormsAuthentication.FormsCookieName];
                    if (cookie != null)
                    {
                        //登录用户主体信息
                        var ticket   = FormsAuthentication.Decrypt(cookie.Value);
                        var identity = new NHHIdentity("Forms", ticket.UserData);
                        this.LoadUserConfig(identity.UserID);
                        var principal = new NHHPrincipal(identity, GetUserPermissions(identity.UserID));
                        NHHWebContext.Current.User = principal;
                    }
                }
                break;
            }

            case "NONE":
            default:
            {
                break;
            }
            }
        }
Ejemplo n.º 3
0
 protected void context_AuthenticateRequest(object sender, EventArgs e)
 {
     var type = ParamManager.GetStringValue("auth:type").ToUpper();
     switch (type)
     {
         case "NHH":
             {
                 var head = HttpContext.Current.Request.Headers[NHHAuthentication.NHHAuthHeaderName];
                 if (head != null)
                 {
                     var ticket = NHHAuthentication.Decrypt(head);
                     var identity = new NHHIdentity("NHH",ticket);
                     this.LoadUserConfig(identity.UserID);
                     var principal = new NHHPrincipal(identity, GetUserPermissions(identity.UserID));
                     NHHWebContext.Current.User = principal;
                 }
                 break;
             }
         case "FROMS":
             {
                 if (FormsAuthentication.IsEnabled)
                 {
                     var cookie = HttpContext.Current.Request.Cookies[FormsAuthentication.FormsCookieName];
                     if (cookie != null)
                     {
                         //登录用户主体信息
                         var ticket = FormsAuthentication.Decrypt(cookie.Value);
                         var identity = new NHHIdentity("Forms",ticket.UserData);
                         this.LoadUserConfig(identity.UserID);
                         var principal = new NHHPrincipal(identity, GetUserPermissions(identity.UserID));
                         NHHWebContext.Current.User = principal;
                     }
                 }
                 break;
             }
         case "NONE":
         default:
             {
                 break;
             }
     }
 }
Ejemplo n.º 4
0
 /// <summary>
 /// 登录用户主体信息
 /// </summary>
 /// <param name="identity">身份标识信息</param>
 /// <param name="permissions">功能权限</param>
 public NHHPrincipal(NHHIdentity identity, List <string> permissions)
 {
     this.m_Identity    = identity;
     this.m_Permissions = permissions ?? new List <string>();
 }
Ejemplo n.º 5
0
 /// <summary>
 /// 登录用户主体信息
 /// </summary>
 /// <param name="identity">身份标识信息</param>
 public NHHPrincipal(NHHIdentity identity)
 {
     this.m_Identity = identity;
 }
Ejemplo n.º 6
0
 /// <summary>
 /// 登录用户主体信息
 /// </summary>
 /// <param name="identity">身份标识信息</param>
 /// <param name="permissions">功能权限</param>
 public NHHPrincipal(NHHIdentity identity, List<string> permissions)
 {
     this.m_Identity = identity;
     this.m_Permissions = permissions ?? new List<string>();
 }
Ejemplo n.º 7
0
 /// <summary>
 /// 登录用户主体信息
 /// </summary>
 /// <param name="identity">身份标识信息</param>
 public NHHPrincipal(NHHIdentity identity)
 {
     this.m_Identity = identity;
 }