Esempio n. 1
0
 void app_AuthenticateRequest(object sender, EventArgs e)
 {
     if (HttpContext.Current.User != null)
     {
         var cookie = HttpContext.Current.Request.Cookies[FormsAuthentication.FormsCookieName];
         if (cookie != null)
         {
             var ticket = FormsAuthentication.Decrypt(cookie.Value);
             if (!string.IsNullOrEmpty(ticket.UserData))
             {
                 UserTicket     ut        = UserTicket.Build(ticket.UserData);
                 BzureUserModel userModel = new BzureUserModel(ut.User)
                 {
                     IsAuthenticated = true
                 };
                 BzurePrincipal BzurePrincipal = new BzurePrincipal(userModel)
                 {
                     TicketData = ut.TicketData
                 };
                 HttpContext.Current.User = BzurePrincipal;
                 System.Threading.Thread.CurrentPrincipal = BzurePrincipal;
             }
         }
     }
 }
Esempio n. 2
0
        /// <summary>
        /// 当前用户是否具有指定
        /// </summary>
        /// <param name="Me"></param>
        /// <param name="droit"></param>
        /// <returns></returns>
        public static bool Authorize(this Me Me, IDroit droit)
        {
            BzurePrincipal principal = Me.Principal as BzurePrincipal;

            if (principal == default(BzurePrincipal))
            {
                return(false);
            }
            return(principal.GetPermission().Authentication(droit));
        }
Esempio n. 3
0
        protected override bool AuthorizeCore(HttpContextBase httpContext)
        {
            if (httpContext == null)
            {
                throw new ArgumentNullException("httpContext");
            }
            if (!httpContext.User.Identity.IsAuthenticated)
            {
                return(false);
            }
            BzurePrincipal principal = httpContext.User as BzurePrincipal;

            if (principal == default(BzurePrincipal))
            {
                return(false);
            }
            if (Users.Split(',').Contains(principal.Identity.Name))
            {
                return(true);
            }
            return(false);
        }
Esempio n. 4
0
        protected override bool AuthorizeCore(HttpContextBase httpContext)
        {
            foreach (IAccessCode code in codes)
            {
                this._droit.AddAccessCode(code);
            }
            IDroit droit = this._droit.Copy();

            if (httpContext == null)
            {
                throw new ArgumentNullException("httpContext");
            }
            if (!httpContext.User.Identity.IsAuthenticated)
            {
                return(false);
            }
            BzurePrincipal principal = httpContext.User as BzurePrincipal;

            if (principal == default(BzurePrincipal))
            {
                return(false);
            }
            return(principal.GetPermission().Authentication(droit));
        }