Exemplo n.º 1
0
        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
        }
Exemplo n.º 2
0
 public static void NamedPermissionSetCallMethods()
 {
     NamedPermissionSet nps = new NamedPermissionSet("Test");
     PermissionSet ps = nps.Copy();
     NamedPermissionSet nps2 = nps.Copy("Test");
     nps.Equals(nps2);
     int hash = nps.GetHashCode();
     SecurityElement se = new SecurityElement("");
     nps.FromXml(se);
     se = nps.ToXml();
 }
Exemplo n.º 3
0
        public static void NamedPermissionSetCallMethods()
        {
            NamedPermissionSet nps  = new NamedPermissionSet("Test");
            PermissionSet      ps   = nps.Copy();
            NamedPermissionSet nps2 = nps.Copy("Test");

            nps.Equals(nps2);
            int             hash = nps.GetHashCode();
            SecurityElement se   = new SecurityElement("");

            nps.FromXml(se);
            se = nps.ToXml();
        }
Exemplo n.º 4
0
        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");
        }
Exemplo n.º 5
0
        // Change a named permission set.
        public NamedPermissionSet ChangeNamedPermissionSet
            (String name, PermissionSet pSet)
        {
            // Validate the parameters.
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (pSet == null)
            {
                throw new ArgumentNullException("pSet");
            }

            // Find the existing permission set with this name.
            NamedPermissionSet current = GetNamedPermissionSet(name);

            if (current == null)
            {
                throw new ArgumentException
                          (_("Security_PermissionSetNotFound"));
            }

            // Make a copy of the previous permission set.
            NamedPermissionSet prev =
                (NamedPermissionSet)(current.Copy());

            // Clear the permission set and recreate it from "pSet".
            current.CopyFrom(pSet);

            // Return the previsou permission set.
            return(prev);
        }
Exemplo n.º 6
0
        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");
        }
Exemplo n.º 7
0
 /// <summary>Returns the <see cref="T:System.Security.NamedPermissionSet" /> in the current policy level with the specified name.</summary>
 /// <returns>The <see cref="T:System.Security.NamedPermissionSet" /> in the current policy level with the specified name, if found; otherwise, null.</returns>
 /// <param name="name">The name of the <see cref="T:System.Security.NamedPermissionSet" /> to find. </param>
 /// <exception cref="T:System.ArgumentNullException">The <paramref name="name" /> parameter is null. </exception>
 public NamedPermissionSet GetNamedPermissionSet(string name)
 {
     if (name == null)
     {
         throw new ArgumentNullException("name");
     }
     foreach (object obj in this.named_permission_sets)
     {
         NamedPermissionSet namedPermissionSet = (NamedPermissionSet)obj;
         if (namedPermissionSet.Name == name)
         {
             return((NamedPermissionSet)namedPermissionSet.Copy());
         }
     }
     return(null);
 }
Exemplo n.º 8
0
 /// <summary>Adds a <see cref="T:System.Security.NamedPermissionSet" /> to the current policy level.</summary>
 /// <param name="permSet">The <see cref="T:System.Security.NamedPermissionSet" /> to add to the current policy level. </param>
 /// <exception cref="T:System.ArgumentNullException">The <paramref name="permSet" /> parameter is null. </exception>
 /// <exception cref="T:System.ArgumentException">The <paramref name="permSet" /> parameter has the same name as an existing <see cref="T:System.Security.NamedPermissionSet" /> in the <see cref="T:System.Security.Policy.PolicyLevel" />. </exception>
 /// <PermissionSet>
 ///   <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="ControlEvidence" />
 /// </PermissionSet>
 public void AddNamedPermissionSet(NamedPermissionSet permSet)
 {
     if (permSet == null)
     {
         throw new ArgumentNullException("permSet");
     }
     foreach (object obj in this.named_permission_sets)
     {
         NamedPermissionSet namedPermissionSet = (NamedPermissionSet)obj;
         if (permSet.Name == namedPermissionSet.Name)
         {
             throw new ArgumentException(Locale.GetText("This NamedPermissionSet is the same an existing NamedPermissionSet."));
         }
     }
     this.named_permission_sets.Add(permSet.Copy());
 }
Exemplo n.º 9
0
        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");
        }
Exemplo n.º 10
0
 public void Copy_Name_Empty()
 {
     NamedPermissionSet nps  = new NamedPermissionSet(name);
     NamedPermissionSet copy = (NamedPermissionSet)nps.Copy(String.Empty);
 }
Exemplo n.º 11
0
 public void Copy_Name_Null()
 {
     NamedPermissionSet nps  = new NamedPermissionSet(name);
     NamedPermissionSet copy = (NamedPermissionSet)nps.Copy(null);
 }
Exemplo n.º 12
0
        [System.Security.SecuritySafeCritical]  // auto-generated
        public void AddNamedPermissionSet(NamedPermissionSet permSet) {
            if (permSet == null)
                throw new ArgumentNullException("permSet");
            Contract.EndContractBlock();

            CheckLoaded();
            LoadAllPermissionSets();

            lock (this) {
                IEnumerator enumerator = m_namedPermissionSets.GetEnumerator();
                while (enumerator.MoveNext()) {
                    if (((NamedPermissionSet)enumerator.Current).Name.Equals(permSet.Name))
                        throw new ArgumentException(Environment.GetResourceString("Argument_DuplicateName"));
                }

                NamedPermissionSet npsCopy = (NamedPermissionSet)permSet.Copy();
                npsCopy.IgnoreTypeLoadFailures = true;
                m_namedPermissionSets.Add(npsCopy);
            }
        }
Exemplo n.º 13
0
                public void AddNamedPermissionSet (NamedPermissionSet permSet)
                {
                        if (permSet == null)
                                throw new ArgumentNullException ("permSet");

			foreach (NamedPermissionSet n in named_permission_sets) {
				if (permSet.Name == n.Name) {
					throw new ArgumentException (
						Locale.GetText ("This NamedPermissionSet is the same an existing NamedPermissionSet."));
				}
			}
                        named_permission_sets.Add (permSet.Copy ());
                }
Exemplo n.º 14
0
        /// <include file='doc\PolicyLevel.uex' path='docs/doc[@for="PolicyLevel.AddNamedPermissionSet"]/*' />
        public void AddNamedPermissionSet( NamedPermissionSet permSet )
        {
            CheckLoaded( true );
            LoadAllPermissionSets();
        
            lock (this)
            {
                if (permSet == null)
                    throw new ArgumentNullException("permSet");

                IEnumerator enumerator = m_namedPermissionSets.GetEnumerator();
            
                while (enumerator.MoveNext())
                {
                    if (((NamedPermissionSet)enumerator.Current).Name.Equals( permSet.Name ))
                    {
                        throw new ArgumentException( Environment.GetResourceString( "Argument_DuplicateName" ) );
                    }
                }
            
                m_namedPermissionSets.Add( permSet.Copy() );
            }
        }