Inheritance: System.Security.CodeAccessPermission, IBuiltInPermission
コード例 #1
1
		public void SetPermission_Unrestricted ()
		{
			SecurityPermission sp = new SecurityPermission (PermissionState.Unrestricted);
			PermissionSet ps = new PermissionSet (PermissionState.Unrestricted);
			Assert.AreEqual (0, ps.Count, "Empty");
			Assert.IsTrue (ps.IsUnrestricted (), "State-Unrestricted");

			ZoneIdentityPermission zip = new ZoneIdentityPermission (SecurityZone.MyComputer);
			ZoneIdentityPermission zipr = (ZoneIdentityPermission)ps.SetPermission (zip);
			Assert.AreEqual (1, ps.Count, "ZoneIdentityPermission");
			Assert.AreEqual (SecurityZone.MyComputer, zipr.SecurityZone, "SecurityZone");
#if NET_2_0
			// Adding a non unrestricted identity permission now results in 
			// a permission set loosing it's unrestricted status
			Assert.IsTrue (!ps.IsUnrestricted (), "State-Unrestricted-2");
#else
			Assert.IsTrue (ps.IsUnrestricted (), "State-Unrestricted-2");
#endif
			zip = new ZoneIdentityPermission (SecurityZone.Intranet);
			zipr = (ZoneIdentityPermission)ps.SetPermission (zip);
			Assert.AreEqual (1, ps.Count, "ZoneIdentityPermission-2");
			Assert.AreEqual (SecurityZone.Intranet, zipr.SecurityZone, "SecurityZone-2");

			SecurityPermission result = (SecurityPermission)ps.SetPermission (sp);
			Assert.AreEqual (2, ps.Count, "SecurityPermission");
			Assert.AreEqual (SecurityPermissionFlag.AllFlags, result.Flags, "Flags");
			Assert.IsTrue (!ps.IsUnrestricted (), "State-None");

			sp = new SecurityPermission (SecurityPermissionFlag.ControlAppDomain);
			result = (SecurityPermission)ps.SetPermission (sp);
			Assert.AreEqual (2, ps.Count, "SecurityPermission-2");
			Assert.AreEqual (SecurityPermissionFlag.ControlAppDomain, result.Flags, "Flags-2");
		}
コード例 #2
0
        public override IPermission Union(IPermission target)
        {
            ZoneIdentityPermission zip = Cast(target);

            if (zip == null)
            {
                return((zone == SecurityZone.NoZone) ? null : Copy());
            }

            if (zone == zip.zone || zip.zone == SecurityZone.NoZone)
            {
                return(Copy());
            }

            if (zone == SecurityZone.NoZone)
            {
                return(zip.Copy());
            }
#if NET_2_0
            throw new ArgumentException(Locale.GetText(
                                            "Union impossible"));
#else
            return(null);
#endif
        }
コード例 #3
0
		private ZoneIdentityPermission BasicTestZone (SecurityZone zone, bool special)
		{
			ZoneIdentityPermission zip = new ZoneIdentityPermission (zone);
			Assert.AreEqual (zone, zip.SecurityZone, "SecurityZone");
			
			ZoneIdentityPermission copy = (ZoneIdentityPermission) zip.Copy ();
			Assert.IsTrue (Same (zip, copy), "Equals-Copy");
			Assert.IsTrue (zip.IsSubsetOf (copy), "IsSubset-1");
			Assert.IsTrue (copy.IsSubsetOf (zip), "IsSubset-2");
			if (special) {
				Assert.IsFalse (zip.IsSubsetOf (null), "IsSubset-Null");
			}
			
			IPermission intersect = zip.Intersect (copy);
			if (special) {
				Assert.IsTrue (intersect.IsSubsetOf (zip), "IsSubset-3");
				Assert.IsFalse (Object.ReferenceEquals (zip, intersect), "!ReferenceEquals1");
				Assert.IsTrue (intersect.IsSubsetOf (copy), "IsSubset-4");
				Assert.IsFalse (Object.ReferenceEquals (copy, intersect), "!ReferenceEquals2");
			}

			Assert.IsNull (zip.Intersect (null), "Intersect with null");

			intersect = zip.Intersect (new ZoneIdentityPermission (PermissionState.None));
			Assert.IsNull (intersect, "Intersect with PS.None");

			// note: can't be tested with PermissionState.Unrestricted

			// XML roundtrip
			SecurityElement se = zip.ToXml ();
			copy.FromXml (se);
			Assert.IsTrue (Same (zip, copy), "Equals-Xml");

			return zip;
		}
コード例 #4
0
        /// <summary>Creates a permission that is the union of the current permission and the specified permission.</summary>
        /// <returns>A new permission that represents the union of the current permission and the specified permission.</returns>
        /// <param name="target">A permission to combine with the current permission. It must be of the same type as the current permission. </param>
        /// <exception cref="T:System.ArgumentException">The <paramref name="target" /> parameter is not null and is not of the same type as the current permission. -or-The two permissions are not equal and the current permission does not represent the <see cref="F:System.Security.SecurityZone.NoZone" /> security zone.</exception>
        public override IPermission Union(IPermission target)
        {
            ZoneIdentityPermission zoneIdentityPermission = this.Cast(target);

            if (zoneIdentityPermission == null)
            {
                IPermission result;
                if (this.zone == SecurityZone.NoZone)
                {
                    IPermission permission = null;
                    result = permission;
                }
                else
                {
                    result = this.Copy();
                }
                return(result);
            }
            if (this.zone == zoneIdentityPermission.zone || zoneIdentityPermission.zone == SecurityZone.NoZone)
            {
                return(this.Copy());
            }
            if (this.zone == SecurityZone.NoZone)
            {
                return(zoneIdentityPermission.Copy());
            }
            throw new ArgumentException(Locale.GetText("Union impossible"));
        }
コード例 #5
0
        /// <include file='doc\ZoneIdentityPermission.uex' path='docs/doc[@for="ZoneIdentityPermission.Union"]/*' />
        public override IPermission Union(IPermission target)
        {
            if (target == null)
            {
                return(this.m_zone != SecurityZone.NoZone ? this.Copy() : null);
            }
            else if (!VerifyType(target))
            {
                throw new
                      ArgumentException(
                          String.Format(Environment.GetResourceString("Argument_WrongType"), this.GetType().FullName)
                          );
            }

            ZoneIdentityPermission operand = (ZoneIdentityPermission)target;

            if (this.m_zone == operand.m_zone || operand.m_zone == SecurityZone.NoZone)
            {
                return(this.Copy());
            }
            else if (this.m_zone == SecurityZone.NoZone)
            {
                return(operand.Copy());
            }
            else
            {
                return(null);
            }
        }
コード例 #6
0
		private bool Same (ZoneIdentityPermission zip1, ZoneIdentityPermission zip2)
		{
#if NET_2_0
			return zip1.Equals (zip2);
#else
			return (zip1.SecurityZone == zip2.SecurityZone);
#endif
		}
コード例 #7
0
		public void PermissionStateUnrestricted ()
		{
			// In 2.0 Unrestricted are permitted for identity permissions
			ZoneIdentityPermission zip = new ZoneIdentityPermission (PermissionState.Unrestricted);
			Assert.AreEqual (SecurityZone.NoZone, zip.SecurityZone);
			SecurityElement se = zip.ToXml ();
			Assert.AreEqual (5, se.Children.Count, "Count");
			// and they aren't equals to None
			Assert.IsFalse (zip.Equals (new ZoneIdentityPermission (PermissionState.None)));
		}
コード例 #8
0
        /// <summary>Determines whether the current permission is a subset of the specified permission.</summary>
        /// <returns>true if the current permission is a subset of the specified permission; otherwise, false.</returns>
        /// <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>
        /// <exception cref="T:System.ArgumentException">The <paramref name="target" /> parameter is not null, this permission does not represent the <see cref="F:System.Security.SecurityZone.NoZone" /> security zone, and the specified permission is not equal to the current permission. </exception>
        public override bool IsSubsetOf(IPermission target)
        {
            ZoneIdentityPermission zoneIdentityPermission = this.Cast(target);

            if (zoneIdentityPermission == null)
            {
                return(this.zone == SecurityZone.NoZone);
            }
            return(this.zone == SecurityZone.NoZone || this.zone == zoneIdentityPermission.zone);
        }
コード例 #9
0
        public override bool IsSubsetOf(IPermission target)
        {
            ZoneIdentityPermission zip = Cast(target);

            if (zip == null)
            {
                return(zone == SecurityZone.NoZone);
            }

            return((zone == SecurityZone.NoZone) || (zone == zip.zone));
        }
コード例 #10
0
        /// <summary>Creates and returns a permission that is the intersection of the current permission and the specified permission.</summary>
        /// <returns>A new permission that represents the intersection of the current permission and the specified permission. This new permission is null if the intersection is empty.</returns>
        /// <param name="target">A permission to intersect with the current permission. It must be of the same type as the current permission. </param>
        /// <exception cref="T:System.ArgumentException">The <paramref name="target" /> parameter is not null and is not of the same type as the current permission. </exception>
        public override IPermission Intersect(IPermission target)
        {
            ZoneIdentityPermission zoneIdentityPermission = this.Cast(target);

            if (zoneIdentityPermission == null || this.zone == SecurityZone.NoZone)
            {
                return(null);
            }
            if (this.zone == zoneIdentityPermission.zone)
            {
                return(this.Copy());
            }
            return(null);
        }
コード例 #11
0
        private ZoneIdentityPermission Cast(IPermission target)
        {
            if (target == null)
            {
                return(null);
            }
            ZoneIdentityPermission zoneIdentityPermission = target as ZoneIdentityPermission;

            if (zoneIdentityPermission == null)
            {
                CodeAccessPermission.ThrowInvalidPermission(target, typeof(ZoneIdentityPermission));
            }
            return(zoneIdentityPermission);
        }
コード例 #12
0
        public override bool IsSubsetOf(IPermission target)
        {
            if (target == null)
            {
                return(this.m_zones == 0);
            }
            ZoneIdentityPermission permission = target as ZoneIdentityPermission;

            if (permission == null)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", new object[] { base.GetType().FullName }));
            }
            return((this.m_zones & permission.m_zones) == this.m_zones);
        }
コード例 #13
0
        /// <summary>确定当前权限是否为指定权限的子集。</summary>
        /// <returns>如果当前权限是指定权限的子集,则为 true;否则为 false。</returns>
        /// <param name="target">将要测试子集关系的权限。此权限必须与当前权限属于同一类型。</param>
        /// <exception cref="T:System.ArgumentException">
        /// <paramref name="target" /> 参数不是 null,此权限不表示 <see cref="F:System.Security.SecurityZone.NoZone" /> 安全区域,而且指定的权限与当前权限不相等。</exception>
        public override bool IsSubsetOf(IPermission target)
        {
            if (target == null)
            {
                return((int)this.m_zones == 0);
            }
            ZoneIdentityPermission identityPermission = target as ZoneIdentityPermission;

            if (identityPermission == null)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", (object)this.GetType().FullName));
            }
            return(((int)this.m_zones & (int)identityPermission.m_zones) == (int)this.m_zones);
        }
コード例 #14
0
        public void AptcaIsPresentInSecurityCryptography()
        {
            try
            {
                ZoneIdentityPermission zoneIdentityPermission = new ZoneIdentityPermission(PermissionState.None);
                zoneIdentityPermission.Deny();

                Type type = typeof(CryptographySettings);
                object createdObject = Activator.CreateInstance(type);
            }
            finally
            {
                ZoneIdentityPermission.RevertDeny();
            }
        }
コード例 #15
0
        public void AptcaIsPresentInExceptionHandling()
        {
            try
            {
                ZoneIdentityPermission zoneIdentityPermission = new ZoneIdentityPermission(PermissionState.None);
                zoneIdentityPermission.Deny();

                Type type = typeof(ExceptionHandlingSettings);
                object createdObject = Activator.CreateInstance(type);
            }
            finally
            {
                ZoneIdentityPermission.RevertDeny();
            }
        }
コード例 #16
0
        public void AptcaIsPresentInPolicyInjection()
        {
            try
            {
                ZoneIdentityPermission zoneIdentityPermission = new ZoneIdentityPermission(PermissionState.None);
                zoneIdentityPermission.Deny();

                Type type = typeof(CustomMatchingRuleData);
                object createdObject = Activator.CreateInstance(type);
            }
            finally
            {
                ZoneIdentityPermission.RevertDeny();
            }
        }
コード例 #17
0
        public void AptcaIsPresentInLogging()
        {
            try
            {
                ZoneIdentityPermission zoneIdentityPermission = new ZoneIdentityPermission(PermissionState.None);
                zoneIdentityPermission.Deny();

                Type type = typeof(LogEntry);
                object createdObject = Activator.CreateInstance(type);
            }
            finally
            {
                ZoneIdentityPermission.RevertDeny();
            }
        }
コード例 #18
0
        public void AptcaIsPresentInValidationIntegrationAspNet()
        {
            try
            {
                ZoneIdentityPermission zoneIdentityPermission = new ZoneIdentityPermission(PermissionState.None);
                zoneIdentityPermission.Deny();

                Type type = typeof(PropertyProxyValidator);
                object createdObject = Activator.CreateInstance(type);
            }
            finally
            {
                ZoneIdentityPermission.RevertDeny();
            }
        }
コード例 #19
0
        public void AptcaIsPresentInCachingDatabase()
        {
            try
            {
                ZoneIdentityPermission zoneIdentityPermission = new ZoneIdentityPermission(PermissionState.None);
                zoneIdentityPermission.Deny();

                Type type = typeof(DataCacheStorageData);
                object createdObject = Activator.CreateInstance(type);
            }
            finally
            {
                ZoneIdentityPermission.RevertDeny();
            }
        }
コード例 #20
0
        public void AptcaIsPresentInAppSettingsConfigurationEnvironmentalOverrides()
        {
            try
            {
                ZoneIdentityPermission zoneIdentityPermission = new ZoneIdentityPermission(PermissionState.None);
                zoneIdentityPermission.Deny();

                Type type = typeof(EnvironmentNode);
                object createdObject = Activator.CreateInstance(type);
            }
            finally
            {
                ZoneIdentityPermission.RevertDeny();
            }
        }
コード例 #21
0
        public void AptcaIsPresentInCaching()
        {
            try
            {
                ZoneIdentityPermission zoneIdentityPermission = new ZoneIdentityPermission(PermissionState.None);
                zoneIdentityPermission.Deny();

                Type type = typeof(PriorityDateComparer);
                object createdObject = Activator.CreateInstance(type, new Hashtable());
            }
            finally
            {
                ZoneIdentityPermission.RevertDeny();
            }
        }
コード例 #22
0
        public void AptcaIsPresentInSecurityAzman()
        {
            try
            {
                ZoneIdentityPermission zoneIdentityPermission = new ZoneIdentityPermission(PermissionState.None);
                zoneIdentityPermission.Deny();

                Type type = typeof(AzManAuthorizationProviderData);
                object createdObject = Activator.CreateInstance(type);
            }
            finally
            {
                ZoneIdentityPermission.RevertDeny();
            }
        }
コード例 #23
0
        public override bool IsSubsetOf(IPermission target)
        {
            if (target == null)
            {
                return(this.m_zones == 0);
            }

            ZoneIdentityPermission that = target as ZoneIdentityPermission;

            if (that == null)
            {
                throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Argument_WrongType"), this.GetType().FullName));
            }
            return((this.m_zones & that.m_zones) == this.m_zones);
        }
コード例 #24
0
        public void AptcaIsPresentInLoggingDatabase()
        {
            try
            {
                ZoneIdentityPermission zoneIdentityPermission = new ZoneIdentityPermission(PermissionState.None);
                zoneIdentityPermission.Deny();

                Type type = typeof(FormattedDatabaseTraceListenerData);
                object createdObject = Activator.CreateInstance(type);
            }
            finally
            {
                ZoneIdentityPermission.RevertDeny();
            }
        }
コード例 #25
0
        public override IPermission Union(IPermission target)
        {
            if (target == null)
            {
                return(this.m_zones != 0 ? this.Copy() : null);
            }

            ZoneIdentityPermission that = target as ZoneIdentityPermission;

            if (that == null)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", this.GetType().FullName));
            }
            return(new ZoneIdentityPermission(this.m_zones | that.m_zones));
        }
コード例 #26
0
        public void CheckAptcaIsPresentInDataSqlCe()
        {
            try
            {
                ZoneIdentityPermission zoneIdentityPermission = new ZoneIdentityPermission(PermissionState.None);
                zoneIdentityPermission.Deny();

                Type type = typeof(SqlCeDatabase);

                object createdObject = Activator.CreateInstance(type, "connectionString");
            }
            finally
            {
                ZoneIdentityPermission.RevertDeny();
            }
        }
コード例 #27
0
        // helpers

        private ZoneIdentityPermission Cast(IPermission target)
        {
            if (target == null)
            {
                return(null);
            }

            ZoneIdentityPermission zip = (target as ZoneIdentityPermission);

            if (zip == null)
            {
                ThrowInvalidPermission(target, typeof(ZoneIdentityPermission));
            }

            return(zip);
        }
コード例 #28
0
        public override IPermission Intersect(IPermission target)
        {
            ZoneIdentityPermission zip = Cast(target);

            if (zip == null || zone == SecurityZone.NoZone)
            {
                return(null);
            }

            if (zone == zip.zone)
            {
                return(Copy());
            }

            return(null);
        }
コード例 #29
0
        public void AptcaIsPresentInCachingCryptography()
        {
            try
            {
                ZoneIdentityPermission zoneIdentityPermission = new ZoneIdentityPermission(PermissionState.None);
                zoneIdentityPermission.Deny();

                ISymmetricCryptoProvider symmetricCryptoProvider = null;

                Type type = typeof(SymmetricStorageEncryptionProvider);
                object createdObject = Activator.CreateInstance(type, symmetricCryptoProvider);
            }
            finally
            {
                ZoneIdentityPermission.RevertDeny();
            }
        }
コード例 #30
0
        public void AptcaIsPresentInData()
        {
            try
            {
                ZoneIdentityPermission zoneIdentityPermission = new ZoneIdentityPermission(PermissionState.None);
                zoneIdentityPermission.Deny();

                DbProviderFactory factory = DbProviderFactories.GetFactory("System.Data.SqlClient");

                Type type = typeof(GenericDatabase);
                object createdObject = Activator.CreateInstance(type, "connectionString", factory);
            }
            finally
            {
                ZoneIdentityPermission.RevertDeny();
            }
        }
コード例 #31
0
        /// <summary>创建一个权限,该权限是当前权限与指定权限的并集。</summary>
        /// <returns>一个新权限,它表示当前权限与指定权限的并集。</returns>
        /// <param name="target">将与当前权限合并的权限。它必须与当前权限属于同一类型。</param>
        /// <exception cref="T:System.ArgumentException">
        /// <paramref name="target" /> 参数不是 null,而且与当前权限不是同一类型。- 或 -这两个权限不相等,而且当前权限不表示 <see cref="F:System.Security.SecurityZone.NoZone" /> 安全区域。</exception>
        public override IPermission Union(IPermission target)
        {
            if (target == null)
            {
                if ((int)this.m_zones == 0)
                {
                    return((IPermission)null);
                }
                return(this.Copy());
            }
            ZoneIdentityPermission identityPermission = target as ZoneIdentityPermission;

            if (identityPermission == null)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", (object)this.GetType().FullName));
            }
            return((IPermission) new ZoneIdentityPermission(this.m_zones | identityPermission.m_zones));
        }
コード例 #32
0
        public override IPermission Union(IPermission target)
        {
            if (target == null)
            {
                if (this.m_zones == 0)
                {
                    return(null);
                }
                return(this.Copy());
            }
            ZoneIdentityPermission permission = target as ZoneIdentityPermission;

            if (permission == null)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", new object[] { base.GetType().FullName }));
            }
            return(new ZoneIdentityPermission(this.m_zones | permission.m_zones));
        }
 private void AppendZoneOrigin(ZoneIdentityPermission z, UrlIdentityPermission u)
 {
     if (z != null)
     {
         if (this.m_zoneList == null)
         {
             this.m_zoneList = new ArrayList();
         }
         z.AppendZones(this.m_zoneList);
     }
     if (u != null)
     {
         if (this.m_originList == null)
         {
             this.m_originList = new ArrayList();
         }
         u.AppendOrigin(this.m_originList);
     }
 }
コード例 #34
0
        public void AptcaIsPresentInCommon()
        {
            try
            {
                ZoneIdentityPermission zoneIdentityPermission = new ZoneIdentityPermission(PermissionState.None);
                zoneIdentityPermission.Deny();

                Type type = typeof(ByteArrayTypeConverter);
                object createdObject = Activator.CreateInstance(type);
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                ZoneIdentityPermission.RevertDeny();
            }
        }
コード例 #35
0
        public override IPermission Intersect(IPermission target)
        {
            if (target == null)
            {
                return(null);
            }

            ZoneIdentityPermission that = target as ZoneIdentityPermission;

            if (that == null)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", this.GetType().FullName));
            }
            uint newZones = this.m_zones & that.m_zones;

            if (newZones == 0)
            {
                return(null);
            }
            return(new ZoneIdentityPermission(newZones));
        }
コード例 #36
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 <see langword="null" /> if the intersection is empty.</returns>
        /// <exception cref="T:System.ArgumentException">The <paramref name="target" /> parameter is not <see langword="null" /> and is not of the same type as the current permission. </exception>
        // Token: 0x06002683 RID: 9859 RVA: 0x0008B978 File Offset: 0x00089B78
        public override IPermission Intersect(IPermission target)
        {
            if (target == null)
            {
                return(null);
            }
            ZoneIdentityPermission zoneIdentityPermission = target as ZoneIdentityPermission;

            if (zoneIdentityPermission == null)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", new object[]
                {
                    base.GetType().FullName
                }));
            }
            uint num = this.m_zones & zoneIdentityPermission.m_zones;

            if (num == 0U)
            {
                return(null);
            }
            return(new ZoneIdentityPermission(num));
        }
コード例 #37
0
		public void RemovePermission_Unrestricted ()
		{
			PermissionSet ps = new PermissionSet (PermissionState.Unrestricted);
			Assert.IsNull (ps.RemovePermission (typeof (SecurityPermission)), "Empty");
			SecurityPermission sp = new SecurityPermission (SecurityPermissionFlag.Assertion);
			ps.AddPermission (sp);
			Assert.IsNull (ps.RemovePermission (typeof (SecurityPermission)), "SecurityPermissionn");
			ZoneIdentityPermission zip = new ZoneIdentityPermission (SecurityZone.MyComputer);
			ps.AddPermission (zip);
			ZoneIdentityPermission removed = (ZoneIdentityPermission)ps.RemovePermission (typeof (ZoneIdentityPermission));
#if NET_2_0
			// identity permissions aren't added to unrestricted permission sets
			// so they cannot be removed later (hence the null)
			Assert.IsNull (removed, "ZoneIdentityPermission");
#else
			Assert.IsNotNull (removed, "ZoneIdentityPermission");
#endif
		}
コード例 #38
0
		public void IsSubset_OneNonIUnrestrictedPermission ()
		{
			ZoneIdentityPermission zip = new ZoneIdentityPermission (SecurityZone.MyComputer);
			PermissionSet ps1 = new PermissionSet (PermissionState.None);
			ps1.AddPermission (zip);
			PermissionSet ps2 = new PermissionSet (PermissionState.None);
			Assert.IsTrue (!ps1.IsSubsetOf (null), "PS1.IsSubset(null)");
			Assert.IsTrue (!ps1.IsSubsetOf (ps2), "PS1.IsSubset(None)");
			Assert.IsTrue (ps2.IsSubsetOf (ps1), "None.IsSubset(PS1)");

			PermissionSet ps3 = ps1.Copy ();
			Assert.IsTrue (ps1.IsSubsetOf (ps3), "PS1.IsSubset(PS3)");
			Assert.IsTrue (ps3.IsSubsetOf (ps1), "PS3.IsSubset(PS1)");

			PermissionSet ups1 = new PermissionSet (PermissionState.Unrestricted);
			ups1.AddPermission (zip);
			Assert.IsTrue (ps1.IsSubsetOf (ups1), "PS1.IsSubset(Unrestricted)");
			Assert.IsTrue (!ups1.IsSubsetOf (ps1), "Unrestricted.IsSubset(PS1)");

			PermissionSet ups2 = new PermissionSet (PermissionState.Unrestricted);
#if NET_2_0
			// as ZoneIdentityPermission isn't added UPS1Z == UPS2
			Assert.IsTrue (ups1.IsSubsetOf (ups2), "UPS1Z.IsSubset(UPS2)");
#else
			Assert.IsTrue (!ups1.IsSubsetOf (ups2), "UPS1Z.IsSubset(UPS2)");
#endif
			Assert.IsTrue (ups2.IsSubsetOf (ups1), "UPS2.IsSubset(UPS1Z)");
			ups2.AddPermission (zip);
			Assert.IsTrue (ups1.IsSubsetOf (ups2), "UPS1Z.IsSubset(UPS2Z)");
			Assert.IsTrue (ups2.IsSubsetOf (ups1), "UPS2Z.IsSubset(UPS1Z)");
		}
コード例 #39
0
		public void Intersect_OneNonIUnrestrictedPermission ()
		{
			ZoneIdentityPermission zip = new ZoneIdentityPermission (SecurityZone.MyComputer);
			PermissionSet ps1 = new PermissionSet (PermissionState.None);
			ps1.AddPermission (zip);
			PermissionSet ps2 = new PermissionSet (PermissionState.None);
			Assert.IsNull (ps1.Intersect (null), "PS1 N null");
			Assert.IsNull (ps1.Intersect (ps2), "PS1 N None");
			Assert.IsNull (ps2.Intersect (ps1), "None N PS1");

			PermissionSet ps3 = ps1.Copy ();
			Compare ("PS1 N PS3", ps1.Intersect (ps3), false, 1);
			Compare ("PS3 N PS1", ps3.Intersect (ps1), false, 1);

			PermissionSet ups1 = new PermissionSet (PermissionState.Unrestricted);
			ups1.AddPermission (zip);
			Compare ("PS1 N Unrestricted", ps1.Intersect (ups1), false, 1);
			Compare ("Unrestricted N PS1", ups1.Intersect (ps1), false, 1);

			PermissionSet ups2 = new PermissionSet (PermissionState.Unrestricted);
			Compare ("UPS1 N UPS2", ups1.Intersect (ups2), true, 0);
			Compare ("UPS2 N UPS1", ups2.Intersect (ups1), true, 0);
			ups2.AddPermission (zip);
#if NET_2_0
			// Identity permissions aren't added to unrestricted permission sets in 2.0
			Compare ("UPS1 N UPS2+ZIP", ups1.Intersect (ups2), true, 0);
			Compare ("UPS2+ZIP N UPS1", ups2.Intersect (ups1), true, 0);
#else
			Compare ("UPS1 N UPS2+ZIP", ups1.Intersect (ups2), true, 1);
			Compare ("UPS2+ZIP N UPS1", ups2.Intersect (ups1), true, 1);
#endif
		}
コード例 #40
0
		public void Copy_Unrestricted ()
		{
			PermissionSet ps = new PermissionSet (PermissionState.Unrestricted);
			PermissionSet copy = ps.Copy ();
			Assert.IsTrue (copy.IsUnrestricted (), "1.State");
			Assert.AreEqual (0, copy.Count, "1.Count");

			SecurityPermission sp = new SecurityPermission (SecurityPermissionFlag.ControlEvidence);
			IPermission result = ps.AddPermission (sp);
			Assert.IsNotNull (result, "1.Add");
			copy = ps.Copy ();
			Assert.IsTrue (copy.IsUnrestricted (), "2.State");
			Assert.AreEqual (0, copy.Count, "2.Count");

			ZoneIdentityPermission zip = new ZoneIdentityPermission (SecurityZone.MyComputer);
			result = ps.AddPermission (zip);
			Assert.IsNotNull (result, "2.Add");
			copy = ps.Copy ();
			Assert.IsTrue (copy.IsUnrestricted (), "3.State");
#if NET_2_0
			// Identity permissions aren't added to unrestricted permission sets in 2.0
			Assert.AreEqual (0, copy.Count, "3.Count");
#else
			Assert.AreEqual (1, copy.Count, "3.Count");
#endif
		}
コード例 #41
0
		public void Copy_None ()
		{
			PermissionSet ps = new PermissionSet (PermissionState.None);
			PermissionSet copy = ps.Copy ();
			Assert.IsTrue (!copy.IsUnrestricted (), "1.State");
			Assert.AreEqual (0, copy.Count, "1.Count");

			SecurityPermission sp = new SecurityPermission (SecurityPermissionFlag.ControlEvidence);
			IPermission result = ps.AddPermission (sp);
			Assert.IsNotNull (result, "1.Add");
			copy = ps.Copy ();
			Assert.IsTrue (!copy.IsUnrestricted (), "2.State");
			Assert.AreEqual (1, copy.Count, "2.Count");

			ZoneIdentityPermission zip = new ZoneIdentityPermission (SecurityZone.MyComputer);
			result = ps.AddPermission (zip);
			Assert.IsNotNull (result, "2.Add");
			copy = ps.Copy ();
			Assert.IsTrue (!copy.IsUnrestricted (), "3.State");
			Assert.AreEqual (2, copy.Count, "3.Count");
		}
コード例 #42
0
		public void AddPermission_SetUnrestricted ()
		{
			PermissionSet ps = new PermissionSet (PermissionState.Unrestricted);
			SecurityPermission sp = new SecurityPermission (SecurityPermissionFlag.ControlEvidence);
			IPermission result = ps.AddPermission (sp);
			Assert.IsNotNull (result, "Add(SecurityPermission)");
			Assert.AreEqual (SecurityPermissionFlag.AllFlags, (result as SecurityPermission).Flags, "SecurityPermission");
			Assert.AreEqual (0, ps.Count, "0");
			ZoneIdentityPermission zip = new ZoneIdentityPermission (SecurityZone.MyComputer);
			result = ps.AddPermission (zip);
			Assert.IsNotNull (result, "Add(ZoneIdentityPermission)");
#if NET_2_0
			// Identity permissions aren't added to unrestricted permission sets in 2.0
			Assert.AreEqual (SecurityZone.NoZone, (result as ZoneIdentityPermission).SecurityZone, "ZoneIdentityPermission");
			Assert.AreEqual (0, ps.Count, "1");
#else
			Assert.AreEqual (zip.SecurityZone, (result as ZoneIdentityPermission).SecurityZone, "ZoneIdentityPermission");
			Assert.AreEqual (1, ps.Count, "1");
#endif
		}
コード例 #43
0
 [System.Security.SecurityCritical]  // auto-generated
 internal void UpdateGrant(PermissionSet in_g, out ZoneIdentityPermission z,out UrlIdentityPermission u)
 {
     z = null;
     u = null;
     if (in_g != null)
     {
         if (GrantSet == null)
             GrantSet = in_g.Copy();
         else
             GrantSet.InplaceIntersect(in_g);
         
         z = (ZoneIdentityPermission)in_g.GetPermission(ZoneToken);
         u = (UrlIdentityPermission)in_g.GetPermission(UrlToken);
     }
 }
コード例 #44
0
 int IBuiltInPermission.GetTokenIndex()
 {
     return(ZoneIdentityPermission.GetTokenIndex());
 }
コード例 #45
0
		public void PermissionStateUnrestricted ()
		{
			ZoneIdentityPermission zip = new ZoneIdentityPermission (PermissionState.Unrestricted);
		}
コード例 #46
0
		public void SetPermission_None ()
		{
			PermissionSet ps = new PermissionSet (PermissionState.None);
			Assert.AreEqual (0, ps.Count, "Empty");
			Assert.IsTrue (!ps.IsUnrestricted (), "State-None");

			SecurityPermission sp = new SecurityPermission (PermissionState.Unrestricted);
			SecurityPermission result = (SecurityPermission)ps.SetPermission (sp);
			Assert.AreEqual (1, ps.Count, "SecurityPermission");
			Assert.AreEqual (SecurityPermissionFlag.AllFlags, result.Flags, "Flags");
			Assert.IsTrue (!ps.IsUnrestricted (), "State-None-2");

			sp = new SecurityPermission (SecurityPermissionFlag.ControlAppDomain);
			result = (SecurityPermission)ps.SetPermission (sp);
			Assert.AreEqual (1, ps.Count, "SecurityPermission-2");
			Assert.AreEqual (SecurityPermissionFlag.ControlAppDomain, result.Flags, "Flags");

			ZoneIdentityPermission zip = new ZoneIdentityPermission (SecurityZone.MyComputer);
			ZoneIdentityPermission zipr = (ZoneIdentityPermission) ps.SetPermission (zip);
			Assert.AreEqual (2, ps.Count, "ZoneIdentityPermission");
			Assert.AreEqual (SecurityZone.MyComputer, zipr.SecurityZone, "SecurityZone");

			zip = new ZoneIdentityPermission (SecurityZone.Intranet);
			zipr = (ZoneIdentityPermission)ps.SetPermission (zip);
			Assert.AreEqual (2, ps.Count, "ZoneIdentityPermission");
			Assert.AreEqual (SecurityZone.Intranet, zipr.SecurityZone, "SecurityZone");
		}
コード例 #47
0
		public void PermissionStateInvalid ()
		{
			ZoneIdentityPermission zip = new ZoneIdentityPermission ((PermissionState)2);
		}
コード例 #48
0
		public void Union_OneNonIUnrestrictedPermission ()
		{
			ZoneIdentityPermission zip = new ZoneIdentityPermission (SecurityZone.MyComputer);
			PermissionSet ps1 = new PermissionSet (PermissionState.None);
			ps1.AddPermission (zip);
			PermissionSet ps2 = new PermissionSet (PermissionState.None);
			Compare ("PS1 U null", ps1.Union (null), false, 1);
			Compare ("PS1 U None", ps1.Union (ps2), false, 1);
			Compare ("None U PS1", ps2.Union (ps1), false, 1);

			PermissionSet ps3 = ps1.Copy ();
			Compare ("PS1 U PS3", ps1.Union (ps3), false, 1);
			Compare ("PS3 U PS1", ps3.Union (ps1), false, 1);

			PermissionSet ups1 = new PermissionSet (PermissionState.Unrestricted);
			ups1.AddPermission (zip);
#if NET_2_0
			// Identity permissions aren't added to unrestricted permission sets in 2.0
			Compare ("PS1 U Unrestricted", ps1.Union (ups1), true, 0);
			Compare ("Unrestricted U PS1", ups1.Union (ps1), true, 0);
			PermissionSet ups2 = new PermissionSet (PermissionState.Unrestricted);
			Compare ("UPS1 U UPS2", ups1.Union (ups1), true, 0);
			Compare ("UPS2 U UPS1", ups2.Union (ups1), true, 0);
			ups2.AddPermission (zip);
			Compare ("UPS1 U UPS2+ZIP", ups1.Union (ups2), true, 0);
			Compare ("UPS2+ZIP U UPS1", ups2.Union (ups1), true, 0);
#else
			Compare ("PS1 U Unrestricted", ps1.Union (ups1), true, 1);
			Compare ("Unrestricted U PS1", ups1.Union (ps1), true, 1);
			PermissionSet ups2 = new PermissionSet (PermissionState.Unrestricted);
			Compare ("UPS1 U UPS2", ups1.Union (ups1), true, 1);
			Compare ("UPS2 U UPS1", ups2.Union (ups1), true, 1);
			ups2.AddPermission (zip);
			Compare ("UPS1 U UPS2+ZIP", ups1.Union (ups2), true, 1);
			Compare ("UPS2+ZIP U UPS1", ups2.Union (ups1), true, 1);
#endif
		}