/// <summary>
        /// 为指定<see cref="IGrantee" />授予特定的<see cref="Permission" />。
        /// 目前只支持被授权者为<see cref="GroupGrantee.AllUsers" />。
        /// </summary>
        /// <param name="grantee">被授权者。</param>
        /// <param name="permission">被授予的权限。</param>
        internal void GrantPermission(IGrantee grantee, Permission permission)
        {
            if (grantee == null)
                throw new ArgumentNullException("grantee");

            _grants.Add(new Grant(grantee, permission), true);
        }
Esempio n. 2
0
        /// <summary>
        /// 构造一个新的<see cref="Grant" />实体。
        /// </summary>
        /// <param name="grantee">被授权者。目前只支持<see cref="GroupGrantee.AllUsers" />。</param>
        /// <param name="permission">权限。</param>
        public Grant(IGrantee grantee, Permission permission)
        {
            if (grantee == null)
                throw new ArgumentNullException("grantee");

            Grantee = grantee;
            Permission = permission;
        }
 public void RevokeAllPermissions(IGrantee grantee)
 {
     if (grantee == null)
     {
         throw new ArgumentNullException("grantee");
     }
     this._grants.RemoveWhere(e => e.Grantee == grantee);
 }
 public void GrantPermission(IGrantee grantee, Permission permission)
 {
     if (grantee == null)
     {
         throw new ArgumentNullException("grantee");
     }
     this._grants.Add(new Grant(grantee, permission));
 }
Esempio n. 5
0
 public void RevokeAllPermissions(IGrantee grantee)
 {
     if (grantee == null)
     {
         throw new ArgumentNullException("grantee");
     }
     this._grants.RemoveWhere(e => e.Grantee == grantee);
 }
Esempio n. 6
0
 public void GrantPermission(IGrantee grantee, Permission permission)
 {
     if (grantee == null)
     {
         throw new ArgumentNullException("grantee");
     }
     this._grants.Add(new Grant(grantee, permission));
 }
Esempio n. 7
0
 public Grant(IGrantee grantee, Permission permission)
 {
     if (grantee == null)
     {
         throw new ArgumentNullException("grantee");
     }
     this.Grantee    = grantee;
     this.Permission = permission;
 }
        /// <summary>
        /// Grants permission to a <see cref="IGrantee" /> instance with specified <see cref="Permission" />.
        /// Currently the supported grantee is <see cref="GroupGrantee.AllUsers" />.
        /// </summary>
        /// <param name="grantee">The grantee</param>
        /// <param name="permission">The permission</param>
        internal void GrantPermission(IGrantee grantee, Permission permission)
        {
            if (grantee == null)
            {
                throw new ArgumentNullException("grantee");
            }

            _grants.Add(new Grant(grantee, permission), true);
        }
Esempio n. 9
0
 private static string ConvertGrantee(IGrantee grantee)
 {
     if (grantee.GetType().Equals(typeof(CanonicalGrantee)))
     {
         return(ConvertCanonicalGrantee((CanonicalGrantee)grantee));
     }
     else if (grantee.GetType().Equals(typeof(GroupGrantee)))
     {
         return(ConvertGroupGrantee((GroupGrantee)grantee));
     }
     return(null);
 }
        /**
         * 取消指定{@link Grantee}已分配的所有权限。
         * @param grantee
         *           被授权者。目前只支持被授权者为{@link GroupGrantee#AllUsers}。
         */
        /// <summary>
        /// 取消指定<see cref="IGrantee" />已分配的所有权限。
        /// </summary>
        /// <param name="grantee">被授权者。</param>
        internal void RevokeAllPermissions(IGrantee grantee)
        {
            if (grantee == null)
                throw new ArgumentNullException("grantee");

            foreach (var e in _grants.Keys)
            {
                if (e.Grantee == grantee)
                {
                    _grants.Remove(e);
                }
            }
        }
        /**
         * Revoke all permissions on a specific grantee.
         * @param grantee
         *           The grantee, currently only <see cref="GroupGrantee.AllUsers" /> is supported.
         */
        /// <summary>
        /// Invoke the <see cref="IGrantee" /> instance's all permissions.
        /// </summary>
        /// <param name="grantee">The grantee instanc</param>
        internal void RevokeAllPermissions(IGrantee grantee)
        {
            if (grantee == null)
            {
                throw new ArgumentNullException("grantee");
            }

            foreach (var e in _grants.Keys)
            {
                if (e.Grantee == grantee)
                {
                    _grants.Remove(e);
                }
            }
        }
Esempio n. 12
0
        /// <summary>
        /// Revokes the permissions of a grantee by removing the grantee from the access control list (ACL).
        /// </summary>
        /// <param name="grantee"></param>
        public void RevokeAllPermissions(IGrantee grantee)
        {
            var grantsToRemove = new List <Grant>();

            foreach (Grant grant in _grants)
            {
                if (grant.Grantee.Equals(grantee))
                {
                    grantsToRemove.Add(grant);
                }
            }

            foreach (Grant grant in grantsToRemove)
            {
                _grants.Remove(grant);
            }
        }
        /**
         * 取消指定{@link Grantee}已分配的所有权限。
         * @param grantee
         *           被授权者。目前只支持被授权者为{@link GroupGrantee#AllUsers}。
         */
        /// <summary>
        /// 取消指定<see cref="IGrantee" />已分配的所有权限。
        /// </summary>
        /// <param name="grantee">被授权者。</param>
        internal void RevokeAllPermissions(IGrantee grantee)
        {
            if (grantee == null)
                throw new ArgumentNullException("grantee");

            _grants.RemoveWhere(e => e.Grantee == grantee);
        }
Esempio n. 14
0
 /// <summary>
 /// Adds a grantee to the access control list (ACL) with the given permission.
 /// If this access control list already contains the grantee (i.e. the same grantee object) the permission for the grantee will be updated.
 /// </summary>
 /// <param name="grantee"></param>
 /// <param name="permission"></param>
 public void GrantPermission(IGrantee grantee, string permission)
 {
     _grants.Add(new Grant(grantee, permission));
 }
        public AccessControlList Unmarshall(Stream inputStream)
        {
            AccessControlList acl              = new AccessControlList();
            string            ownerId          = null;
            string            ownerDisplayName = null;
            IGrantee          grantee          = null;
            string            granteeType      = null;
            string            userId           = null;
            string            userDisplayName  = null;
            string            groupUri         = null;
            string            permission       = null;
            bool          insideGrant          = false;
            StringBuilder currText             = new StringBuilder();

            XmlReader xr = XmlReader.Create(new BufferedStream(inputStream));

            while (xr.Read())
            {
                if (xr.NodeType.Equals(XmlNodeType.Element))
                {
                    if (xr.Name.Equals("Grant"))
                    {
                        insideGrant = true;
                    }
                    else if (xr.Name.Equals("Grantee"))
                    {
                        granteeType = xr.GetAttribute("xsi:type");
                    }
                }
                else if (xr.NodeType.Equals(XmlNodeType.EndElement))
                {
                    if (xr.Name.Equals("DisplayName"))
                    {
                        if (!insideGrant)
                        {
                            ownerId = currText.ToString();
                        }
                        else
                        {
                            userId = currText.ToString();
                        }
                    }
                    else if (xr.Name.Equals("ID"))
                    {
                        if (!insideGrant)
                        {
                            ownerDisplayName = currText.ToString();
                        }
                        else
                        {
                            userDisplayName = currText.ToString();
                        }
                    }
                    else if (xr.Name.Equals("URI"))
                    {
                        groupUri = currText.ToString();
                    }
                    else if (xr.Name.Equals("Owner"))
                    {
                        acl.Owner = new Owner(ownerId, ownerDisplayName);
                    }
                    else if (xr.Name.Equals("Grantee"))
                    {
                        if (granteeType.Equals("CanonicalUser"))
                        {
                            grantee = new CanonicalGrantee(userId, userDisplayName);
                        }
                        else if (granteeType.Equals("Group"))
                        {
                            grantee = new GroupGrantee(groupUri);
                        }
                    }
                    else if (xr.Name.Equals("Permission"))
                    {
                        permission = currText.ToString();
                    }
                    else if (xr.Name.Equals("Grant"))
                    {
                        acl.GrantPermission(grantee, permission);
                        insideGrant = false;
                    }

                    currText.Clear();
                }
                else if (xr.NodeType.Equals(XmlNodeType.Text))
                {
                    currText.Append(xr.Value);
                }
            }

            return(acl);
        }
Esempio n. 16
0
 /// <summary>
 /// Constructs a new Grant object using the specified grantee and permission objects.
 /// </summary>
 /// <param name="grantee"></param>
 /// <param name="permission"></param>
 public Grant(IGrantee grantee, string permission)
 {
     Grantee    = grantee;
     Permission = permission;
 }