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; } } } }
/// <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)); }
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); }
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)); }