Example #1
0
		static XmlElement FindAndRemove (PolicyAssertionCollection collection, string name, string ns)
		{
			var element = collection.Find (name, ns);
			if (element != null)
				collection.Remove (element);
			return element;
		}
		public CustomPolicyConversionContext (WS.Binding binding, ServiceEndpoint endpoint)
			: base (endpoint)
		{
			this.binding = binding;
			assertions = new PolicyAssertionCollection ();
			binding_elements = ((CustomBinding)endpoint.Binding).Elements;
		}
Example #3
0
		internal static List<XmlElement> FindAssertionByNS (
			PolicyAssertionCollection collection, string ns)
		{
			var list = new List<XmlElement> ();
			foreach (var assertion in collection) {
				if (assertion.NamespaceURI.Equals (ns))
					list.Add (assertion);
			}
			return list;
		}
        internal static void ExportRetransmissionEnabledAssertion(UdpTransportBindingElement bindingElement, PolicyAssertionCollection assertions)
        {
            if (bindingElement == null)
            {
                throw FxTrace.Exception.ArgumentNull("bindingElement");
            }

            if (assertions == null)
            {
                throw FxTrace.Exception.ArgumentNull("assertions");
            }

            if (bindingElement.RetransmissionSettings.Enabled)
            {
                XmlElement assertion = Document.CreateElement(UdpConstants.WsdlSoapUdpTransportPrefix, UdpConstants.RetransmissionEnabled, UdpConstants.WsdlSoapUdpTransportNamespace);
                assertions.Add(assertion);
            }
        }
        public static void ExportRequireContextAssertion(ContextBindingElement bindingElement, PolicyAssertionCollection assertions)
        {
            if (bindingElement == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("bindingElement");
            }
            if (assertions == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("assertions");
            }
            if (bindingElement.ContextExchangeMechanism != ContextExchangeMechanism.ContextSoapHeader)
            {
                XmlElement item = Document.CreateElement(null, "HttpUseCookie", "http://schemas.xmlsoap.org/soap/http");
                assertions.Add(item);
            }
            else
            {
                XmlElement element = Document.CreateElement(null, "IncludeContext", "http://schemas.microsoft.com/ws/2006/05/context");
                System.Xml.XmlAttribute node = Document.CreateAttribute("ProtectionLevel");
                switch (bindingElement.ProtectionLevel)
                {
                    case ProtectionLevel.Sign:
                        node.Value = "Sign";
                        break;

                    case ProtectionLevel.EncryptAndSign:
                        node.Value = "EncryptAndSign";
                        break;

                    default:
                        node.Value = "None";
                        break;
                }
                element.Attributes.Append(node);
                assertions.Add(element);
            }
        }
        public static void ExportRequireContextAssertion(ContextBindingElement bindingElement, PolicyAssertionCollection assertions)
        {
            if (bindingElement == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("bindingElement");
            }
            if (assertions == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("assertions");
            }

            if (bindingElement.ContextExchangeMechanism == ContextExchangeMechanism.ContextSoapHeader)
            {
                XmlElement assertion = Document.CreateElement(null, IncludeContextName, WscNamespace);
                XmlAttribute protectionLevelAttribute = Document.CreateAttribute(ProtectionLevelName);
                switch (bindingElement.ProtectionLevel)
                {
                    case ProtectionLevel.EncryptAndSign:
                        protectionLevelAttribute.Value = EncryptAndSignName;
                        break;
                    case ProtectionLevel.Sign:
                        protectionLevelAttribute.Value = SignName;
                        break;
                    default:
                        protectionLevelAttribute.Value = NoneName;
                        break;
                }
                assertion.Attributes.Append(protectionLevelAttribute);

                assertions.Add(assertion);
            }
            else
            {
                XmlElement assertion = Document.CreateElement(null, HttpUseCookieName, HttpNamespace);
                assertions.Add(assertion);
            }
        }
		// For some reason PolicyAssertionCollection.Find is not working as expected,
		// so do the lookup manually.
		XmlNode FindAssertion (PolicyAssertionCollection assertionCollection, string name)
		{
			foreach (XmlNode node in assertionCollection)
				if (node.Name == name)
					return node;

			return null;
		}
Example #8
0
		internal static XmlElement GetMtomMessageEncodingPolicy (PolicyAssertionCollection collection)
		{
			return FindAndRemove (collection, "OptimizedMimeSerialization", MimeSerializationNS);
		}
Example #9
0
		internal static XmlElement GetBinaryMessageEncodingPolicy (PolicyAssertionCollection collection)
		{
			return FindAndRemove (collection, "BinaryEncoding", NetBinaryEncodingNS);
		}
Example #10
0
		internal static XmlElement GetStreamedMessageFramingPolicy (PolicyAssertionCollection collection)
		{
			return FindAndRemove (collection, "Streamed", FramingPolicyNS);	
		}
Example #11
0
		internal static XmlElement GetTransportBindingPolicy (PolicyAssertionCollection collection)
		{
			return FindAndRemove (collection, "TransportBinding", SecurityPolicyNS);
		}
Example #12
0
		public static PolicyAssertionCollection AssertPolicy (
			WS.ServiceDescription sd, XmlElement element, TestLabel label)
		{
			label.EnterScope ("wsp:Policy");
			Assert.That (element.NamespaceURI, Is.EqualTo (WspNamespace), label.Get ());
			Assert.That (element.LocalName, Is.EqualTo ("Policy") | Is.EqualTo ("PolicyReference"), label.Get ());

			var policy = ResolvePolicy (sd, element);
			Assert.That (policy, Is.Not.Null, label.Get ());

			label.EnterScope ("wsp:ExactlyOne");
			var exactlyOne = AssertExactlyOneChildElement (policy);
			Assert.That (exactlyOne, Is.Not.Null, label.Get ());
			Assert.That (exactlyOne.NamespaceURI, Is.EqualTo (WspNamespace), label.Get ());
			Assert.That (exactlyOne.LocalName, Is.EqualTo ("ExactlyOne"), label.Get ());
			label.LeaveScope ();

			label.EnterScope ("wsp:Any");
			var all = AssertExactlyOneChildElement (exactlyOne);
			Assert.That (all, Is.Not.Null, label.Get ());
			Assert.That (all.NamespaceURI, Is.EqualTo (WspNamespace), label.Get ());
			Assert.That (all.LocalName, Is.EqualTo ("All"), label.Get ());
			label.LeaveScope ();

			var collection = new PolicyAssertionCollection ();

			label.EnterScope ("assertions");
			foreach (var node in all.ChildNodes) {
				if (node is XmlWhitespace)
					continue;
				Assert.That (node, Is.InstanceOfType (typeof (XmlElement)), label.ToString ());
				collection.Add ((XmlElement)node);
			}
			label.LeaveScope ();

			label.LeaveScope ();

			return collection;
		}
Example #13
0
		public static void AssertPolicy (
			PolicyAssertionCollection assertions, QName qname, TestLabel label)
		{
			var assertion = assertions.Find (qname.Name, qname.Namespace);
			label.EnterScope (qname.Name);
			Assert.That (assertion, Is.Not.Null, label.ToString ());
			assertions.Remove (assertion);
			label.LeaveScope ();
		}
		public CustomPolicyConversionContext (ServiceEndpoint endpoint)
			: base (endpoint)
		{
			assertions = new PolicyAssertionCollection ();
			binding_elements = endpoint.Binding.CreateBindingElements ();
		}
 public static bool TryImportRequireContextAssertion(PolicyAssertionCollection assertions, out ContextBindingElement bindingElement)
 {
     if (assertions == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("assertions");
     }
     bindingElement = null;
     foreach (XmlElement element in assertions)
     {
         if (((element.LocalName == "IncludeContext") && (element.NamespaceURI == "http://schemas.microsoft.com/ws/2006/05/context")) && ContainOnlyWhitespaceChild(element))
         {
             string attribute = element.GetAttribute("ProtectionLevel");
             if ("EncryptAndSign".Equals(attribute, StringComparison.Ordinal))
             {
                 bindingElement = new ContextBindingElement(ProtectionLevel.EncryptAndSign);
             }
             else if ("Sign".Equals(attribute, StringComparison.Ordinal))
             {
                 bindingElement = new ContextBindingElement(ProtectionLevel.Sign);
             }
             else if ("None".Equals(attribute, StringComparison.Ordinal))
             {
                 bindingElement = new ContextBindingElement(ProtectionLevel.None);
             }
             if (bindingElement != null)
             {
                 assertions.Remove(element);
                 return true;
             }
         }
     }
     return false;
 }
 internal BindingOnlyPolicyConversionContext(ServiceEndpoint endpoint, IEnumerable<XmlElement> bindingPolicy)
     : base(endpoint)
 {
     this.bindingPolicy = new PolicyAssertionCollection(bindingPolicy);
 }
        public static bool TryImportRequireContextAssertion(PolicyAssertionCollection assertions, out ContextBindingElement bindingElement)
        {
            if (assertions == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("assertions");
            }

            bindingElement = null;

            foreach (XmlElement assertion in assertions)
            {
                if (assertion.LocalName == IncludeContextName
                    && assertion.NamespaceURI == WscNamespace
                    && ContainOnlyWhitespaceChild(assertion))
                {  
                    string protectionLevelAttribute = assertion.GetAttribute(ProtectionLevelName);
                    if (EncryptAndSignName.Equals(protectionLevelAttribute, StringComparison.Ordinal))
                    {
                        bindingElement = new ContextBindingElement(ProtectionLevel.EncryptAndSign);
                    }
                    else if (SignName.Equals(protectionLevelAttribute, StringComparison.Ordinal))
                    {
                        bindingElement = new ContextBindingElement(ProtectionLevel.Sign);
                    }
                    else if (NoneName.Equals(protectionLevelAttribute, StringComparison.Ordinal))
                    {
                        bindingElement = new ContextBindingElement(ProtectionLevel.None);
                    }

                    if (bindingElement != null)
                    {
                        assertions.Remove(assertion);
                        return true;
                    }
                }
            }

            return false;
        }
 internal ExportedPolicyConversionContext(ServiceEndpoint endpoint) : base(endpoint)
 {
     this.bindingElements = endpoint.Binding.CreateBindingElements();
     this.bindingAssertions = new PolicyAssertionCollection();
     this.operationBindingAssertions = new Dictionary<OperationDescription, PolicyAssertionCollection>();
     this.messageBindingAssertions = new Dictionary<MessageDescription, PolicyAssertionCollection>();
     this.faultBindingAssertions = new Dictionary<FaultDescription, PolicyAssertionCollection>();
 }
Example #19
0
		public static void Dump (PolicyAssertionCollection assertions)
		{
			foreach (var assertion in assertions)
				Console.WriteLine ("ASSERTION: {0}", assertion.OuterXml);
		}