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


C# Security.NamedPermissionSet类代码示例

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


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

示例1: Work

		// S1006/ImperativeSecurity
		public static void Work()
		{
			NamedPermissionSet permissions = new NamedPermissionSet("Custom");
			permissions.Demand();		
					
			SecureClass.RevertDocument();
		}
开发者ID:dbremner,项目名称:smokey,代码行数:8,代码来源:APTCA3.cs

示例2: 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

示例3: CreatePermissionSet

 protected internal override System.Security.PermissionSet CreatePermissionSet() {
     System.Security.PermissionSet permissionSet;
     if (ContainsKey(KEY.SaveFile)) {
         permissionSet = new NamedPermissionSet("FullTrust");
     }
     else {
         permissionSet = new System.Security.PermissionSet(System.Security.Permissions.PermissionState.None);
         permissionSet.AddPermission(new OdbcPermission(this));
     }
     return permissionSet;
 }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:11,代码来源:OdbcConnectionString.cs

示例4: Description

		public void Description () 
		{
			NamedPermissionSet nps = new NamedPermissionSet (name);
			// null by default (not empty)
			AssertNull ("Description", nps.Description);
			// is null-able (without exception)
			nps.Description = null;
			AssertNull ("Description(null)", nps.Description);
			nps.Description = sentinel;
			AssertEquals ("Description", sentinel, nps.Description);
		}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:11,代码来源:NamedPermissionSetTest.cs

示例5: ConstructorNameReserved

		public void ConstructorNameReserved ()
		{
			NamedPermissionSet nps = new NamedPermissionSet ("FullTrust");
			Assert.AreEqual ("FullTrust", nps.Name, "Name");
			Assert.IsNull (nps.Description, "Description");
			Assert.IsTrue (nps.IsUnrestricted (), "IsUnrestricted");
			Assert.IsTrue (!nps.IsEmpty (), "IsEmpty");
			Assert.IsTrue (!nps.IsReadOnly, "IsReadOnly");
			Assert.IsTrue (!nps.IsSynchronized, "IsSynchronized");
			Assert.AreEqual (0, nps.Count, "Count");
		}
开发者ID:symform,项目名称:mono,代码行数:11,代码来源:NamedPermissionSetTest.cs

示例6: ShouldWorkEvenWithLowestPossiblePermissions

        public void ShouldWorkEvenWithLowestPossiblePermissions()
        {
            // based on: https://msdn.microsoft.com/en-us/library/bb384237(v=vs.110).aspx
            Evidence evidence = new Evidence();
            evidence.AddHostEvidence(new Zone(SecurityZone.Internet));
            PermissionSet permissionSet = new NamedPermissionSet("Internet", SecurityManager.GetStandardSandbox(evidence));
            permissionSet.SetPermission(new ReflectionPermission(ReflectionPermissionFlag.RestrictedMemberAccess));
            AppDomainSetup appDomainSetup = new AppDomainSetup
            {
                ApplicationBase = "."
            };

            AppDomain sandbox = AppDomain.CreateDomain("Sandbox", evidence, appDomainSetup, permissionSet, null);
            CrossDomain crossDomain = (CrossDomain)sandbox.CreateInstanceAndUnwrap(typeof(CrossDomain).Assembly.FullName, typeof(CrossDomain).FullName);

            Assert.AreEqual(3, crossDomain.RunArrayProvider());
        }
开发者ID:adamsitnik,项目名称:slinq,代码行数:17,代码来源:SandboxPermissionsTests.cs

示例7: Access

        public static void Access()
        {
            // This security check fails if the caller
             // does not have full trust.
             NamedPermissionSet pset= new NamedPermissionSet("FullTrust");

             // This try-catch block shows the caller's permissions.
             // Correct code would either not catch the exception,
             // or would rethrow it.
             try
             {
            pset.Demand();
             }
             catch (SecurityException e)
             {
            Console.WriteLine("Demand for full trust:{0}", e.Message);
             }
             // Call the type that requires full trust.
             // Violates rule AptcaMethodsShouldOnlyCallAptcaMethods.
             ClassRequiringFullTrust.DoWork();
        }
开发者ID:terryjintry,项目名称:OLSource1,代码行数:21,代码来源:ca2116--aptca-methods-should-only-call-aptca-methods_2.cs

示例8: ToXml_Unrestricted

		public void ToXml_Unrestricted () 
		{
			NamedPermissionSet ps = new NamedPermissionSet (name, PermissionState.Unrestricted);
			SecurityElement se = ps.ToXml ();
			Assert.IsTrue (ps.ToString().StartsWith ("<PermissionSet"), "Unrestricted.ToString().StartsWith");
			Assert.AreEqual ("System.Security.NamedPermissionSet", (se.Attributes ["class"] as string), "Unrestricted.class");
			Assert.AreEqual ("1", (se.Attributes ["version"] as string), "Unrestricted.version");
			Assert.AreEqual (name, (se.Attributes ["Name"] as string), "Unrestricted.Name");
			Assert.IsNull ((se.Attributes ["Description"] as string), "Unrestricted.Description");
			Assert.AreEqual ("true", (se.Attributes ["Unrestricted"] as string), "Unrestricted.Unrestricted");
		}
开发者ID:symform,项目名称:mono,代码行数:11,代码来源:NamedPermissionSetTest.cs

示例9: Equals

		public void Equals () 
		{
			NamedPermissionSet psn = new NamedPermissionSet (name, PermissionState.None);
			NamedPermissionSet psu = new NamedPermissionSet (name, PermissionState.Unrestricted);
			Assert.IsTrue (!psn.Equals (psu), "psn!=psu");
			Assert.IsTrue (!psu.Equals (psn), "psu!=psn");
			NamedPermissionSet cpsn = (NamedPermissionSet) psn.Copy ();
			Assert.IsTrue (cpsn.Equals (psn), "cpsn==psn");
			Assert.IsTrue (psn.Equals (cpsn), "psn==cpsn");
			NamedPermissionSet cpsu = (NamedPermissionSet) psu.Copy ();
			Assert.IsTrue (cpsu.Equals (psu), "cpsu==psu");
			Assert.IsTrue (psu.Equals (cpsu), "psu==cpsu");
			cpsn.Description = sentinel;
			Assert.IsTrue (cpsn.Equals (psn), "cpsn+desc==psn");
			Assert.IsTrue (psn.Equals (cpsn), "psn==cpsn+desc");
			cpsn.Description = sentinel;
			Assert.IsTrue (cpsu.Equals (psu), "cpsu+desc==psu");
			Assert.IsTrue (psu.Equals (cpsu), "psu==cpsu+desc");
		}
开发者ID:symform,项目名称:mono,代码行数:19,代码来源:NamedPermissionSetTest.cs

示例10: FromXml_NoName

		public void FromXml_NoName ()
		{
			NamedPermissionSet nps = new NamedPermissionSet (name, PermissionState.None);
			SecurityElement se = nps.ToXml ();

			SecurityElement w = new SecurityElement (se.Tag);
			w.AddAttribute ("class", se.Attribute ("class"));
			w.AddAttribute ("version", "1");
			nps.FromXml (w);

			// having a null name can badly influence the rest of the class code
			Assert.IsNull (nps.Name, "Name");
			NamedPermissionSet copy = (NamedPermissionSet) nps.Copy ();
			Assert.IsNull (copy.Name, "Copy.Name");

			copy = nps.Copy ("name");
			Assert.AreEqual ("name", copy.Name, "Copy(Name).Name");

			se = nps.ToXml ();
			Assert.IsNull (se.Attribute ("Name"), "Name attribute");
#if NET_2_0
			Assert.AreEqual (0, nps.GetHashCode (), "GetHashCode");
			Assert.IsTrue (nps.Equals (nps), "Equals-self");
#endif
		}
开发者ID:symform,项目名称:mono,代码行数:25,代码来源:NamedPermissionSetTest.cs

示例11: FromXml

		public void FromXml () 
		{
			NamedPermissionSet nps = new NamedPermissionSet (name, PermissionState.None);
			SecurityElement se = nps.ToXml ();
			Assert.IsNotNull (se, "ToXml()");

			NamedPermissionSet nps2 = (NamedPermissionSet) nps.Copy ();
			nps2.FromXml (se);
			Assert.AreEqual (name, nps2.Name, "FromXml-Copy.Name");
			// strangely it's empty when converted from XML (but null when created)
			Assert.AreEqual ("", nps2.Description, "FromXml-Copy.Description");
			Assert.IsTrue (!nps2.IsUnrestricted () , "FromXml-Copy.IsUnrestricted");

			se.AddAttribute ("Description", sentinel);
			nps2.FromXml (se);
			Assert.AreEqual (name, nps2.Name, "FromXml-Add1.Name");
			Assert.AreEqual (sentinel, nps2.Description, "FromXml-Add1.Description");
			Assert.IsTrue (!nps2.IsUnrestricted () , "FromXml-Add1.IsUnrestricted");

			se.AddAttribute ("Unrestricted", "true");
			nps2.FromXml (se);
			Assert.AreEqual (name, nps2.Name, "FromXml-Add2.Name");
			Assert.AreEqual (sentinel, nps2.Description, "FromXml-Add2.Description");
			Assert.IsTrue (nps2.IsUnrestricted () , "FromXml-Add2.IsUnrestricted");
		}
开发者ID:symform,项目名称:mono,代码行数:25,代码来源:NamedPermissionSetTest.cs

示例12: 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

示例13: FromXml_NoVersion

		public void FromXml_NoVersion ()
		{
			NamedPermissionSet nps = new NamedPermissionSet (name, PermissionState.None);
			SecurityElement se = nps.ToXml ();

			SecurityElement w = new SecurityElement (se.Tag);
			w.AddAttribute ("class", se.Attribute ("class"));
			w.AddAttribute ("Name", se.Attribute ("Name"));
			nps.FromXml (w);
		}
开发者ID:symform,项目名称:mono,代码行数:10,代码来源:NamedPermissionSetTest.cs

示例14: CreatePermissionSetByName

        private static PermissionSet/*!*/ CreatePermissionSetByName() {
            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;
        }       
开发者ID:jcteague,项目名称:ironruby,代码行数:24,代码来源:Driver.cs

示例15: ConstructorNameEmpty

		public void ConstructorNameEmpty () 
		{
			NamedPermissionSet nps = new NamedPermissionSet ("");
		}
开发者ID:symform,项目名称:mono,代码行数:4,代码来源:NamedPermissionSetTest.cs


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