Пример #1
0
        /// <summary>
        /// Creates and returns a permission that is the intersection
        /// of the current permission and the specified permission.
        /// </summary>
        /// <param name="target">A permission to intersect with the current permission.
        /// It must be of the same type as the current permission.</param>
        /// <returns>A new permission that represents the intersection of the current permission
        /// and the specified permission. This new permission is null if the intersectionis empty.</returns>
        public override System.Security.IPermission Intersect(System.Security.IPermission target)
        {
            // If 'target' is null, return null.
            if (target == null)
            {
                return(null);
            }

            // Both objects must be the same type.
            FileAccessPermission filePerm = VerifyTypeMatch(target);

            // If 'this' and 'target' are unrestricted, return a new unrestricted permission.
            if (_specifiedAsUnrestricted && filePerm._specifiedAsUnrestricted)
            {
                return(Clone(true, PermissionType.Unrestricted));
            }

            // Calculate the intersected permissions. If there are none, return null.
            PermissionType val = (PermissionType)Math.Min((Int32)_permission, (Int32)filePerm._permission);

            if (val == 0)
            {
                return(null);
            }

            // Get the intersect.
            val = new PermissionSource(_permission).Intersect(filePerm._permission);

            // Return a new object with the intersected permission value.
            return(Clone(false, val));
        }
Пример #2
0
        public override System.Security.IPermission Union(System.Security.IPermission target)
        {
            MemberAccessPermission result = (MemberAccessPermission)Copy();

            result.items.AddRange(((MemberAccessPermission)target).CloneItems());
            return(result);
        }
Пример #3
0
        /// <summary>
        /// Verify the type.
        /// </summary>
        /// <param name="target">The current target.</param>
        /// <returns>The file access permission is a match; else throw exception.</returns>
        private FileAccessPermission VerifyTypeMatch(System.Security.IPermission target)
        {
            if (GetType() != target.GetType())
            {
                throw new ArgumentException(String.Format("target must be of the {0} type", GetType().FullName));
            }

            return((FileAccessPermission)target);
        }
Пример #4
0
		public System.Security.IPermission Intersect(System.Security.IPermission target)
		{
			Report("{0}.Intersect(...)", this.GetType().FullName);

			if (target == null)
			{
				return null;
			}
			VerifyTargetType(target);
			GisaPrincipalPermission GisaTargetPermission = (GisaPrincipalPermission)target;

			GisaPrincipalPermission Result = new GisaPrincipalPermission(mPrincipal, null);
            

			ArrayList All = new ArrayList();

			if (this.mClassName != null && GisaTargetPermission.mClassName != null && this.mClassName.Equals(GisaTargetPermission.mClassName))
			{

				Result.mClassName = (string)(this.mClassName.Clone());
			}
			else
			{
				return null;
			}

			if (this.mOperations != null && GisaTargetPermission.mOperations != null)
			{
				foreach (string op in this.mOperations)
				{
					if (System.Array.IndexOf(GisaTargetPermission.mOperations, op) >= GisaTargetPermission.mOperations.GetLowerBound(0))
					{
						All.Add(op);
					}
				}
			}

			if (All.Count == 0)
			{
				return null;
			}
			else
			{

                Result.mOperations = new string[All.Count - 1];
                All.CopyTo(Result.mOperations);
                return Result;
//Nitro: TODO: INSTANT C# TODO TASK: The following 'ReDim' could not be resolved. A possible reason may be that the object of the ReDim was not declared as an array.
                /*
				ReDim Result.mOperations(All.Count - 1);
				All.CopyTo(Result.mOperations);
				return Result;
                */
			}

		}
Пример #5
0
 public override System.Security.IPermission CreatePermission()
 {
     System.Security.IPermission result = null;
     foreach (string perm in neededPermissions)
     {
         var p = new ApplicationDefinedPermission(PermissionState.Unrestricted)
         {
             Name = perm
         };
         result = (result == null ? p : result.Intersect(p));
     }
     return(result);
 }
 /// <summary>
 /// If the two operations allow the exact set of operations
 /// </summary>
 public bool IsSubsetOf(System.Security.IPermission target)
 {
     if (target == null)
     {
         return(!this.m_isUnrestricted);
     }
     else
     {
         var permission = target as PolicyPermission;
         return(permission.m_isUnrestricted == this.m_isUnrestricted &&
                this.m_policyId.StartsWith(permission.m_policyId));
     }
 }
Пример #7
0
		public System.Security.IPermission Union(System.Security.IPermission target)
		{
			Report("{0}.Union(...)", this.GetType().FullName);

			if (target == null)
			{
				return new GisaPrincipalPermission(mPrincipal, mClassName, this.mOperations);
			}
			else
			{
				VerifyTargetType(target);

				GisaPrincipalPermission GisaTargetPermission = (GisaPrincipalPermission)target;

				GisaPrincipalPermission Result = new GisaPrincipalPermission(mPrincipal, null);
				ArrayList All = new ArrayList();

				if (this.mClassName != null && GisaTargetPermission.mClassName != null && this.mClassName.Equals(GisaTargetPermission.mClassName))
				{

					Result.mClassName = (string)(this.mClassName.Clone());
				}
				else
				{
					Result.mClassName = null;
				}


				if (this.mOperations != null)
				{
					All.AddRange(this.mOperations);
				}

				if (GisaTargetPermission.mOperations != null)
				{
					foreach (string s in GisaTargetPermission.mOperations)
					{
						if (! (All.Contains(s)))
						{
							All.Add(s);
						}
					}
				}

//Nitro: TODO: INSTANT C# TODO TASK: The following 'ReDim' could not be resolved. A possible reason may be that the object of the ReDim was not declared as an array.
                Result.mOperations = new string[All.Count - 1];
                All.CopyTo(Result.mOperations);
                return Result;
			}
		}
Пример #8
0
        public override bool IsSubsetOf(System.Security.IPermission target)
        {
            var p = target as ApplicationDefinedPermission;

            if (p == null || p.Name == null || Name == null)
            {
                return(false);
            }

            return
                (this.Name.Length > p.Name.Length &&
                 this.Name.Substring(0, p.Name.Length) == p.Name &&
                 this.name[p.name.Length] == '.');
        }
Пример #9
0
        /// <summary>
        /// Determines whether the current permission
        /// is a subset of the specified permission.
        /// </summary>
        /// <param name="target">A permission that is to be tested for the subset relationship.
        /// This permission must be of the same type as the current permission.</param>
        /// <returns>True if the current permission is a subset of the specified permission; otherwise, false.</returns>
        public override bool IsSubsetOf(System.Security.IPermission target)
        {
            // If 'target' is null and this permission allows nothing, return true.
            if (target == null)
            {
                return(_permission == 0);
            }

            // Both objects must be the same type.
            FileAccessPermission filePerm = VerifyTypeMatch(target);

            // Return true if the permissions of 'this' is a subset of 'target'.
            return(new PermissionSource(_permission).IsSubsetOf(filePerm._permission));
        }
 /// <summary>
 /// Intersect the permission
 /// </summary>
 public System.Security.IPermission Intersect(System.Security.IPermission target)
 {
     if (target == null)
     {
         return(null);
     }
     if ((target as IUnrestrictedPermission)?.IsUnrestricted() == false)
     {
         return(target);
     }
     else
     {
         return(this.Copy());
     }
 }
Пример #11
0
 public override bool IsSubsetOf(System.Security.IPermission target)
 {
     if (base.IsSubsetOf(target))
     {
         foreach (MemberAccessPermissionItem targetItem in ((MemberAccessPermission)target).items)
         {
             if (targetItem.ObjectType == ObjectType &&
                 targetItem.MemberName == MemberName &&
                 targetItem.Operation == Operation)
             {
                 return(targetItem.Modifier == Modifier);
             }
         }
         return(true);
     }
     return(false);
 }
Пример #12
0
		private void VerifyTargetType(System.Security.IPermission target)
		{
			if (target == null || target is GisaPrincipalPermission)
			{
				return;
			}

			string targetTypeFullName = "unknown";
			try
			{
				targetTypeFullName = ((object)target).GetType().FullName;
			}
			catch (InvalidCastException)
			{
				targetTypeFullName = "unknown";
			}
			throw new ArgumentException(string.Format("The type of target is {0} and should be {1}", targetTypeFullName, this.GetType().FullName), "target");
		}
Пример #13
0
        /// <summary>
        /// Creates a permission that is the union of the current permission and the specified permission.
        /// </summary>
        /// <param name="target">A permission to combine with the current permission. It must be of the same
        /// type as the current permission.</param>
        /// <returns>A new permission that represents the union of the current permission and
        /// the specified permission.</returns>
        public override System.Security.IPermission Union(System.Security.IPermission target)
        {
            // If 'target' is null, then return a copy of 'this'.
            if (target == null)
            {
                return(Copy());
            }

            // Both objects must be the same type.
            FileAccessPermission filePerm = VerifyTypeMatch(target);

            // If 'this' or 'target' are unrestricted, return a new unrestricted permission.
            if (_specifiedAsUnrestricted || filePerm._specifiedAsUnrestricted)
            {
                return(Clone(true, PermissionType.Unrestricted));
            }

            // Return a new object with the calculated, unioned permission value.
            return(Clone(false, new PermissionSource(_permission).Union(filePerm._permission)));
        }
Пример #14
0
		public bool IsSubsetOf(System.Security.IPermission target)
		{
			Report("{0}.IsSubsetOf(...)", this.GetType().FullName);

			//FIXME: mClassName missing

			if (target == null)
			{
				return this.mOperations == null;
			}
			VerifyTargetType(target);

			if (! (this == target))
			{
				GisaPrincipalPermission GisaTargetPermission = (GisaPrincipalPermission)target;

				if (this.mOperations != null)
				{
					if (GisaTargetPermission.mOperations != null)
					{
						foreach (string s in this.mOperations)
						{
							if (System.Array.IndexOf(((GisaPrincipalPermission)target).mOperations, s) < ((GisaPrincipalPermission)target).mOperations.GetLowerBound(0))
							{
								return false;
							}
						}
					}
				}
				else
				{
					return GisaTargetPermission.mOperations == null;
				}
			}
			return true;
		}
 public IPermission Union(IPermission target)
 {
     throw new NotImplementedException();
 }
 public bool IsSubsetOf(IPermission target)
 {
     throw new NotImplementedException();
 }
 public IPermission Intersect(IPermission target)
 {
     throw new NotImplementedException();
 }
Пример #18
0
 public override System.Security.IPermission Intersect(System.Security.IPermission target)
 {
     throw new NotImplementedException();
 }
 public bool IsSubsetOf(IPermission target)
 {
     throw new NotImplementedException();
 }
Пример #20
0
 public override IPermission Intersect(System.Security.IPermission target)
 {
     return(null);
 }
 public IPermission Intersect(IPermission target)
 {
     throw new NotImplementedException();
 }
 public System.Security.IPermission Union(System.Security.IPermission target)
 {
     throw new NotImplementedException();
 }
 public IPermission Union(IPermission target)
 {
     throw new NotImplementedException();
 }