public PermissionItem([NotNull] string name, string parent = null, PermissionAuthorizeScope scope = PermissionAuthorizeScope.Common) { Check.NotNull(name, nameof(name)); this.Name = name; this.Scope = scope; this.Parent = parent; this.Sort = _sort++; this.HashCode = this.Name.GetHashCode() + this.Scope.GetHashCode(); }
/// <summary> /// Permission 转树形数据结构 /// </summary> /// <param name="permission"></param> /// <param name="scope"></param> /// <param name="defaultParent"></param> /// <returns></returns> static List <PermissionItem> PermissionToTree(string permission, PermissionAuthorizeScope scope, string defaultParent = null) { var result = new List <PermissionItem>(); var permissionArray = PermissionToArray(permission).Reverse <string>().ToList(); if (permissionArray.Count == 0) { return(result); } var maxCount = permissionArray.Count; var index = 0; var parentIndex = index + 1; while (true) { var newPermission = permissionArray[index]; if (maxCount == parentIndex) { result.Add( new PermissionItem(newPermission, defaultParent, scope) ); break; } result.Add( new PermissionItem(newPermission, permissionArray[parentIndex], scope) ); index++; parentIndex = index + 1; } return(result); }
public PermissionInfo(string name, PermissionAuthorizeScope scope) { Name = name; Scope = scope; }
/// <summary> /// Creates a new instance of <see cref="PermissionAuthorizeAttribute"/> class. /// </summary> /// <param name="permissions">A list of permissions to authorize</param> public PermissionAuthorizeAttribute(params string[] permissions) { this.Permissions = permissions; this.Scope = PermissionAuthorizeScope.Common; this.Policy = PermissionAuthorizationPolicyProvider.POLICY_NAME; }