private void Initialize(string moduleName, MenuItem item) { if (item.ReadOnlyProperties != null) { var roleName = item.ReadOnlyProperties["role"]; if (!string.IsNullOrEmpty(roleName) && item.Visible) { item.Visible = Kooboo.CMS.Sites.Services.ServiceFactory.UserManager.IsInRole(Site.Current , HttpContext.Current.User.Identity.Name , roleName); } string permissionGroup = item.ReadOnlyProperties["permissionGroup"]; string permissionName = item.ReadOnlyProperties["permissionName"]; if (!string.IsNullOrEmpty(permissionName)) { var permission = new Permission() { AreaName = moduleName, Group = permissionGroup, Name = permissionName }; item.Visible = Kooboo.CMS.Sites.Services.ServiceFactory.UserManager.Authorize(Site.Current , HttpContext.Current.User.Identity.Name , permission); } } if (item.Items != null) { foreach (var chd in item.Items) { Initialize(moduleName, chd); } } }
public Permission(Permission p) { this.AreaName = p.AreaName; this.Group = p.Group; this.Name = p.Name; this.DisplayName = p.DisplayName; }
public static bool Authorize(this RequestContext requestContext, Permission permission) { IPrincipal user = requestContext.HttpContext.User; if (!user.Identity.IsAuthenticated) { return false; } var site = GetSite(requestContext); return Kooboo.CMS.Sites.Services.ServiceFactory.UserManager.Authorize(site, user.Identity.Name, permission); }
public CheckPermission(Permission permission) : base(permission) { }
//public IEnumerable<string> Users { get; set; } //public void AddUser(string userName) //{ // Users = Users.Concat(new[] { userName }); //} //public void RemoveUser(string userName) //{ // Users = Users.Where(it => string.Compare(it, userName, true) != 0); //} //public bool IsUserInRole(string userName) //{ // return this.Users.Any(it => string.Compare(it, userName, true) == 0); //} public bool HasPermission(Permission permission) { return this.Permissions.Any(it => permission == it); }
public virtual void AddPermission(Permission permission) { permissions.Add(permission); }