当前位置: 首页>>代码示例>>C#>>正文


C# NamedPermissionSet.AddPermission方法代码示例

本文整理汇总了C#中System.Security.NamedPermissionSet.AddPermission方法的典型用法代码示例。如果您正苦于以下问题:C# NamedPermissionSet.AddPermission方法的具体用法?C# NamedPermissionSet.AddPermission怎么用?C# NamedPermissionSet.AddPermission使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Security.NamedPermissionSet的用法示例。


在下文中一共展示了NamedPermissionSet.AddPermission方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Copy_Name

		public void Copy_Name ()
		{
			NamedPermissionSet nps = new NamedPermissionSet (name);
			nps.Description = sentinel;
			nps.AddPermission (new SecurityPermission (SecurityPermissionFlag.Assertion));
			NamedPermissionSet copy = (NamedPermissionSet)nps.Copy ("Copy");
			Assert.AreEqual ("Copy", copy.Name, "Name");
			Assert.AreEqual (nps.Description, copy.Description, "Description");
			Assert.AreEqual (nps.Count, copy.Count, "Count");
		}
开发者ID:symform,项目名称:mono,代码行数:10,代码来源:NamedPermissionSetTest.cs

示例2: CreateAppDomain

        private void CreateAppDomain()
        {
            // Locking s_AppDomains must happen in a CER so we don't orphan a lock that gets taken by AppDomain.DomainUnload.
            bool lockHeld = false;
            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
                try { }
                finally
                {
                    Monitor.Enter(s_AppDomains.SyncRoot);
                    lockHeld = true;
                }

                if (s_CleanedUp)
                {
                    throw new InvalidOperationException(SR.GetString(SR.net_cant_perform_during_shutdown));
                }

                // Create singleton.
                if (s_AppDomainInfo == null)
                {
                    s_AppDomainInfo = new AppDomainSetup();
                    s_AppDomainInfo.DisallowBindingRedirects = true;
                    s_AppDomainInfo.DisallowCodeDownload = true;

                    NamedPermissionSet perms = new NamedPermissionSet("__WebProxySandbox", PermissionState.None);
                    perms.AddPermission(new SecurityPermission(SecurityPermissionFlag.Execution));
                }

                // If something's already in s_ExcessAppDomain, try to dislodge it again.
                AppDomain excessAppDomain = s_ExcessAppDomain;
                if (excessAppDomain != null)
                {
                    TimerThread.GetOrCreateQueue(0).CreateTimer(new TimerThread.Callback(CloseAppDomainCallback), excessAppDomain);
                    throw new InvalidOperationException(SR.GetString(SR.net_cant_create_environment));
                }

                appDomainIndex = s_NextAppDomainIndex++;
                try { }
                finally
                {
                    //                                                                                                            
                    s_ExcessAppDomain = AppDomain.CreateDomain(c_appDomainName, null, s_AppDomainInfo);

                    try
                    {
                        s_AppDomains.Add(appDomainIndex, s_ExcessAppDomain);

                        // This indicates to the finally and the finalizer that everything succeeded.
                        scriptDomain = s_ExcessAppDomain;
                    }
                    finally
                    {
                        // ReferenceEquals has a ReliabilityContract.
                        if (object.ReferenceEquals(scriptDomain, s_ExcessAppDomain))
                        {
                            s_ExcessAppDomain = null;
                        }
                        else
                        {
                            // Something failed.  Leave the domain in s_ExcessAppDomain until we can get rid of it.  No
                            // more AppDomains can be created until we do.  In the mean time, keep attempting to get the
                            // TimerThread to remove it.  Also, might as well remove it from the hash if it made it in.
                            try
                            {
                                s_AppDomains.Remove(appDomainIndex);
                            }
                            finally
                            {
                                // Can't call AppDomain.Unload from a user thread (or in a lock).
                                TimerThread.GetOrCreateQueue(0).CreateTimer(new TimerThread.Callback(CloseAppDomainCallback), s_ExcessAppDomain);
                            }
                        }
                    }
                }
            }
            finally
            {
                if (lockHeld)
                {
                    Monitor.Exit(s_AppDomains.SyncRoot);
                }
            }
        }
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:85,代码来源:_autowebproxyscriptwrapper.cs

示例3: SecurityTemplate

        /// <summary>
        /// Creates a new instance providing default "FullTrust", "Nothing", "MediumTrust" and "LowTrust" permissionsets
        /// </summary>
        /// <param name="allowUnmanagedCode">NCover requires unmangaged code permissions, set this flag <c>true</c> in this case.</param>
        public SecurityTemplate(bool allowUnmanagedCode)
        {
            PolicyLevel pLevel = PolicyLevel.CreateAppDomainLevel();

            // NOTHING permissionset
            if (null == pLevel.GetNamedPermissionSet(PERMISSIONSET_NOTHING) )
            {
                NamedPermissionSet noPermissionSet = new NamedPermissionSet(PERMISSIONSET_NOTHING, PermissionState.None);
                noPermissionSet.AddPermission(new SecurityPermission(SecurityPermissionFlag.NoFlags));
                pLevel.AddNamedPermissionSet(noPermissionSet);
            }            

            // FULLTRUST permissionset
            if (null == pLevel.GetNamedPermissionSet(PERMISSIONSET_FULLTRUST))
            {
                NamedPermissionSet fulltrustPermissionSet = new NamedPermissionSet(PERMISSIONSET_FULLTRUST, PermissionState.Unrestricted);
                pLevel.AddNamedPermissionSet(fulltrustPermissionSet);
            }
            // MEDIUMTRUST permissionset (corresponds to ASP.Net permission set in web_mediumtrust.config)
            NamedPermissionSet mediumTrustPermissionSet = new NamedPermissionSet(PERMISSIONSET_MEDIUMTRUST, PermissionState.None);
            mediumTrustPermissionSet.AddPermission(new AspNetHostingPermission(AspNetHostingPermissionLevel.Medium));
            mediumTrustPermissionSet.AddPermission(new DnsPermission(PermissionState.Unrestricted));
            mediumTrustPermissionSet.AddPermission(new EnvironmentPermission(EnvironmentPermissionAccess.Read,
                                                                             "TEMP;TMP;USERNAME;OS;COMPUTERNAME"));
            mediumTrustPermissionSet.AddPermission(new FileIOPermission(FileIOPermissionAccess.AllAccess,
                                                                        AppDomain.CurrentDomain.BaseDirectory));
            IsolatedStorageFilePermission isolatedStorageFilePermission = new IsolatedStorageFilePermission(PermissionState.None);
            isolatedStorageFilePermission.UsageAllowed = IsolatedStorageContainment.AssemblyIsolationByUser;
            isolatedStorageFilePermission.UserQuota = 9223372036854775807;
            mediumTrustPermissionSet.AddPermission(isolatedStorageFilePermission);
            mediumTrustPermissionSet.AddPermission(new PrintingPermission(PrintingPermissionLevel.DefaultPrinting));
            SecurityPermissionFlag securityPermissionFlag = SecurityPermissionFlag.Assertion | SecurityPermissionFlag.Execution |
                                           SecurityPermissionFlag.ControlThread | SecurityPermissionFlag.ControlPrincipal |
                                           SecurityPermissionFlag.RemotingConfiguration;
            if (allowUnmanagedCode)
            {
                securityPermissionFlag |= SecurityPermissionFlag.UnmanagedCode;
            }
            mediumTrustPermissionSet.AddPermission(new SecurityPermission(securityPermissionFlag));
            mediumTrustPermissionSet.AddPermission(new System.Net.Mail.SmtpPermission(System.Net.Mail.SmtpAccess.Connect));
            mediumTrustPermissionSet.AddPermission(new SqlClientPermission(PermissionState.Unrestricted));
            mediumTrustPermissionSet.AddPermission(new WebPermission());
            pLevel.AddNamedPermissionSet(mediumTrustPermissionSet);

            // LOWTRUST permissionset (corresponds to ASP.Net permission set in web_mediumtrust.config)
            NamedPermissionSet lowTrustPermissionSet = new NamedPermissionSet(PERMISSIONSET_LOWTRUST, PermissionState.None);
            lowTrustPermissionSet.AddPermission(new AspNetHostingPermission(AspNetHostingPermissionLevel.Low));
            lowTrustPermissionSet.AddPermission(new FileIOPermission(FileIOPermissionAccess.Read|FileIOPermissionAccess.PathDiscovery,
                                                                        AppDomain.CurrentDomain.BaseDirectory));
            IsolatedStorageFilePermission isolatedStorageFilePermissionLow = new IsolatedStorageFilePermission(PermissionState.None);
            isolatedStorageFilePermissionLow.UsageAllowed = IsolatedStorageContainment.AssemblyIsolationByUser;
            isolatedStorageFilePermissionLow.UserQuota = 1048576;
            lowTrustPermissionSet.AddPermission(isolatedStorageFilePermissionLow);
            SecurityPermissionFlag securityPermissionFlagLow = SecurityPermissionFlag.Execution;
            if (allowUnmanagedCode)
            {
                securityPermissionFlagLow |= SecurityPermissionFlag.UnmanagedCode;
            }
            lowTrustPermissionSet.AddPermission(new SecurityPermission(securityPermissionFlagLow));
            pLevel.AddNamedPermissionSet(lowTrustPermissionSet);

//            UnionCodeGroup rootCodeGroup = new UnionCodeGroup(new AllMembershipCondition(), new PolicyStatement(noPermissionSet, PolicyStatementAttribute.Nothing));
//            pLevel.RootCodeGroup = rootCodeGroup;
            _domainPolicy = pLevel;
        }
开发者ID:kog,项目名称:Solenoid-Expressions,代码行数:69,代码来源:SecurityTemplate.cs

示例4: CreateBuiltinPermissionSet

	// Create a builtin permission set by name.
	private static PermissionSet CreateBuiltinPermissionSet(String name)
			{
				NamedPermissionSet set = null;
				switch(name)
				{
					case "Execution":
					{
						set = new NamedPermissionSet
							("Execution", PermissionState.None);
						set.Description = _("Arg_PermissionsExecution");
						set.AddPermission(new SecurityPermission
								(SecurityPermissionFlag.Execution));
					}
					break;

					case "FullTrust":
					{
						set = new NamedPermissionSet
							("FullTrust", PermissionState.Unrestricted);
						set.Description = _("Arg_PermissionsFullTrust");
					}
					break;

					case "Internet":
					{
						set = new NamedPermissionSet
							("Internet", PermissionState.None);
						set.Description = _("Arg_PermissionsInternet");
					}
					break;

					case "LocalIntranet":
					{
						set = new NamedPermissionSet
							("LocalIntranet", PermissionState.None);
						set.Description = _("Arg_PermissionsLocalIntranet");
					}
					break;

					case "Nothing":
					{
						set = new NamedPermissionSet
							("Nothing", PermissionState.None);
						set.Description = _("Arg_PermissionsNothing");
					}
					break;

					case "SkipVerification":
					{
						set = new NamedPermissionSet
							("SkipVerification", PermissionState.None);
						set.Description = _("Arg_PermissionsSkipVerification");
						set.AddPermission(new SecurityPermission
								(SecurityPermissionFlag.SkipVerification));
					}
					break;
				}
				return set;
			}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:60,代码来源:PermissionSetAttribute.cs

示例5: Copy

		public void Copy ()
		{
			NamedPermissionSet nps = new NamedPermissionSet (name);
			nps.Description = sentinel;
			nps.AddPermission (new SecurityPermission (SecurityPermissionFlag.Assertion));
			NamedPermissionSet copy = (NamedPermissionSet)nps.Copy ();
			AssertEquals ("Name", nps.Name, copy.Name);
			AssertEquals ("Description", nps.Description, copy.Description);
			AssertEquals ("Count", nps.Count, copy.Count);
		}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:10,代码来源:NamedPermissionSetTest.cs

示例6: CreateAppDomain

 private void CreateAppDomain()
 {
     bool lockTaken = false;
     RuntimeHelpers.PrepareConstrainedRegions();
     try
     {
         Monitor.Enter(s_AppDomains.SyncRoot, ref lockTaken);
         if (s_CleanedUp)
         {
             throw new InvalidOperationException(SR.GetString("net_cant_perform_during_shutdown"));
         }
         if (s_AppDomainInfo == null)
         {
             s_AppDomainInfo = new AppDomainSetup();
             s_AppDomainInfo.DisallowBindingRedirects = true;
             s_AppDomainInfo.DisallowCodeDownload = true;
             NamedPermissionSet permSet = new NamedPermissionSet("__WebProxySandbox", PermissionState.None);
             permSet.AddPermission(new SecurityPermission(SecurityPermissionFlag.Execution));
             ApplicationTrust trust = new ApplicationTrust {
                 DefaultGrantSet = new PolicyStatement(permSet)
             };
             s_AppDomainInfo.ApplicationTrust = trust;
             s_AppDomainInfo.ApplicationBase = Environment.SystemDirectory;
         }
         AppDomain context = s_ExcessAppDomain;
         if (context != null)
         {
             TimerThread.GetOrCreateQueue(0).CreateTimer(new TimerThread.Callback(AutoWebProxyScriptWrapper.CloseAppDomainCallback), context);
             throw new InvalidOperationException(SR.GetString("net_cant_create_environment"));
         }
         this.appDomainIndex = s_NextAppDomainIndex++;
         try
         {
         }
         finally
         {
             PermissionSet grantSet = new PermissionSet(PermissionState.None);
             grantSet.AddPermission(new SecurityPermission(SecurityPermissionFlag.Execution));
             s_ExcessAppDomain = AppDomain.CreateDomain("WebProxyScript", null, s_AppDomainInfo, grantSet, null);
             try
             {
                 s_AppDomains.Add(this.appDomainIndex, s_ExcessAppDomain);
                 this.scriptDomain = s_ExcessAppDomain;
             }
             finally
             {
                 if (object.ReferenceEquals(this.scriptDomain, s_ExcessAppDomain))
                 {
                     s_ExcessAppDomain = null;
                 }
                 else
                 {
                     try
                     {
                         s_AppDomains.Remove(this.appDomainIndex);
                     }
                     finally
                     {
                         TimerThread.GetOrCreateQueue(0).CreateTimer(new TimerThread.Callback(AutoWebProxyScriptWrapper.CloseAppDomainCallback), s_ExcessAppDomain);
                     }
                 }
             }
         }
     }
     finally
     {
         if (lockTaken)
         {
             Monitor.Exit(s_AppDomains.SyncRoot);
         }
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:72,代码来源:AutoWebProxyScriptWrapper.cs


注:本文中的System.Security.NamedPermissionSet.AddPermission方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。