using System; using System.Collections.Generic; using System.Linq; public class SecurityContext { public int? TenantId { get; set; } public string UserId { get; set; } public string Username { get; set; } public List<PermissionEnum> Permissions { get; set; } public bool PermissionsAreEnforced { get; set; } public bool HasAnyPermission(params PermissionEnum[] permissions) { var items = new List<PermissionEnum>(permissions); return items.Any(x => Permissions.Contains(x)); } private static LocalDataStoreSlot _localSlot; static SecurityContext() { _localSlot = System.Threading.Thread.AllocateDataSlot(); } public static SecurityContext Current { get { if (System.Web.HttpContext.Current == null) { return (SecurityContext)System.Threading.Thread.GetData(_localSlot); } return (SecurityContext)System.Web.HttpContext.Current?.Items["SecurityContext"]; } set { if (System.Web.HttpContext.Current != null) { System.Web.HttpContext.Current.Items["SecurityContext"] = value; } else { System.Threading.Thread.SetData(_localSlot, value); } } } }
ScrewTurn Wiki version 3.0.1.400. Some of the icons created by FamFamFam. Except where noted, all contents Copyright © 1999-2024, Patrick Jasinski.