ToXml() публичный Метод

public ToXml ( ) : SecurityElement
Результат SecurityElement
Пример #1
0
 public static void ApplicationTrustCallMethods()
 {
     ApplicationTrust at = new ApplicationTrust();
     SecurityElement se = new SecurityElement("");
     at.FromXml(se);
     se = at.ToXml();
 }
		public void ApplicationIdentity ()
		{
			ApplicationTrust at = new ApplicationTrust ();
			at.ApplicationIdentity = new ApplicationIdentity ("Mono Unit Test");
			Assert.IsNotNull (at.ApplicationIdentity, "not null");
			string expected = AdjustLineEnds ("<ApplicationTrust version=\"1\"\r\nFullName=\"Mono Unit Test, Culture=neutral\">\r\n<DefaultGrant>\r\n<PolicyStatement version=\"1\">\r\n<PermissionSet class=\"System.Security.PermissionSet\"\r\nversion=\"1\"/>\r\n</PolicyStatement>\r\n</DefaultGrant>\r\n</ApplicationTrust>\r\n");
			Assert.AreEqual (expected, AdjustLineEnds (at.ToXml ().ToString ()), "XML");
		}
 internal void InternalSetApplicationTrust(System.Security.Policy.ApplicationTrust value)
 {
     if (value != null)
     {
         this._ApplicationTrust = value.ToXml().ToString();
     }
     else
     {
         this._ApplicationTrust = null;
     }
 }
		public void Constructor_Empty ()
		{
			ApplicationTrust at = new ApplicationTrust ();
			Assert.IsNull (at.ApplicationIdentity, "ApplicationIdentity");
			Assert.AreEqual (PolicyStatementAttribute.Nothing, at.DefaultGrantSet.Attributes, "DefaultGrantSet.Attributes");
			Assert.AreEqual (String.Empty, at.DefaultGrantSet.AttributeString, "DefaultGrantSet.AttributeString");
			Assert.IsTrue (at.DefaultGrantSet.PermissionSet.IsEmpty (), "DefaultGrantSet.PermissionSet.IsEmpty");
			Assert.IsFalse (at.DefaultGrantSet.PermissionSet.IsUnrestricted (), "DefaultGrantSet.PermissionSet.IsUnrestricted");
			Assert.IsNull (at.ExtraInfo, "ExtraInfo");
			Assert.IsFalse (at.IsApplicationTrustedToRun, "IsApplicationTrustedToRun");
			Assert.IsFalse (at.Persist, "Persist");
			string expected = AdjustLineEnds ("<ApplicationTrust version=\"1\">\r\n<DefaultGrant>\r\n<PolicyStatement version=\"1\">\r\n<PermissionSet class=\"System.Security.PermissionSet\"\r\nversion=\"1\"/>\r\n</PolicyStatement>\r\n</DefaultGrant>\r\n</ApplicationTrust>\r\n");
			Assert.AreEqual (expected, AdjustLineEnds (at.ToXml ().ToString ()), "XML");
		}
		public int Add(ApplicationTrust trust)
		{
			if (trust == null)
			{
				throw new ArgumentNullException("trust");
			}
			if (trust.ApplicationIdentity == null)
			{
				throw new ArgumentException(Environment.GetResourceString("Argument_ApplicationTrustShouldHaveIdentity"));
			}
			if (this.m_storeBounded)
			{
				this.CommitApplicationTrust(trust.ApplicationIdentity, trust.ToXml().ToString());
				return -1;
			}
			return this.AppTrusts.Add(trust);
		}
 public int Add(ApplicationTrust trust)
 {
     if (trust == null)
     {
         throw new ArgumentNullException("trust");
     }
     if (trust.ApplicationIdentity == null)
     {
         throw new ArgumentException(Environment.GetResourceString("Argument_ApplicationTrustShouldHaveIdentity"));
     }
     if (this.m_storeBounded)
     {
         this.CommitApplicationTrust(trust.ApplicationIdentity, trust.ToXml().ToString());
         return -1;
     }
     return this.AppTrusts.Add(trust);
 }
        public int Add(ApplicationTrust trust)
        {
            if (trust == null)
            {
                throw new ArgumentNullException("trust");
            }
            if (trust.ApplicationIdentity == null)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_ApplicationTrustShouldHaveIdentity"));
            }

            // Add the trust decision of the application to the fusion store.
            if (m_storeBounded)
            {
                CommitApplicationTrust(trust.ApplicationIdentity, trust.ToXml().ToString());
                return(-1);
            }
            else
            {
                return(AppTrusts.Add(trust));
            }
        }
		public void ExtraInfo ()
		{
			ApplicationTrust at = new ApplicationTrust ();
			at.ExtraInfo = "Mono";
			Assert.IsNotNull (at.ExtraInfo, "not null");

			string expected = AdjustLineEnds ("<ApplicationTrust version=\"1\">\r\n<DefaultGrant>\r\n<PolicyStatement version=\"1\">\r\n<PermissionSet class=\"System.Security.PermissionSet\"\r\nversion=\"1\"/>\r\n</PolicyStatement>\r\n</DefaultGrant>\r\n<ExtraInfo Data=\"0001000000FFFFFFFF01000000000000000601000000044D6F6E6F0B\"/>\r\n</ApplicationTrust>\r\n");
			Assert.AreEqual (expected, AdjustLineEnds (at.ToXml ().ToString ()), "XML");

			at.ExtraInfo = null;
			Assert.IsNull (at.ExtraInfo, "null");
		}
		public void FromXml_NoChild ()
		{
			ApplicationTrust at = new ApplicationTrust ();
			SecurityElement se = at.ToXml ();

			SecurityElement w = new SecurityElement (se.Tag);
			w.AddAttribute ("version", "1");

			at.FromXml (w);

			Assert.IsNull (at.ApplicationIdentity, "ApplicationIdentity");
			Assert.AreEqual (PolicyStatementAttribute.Nothing, at.DefaultGrantSet.Attributes, "DefaultGrantSet.Attributes");
			Assert.AreEqual (String.Empty, at.DefaultGrantSet.AttributeString, "DefaultGrantSet.AttributeString");
			Assert.IsTrue (at.DefaultGrantSet.PermissionSet.IsEmpty (), "DefaultGrantSet.PermissionSet.IsEmpty");
			Assert.IsFalse (at.DefaultGrantSet.PermissionSet.IsUnrestricted (), "DefaultGrantSet.PermissionSet.IsUnrestricted");
			Assert.IsNull (at.ExtraInfo, "ExtraInfo");
			Assert.IsFalse (at.IsApplicationTrustedToRun, "IsApplicationTrustedToRun");
			Assert.IsFalse (at.Persist, "Persist");
		}
		public void FromXml_NoVersion ()
		{
			ApplicationTrust at = new ApplicationTrust ();
			SecurityElement se = at.ToXml ();

			SecurityElement w = new SecurityElement (se.Tag);
			foreach (SecurityElement child in se.Children)
				w.AddChild (child);

			at.FromXml (w);
		}
		public void FromXml_InvalidVersion ()
		{
			ApplicationTrust at = new ApplicationTrust ();
			SecurityElement se = at.ToXml ();

			SecurityElement w = new SecurityElement (se.Tag);
			w.AddAttribute ("version", "2");
			foreach (SecurityElement child in se.Children)
				w.AddChild (child);

			at.FromXml (w);
		}
		public void FromXml_InvalidTag ()
		{
			ApplicationTrust at = new ApplicationTrust ();
			SecurityElement se = at.ToXml ();
			se.Tag = "MonoTrust";
			at.FromXml (se);
		}
		public void ToFromXmlRoundtrip ()
		{
			ApplicationTrust at = new ApplicationTrust ();
			at.ApplicationIdentity = new ApplicationIdentity ("Mono Unit Test");
			at.DefaultGrantSet = new PolicyStatement (new PermissionSet (PermissionState.Unrestricted));
			at.ExtraInfo = "Mono";
			at.IsApplicationTrustedToRun = true;
			at.Persist = true;

			SecurityElement se = at.ToXml ();
			string expected = AdjustLineEnds ("<ApplicationTrust version=\"1\"\r\nFullName=\"Mono Unit Test, Culture=neutral\"\r\nTrustedToRun=\"true\"\r\nPersist=\"true\">\r\n<DefaultGrant>\r\n<PolicyStatement version=\"1\">\r\n<PermissionSet class=\"System.Security.PermissionSet\"\r\nversion=\"1\"\r\nUnrestricted=\"true\"/>\r\n</PolicyStatement>\r\n</DefaultGrant>\r\n<ExtraInfo Data=\"0001000000FFFFFFFF01000000000000000601000000044D6F6E6F0B\"/>\r\n</ApplicationTrust>\r\n");
			Assert.AreEqual (expected, AdjustLineEnds (at.ToXml ().ToString ()), "XML");

			ApplicationTrust copy = new ApplicationTrust ();
			copy.FromXml (se);
			se = copy.ToXml ();
			Assert.AreEqual (expected, AdjustLineEnds (at.ToXml ().ToString ()), "Copy");
		}
		public void Persist ()
		{
			ApplicationTrust at = new ApplicationTrust ();
			at.Persist = true;
			Assert.IsTrue (at.Persist, "true");

			string expected = AdjustLineEnds ("<ApplicationTrust version=\"1\"\r\nPersist=\"true\">\r\n<DefaultGrant>\r\n<PolicyStatement version=\"1\">\r\n<PermissionSet class=\"System.Security.PermissionSet\"\r\nversion=\"1\"/>\r\n</PolicyStatement>\r\n</DefaultGrant>\r\n</ApplicationTrust>\r\n");
			Assert.AreEqual (expected, AdjustLineEnds (at.ToXml ().ToString ()), "XML");

			at.Persist = false;
			Assert.IsFalse (at.Persist, "false");
		}
		public void ExtraInfo_NotSerializable ()
		{
			ApplicationTrust at = new ApplicationTrust ();
			at.ExtraInfo = this;
			SecurityElement se = at.ToXml ();
		}
Пример #16
0
 internal void InternalSetApplicationTrust(ApplicationTrust value)
 {
     if (value != null)
     {
         _ApplicationTrust = value.ToXml().ToString();
     }
     else
     {
         _ApplicationTrust = null;
     }
 }
		public void DefaultGrantSet ()
		{
			ApplicationTrust at = new ApplicationTrust ();
			at.DefaultGrantSet = new PolicyStatement (new PermissionSet (PermissionState.Unrestricted));
			Assert.IsNotNull (at.DefaultGrantSet, "not null");
			string expected = AdjustLineEnds ("<ApplicationTrust version=\"1\">\r\n<DefaultGrant>\r\n<PolicyStatement version=\"1\">\r\n<PermissionSet class=\"System.Security.PermissionSet\"\r\nversion=\"1\"\r\nUnrestricted=\"true\"/>\r\n</PolicyStatement>\r\n</DefaultGrant>\r\n</ApplicationTrust>\r\n");
			Assert.AreEqual (expected, AdjustLineEnds (at.ToXml ().ToString ()), "XML");

			at.DefaultGrantSet = null;
			// returns to defaults
			Assert.IsNotNull (at.DefaultGrantSet, "null");
			Assert.AreEqual (PolicyStatementAttribute.Nothing, at.DefaultGrantSet.Attributes, "DefaultGrantSet.Attributes");
			Assert.AreEqual (String.Empty, at.DefaultGrantSet.AttributeString, "DefaultGrantSet.AttributeString");
			Assert.IsTrue (at.DefaultGrantSet.PermissionSet.IsEmpty (), "DefaultGrantSet.PermissionSet.IsEmpty");
			Assert.IsFalse (at.DefaultGrantSet.PermissionSet.IsUnrestricted (), "DefaultGrantSet.PermissionSet.IsUnrestricted");
		}
Пример #18
0
        [System.Security.SecurityCritical]  // auto-generated
        public int Add (ApplicationTrust trust) {
            if (trust == null)
                throw new ArgumentNullException("trust"); 
            if (trust.ApplicationIdentity == null)
                throw new ArgumentException(Environment.GetResourceString("Argument_ApplicationTrustShouldHaveIdentity")); 
            Contract.EndContractBlock(); 

            // Add the trust decision of the application to the fusion store. 
            if (m_storeBounded) {
                CommitApplicationTrust(trust.ApplicationIdentity, trust.ToXml().ToString());
                return -1;
            } else { 
                return AppTrusts.Add(trust);
            } 
        } 
		internal void InternalSetApplicationTrust(ApplicationTrust value)
		{
			if (value != null)
			{
				this._ApplicationTrust = value.ToXml().ToString();
				return;
			}
			this._ApplicationTrust = null;
		}