Пример #1
0
        /// <summary>
        /// Verifica se a permissão informada é um subconjunto da instancia.
        /// </summary>
        /// <param name="target"></param>
        /// <returns></returns>
        public bool IsSubsetOf(IPermission target)
        {
            if (target == null)
            {
                return(this.IsEmpty());
            }
            SystemPermission permission = target as SystemPermission;

            if (permission == null)
            {
                throw new ArgumentException(string.Format(Properties.Resources.Argument_WrongType, base.GetType().FullName));
            }
            if (permission.IsUnrestricted())
            {
                return(true);
            }
            if (!this.IsUnrestricted() && (((((this._read == null) || this._read.IsSubsetOf(permission._read)) && ((this._write == null) || this._write.IsSubsetOf(permission._write))) && (((this._execute == null) || this._execute.IsSubsetOf(permission._execute)) && ((this._pathDiscovery == null) || this._pathDiscovery.IsSubsetOf(permission._pathDiscovery)))) && ((this._viewAcl == null) || this._viewAcl.IsSubsetOf(permission._viewAcl))))
            {
                if (this._changeAcl != null)
                {
                    return(this._changeAcl.IsSubsetOf(permission._changeAcl));
                }
                return(true);
            }
            return(false);
        }
Пример #2
0
        /// <summary>
        /// Recupera a intercessão da instancia com a permissão informada.
        /// </summary>
        /// <param name="target"></param>
        /// <returns></returns>
        public IPermission Intersect(IPermission target)
        {
            if (target == null)
            {
                return(null);
            }
            SystemPermission permission = target as SystemPermission;

            if (permission == null)
            {
                throw new ArgumentException(string.Format(Properties.Resources.Argument_WrongType, base.GetType().FullName));
            }
            if (this.IsUnrestricted())
            {
                return(target.Copy());
            }
            if (permission.IsUnrestricted())
            {
                return(this.Copy());
            }
            SystemAccess access  = (this._read == null) ? null : this._read.Intersect(permission._read);
            SystemAccess access2 = (this._write == null) ? null : this._write.Intersect(permission._write);
            SystemAccess access3 = (this._execute == null) ? null : this._execute.Intersect(permission._execute);
            SystemAccess access4 = (this._pathDiscovery == null) ? null : this._pathDiscovery.Intersect(permission._pathDiscovery);
            SystemAccess access5 = (this._viewAcl == null) ? null : this._viewAcl.Intersect(permission._viewAcl);
            SystemAccess access6 = (this._changeAcl == null) ? null : this._changeAcl.Intersect(permission._changeAcl);

            if (((((access == null) || access.IsEmpty()) && ((access2 == null) || access2.IsEmpty())) && (((access3 == null) || access3.IsEmpty()) && ((access4 == null) || access4.IsEmpty()))) && (((access5 == null) || access5.IsEmpty()) && ((access6 == null) || access6.IsEmpty())))
            {
                return(null);
            }
            SystemPermission permission2 = new SystemPermission(PermissionState.None);

            permission2._unrestricted  = false;
            permission2._read          = access;
            permission2._write         = access2;
            permission2._execute       = access3;
            permission2._pathDiscovery = access4;
            permission2._viewAcl       = access5;
            permission2._changeAcl     = access6;
            return(permission2);
        }
Пример #3
0
        /// <summary>
        /// Cria uma cópia da permissão.
        /// </summary>
        /// <returns></returns>
        public IPermission Copy()
        {
            SystemPermission permission = new SystemPermission(PermissionState.None);

            if (this._unrestricted)
            {
                permission._unrestricted = true;
                return(permission);
            }
            permission._unrestricted = false;
            if (this._read != null)
            {
                permission._read = this._read.Copy();
            }
            if (this._write != null)
            {
                permission._write = this._write.Copy();
            }
            if (this._execute != null)
            {
                permission._execute = this._execute.Copy();
            }
            if (this._pathDiscovery != null)
            {
                permission._pathDiscovery = this._pathDiscovery.Copy();
            }
            if (this._viewAcl != null)
            {
                permission._viewAcl = this._viewAcl.Copy();
            }
            if (this._changeAcl != null)
            {
                permission._changeAcl = this._changeAcl.Copy();
            }
            return(permission);
        }
Пример #4
0
        /// <summary>
        /// Compara um objeto com a instancia.
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public override bool Equals(object obj)
        {
            SystemPermission permission = obj as SystemPermission;

            if (permission == null)
            {
                return(false);
            }
            if (!this._unrestricted || !permission._unrestricted)
            {
                if (this._unrestricted != permission._unrestricted)
                {
                    return(false);
                }
                if (this._read == null)
                {
                    if ((permission._read != null) && !permission._read.IsEmpty())
                    {
                        return(false);
                    }
                }
                else if (!this._read.Equals(permission._read))
                {
                    return(false);
                }
                if (this._write == null)
                {
                    if ((permission._write != null) && !permission._write.IsEmpty())
                    {
                        return(false);
                    }
                }
                else if (!this._write.Equals(permission._write))
                {
                    return(false);
                }
                if (this._execute == null)
                {
                    if ((permission._execute != null) && !permission._execute.IsEmpty())
                    {
                        return(false);
                    }
                }
                else if (!this._execute.Equals(permission._execute))
                {
                    return(false);
                }
                if (this._pathDiscovery == null)
                {
                    if ((permission._pathDiscovery != null) && !permission._pathDiscovery.IsEmpty())
                    {
                        return(false);
                    }
                }
                else if (!this._pathDiscovery.Equals(permission._pathDiscovery))
                {
                    return(false);
                }
                if (this._viewAcl == null)
                {
                    if ((permission._viewAcl != null) && !permission._viewAcl.IsEmpty())
                    {
                        return(false);
                    }
                }
                else if (!this._viewAcl.Equals(permission._viewAcl))
                {
                    return(false);
                }
                if (this._changeAcl == null)
                {
                    if ((permission._changeAcl != null) && !permission._changeAcl.IsEmpty())
                    {
                        return(false);
                    }
                }
                else if (!this._changeAcl.Equals(permission._changeAcl))
                {
                    return(false);
                }
            }
            return(true);
        }