public static bool CanSee(this ClaimsPrincipal @this, Feature feature) { foreach (var notPermission in feature.NotPermissions) { if (@this.IsInRole(notPermission)) { return(false); } } if (feature.Permissions.None()) { if (feature.Parent != null) { return(@this.CanSee(feature.Parent)); } return(true); } return(feature.Permissions.Any(p => @this.IsInRole(p))); }
static AuthroziedFeatureInfo GetAuthorizationInfo(ClaimsPrincipal user, Feature feature) { if (user.CanSee(feature)) { return new AuthroziedFeatureInfo { Feature = feature } } ; var hasPermittedChildNodes = feature.GetAllChildren().Cast <Feature>().Any(c => user.CanSee(c)); if (hasPermittedChildNodes) { return new AuthroziedFeatureInfo { Feature = feature, IsDisabled = true } } ; return(null); } } }