ToXml() public méthode

public ToXml ( ) : SecurityElement
Résultat SecurityElement
Exemple #1
0
 public static void PolicyStatementCallMethods()
 {
     PolicyStatement ps = new PolicyStatement(new PermissionSet(new PermissionState()));
     PolicyStatement ps2 = ps.Copy();
     bool equals = ps.Equals(ps2);
     int hash = ps.GetHashCode();
     SecurityElement se = new SecurityElement("");
     PolicyLevel pl = (PolicyLevel)Activator.CreateInstance(typeof(PolicyLevel), true);
     ps.FromXml(se);
     ps.FromXml(se, pl);
     se = ps.ToXml();
     se = ps.ToXml(pl);
 }
		public void Constructor_PermissionSetPolicyStatementAttribute_Null ()
		{
			PolicyStatement ps = new PolicyStatement (null, PolicyStatementAttribute.All);
			Assert.AreEqual (PolicyStatementAttribute.All, ps.Attributes, "Attributes");
			Assert.AreEqual ("Exclusive LevelFinal", ps.AttributeString, "AttributeString");
			Assert.AreEqual (Empty.ToString (), ps.PermissionSet.ToString (), "PermissionSet");
			Assert.AreEqual (ps.ToXml ().ToString (), ps.Copy ().ToXml ().ToString (), "Copy");
		}
		public void Constructor_PermissionSet_Null ()
		{
			PolicyStatement ps = new PolicyStatement (null);
			Assert.AreEqual (PolicyStatementAttribute.Nothing, ps.Attributes, "Attributes");
			Assert.AreEqual (String.Empty, ps.AttributeString, "AttributeString");
			Assert.AreEqual (Empty.ToString (), ps.PermissionSet.ToString (), "PermissionSet");
			Assert.AreEqual (ps.ToXml ().ToString (), ps.Copy ().ToXml ().ToString (), "Copy");
		}
		public void Constructor_PermissionSet_Unrestricted ()
		{
			PermissionSet pset = new PermissionSet (PermissionState.Unrestricted);
			PolicyStatement ps = new PolicyStatement (pset);
			Assert.AreEqual (PolicyStatementAttribute.Nothing, ps.Attributes, "Attributes");
			Assert.AreEqual (String.Empty, ps.AttributeString, "AttributeString");
			Assert.AreEqual (Unrestricted.ToString (), ps.PermissionSet.ToString (), "PermissionSet");
			Assert.AreEqual (ps.ToXml ().ToString (), ps.Copy ().ToXml ().ToString (), "Copy");
		}
Exemple #5
0
        public SecurityElement ToXml()
        {
            SecurityElement elRoot = new SecurityElement("ApplicationTrust");

            elRoot.AddAttribute("version", "1");

#if FEATURE_CLICKONCE
            if (m_appId != null)
            {
                elRoot.AddAttribute("FullName", SecurityElement.Escape(m_appId.FullName));
            }
            if (m_appTrustedToRun)
            {
                elRoot.AddAttribute("TrustedToRun", "true");
            }
            if (m_persist)
            {
                elRoot.AddAttribute("Persist", "true");
            }
#endif // FEATURE_CLICKONCE

            if (m_psDefaultGrant != null)
            {
                SecurityElement elDefaultGrant = new SecurityElement("DefaultGrant");
                elDefaultGrant.AddChild(m_psDefaultGrant.ToXml());
                elRoot.AddChild(elDefaultGrant);
            }
            if (m_fullTrustAssemblies.Count > 0)
            {
                SecurityElement elFullTrustAssemblies = new SecurityElement("FullTrustAssemblies");
                foreach (StrongName fullTrustAssembly in m_fullTrustAssemblies)
                {
                    elFullTrustAssemblies.AddChild(fullTrustAssembly.ToXml());
                }
                elRoot.AddChild(elFullTrustAssemblies);
            }

#if FEATURE_CLICKONCE
            if (ExtraInfo != null)
            {
                elRoot.AddChild(ObjectToXml("ExtraInfo", ExtraInfo));
            }
#endif // FEATURE_CLICKONCE
            return(elRoot);
        }
        public SecurityElement ToXml()
        {
            SecurityElement elRoot = new SecurityElement("ApplicationTrust");

            elRoot.AddAttribute("version", "1");

            if (m_appId != null)
            {
                elRoot.AddAttribute("FullName", SecurityElement.Escape(m_appId.FullName));
            }
            if (m_appTrustedToRun)
            {
                elRoot.AddAttribute("TrustedToRun", "true");
            }
            if (m_persist)
            {
                elRoot.AddAttribute("Persist", "true");
            }

            if (m_psDefaultGrant != null)
            {
                SecurityElement elDefaultGrant = new SecurityElement("DefaultGrant");
                elDefaultGrant.AddChild(m_psDefaultGrant.ToXml());
                elRoot.AddChild(elDefaultGrant);
            }
            if (m_fullTrustAssemblies != null)
            {
                SecurityElement elFullTrustAssemblies = new SecurityElement("FullTrustAssemblies");
                for (int index = 0; index < m_fullTrustAssemblies.Length; index++)
                {
                    if (m_fullTrustAssemblies[index] != null)
                    {
                        elFullTrustAssemblies.AddChild(m_fullTrustAssemblies[index].ToXml());
                    }
                }
                elRoot.AddChild(elFullTrustAssemblies);
            }
            if (ExtraInfo != null)
            {
                elRoot.AddChild(ObjectToXml("ExtraInfo", ExtraInfo));
            }

            return(elRoot);
        }
        [System.Security.SecurityCritical]  // auto-generated
        private void Cache (int count, byte[] serializedEvidence, PolicyStatement policy) {
            if (m_configId == ConfigId.None)
                return;
            if (serializedEvidence == null)
                return;

            byte[] policyArray = new SecurityDocument(policy.ToXml(null, true)).m_data;
            Config.AddCacheEntry(m_configId, count, serializedEvidence, policyArray);
        }
 private void Cache(int count, byte[] serializedEvidence, PolicyStatement policy)
 {
     if (this.m_configId != System.Security.Policy.ConfigId.None)
     {
         byte[] data = new SecurityDocument(policy.ToXml(null, true)).m_data;
         Config.AddCacheEntry(this.m_configId, count, serializedEvidence, data);
     }
 }
Exemple #9
0
 private void Cache( int count, char[] serializedEvidence, PolicyStatement policy )
 {
     BCLDebug.Assert( m_configId != ConfigId.None, "PolicyLevels must have a vliad config id to save to the cache" );
 
     char[] policyArray = policy.ToXml().ToString().ToCharArray();
     
     Config.AddCacheEntry( m_configId, count, serializedEvidence, policyArray );
 }
Exemple #10
0
        private void CombinePolicy( PolicyStatement left, PolicyStatement right )
        {
#if _DEBUG
            if (debug)
            {
                DEBUG_OUT( "left = \n" + (left == null ? "<null>" : left.ToXml().ToString() ) );
                DEBUG_OUT( "right = \n" + (right == null ? "<null>" : right.ToXml().ToString() ) );
            } 
#endif
            if (right == null)
            {
                return;
            }
            else
            {
                // An exception somewhere in here means that a permission
                // failed some operation.  This simply means that it will be
                // dropped from the grant set which is safe operation that
                // can be ignored.
                
                try
                {
                    left.GetPermissionSetNoCopy().InplaceUnion( right.GetPermissionSetNoCopy() );
                }
                catch (Exception)
                {
                }
                left.Attributes = left.Attributes | right.Attributes;
            }

#if _DEBUG
            if (debug)          
                DEBUG_OUT( "outcome =\n" + left.ToXml().ToString() );
#endif
        }
		public void Constructor_Copy ()
		{
			PermissionSet original = new PermissionSet (PermissionState.None);
			PolicyStatement ps = new PolicyStatement (original, PolicyStatementAttribute.All);
			Assert.AreEqual (Empty.ToString (), ps.PermissionSet.ToString (), "PermissionSet");
			Assert.AreEqual (ps.ToXml ().ToString (), ps.Copy ().ToXml ().ToString (), "Copy");

			original.AddPermission (new SecurityPermission (SecurityPermissionFlag.AllFlags));
			Assert.AreEqual (Empty.ToString (), ps.PermissionSet.ToString (), "PermissionSet");
			Assert.AreEqual (ps.ToXml ().ToString (), ps.Copy ().ToXml ().ToString (), "Copy");
		}
		public void ToFromXml_RoundTrip ()
		{
			PolicyStatement ps1 = new PolicyStatement (Unrestricted, PolicyStatementAttribute.All);
			SecurityElement se = ps1.ToXml ();

			PolicyStatement ps2 = new PolicyStatement (null);
			ps2.FromXml (se, null);

			Assert.AreEqual (ps1.ToXml ().ToString (), ps2.ToXml ().ToString (), "Xml");
		}
		public void ToFromXml_PolicyLevelNull ()
		{
			PolicyStatement ps = new PolicyStatement (null);
			SecurityElement se = ps.ToXml (null);
			ps.FromXml (se, null);
		}