Inheritance: System.Security.CodeAccessPermission, IUnrestrictedPermission
        public override bool IsSubsetOf(IPermission target)
        {
            if (target == null)
            {
                // do not use Cast - different permissions (and earlier Fx) return false :-/
                return(true);
            }

            ResourcePermissionBase rpb = (target as ResourcePermissionBase);

            if (rpb == null)
            {
                return(false);
            }
            if (rpb.IsUnrestricted())
            {
                return(true);
            }
            if (IsUnrestricted())
            {
                return(rpb.IsUnrestricted());
            }
            foreach (ResourcePermissionBaseEntry entry in _list)
            {
                if (!rpb.Exists(entry))
                {
                    return(false);
                }
            }
            return(true);
        }
        public override IPermission Union(IPermission target)
        {
            if (target == null)
            {
                return(this.Copy());
            }
            if (target.GetType() != base.GetType())
            {
                throw new ArgumentException(SR.GetString("PermissionTypeMismatch"), "target");
            }
            ResourcePermissionBase base2 = (ResourcePermissionBase)target;
            ResourcePermissionBase base3 = null;

            if (this.IsUnrestricted() || base2.IsUnrestricted())
            {
                base3 = this.CreateInstance();
                base3.isUnrestricted = true;
                return(base3);
            }
            Hashtable hashtable = (Hashtable)this.UnionOfContents(this.rootTable, base2.rootTable);

            if (hashtable != null)
            {
                base3           = this.CreateInstance();
                base3.rootTable = hashtable;
            }
            return(base3);
        }
Beispiel #3
0
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public override IPermission Union(IPermission target)
        {
            if (target == null)
            {
                return(this.Copy());
            }

            if (target.GetType() != this.GetType())
            {
                throw new ArgumentException(SR.GetString(SR.PermissionTypeMismatch), "target");
            }

            ResourcePermissionBase targetPermission = (ResourcePermissionBase)target;
            ResourcePermissionBase newPermission    = null;

            if (this.IsUnrestricted() || targetPermission.IsUnrestricted())
            {
                newPermission = CreateInstance();
                newPermission.isUnrestricted = true;
            }
            else
            {
                Hashtable newPermissionRootTable = (Hashtable)UnionOfContents(this.rootTable, targetPermission.rootTable);
                if (newPermissionRootTable != null)
                {
                    newPermission           = CreateInstance();
                    newPermission.rootTable = newPermissionRootTable;
                }
            }
            return(newPermission);
        }
Beispiel #4
0
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public override bool IsSubsetOf(IPermission target)
        {
            if (target == null)
            {
                return(IsEmpty);
            }

            if (target.GetType() != this.GetType())
            {
                return(false);
            }

            ResourcePermissionBase targetPermission = (ResourcePermissionBase)target;

            if (targetPermission.IsUnrestricted())
            {
                return(true);
            }
            else if (this.IsUnrestricted())
            {
                return(false);
            }

            return(IsContentSubset(this.rootTable, targetPermission.rootTable));
        }
Beispiel #5
0
        /// <include file='doc\ResourcePermissionBase.uex' path='docs/doc[@for="ResourcePermissionBase.Intersect"]/*' />
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public override IPermission Intersect(IPermission target)
        {
            if (target == null)
            {
                return(null);
            }

            if (target.GetType() != this.GetType())
            {
                throw new ArgumentException("target");
            }

            ResourcePermissionBase targetPermission = (ResourcePermissionBase)target;

            if (this.IsUnrestricted())
            {
                return(targetPermission.Copy());
            }

            if (targetPermission.IsUnrestricted())
            {
                return(this.Copy());
            }

            ResourcePermissionBase newPermission = null;
            Hashtable newPermissionRootTable     = (Hashtable)IntersectContents(this.rootTable, targetPermission.rootTable);

            if (newPermissionRootTable != null)
            {
                newPermission           = CreateInstance();
                newPermission.rootTable = newPermissionRootTable;
            }
            return(newPermission);
        }
        public override IPermission Copy()
        {
            ResourcePermissionBase base2 = this.CreateInstance();

            base2.tagNames             = this.tagNames;
            base2.permissionAccessType = this.permissionAccessType;
            base2.isUnrestricted       = this.isUnrestricted;
            base2.rootTable            = this.CopyChildren(this.rootTable, 0);
            return(base2);
        }
Beispiel #7
0
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public override IPermission Copy()
        {
            ResourcePermissionBase permission = CreateInstance();

            permission.tagNames             = this.tagNames;
            permission.permissionAccessType = this.permissionAccessType;
            permission.isUnrestricted       = this.isUnrestricted;
            permission.rootTable            = CopyChildren(this.rootTable, 0);
            return(permission);
        }
Beispiel #8
0
        // Make a copy of this permission object.
        public override IPermission Copy()
        {
            ResourcePermissionBase perm =
                (ResourcePermissionBase)
                Activator.CreateInstance(GetType());

            perm.state      = state;
            perm.accessType = accessType;
            perm.tagNames   = tagNames;
            perm.permissions.AddRange(permissions);
            return(perm);
        }
        public override IPermission Copy()
        {
            ResourcePermissionBase copy = CreateFromType(this.GetType(), _unrestricted);

            if (_tags != null)
            {
                copy._tags = (string[])_tags.Clone();
            }
            copy._type = _type;
            // FIXME: shallow or deep copy ?
            copy._list.AddRange(_list);
            return(copy);
        }
        private ResourcePermissionBase Cast(IPermission target)
        {
            if (target == null)
            {
                return(null);
            }

            ResourcePermissionBase rp = (target as ResourcePermissionBase);

            if (rp == null)
            {
                PermissionHelper.ThrowInvalidPermission(target, typeof(ResourcePermissionBase));
            }

            return(rp);
        }
        public override IPermission Union(IPermission target)
        {
            ResourcePermissionBase rpb = Cast(target);

            if (rpb == null)
            {
                return(Copy());
            }
            if (IsEmpty() && rpb.IsEmpty())
            {
                return(null);
            }
            if (rpb.IsEmpty())
            {
                return(Copy());
            }
            if (IsEmpty())
            {
                return(rpb.Copy());
            }

            bool unrestricted             = (IsUnrestricted() || rpb.IsUnrestricted());
            ResourcePermissionBase result = CreateFromType(this.GetType(), unrestricted);

            // strangely unrestricted union doesn't process the elements (while intersect does)
            if (!unrestricted)
            {
                foreach (ResourcePermissionBaseEntry entry in _list)
                {
                    result.AddPermissionAccess(entry);
                }
                foreach (ResourcePermissionBaseEntry entry in rpb._list)
                {
                    // don't add twice
                    if (!result.Exists(entry))
                    {
                        result.AddPermissionAccess(entry);
                    }
                }
            }
            return(result);
        }
        public override IPermission Intersect(IPermission target)
        {
            ResourcePermissionBase rpb = Cast(target);

            if (rpb == null)
            {
                return(null);
            }

            bool su = this.IsUnrestricted();
            bool tu = rpb.IsUnrestricted();

            // if one is empty we return null (unless the other one is unrestricted)
            if (IsEmpty() && !tu)
            {
                return(null);
            }
            if (rpb.IsEmpty() && !su)
            {
                return(null);
            }

            ResourcePermissionBase result = CreateFromType(this.GetType(), (su && tu));

            foreach (ResourcePermissionBaseEntry entry in _list)
            {
                if (tu || rpb.Exists(entry))
                {
                    result.AddPermissionAccess(entry);
                }
            }
            foreach (ResourcePermissionBaseEntry entry in rpb._list)
            {
                // don't add twice
                if ((su || this.Exists(entry)) && !result.Exists(entry))
                {
                    result.AddPermissionAccess(entry);
                }
            }
            return(result);
        }