protected override bool AuthorizeCore(HttpContextBase httpContext) { if (httpContext == null) { throw new ArgumentNullException("httpContext"); } if (httpContext.User.Identity.IsAuthenticated) { PrfPrincipal user = (PrfPrincipal)httpContext.User; return(this._permissions.Select(x => user.HasPermission(x)).Aggregate((x, y) => x && y)); } return(false); }
protected void Application_PostAuthenticateRequest(Object sender, EventArgs e) { if (Request.IsAuthenticated) { string username = HttpContext.Current.User.Identity.Name; var identity = new ExpandedIdentity(username); AdminUser user = ServiceLocator.Current.GetInstance <IUserTasks>().GetAdminUser(username); string[] permissions = user != null && user.AdminRoles.Any() ? user.AdminRoles .Select(x => x.AdminPermissions) .Aggregate((x, y) => x.Concat(y).ToList()) .Select(z => z.Name) .Distinct() .ToArray() : new string[] { }; var principal = new PrfPrincipal(identity, Roles.Provider.GetRolesForUser(username), permissions, user != null && user.Affiliations != null ? user.Affiliations.Select(x => x.Name).ToArray() : new string[] { } ); HttpContext.Current.User = principal; Thread.CurrentPrincipal = principal; } }