Example #1
0
        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();
        }
Example #2
0
        /// <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);
        }
Example #3
0
 public PermissionInfo(string name, PermissionAuthorizeScope scope)
 {
     Name  = name;
     Scope = scope;
 }
Example #4
0
 /// <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;
 }