상속: ICollection, IEnumerable
예제 #1
0
        // 2.0 metadata format

        internal static PermissionSetCollection CreateFromBinaryFormat(byte[] data)
        {
            if ((data == null) || (data [0] != 0x2E) || (data.Length < 2))
            {
                string msg = Locale.GetText("Invalid data in 2.0 metadata format.");
                throw new SecurityException(msg);
            }

            int pos     = 1;
            int numattr = PermissionSet.ReadEncodedInt(data, ref pos);
            PermissionSetCollection psc = new PermissionSetCollection();

            for (int i = 0; i < numattr; i++)
            {
                IPermission p = PermissionSet.ProcessAttribute(data, ref pos);
                if (p == null)
                {
                    string msg = Locale.GetText("Unsupported data found in 2.0 metadata format.");
                    throw new SecurityException(msg);
                }

                PermissionSet ps = new PermissionSet(PermissionState.None);
                ps.DeclarativeSecurity = true;
                ps.AddPermission(p);
                psc.Add(ps);
            }
            return(psc);
        }
예제 #2
0
		public PermissionSetCollection Copy ()
		{
			PermissionSetCollection psc = new PermissionSetCollection ();
			foreach (PermissionSet ps in _list) {
				psc._list.Add (ps.Copy ());
			}
			return psc;
		}
예제 #3
0
        public PermissionSetCollection Copy()
        {
            PermissionSetCollection psc = new PermissionSetCollection();

            foreach (PermissionSet ps in _list)
            {
                psc._list.Add(ps.Copy());
            }
            return(psc);
        }
예제 #4
0
		public void FromXml_Roundtrip ()
		{
			PermissionSetCollection psc = new PermissionSetCollection ();
			string expected = psc.ToString ();
			SecurityElement se = psc.ToXml ();
			psc.FromXml (se);
			string actual = psc.ToString ();
			Assert.AreEqual (expected, actual, "Empty");

			PermissionSet none = new PermissionSet (PermissionState.None);
			psc.Add (none);
			expected = psc.ToString ();
			se = psc.ToXml ();
			psc.FromXml (se);
			actual = psc.ToString ();
			Assert.AreEqual (expected, actual, "1-None");

			none.AddPermission (new SecurityPermission (SecurityPermissionFlag.Assertion));
			expected = psc.ToString ();
			se = psc.ToXml ();
			psc.FromXml (se);
			actual = psc.ToString ();
			Assert.AreEqual (expected, actual, "1-Assertion");
			Assert.AreEqual (1, psc.Count, "1");

			PermissionSet unr = new PermissionSet (PermissionState.Unrestricted);
			psc.Add (unr);
			expected = psc.ToString ();
			se = psc.ToXml ();
			psc.FromXml (se);
			actual = psc.ToString ();
			Assert.AreEqual (expected, actual, "2-Assertion+Unrestricted");
			Assert.AreEqual (2, psc.Count, "2");
		}
예제 #5
0
		public void FromXml_BadName ()
		{
			PermissionSetCollection psc = new PermissionSetCollection ();
			SecurityElement se = new SecurityElement ("PermissionZetCollection");
			psc.FromXml (se);
		}
예제 #6
0
		public void FromXml_Null ()
		{
			PermissionSetCollection psc = new PermissionSetCollection ();
			psc.FromXml (null);
		}
예제 #7
0
		public void RemoveSet ()
		{
			PermissionSetCollection psc = new PermissionSetCollection ();
			PermissionSet unr = new PermissionSet (PermissionState.Unrestricted);
			psc.Add (unr);
			psc.RemoveSet (0);
			Assert.AreEqual (0, psc.Count, "Count");
		}
예제 #8
0
		public void RemoveSet_Zero_Empty ()
		{
			PermissionSetCollection psc = new PermissionSetCollection ();
			psc.RemoveSet (0);
		}
예제 #9
0
		public void GetSet ()
		{
			PermissionSetCollection psc = new PermissionSetCollection ();
			PermissionSet unr = new PermissionSet (PermissionState.Unrestricted);
			psc.Add (unr);
			PermissionSet ps = psc.GetSet (0);
			Assert.AreEqual (unr.ToString (), ps.ToString (), "Same XML");
			Assert.IsTrue (Object.ReferenceEquals (unr, ps), "Same Object Reference");
		}
예제 #10
0
		public void Add ()
		{
			PermissionSet none = new PermissionSet (PermissionState.None);
			PermissionSet unr = new PermissionSet (PermissionState.Unrestricted);
			PermissionSetCollection psc = new PermissionSetCollection ();
			Assert.AreEqual (0, psc.PermissionSets.Count, "Count-0");
			Assert.AreEqual (0, psc.Count, "Count-0");
			psc.Add (none);
			Assert.AreEqual (1, psc.PermissionSets.Count, "Count-1");
			// re-add same permissionset
			psc.Add (none);
			Assert.AreEqual (2, psc.PermissionSets.Count, "Count-2");
			psc.Add (unr);
			Assert.AreEqual (3, psc.PermissionSets.Count, "Count-3");
			Assert.AreEqual (3, psc.Count, "Count-3");
		}
예제 #11
0
		public void Add_Null ()
		{
			PermissionSetCollection psc = new PermissionSetCollection ();
			psc.Add (null);
		}
예제 #12
0
		public void SyncRoot ()
		{
			PermissionSetCollection psc = new PermissionSetCollection ();
			Assert.IsNull (psc.SyncRoot, "SyncRoot");
		}
예제 #13
0
		public void Constructor ()
		{
			PermissionSetCollection psc = new PermissionSetCollection ();
			Assert.AreEqual (0, psc.Count, "Count");
			Assert.IsFalse (psc.IsSynchronized, "IsSynchronized");
			Assert.AreEqual (0, psc.PermissionSets.Count, "PermissionSets.Count");
			Assert.AreEqual (psc.ToXml ().ToString (), psc.ToString (), "ToXml().ToString()==ToString()");
			Assert.IsNotNull (psc.GetEnumerator (), "GetEnumerator");
		}
예제 #14
0
		// 2.0 metadata format

		internal static PermissionSetCollection CreateFromBinaryFormat (byte[] data)
		{
			if ((data == null) || (data [0] != 0x2E) || (data.Length < 2)) {
				string msg = Locale.GetText ("Invalid data in 2.0 metadata format.");
				throw new SecurityException (msg);
			}

			int pos = 1;
			int numattr = PermissionSet.ReadEncodedInt (data, ref pos);
			PermissionSetCollection psc = new PermissionSetCollection ();
			for (int i = 0; i < numattr; i++) {
				IPermission p = PermissionSet.ProcessAttribute (data, ref pos);
				if (p == null) {
					string msg = Locale.GetText ("Unsupported data found in 2.0 metadata format.");
					throw new SecurityException (msg);
				}

				PermissionSet ps = new PermissionSet (PermissionState.None);
				ps.DeclarativeSecurity = true;
				ps.AddPermission (p); 
				psc.Add (ps);
			}
			return psc;
		}
예제 #15
0
		public void GetSet_Negative ()
		{
			PermissionSetCollection psc = new PermissionSetCollection ();
			psc.GetSet (-1);
		}
예제 #16
0
		public void GetSet_Zero_Empty ()
		{
			PermissionSetCollection psc = new PermissionSetCollection ();
			psc.GetSet (0);
		}
예제 #17
0
		public void Copy ()
		{
			PermissionSet none = new PermissionSet (PermissionState.None);
			PermissionSet unr = new PermissionSet (PermissionState.Unrestricted);
			PermissionSetCollection psc = new PermissionSetCollection ();
			PermissionSetCollection copy = psc.Copy ();
			Assert.AreEqual (0, copy.PermissionSets.Count, "Count-0");
			psc.Add (none);
			Assert.AreEqual (0, copy.PermissionSets.Count, "Count-0b");
			copy = psc.Copy ();
			Assert.AreEqual (1, copy.PermissionSets.Count, "Count-1");
			psc.Add (none); // re-add same permissionset
			Assert.AreEqual (1, copy.PermissionSets.Count, "Count-1b");
			copy = psc.Copy ();
			Assert.AreEqual (2, copy.PermissionSets.Count, "Count-2");
			psc.Add (unr);
			Assert.AreEqual (2, copy.PermissionSets.Count, "Count-2b");
			copy = psc.Copy ();
			Assert.AreEqual (3, copy.PermissionSets.Count, "Count-3");
			Assert.AreEqual (3, copy.Count, "Count-3");
		}
예제 #18
0
		public void RemoveSet_Negative ()
		{
			PermissionSetCollection psc = new PermissionSetCollection ();
			psc.RemoveSet (-1);
		}
예제 #19
0
		public void Copy_References ()
		{
			PermissionSet none = new PermissionSet (PermissionState.None);
			PermissionSetCollection psc = new PermissionSetCollection ();
			psc.Add (none);
			PermissionSetCollection copy = psc.Copy ();
			Assert.AreEqual (1, copy.PermissionSets.Count, "Count-1");

			string before = psc.ToString ();
			none.AddPermission (new SecurityPermission (SecurityPermissionFlag.Assertion));

			Assert.AreEqual (none.ToString (), psc.PermissionSets[0].ToString (), "psc");
			Assert.AreEqual (before, copy.ToString (), "copy");
		}
예제 #20
0
		public void RemoveSet_MaxInt ()
		{
			PermissionSetCollection psc = new PermissionSetCollection ();
			psc.RemoveSet (Int32.MaxValue);
		}
예제 #21
0
		public void CopyTo ()
		{
			PermissionSetCollection psc = new PermissionSetCollection ();
			psc.CopyTo (null, 0);
		}
예제 #22
0
		public void ToXml ()
		{
			PermissionSetCollection psc = new PermissionSetCollection ();
			SecurityElement se = psc.ToXml ();
			Assert.IsNull (se.Children, "Children==null for 0");
			PermissionSet unr = new PermissionSet (PermissionState.Unrestricted);
			psc.Add (unr);
			se = psc.ToXml ();
			Assert.AreEqual (1, se.Children.Count, "Children==1");
			Assert.AreEqual (unr.ToString (), se.Children[0].ToString (), "XML");
		}
예제 #23
0
		public void CopyTo_ICollection ()
		{
			PermissionSetCollection psc = new PermissionSetCollection ();
			ICollection c = (psc as ICollection);
			c.CopyTo (null, 0);
		}