Example #1
0
 /// <summary>
 /// Determines whether two instances of <see cref="T:AclEntry" /> are equal (by value).
 /// </summary>
 /// <param name="x">The first instance.</param>
 /// <param name="y">The second instance.</param>
 /// <returns><c>true</c> if <b>x</b> equals <b>y</b>, <c>false</c> otherwise.</returns>
 public static bool Equals(AclEntry x, AclEntry y)
 {
     if (x is null && !(x is null))
     {
         return(false);
     }
     if (!(x is null) && x is null)
     {
         return(false);
     }
     if (x is null && x is null)
     {
         return(true);
     }
     return(x.Equals(y));
 }
Example #2
0
        /// <summary>
        /// Deletes an ACL entry.
        /// </summary>
        /// <param name="resource">The controlled resource.</param>
        /// <param name="action">The action on the controlled resource.</param>
        /// <param name="subject">The subject whose access to the resource/action is controlled.</param>
        /// <returns><c>true</c> if the entry is deleted, <c>false</c> otherwise.</returns>
        /// <exception cref="ArgumentNullException">If <paramref name="resource"/>, <paramref name="action"/> or <paramref name="subject"/> are <c>null</c>.</exception>
        /// <exception cref="ArgumentException">If <paramref name="resource"/>, <paramref name="action"/> or <paramref name="subject"/> are empty.</exception>
        public bool DeleteEntry(string resource, string action, string subject)
        {
            if (resource == null)
            {
                throw new ArgumentNullException("resource");
            }
            if (resource.Length == 0)
            {
                throw new ArgumentException("Resource cannot be empty.", "resource");
            }
            if (action == null)
            {
                throw new ArgumentNullException("action");
            }
            if (action.Length == 0)
            {
                throw new ArgumentException("Action cannot be empty.", "action");
            }
            if (subject == null)
            {
                throw new ArgumentNullException("subject");
            }
            if (subject.Length == 0)
            {
                throw new ArgumentException("Subject cannot be empty.", "subject");
            }

            AclEntry result = new AclEntry(resource, action, subject, Value.Deny);

            lock (this)
            {
                int index = _entries.FindIndex(delegate(AclEntry x) { return(AclEntry.Equals(x, result)); });
                if (index >= 0)
                {
                    AclEntry entry = _entries[index];
                    _entries.RemoveAt(index);
                    OnAclChanged(new AclEntry[] { entry }, Change.EntryDeleted);
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }