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


C# Security.PermissionSet类代码示例

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


PermissionSet类属于System.Security命名空间,在下文中一共展示了PermissionSet类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreatePermissionSet

        /*!*/
        private static PermissionSet CreatePermissionSet()
        {
            #if CLR2
            string name = "Internet";
            bool foundName = false;
            PermissionSet setIntersection = new PermissionSet(PermissionState.Unrestricted);

            // iterate over each policy level
            IEnumerator e = SecurityManager.PolicyHierarchy();
            while (e.MoveNext()) {
                PolicyLevel level = (PolicyLevel)e.Current;
                PermissionSet levelSet = level.GetNamedPermissionSet(name);
                if (levelSet != null) {
                    foundName = true;
                    setIntersection = setIntersection.Intersect(levelSet);
                }
            }

            if (setIntersection == null || !foundName) {
                setIntersection = new PermissionSet(PermissionState.None);
            } else {
                setIntersection = new NamedPermissionSet(name, setIntersection);
            }

            return setIntersection;
            #else
            // this functionality is not available on Mono (AddHostEvidence is undefined), use dynamic to resolve it at runtime
            dynamic e = new Evidence();
            e.AddHostEvidence(new Zone(SecurityZone.Internet));
            return SecurityManager.GetStandardSandbox((Evidence)e);
            #endif
        }
开发者ID:TerabyteX,项目名称:main,代码行数:33,代码来源:PartialTrustDriver.cs

示例2: NewDomain

		static AppDomain NewDomain () {
			PolicyStatement statement = new PolicyStatement(new PermissionSet(PermissionState.None),PolicyStatementAttribute.Nothing);
			PermissionSet ps = new PermissionSet(PermissionState.None);
			ps.AddPermission(new SecurityPermission(SecurityPermissionFlag.Execution));
			ps.AddPermission(new SecurityPermission(SecurityPermissionFlag.Assertion));
			ps.AddPermission(new SecurityPermission(SecurityPermissionFlag.ControlAppDomain));
			ps.AddPermission(new SecurityPermission(SecurityPermissionFlag.ControlDomainPolicy));
			ps.AddPermission(new SecurityPermission(SecurityPermissionFlag.ControlEvidence));
			ps.AddPermission(new SecurityPermission(SecurityPermissionFlag.ControlPolicy));
			ps.AddPermission(new SecurityPermission(SecurityPermissionFlag.ControlPrincipal));
			ps.AddPermission(new SecurityPermission(SecurityPermissionFlag.ControlThread));
			ps.AddPermission(new SecurityPermission(SecurityPermissionFlag.Infrastructure));
			ps.AddPermission(new SecurityPermission(SecurityPermissionFlag.RemotingConfiguration));
			ps.AddPermission(new SecurityPermission(SecurityPermissionFlag.SerializationFormatter));
			ps.AddPermission(new FileIOPermission(PermissionState.Unrestricted));
			ps.AddPermission(new EnvironmentPermission(PermissionState.Unrestricted));
			ps.AddPermission(new ReflectionPermission(PermissionState.Unrestricted));
			ps.AddPermission(new RegistryPermission(PermissionState.Unrestricted));
			ps.AddPermission(new IsolatedStorageFilePermission(PermissionState.Unrestricted));
			ps.AddPermission(new EventLogPermission(PermissionState.Unrestricted));
			ps.AddPermission(new PerformanceCounterPermission(PermissionState.Unrestricted));
			ps.AddPermission(new DnsPermission(PermissionState.Unrestricted));
			ps.AddPermission(new UIPermission(PermissionState.Unrestricted));
   			PolicyStatement statement1 = new PolicyStatement(ps,PolicyStatementAttribute.Exclusive);
			CodeGroup group;
			group = new UnionCodeGroup(new AllMembershipCondition(),statement);
			group.AddChild(new UnionCodeGroup(new ZoneMembershipCondition(SecurityZone.MyComputer),statement1));
			PolicyLevel level = PolicyLevel.CreateAppDomainLevel();
			level.RootCodeGroup = group;

			AppDomain domain = AppDomain.CreateDomain ("test");
			domain.SetAppDomainPolicy(level);
			return domain;
		}
开发者ID:ItsVeryWindy,项目名称:mono,代码行数:34,代码来源:AssemblyRunner.cs

示例3: CreateAppDomain

        /// <summary>
        /// Creates an AppDomain.
        /// </summary>
        /// <param name="applicationName">The application name for the new AppDomain, or null if none.</param>
        /// <param name="applicationBaseDirectory">The application base directory for the new AppDomain, or null to use the current one.</param>
        /// <param name="configurationFile">The configuration file for the new AppDomain, or null to use the current one.</param>
        /// <param name="enableShadowCopy">If true, enables shadow copying within the AppDomain.</param>
        /// <returns>The new AppDomain.</returns>
        public static AppDomain CreateAppDomain(string applicationName, string applicationBaseDirectory, string configurationFile, bool enableShadowCopy)
        {
            AppDomainSetup appDomainSetup = new AppDomainSetup();

            appDomainSetup.ApplicationName = applicationName ?? string.Empty;
            appDomainSetup.ApplicationBase = applicationBaseDirectory ?? AppDomain.CurrentDomain.BaseDirectory;

            if (configurationFile != null)
            {
                // NOTE: We can also use AppDomainSetup.SetConfigurationBytes but it only applies to
                //       CLR-internal configuration settings such as the assembly binding policy.
                //       In order for other configuration mechanisms to operate correctly, we must
                //       use a real configuration file on disk instead.
                appDomainSetup.ConfigurationFile = configurationFile;
            }

            if (enableShadowCopy)
            {
                appDomainSetup.ShadowCopyFiles = @"true";
                appDomainSetup.ShadowCopyDirectories = null;
            }

            // TODO: Might need to be more careful about how the Evidence is derived.
            Evidence evidence = AppDomain.CurrentDomain.Evidence;
            if (DotNetRuntimeSupport.IsUsingMono)
            {
                return AppDomain.CreateDomain(appDomainSetup.ApplicationName, evidence, appDomainSetup);
            }
            else
            {
                PermissionSet defaultPermissionSet = new PermissionSet(PermissionState.Unrestricted);
                StrongName[] fullTrustAssemblies = new StrongName[0];
                return AppDomain.CreateDomain(appDomainSetup.ApplicationName, evidence, appDomainSetup, defaultPermissionSet, fullTrustAssemblies);
            }
        }
开发者ID:rprouse,项目名称:mbunit-v3,代码行数:43,代码来源:AppDomainUtils.cs

示例4: PermissionSet

        public void GeneratedTypeForAdditionalInterfaceWithMethodsHavingSignaturesMatchingMethodsInTheBaseClassIsVerifiable()
        {
            PermissionSet grantSet = new PermissionSet(PermissionState.None);
            grantSet.AddPermission(
                new SecurityPermission(
                    SecurityPermissionFlag.Execution
                    | SecurityPermissionFlag.ControlEvidence
                    | SecurityPermissionFlag.ControlPolicy));
            grantSet.AddPermission(
                new ReflectionPermission(ReflectionPermissionFlag.RestrictedMemberAccess
                    | ReflectionPermissionFlag.MemberAccess));
            grantSet.AddPermission(new FileIOPermission(PermissionState.Unrestricted));

            AppDomain sandbox =
                AppDomain.CreateDomain(
                    "sandbox",
                    AppDomain.CurrentDomain.Evidence,
                    new AppDomainSetup { ApplicationBase = AppDomain.CurrentDomain.BaseDirectory },
                    grantSet);

            sandbox.DoCallBack(() =>
            {
                InterceptingClassGenerator generator =
                    new InterceptingClassGenerator(typeof(MainType), typeof(IDoSomething), typeof(IDoSomethingToo));
                Type generatedType = generator.GenerateType();
            });
        }
开发者ID:kangkot,项目名称:unity,代码行数:27,代码来源:InterceptingClassGenerationFixture.Desktop.cs

示例5: XmlILModule

        static XmlILModule() {
            AssemblyName asmName;
            AssemblyBuilder asmBldr;

            CreateModulePermissionSet = new PermissionSet(PermissionState.None);
            // CreateDelegate demands MemberAccess permission
            CreateModulePermissionSet.AddPermission(new ReflectionPermission(ReflectionPermissionFlag.MemberAccess));
            // DynamicMethod constructor demands ControlEvidence permissions. 
            // Emitting symbols in DefineDynamicModule (to allow to debug the stylesheet) requires UnmanagedCode permission. 
            CreateModulePermissionSet.AddPermission(new SecurityPermission(SecurityPermissionFlag.ControlEvidence | SecurityPermissionFlag.UnmanagedCode));

            AssemblyId = 0;

            // 1. LRE assembly only needs to execute
            // 2. No temp files need be created
            // 3. Never allow assembly to Assert permissions
            asmName = CreateAssemblyName();
            asmBldr = AppDomain.CurrentDomain.DefineDynamicAssembly(asmName, AssemblyBuilderAccess.Run);

            try {
                CreateModulePermissionSet.Assert();

                // Add custom attribute to assembly marking it as security transparent so that Assert will not be allowed
                // and link demands will be converted to full demands.
                asmBldr.SetCustomAttribute(new CustomAttributeBuilder(XmlILConstructors.Transparent, new object[] {}));

                // Store LREModule once.  If multiple threads are doing this, then some threads might get different
                // modules.  This is OK, since it's not mandatory to share, just preferable.
                LREModule = asmBldr.DefineDynamicModule("System.Xml.Xsl.CompiledQuery", false);
            }
            finally {
                CodeAccessPermission.RevertAssert();
            }
        }
开发者ID:uQr,项目名称:referencesource,代码行数:34,代码来源:XmlILModule.cs

示例6: JintEngine

        public JintEngine(Options options) {
            Visitor = new ExecutionVisitor(options);
            permissionSet = new PermissionSet(PermissionState.None);
            Visitor.AllowClr = allowClr;
            MaxRecursions = 400;
	        MaxSteps = 100 * 1000;

            var global = Visitor.Global as JsObject;

            global["ToBoolean"] = Visitor.Global.FunctionClass.New(new Func<object, Boolean>(Convert.ToBoolean));
            global["ToByte"] = Visitor.Global.FunctionClass.New(new Func<object, Byte>(Convert.ToByte));
            global["ToChar"] = Visitor.Global.FunctionClass.New(new Func<object, Char>(Convert.ToChar));
            global["ToDateTime"] = Visitor.Global.FunctionClass.New(new Func<object, DateTime>(Convert.ToDateTime));
            global["ToDecimal"] = Visitor.Global.FunctionClass.New(new Func<object, Decimal>(Convert.ToDecimal));
            global["ToDouble"] = Visitor.Global.FunctionClass.New(new Func<object, Double>(Convert.ToDouble));
            global["ToInt16"] = Visitor.Global.FunctionClass.New(new Func<object, Int16>(Convert.ToInt16));
            global["ToInt32"] = Visitor.Global.FunctionClass.New(new Func<object, Int32>(Convert.ToInt32));
            global["ToInt64"] = Visitor.Global.FunctionClass.New(new Func<object, Int64>(Convert.ToInt64));
            global["ToSByte"] = Visitor.Global.FunctionClass.New(new Func<object, SByte>(Convert.ToSByte));
            global["ToSingle"] = Visitor.Global.FunctionClass.New(new Func<object, Single>(Convert.ToSingle));
            global["ToString"] = Visitor.Global.FunctionClass.New(new Func<object, String>(Convert.ToString));
            global["ToUInt16"] = Visitor.Global.FunctionClass.New(new Func<object, UInt16>(Convert.ToUInt16));
            global["ToUInt32"] = Visitor.Global.FunctionClass.New(new Func<object, UInt32>(Convert.ToUInt32));
            global["ToUInt64"] = Visitor.Global.FunctionClass.New(new Func<object, UInt64>(Convert.ToUInt64));

            BreakPoints = new List<BreakPoint>();
        }
开发者ID:925coder,项目名称:ravendb,代码行数:27,代码来源:JintEngine.cs

示例7: JintEngine

        public JintEngine()
        {
            PermissionSet = new PermissionSet(PermissionState.None);
            TypeSystem = new TypeSystem();

            _runtime = new JintRuntime(this);
        }
开发者ID:pvginkel,项目名称:Jint2,代码行数:7,代码来源:JintEngine.cs

示例8: Open

      public void Open()
      {
         if(State != CommunicationState.Created)
         {
            return;
         }
         try
         {
            Opening(this,EventArgs.Empty);

            //Permission required to read the providers application name and access config
            PermissionSet permissions = new PermissionSet(PermissionState.None);
            permissions.AddPermission(new AspNetHostingPermission(AspNetHostingPermissionLevel.Minimal));
            permissions.AddPermission(new FileIOPermission(PermissionState.Unrestricted));

            permissions.Assert();

            m_ServiceHostActivator.MembershipApplicationName = Membership.ApplicationName;
            if(Roles.Enabled)
            {
               m_ServiceHostActivator.RolesApplicationName = Roles.ApplicationName;
            }
            PermissionSet.RevertAssert();

            m_ServiceHostActivator.Open();

            State = CommunicationState.Opened;

            Opened(this,EventArgs.Empty);
         }
         catch
         {
            State = CommunicationState.Faulted;
         }
      }
开发者ID:spzenk,项目名称:sfdocsamples,代码行数:35,代码来源:AppDomainHost.cs

示例9: ParsePermissionSet

 private PermissionSet ParsePermissionSet(Parser parser)
 {
     SecurityElement topElement = parser.GetTopElement();
     PermissionSet set = new PermissionSet(PermissionState.None);
     set.FromXml(topElement);
     return set;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:7,代码来源:PermissionSetAttribute.cs

示例10: DownloadManifestAsync

        public static Task<GetManifestCompletedEventArgs> DownloadManifestAsync(this InPlaceHostingManager manager) {
            var tcs = new TaskCompletionSource<GetManifestCompletedEventArgs>();

            manager.GetManifestCompleted += (sender, e) => {
                if(e.Error != null) {
                    tcs.SetException(e.Error);
                    return;
                }

                var trust = new ApplicationTrust();
                var permissions = new PermissionSet(PermissionState.Unrestricted);
                var statement = new PolicyStatement(permissions);

                trust.DefaultGrantSet = statement;
                trust.ApplicationIdentity = e.ApplicationIdentity;
                trust.IsApplicationTrustedToRun = true;

                ApplicationSecurityManager.UserApplicationTrusts.Add(trust);

                tcs.SetResult(e);
            };

            manager.GetManifestAsync();

            return tcs.Task;
        }
开发者ID:migrap,项目名称:ClickOnceMsi,代码行数:26,代码来源:Extensions.cs

示例11: Sandbox

        //Create a SandBox to load Assemblies with "Full Trust"
        public static ServiceBridge Sandbox(string assemblyFilename, string configPath, ResolveEventHandler handler)
        {
            var trustedLoadGrantSet = new PermissionSet(PermissionState.Unrestricted);
            var trustedLoadSetup = new AppDomainSetup();
            trustedLoadSetup.ApplicationBase = Path.GetDirectoryName(assemblyFilename);
            trustedLoadSetup.PrivateBinPath = Path.GetDirectoryName(assemblyFilename);
            //trustedLoadSetup.ConfigurationFile = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
            trustedLoadSetup.ConfigurationFile = configPath;

            AppDomain.CurrentDomain.AssemblyResolve += handler;
            AppDomain appDomain = AppDomain.CreateDomain("ServiceBridge SandBox", null, trustedLoadSetup, trustedLoadGrantSet);
            appDomain.SetData("DataDirectory", configPath.Replace("Web.config", "App_Data"));

            ServiceBridge loader = appDomain.CreateInstanceAndUnwrap(
                typeof(ServiceBridge).Assembly.GetName().FullName,
                typeof(ServiceBridge).FullName,
                false,
                BindingFlags.Default,
                null,
                new object[] { assemblyFilename },
                CultureInfo.InvariantCulture,
                null) as ServiceBridge;

            return loader;
        }
开发者ID:umbraco,项目名称:Visual-Studio-Extension,代码行数:26,代码来源:ServiceBridge.cs

示例12: CreateSkipVerificationSet

        private static PermissionSet CreateSkipVerificationSet() {
            PermissionSet permSet = new PermissionSet(PermissionState.None);
#pragma warning disable 618
            permSet.AddPermission(new SecurityPermission(SecurityPermissionFlag.SkipVerification));
#pragma warning restore 618
            return permSet;
        }
开发者ID:kouvel,项目名称:coreclr,代码行数:7,代码来源:NamedPermissionSet.cs

示例13: PermissionRequestEvidence

 public PermissionRequestEvidence(PermissionSet request, PermissionSet optional, PermissionSet denied)
 {
     if (request == null)
     {
         this.m_request = null;
     }
     else
     {
         this.m_request = request.Copy();
     }
     if (optional == null)
     {
         this.m_optional = null;
     }
     else
     {
         this.m_optional = optional.Copy();
     }
     if (denied == null)
     {
         this.m_denied = null;
     }
     else
     {
         this.m_denied = denied.Copy();
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:27,代码来源:PermissionRequestEvidence.cs

示例14: Create_permission_set_for_sandbox_AppDomain

 private static PermissionSet Create_permission_set_for_sandbox_AppDomain(string beitragspfad)
 {
     PermissionSet permissionSet = new PermissionSet(PermissionState.None);
     permissionSet.AddPermission(new SecurityPermission(SecurityPermissionFlag.Execution));
     permissionSet.AddPermission(new FileIOPermission(FileIOPermissionAccess.AllAccess, beitragspfad));
     return permissionSet;
 }
开发者ID:dotnetpro,项目名称:contest042016,代码行数:7,代码来源:AppDomain_erzeugen.cs

示例15: PermissionSet

 public PermissionSet(PermissionSet permSet) : this()
 {
     if (permSet == null)
     {
         this.Reset();
     }
     else
     {
         this.m_Unrestricted = permSet.m_Unrestricted;
         this.m_CheckedForNonCas = permSet.m_CheckedForNonCas;
         this.m_ContainsCas = permSet.m_ContainsCas;
         this.m_ContainsNonCas = permSet.m_ContainsNonCas;
         this.m_ignoreTypeLoadFailures = permSet.m_ignoreTypeLoadFailures;
         if (permSet.m_permSet != null)
         {
             this.m_permSet = new TokenBasedSet(permSet.m_permSet);
             for (int i = this.m_permSet.GetStartingIndex(); i <= this.m_permSet.GetMaxUsedIndex(); i++)
             {
                 object item = this.m_permSet.GetItem(i);
                 IPermission permission = item as IPermission;
                 ISecurityElementFactory factory = item as ISecurityElementFactory;
                 if (permission != null)
                 {
                     this.m_permSet.SetItem(i, permission.Copy());
                 }
                 else if (factory != null)
                 {
                     this.m_permSet.SetItem(i, factory.Copy());
                 }
             }
         }
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:33,代码来源:PermissionSet.cs


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