Beispiel #1
0
 /// <summary>
 /// Cria um nova instancia com base em dados da outro acesso.
 /// </summary>
 /// <param name="operand"></param>
 private SystemAccess(SystemAccess operand)
 {
     _ignoreCase    = true;
     _set           = operand._set.Copy();
     _allItems      = operand._allItems;
     _pathDiscovery = operand._pathDiscovery;
 }
Beispiel #2
0
        /// <summary>
        /// Faz uma intercessão dos acessos.
        /// </summary>
        /// <param name="operand"></param>
        /// <returns></returns>
        public SystemAccess Intersect(SystemAccess operand)
        {
            if (operand == null)
            {
                return(null);
            }
            if (_allItems)
            {
                if (operand._allItems)
                {
                    return(new SystemAccess(true, this._pathDiscovery));
                }
                return(new SystemAccess(operand._set.Copy(), false, _pathDiscovery));
            }
            if (operand._allItems)
            {
                return(new SystemAccess(_set.Copy(), false, _pathDiscovery));
            }
            StringExpressionSet set = new StringExpressionSet(_ignoreCase, true);

            string[] strArray3 = _set.Intersect(operand._set).ToStringArray();
            if (strArray3 != null)
            {
                set.AddExpressions(strArray3, !set.IsEmpty(), false);
            }
            return(new SystemAccess(set, false, _pathDiscovery));
        }
Beispiel #3
0
 /// <summary>
 /// Verifica se o acesso informado é um subconjunto da instancia.
 /// </summary>
 /// <param name="operand"></param>
 /// <returns></returns>
 public bool IsSubsetOf(SystemAccess operand)
 {
     if (operand == null)
     {
         return(this.IsEmpty());
     }
     if (!operand._allItems && ((!this._pathDiscovery || !_set.IsSubsetOfPathDiscovery(operand._set)) && !this._set.IsSubsetOf(operand._set)))
     {
         return(false);
     }
     return(true);
 }
Beispiel #4
0
 /// <summary>
 /// Realiza a união com o acesso informado.
 /// </summary>
 /// <param name="operand"></param>
 /// <returns></returns>
 public SystemAccess Union(SystemAccess operand)
 {
     if (operand == null)
     {
         if (!this.IsEmpty())
         {
             return(this.Copy());
         }
         return(null);
     }
     if (_allItems || operand._allItems)
     {
         return(new SystemAccess(true, _pathDiscovery));
     }
     return(new SystemAccess(this._set.Union(operand._set), false, this._pathDiscovery));
 }
Beispiel #5
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);
        }
Beispiel #6
0
        /// <summary>
        /// Compara um objeto com a instancia.
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public override bool Equals(object obj)
        {
            SystemAccess operand = obj as SystemAccess;

            if (operand == null)
            {
                return(this.IsEmpty() && (obj == null));
            }
            if (this._pathDiscovery)
            {
                return((this._allItems && operand._allItems) || (operand._set.IsSubsetOf(this._set)));
            }
            if (!this.IsSubsetOf(operand))
            {
                return(false);
            }
            if (!operand.IsSubsetOf(this))
            {
                return(false);
            }
            return(true);
        }
Beispiel #7
0
 /// <summary>
 /// Recupera os dados da permissão do elemento de segurança informado.
 /// </summary>
 /// <param name="esd"></param>
 public void FromXml(SecurityElement esd)
 {
     ValidateElement(esd, this);
     if (XMLUtil.IsUnrestricted(esd))
     {
         _unrestricted = true;
     }
     else
     {
         _unrestricted = false;
         string str = esd.Attribute("Read");
         if (str != null)
         {
             _read = new SystemAccess(str.TrimStart().TrimEnd());
         }
         else
         {
             _read = null;
         }
         str = esd.Attribute("Write");
         if (str != null)
         {
             _write = new SystemAccess(str.TrimStart().TrimEnd());
         }
         else
         {
             _write = null;
         }
         str = esd.Attribute("Execute");
         if (str != null)
         {
             _execute = new SystemAccess(str.TrimStart().TrimEnd());
         }
         else
         {
             _execute = null;
         }
         str = esd.Attribute("PathDiscovery");
         if (str != null)
         {
             _pathDiscovery = new SystemAccess(str.TrimStart().TrimEnd());
             _pathDiscovery.PathDiscovery = true;
         }
         else
         {
             _pathDiscovery = null;
         }
         str = esd.Attribute("ViewAcl");
         if (str != null)
         {
             _viewAcl = new SystemAccess(str.TrimStart().TrimEnd());
         }
         else
         {
             _viewAcl = null;
         }
         str = esd.Attribute("ChangeAcl");
         if (str != null)
         {
             _changeAcl = new SystemAccess(str.TrimStart().TrimEnd());
         }
         else
         {
             _changeAcl = null;
         }
     }
 }
Beispiel #8
0
 /// <summary>
 /// Adiciona uma lista de caminhos e acesso para a permissão.
 /// </summary>
 /// <param name="access"></param>
 /// <param name="control"></param>
 /// <param name="pathListOrig"></param>
 /// <param name="checkForDuplicates"></param>
 /// <param name="needFullPath"></param>
 /// <param name="copyPathList"></param>
 internal void AddPathList(SystemPermissionAccess access, AccessControlActions control, string[] pathListOrig, bool checkForDuplicates, bool needFullPath, bool copyPathList)
 {
     this.VerifyAccess(access);
     if (pathListOrig == null)
     {
         throw new ArgumentNullException("pathList");
     }
     if (pathListOrig.Length == 0)
     {
         throw new ArgumentException(Properties.Resources.Argument_EmptyPath);
     }
     if (!_unrestricted)
     {
         string[] destinationArray = pathListOrig;
         if (copyPathList)
         {
             destinationArray = new string[pathListOrig.Length];
             Array.Copy(pathListOrig, destinationArray, pathListOrig.Length);
         }
         HasIllegalCharacters(destinationArray);
         var values = StringExpressionSet.CreateListFromExpressions(destinationArray, needFullPath);
         if ((access & SystemPermissionAccess.Read) != SystemPermissionAccess.NoAccess)
         {
             if (_read == null)
             {
                 this._read = new SystemAccess();
             }
             this._read.AddExpressions(values, checkForDuplicates);
         }
         if ((access & SystemPermissionAccess.Write) != SystemPermissionAccess.NoAccess)
         {
             if (this._write == null)
             {
                 this._write = new SystemAccess();
             }
             this._write.AddExpressions(values, checkForDuplicates);
         }
         if ((access & SystemPermissionAccess.Execute) != SystemPermissionAccess.NoAccess)
         {
             if (this._execute == null)
             {
                 this._execute = new SystemAccess();
             }
             this._execute.AddExpressions(values, checkForDuplicates);
         }
         if ((control & AccessControlActions.View) != AccessControlActions.None)
         {
             if (this._viewAcl == null)
             {
                 this._viewAcl = new SystemAccess();
             }
             this._viewAcl.AddExpressions(values, checkForDuplicates);
         }
         if ((control & AccessControlActions.Change) != AccessControlActions.None)
         {
             if (this._changeAcl == null)
             {
                 this._changeAcl = new SystemAccess();
             }
             this._changeAcl.AddExpressions(values, checkForDuplicates);
         }
     }
 }