void IPolicyExportExtension.ExportPolicy(MetadataExporter exporter, PolicyConversionContext context)
        {
            if (exporter == null)
            {
                throw new ArgumentNullException("exporter");
            }
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            PolicyAssertionCollection assertions = context.GetBindingAssertions();
            XmlDocument doc = new XmlDocument();

            var messageEncodingElement = ExportAddressingPolicy(context);

            if (messageEncodingElement == null)
            {
                assertions.Add(doc.CreateElement(
                                   "msb", "BinaryEncoding",
                                   "http://schemas.microsoft.com/ws/06/2004/mspolicy/netbinary1"));
            }

            if (transfer_mode == TransferMode.Streamed || transfer_mode == TransferMode.StreamedRequest ||
                transfer_mode == TransferMode.StreamedResponse)
            {
                assertions.Add(doc.CreateElement("msf", "Streamed", "http://schemas.microsoft.com/ws/2006/05/framing/policy"));
            }
        }
Exemple #2
0
        void IPolicyImportExtension.ImportPolicy(MetadataImporter importer, PolicyConversionContext context)
        {
            if (importer == null)
            {
                throw new ArgumentNullException("importer");
            }
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            UdpTransportBindingElement udpBindingElement = null;
            bool multicast = false;
            PolicyAssertionCollection policyAssertions = context.GetBindingAssertions();

            if (policyAssertions.Remove(UdpPolicyStrings.TransportAssertion, UdpPolicyStrings.UdpNamespace) != null)
            {
                udpBindingElement = new UdpTransportBindingElement();
            }
            if (policyAssertions.Remove(UdpPolicyStrings.MulticastAssertion, UdpPolicyStrings.UdpNamespace) != null)
            {
                multicast = true;
            }
            if (udpBindingElement != null)
            {
                udpBindingElement.Multicast = multicast;
                context.BindingElements.Add(udpBindingElement);
            }
        }
Exemple #3
0
        void IPolicyExportExtension.ExportPolicy(MetadataExporter exporter, PolicyConversionContext context)
        {
            if (exporter == null)
            {
                throw new ArgumentNullException("exporter");
            }
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            PolicyAssertionCollection assertions = context.GetBindingAssertions();
            var doc = new System.Xml.XmlDocument();

            ExportAddressingPolicy(context);
            switch (auth_scheme)
            {
            case AuthenticationSchemes.Basic:
            case AuthenticationSchemes.Digest:
            case AuthenticationSchemes.Negotiate:
            case AuthenticationSchemes.Ntlm:
                assertions.Add(doc.CreateElement("http", auth_scheme.ToString() + "Authentication", "http://schemas.microsoft.com/ws/06/2004/policy/http"));
                break;
            }
            var transportProvider = this as ITransportTokenAssertionProvider;

            if (transportProvider != null)
            {
                var token = transportProvider.GetTransportTokenAssertion();
                assertions.Add(CreateTransportBinding(token));
            }
        }
 public static void Dump(PolicyAssertionCollection assertions)
 {
     foreach (var assertion in assertions)
     {
         Console.WriteLine("ASSERTION: {0}", assertion.OuterXml);
     }
 }
		public CustomPolicyConversionContext (WS.Binding binding, ServiceEndpoint endpoint)
			: base (endpoint)
		{
			this.binding = binding;
			assertions = new PolicyAssertionCollection ();
			binding_elements = ((CustomBinding)endpoint.Binding).Elements;
		}
 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);
 }
Exemple #7
0
        public void ExportPolicy_CustomEncoding_Soap12August2004()
        {
            ConnectionOrientedTransportBindingElement binding_element = new NamedPipeTransportBindingElement();
            IPolicyExportExtension  export_extension   = binding_element as IPolicyExportExtension;
            PolicyConversionContext conversion_context = new CustomPolicyConversionContext();

            conversion_context.BindingElements.Add(new MyMessageEncodingElement(MessageVersion.Soap12WSAddressingAugust2004));
            export_extension.ExportPolicy(new WsdlExporter(), conversion_context);

            PolicyAssertionCollection binding_assertions = conversion_context.GetBindingAssertions();
            BindingElementCollection  binding_elements   = conversion_context.BindingElements;

            Assert.AreEqual(1, binding_assertions.Count, "#A0");
            Assert.AreEqual(1, binding_elements.Count, "#A1");

            // UsingAddressing
            XmlNode using_addressing_node = FindAssertionByLocalName(binding_assertions, "UsingAddressing");

            Assert.AreEqual(true, using_addressing_node != null, "#B0");
            Assert.AreEqual("UsingAddressing", using_addressing_node.LocalName, "#B1");
            Assert.AreEqual("http://schemas.xmlsoap.org/ws/2004/08/addressing/policy", using_addressing_node.NamespaceURI, "#B2");
            Assert.AreEqual(String.Empty, using_addressing_node.InnerText, "#B3");
            Assert.AreEqual(0, using_addressing_node.Attributes.Count, "#B4");
            Assert.AreEqual(0, using_addressing_node.ChildNodes.Count, "#B5");
        }
Exemple #8
0
        void IPolicyExportExtension.ExportPolicy(
            MetadataExporter exporter,
            PolicyConversionContext context)
        {
            if (exporter == null)
            {
                throw new ArgumentNullException("exporter");
            }
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            PolicyAssertionCollection assertions = context.GetBindingAssertions();
            XmlDocument doc = new XmlDocument();

            assertions.Add(doc.CreateElement("wsaw", "UsingAddressing", "http://www.w3.org/2006/05/addressing/wsdl"));

            switch (auth_scheme)
            {
            case AuthenticationSchemes.Basic:
            case AuthenticationSchemes.Digest:
            case AuthenticationSchemes.Negotiate:
            case AuthenticationSchemes.Ntlm:
                assertions.Add(doc.CreateElement("http",
                                                 auth_scheme.ToString() + "Authentication",
                                                 "http://schemas.microsoft.com/ws/06/2004/policy/http"));
                break;
            }
        }
Exemple #9
0
        public void ExportPolicyDefault()
        {
            ConnectionOrientedTransportBindingElement binding_element = new NamedPipeTransportBindingElement();
            IPolicyExportExtension  export_extension   = binding_element as IPolicyExportExtension;
            PolicyConversionContext conversion_context = new CustomPolicyConversionContext();

            export_extension.ExportPolicy(new WsdlExporter(), conversion_context);

            PolicyAssertionCollection binding_assertions = conversion_context.GetBindingAssertions();
            BindingElementCollection  binding_elements   = conversion_context.BindingElements;

            Assert.AreEqual(2, binding_assertions.Count, "#A0");
            Assert.AreEqual(0, binding_elements.Count, "#A1");

            // wsaw:UsingAddressing
            XmlNode using_addressing_node = FindAssertion(binding_assertions, "wsaw:UsingAddressing");

            Assert.AreEqual(true, using_addressing_node != null, "#B0");
            Assert.AreEqual("UsingAddressing", using_addressing_node.LocalName, "#B1");
            Assert.AreEqual("http://www.w3.org/2006/05/addressing/wsdl", using_addressing_node.NamespaceURI, "#B2");
            Assert.AreEqual(String.Empty, using_addressing_node.InnerText, "#B3");
            Assert.AreEqual(0, using_addressing_node.Attributes.Count, "#B4");
            Assert.AreEqual(0, using_addressing_node.ChildNodes.Count, "#B5");

            // msb:BinaryEncoding
            XmlNode binary_encoding_node = FindAssertion(binding_assertions, "msb:BinaryEncoding");

            Assert.AreEqual(true, binary_encoding_node != null, "#C0");
            Assert.AreEqual("BinaryEncoding", binary_encoding_node.LocalName, "#C1");
            Assert.AreEqual("http://schemas.microsoft.com/ws/06/2004/mspolicy/netbinary1", binary_encoding_node.NamespaceURI, "#C2");
            Assert.AreEqual(String.Empty, binary_encoding_node.InnerText, "#C3");
            Assert.AreEqual(0, binary_encoding_node.Attributes.Count, "#C4");
            Assert.AreEqual(0, binary_encoding_node.ChildNodes.Count, "#C5");
        }
        void IPolicyImportExtension.ImportPolicy(MetadataImporter importer, PolicyConversionContext context)
        {
            Console.WriteLine("ImportPolicy");
            if (importer == null)
            {
                throw new ArgumentNullException("importer");
            }
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            SsbBindingElement         ssbBindingElement = null;
            PolicyAssertionCollection policyAssertions  = context.GetBindingAssertions();

            if (policyAssertions.Remove(SsbConstants.SsbTransportAssertion, SsbConstants.SsbNs) != null)
            {
                ssbBindingElement = new SsbBindingElement();
                ssbBindingElement.SqlConnectionString = "";
            }
            if (ssbBindingElement != null)
            {
                context.BindingElements.Add(ssbBindingElement);
            }
        }
Exemple #11
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 void ExportPolicy(MetadataExporter exporter,
                                 PolicyConversionContext context)
        {
            PolicyAssertionCollection assertions = context.GetBindingAssertions();
            XmlDocument doc = new XmlDocument();

            assertions.Add(doc.CreateElement("wsoma", "OptimizedMimeSerialization", "http://schemas.xmlsoap.org/ws/2004/09/policy/optimizedmimeserialization"));
        }
        void IPolicyExportExtension.ExportPolicy(MetadataExporter exporter,
                                                 PolicyConversionContext context)
        {
            PolicyAssertionCollection assertions = context.GetBindingAssertions();
            XmlDocument doc = new XmlDocument();

            assertions.Add(doc.CreateElement("msb", "BinaryEncoding", "http://schemas.microsoft.com/ws/06/2004/mspolicy/netbinary1"));
        }
        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();
        }
        static XmlElement FindAndRemove(PolicyAssertionCollection collection, string name, string ns)
        {
            var element = collection.Find(name, ns);

            if (element != null)
            {
                collection.Remove(element);
            }
            return(element);
        }
Exemple #16
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;
		}
        public void ExportPolicyDefault()
        {
            MsmqBindingElementBase  binding_element    = new MsmqTransportBindingElement();
            IPolicyExportExtension  export_extension   = binding_element as IPolicyExportExtension;
            PolicyConversionContext conversion_context = new CustomPolicyConversionContext();

            export_extension.ExportPolicy(new WsdlExporter(), conversion_context);

            PolicyAssertionCollection binding_assertions = conversion_context.GetBindingAssertions();
            BindingElementCollection  binding_elements   = conversion_context.BindingElements;

            Assert.AreEqual(4, binding_assertions.Count, "#A0");
            Assert.AreEqual(0, binding_elements.Count, "#A1");

            // wsaw:UsingAddressing
            XmlNode using_addressing_node = FindAssertion(binding_assertions, "wsaw:UsingAddressing");

            Assert.AreEqual(true, using_addressing_node != null, "#B0");
            Assert.AreEqual("UsingAddressing", using_addressing_node.LocalName, "#B1");
            Assert.AreEqual("http://www.w3.org/2006/05/addressing/wsdl", using_addressing_node.NamespaceURI, "#B2");
            Assert.AreEqual(String.Empty, using_addressing_node.InnerText, "#B3");
            Assert.AreEqual(0, using_addressing_node.Attributes.Count, "#B4");
            Assert.AreEqual(0, using_addressing_node.ChildNodes.Count, "#B5");

            // msb:BinaryEncoding
            XmlNode binary_encoding_node = FindAssertion(binding_assertions, "msb:BinaryEncoding");

            Assert.AreEqual(true, binary_encoding_node != null, "#C0");
            Assert.AreEqual("BinaryEncoding", binary_encoding_node.LocalName, "#C1");
            Assert.AreEqual("http://schemas.microsoft.com/ws/06/2004/mspolicy/netbinary1", binary_encoding_node.NamespaceURI, "#C2");
            Assert.AreEqual(String.Empty, binary_encoding_node.InnerText, "#C3");
            Assert.AreEqual(0, binary_encoding_node.Attributes.Count, "#C4");
            Assert.AreEqual(0, binary_encoding_node.ChildNodes.Count, "#C5");

            // msmq:Authenticated
            XmlNode authenticated_node = FindAssertion(binding_assertions, "msmq:Authenticated");

            Assert.AreEqual(true, authenticated_node != null, "#D0");
            Assert.AreEqual("Authenticated", authenticated_node.LocalName, "#D1");
            Assert.AreEqual("http://schemas.microsoft.com/ws/06/2004/mspolicy/msmq", authenticated_node.NamespaceURI, "#D2");
            Assert.AreEqual(String.Empty, authenticated_node.InnerText, "#D3");
            Assert.AreEqual(0, authenticated_node.Attributes.Count, "#D4");
            Assert.AreEqual(0, authenticated_node.ChildNodes.Count, "#D5");

            // msmq:WindowsDomain
            XmlNode domain_node = FindAssertion(binding_assertions, "msmq:WindowsDomain");

            Assert.AreEqual(true, domain_node != null, "#E0");
            Assert.AreEqual("WindowsDomain", domain_node.LocalName, "#E1");
            Assert.AreEqual("http://schemas.microsoft.com/ws/06/2004/mspolicy/msmq", domain_node.NamespaceURI, "#E2");
            Assert.AreEqual(String.Empty, domain_node.InnerText, "#E3");
            Assert.AreEqual(0, domain_node.Attributes.Count, "#E4");
            Assert.AreEqual(0, domain_node.ChildNodes.Count, "#E5");
        }
        XmlNode FindAssertion(PolicyAssertionCollection assertionCollection, string name)
        {
            foreach (XmlNode node in assertionCollection)
            {
                if (node.Name == name)
                {
                    return(node);
                }
            }

            return(null);
        }
        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);
        }
Exemple #20
0
        public void ExportPolicy_CustomEncoding_Soap12()
        {
            ConnectionOrientedTransportBindingElement binding_element = new NamedPipeTransportBindingElement();
            IPolicyExportExtension  export_extension   = binding_element as IPolicyExportExtension;
            PolicyConversionContext conversion_context = new CustomPolicyConversionContext();

            conversion_context.BindingElements.Add(new MyMessageEncodingElement(MessageVersion.Soap12));
            export_extension.ExportPolicy(new WsdlExporter(), conversion_context);

            PolicyAssertionCollection binding_assertions = conversion_context.GetBindingAssertions();
            BindingElementCollection  binding_elements   = conversion_context.BindingElements;

            Assert.AreEqual(0, binding_assertions.Count, "#A0");
            Assert.AreEqual(1, binding_elements.Count, "#A1");
        }
 private static HttpTransportBindingElement GetHttpTransportBindingElement(PolicyConversionContext policyContext)
 {
     if (policyContext != null)
     {
         WSSecurityPolicy          sp = null;
         PolicyAssertionCollection policyCollection = policyContext.GetBindingAssertions();
         if (WSSecurityPolicy.TryGetSecurityPolicyDriver(policyCollection, out sp) && sp.ContainsWsspHttpsTokenAssertion(policyCollection))
         {
             HttpsTransportBindingElement httpsBinding = new HttpsTransportBindingElement();
             httpsBinding.MessageSecurityVersion = sp.GetSupportedMessageSecurityVersion(SecurityVersion.WSSecurity11);
             return(httpsBinding);
         }
     }
     return(new HttpTransportBindingElement());
 }
Exemple #22
0
        public void ExportPolicy()
        {
            HttpTransportBindingElement http_binding_element = new HttpTransportBindingElement();

            //
            // Specify some non-default values
            //
            http_binding_element.AllowCookies              = !http_binding_element.AllowCookies;
            http_binding_element.AuthenticationScheme      = AuthenticationSchemes.Ntlm;
            http_binding_element.BypassProxyOnLocal        = !http_binding_element.BypassProxyOnLocal;
            http_binding_element.HostNameComparisonMode    = HostNameComparisonMode.WeakWildcard;
            http_binding_element.KeepAliveEnabled          = !http_binding_element.KeepAliveEnabled;
            http_binding_element.ManualAddressing          = !http_binding_element.ManualAddressing;
            http_binding_element.MaxBufferPoolSize         = http_binding_element.MaxBufferPoolSize / 2;
            http_binding_element.MaxBufferSize             = http_binding_element.MaxBufferSize / 2;
            http_binding_element.MaxReceivedMessageSize    = http_binding_element.MaxReceivedMessageSize / 2;
            http_binding_element.ProxyAddress              = new Uri("http://proxyaddress.com");
            http_binding_element.ProxyAuthenticationScheme = AuthenticationSchemes.Basic;
            http_binding_element.Realm        = "RandomRealm";
            http_binding_element.TransferMode = TransferMode.Streamed;
            http_binding_element.UnsafeConnectionNtlmAuthentication = !http_binding_element.UnsafeConnectionNtlmAuthentication;
            http_binding_element.UseDefaultWebProxy       = !http_binding_element.UseDefaultWebProxy;
            http_binding_element.DecompressionEnabled     = !http_binding_element.DecompressionEnabled;
            http_binding_element.ExtendedProtectionPolicy = new ExtendedProtectionPolicy(PolicyEnforcement.WhenSupported);

            //
            // Actual call to ExportPolicy
            //
            IPolicyExportExtension  binding_element    = http_binding_element as IPolicyExportExtension;
            PolicyConversionContext conversion_context = new CustomPolicyConversionContext();

            binding_element.ExportPolicy(new WsdlExporter(), conversion_context);

            PolicyAssertionCollection binding_assertions = conversion_context.GetBindingAssertions();
            BindingElementCollection  binding_elements   = conversion_context.BindingElements;

            Assert.AreEqual(2, binding_assertions.Count, "#A0");
            Assert.AreEqual(0, binding_elements.Count, "#A1");

            // AuthenticationScheme - the only property that causes information to be exported.
            XmlNode authentication_node = FindAssertion(binding_assertions, "http:NtlmAuthentication");

            Assert.AreEqual(true, authentication_node != null, "#B0");
            Assert.AreEqual("NtlmAuthentication", authentication_node.LocalName, "#B1");
            Assert.AreEqual("http://schemas.microsoft.com/ws/06/2004/policy/http", authentication_node.NamespaceURI, "#B2");
            Assert.AreEqual(String.Empty, authentication_node.InnerText, "#B3");
            Assert.AreEqual(0, authentication_node.Attributes.Count, "#B4");
        }
        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);
        }
        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);
            }
        }
Exemple #25
0
        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);
        }
Exemple #26
0
        public void ExportPolicyDefault()
        {
            IPolicyExportExtension  binding_element    = new HttpTransportBindingElement();
            PolicyConversionContext conversion_context = new CustomPolicyConversionContext();

            binding_element.ExportPolicy(new WsdlExporter(), conversion_context);

            PolicyAssertionCollection binding_assertions = conversion_context.GetBindingAssertions();
            BindingElementCollection  binding_elements   = conversion_context.BindingElements;

            Assert.AreEqual(1, binding_assertions.Count, "#A0");
            Assert.AreEqual(0, binding_elements.Count, "#A1");

            // wsaw:UsingAddressing
            XmlNode using_addressing_node = FindAssertion(binding_assertions, "wsaw:UsingAddressing");

            Assert.AreEqual(true, using_addressing_node != null, "#B0");
            Assert.AreEqual("UsingAddressing", using_addressing_node.LocalName, "#B1");
            Assert.AreEqual("http://www.w3.org/2006/05/addressing/wsdl", using_addressing_node.NamespaceURI, "#B2");
            Assert.AreEqual(0, using_addressing_node.Attributes.Count, "#B3");
            Assert.AreEqual(0, using_addressing_node.ChildNodes.Count, "#B4");
            Assert.AreEqual(String.Empty, using_addressing_node.InnerText, "#B5");
        }
Exemple #27
0
        void IPolicyExportExtension.ExportPolicy(MetadataExporter exporter, PolicyConversionContext context)
        {
            if (exporter == null)
            {
                throw new ArgumentNullException("exporter");
            }
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            PolicyAssertionCollection assertions = context.GetBindingAssertions();
            XmlDocument doc = new XmlDocument();

            assertions.Add(doc.CreateElement("wsaw", "UsingAddressing", "http://www.w3.org/2006/05/addressing/wsdl"));
            assertions.Add(doc.CreateElement("msmq", "Authenticated", "http://schemas.microsoft.com/ws/06/2004/mspolicy/msmq"));
            assertions.Add(doc.CreateElement("msb", "BinaryEncoding",
                                             "http://schemas.microsoft.com/ws/06/2004/mspolicy/netbinary1"));

            if (transport_security.MsmqAuthenticationMode == MsmqAuthenticationMode.WindowsDomain)
            {
                assertions.Add(doc.CreateElement("msmq", "WindowsDomain",
                                                 "http://schemas.microsoft.com/ws/06/2004/mspolicy/msmq"));
            }

            if (!durable)
            {
                assertions.Add(doc.CreateElement("msmq", "MsmqVolatile",
                                                 "http://schemas.microsoft.com/ws/06/2004/mspolicy/msmq"));
            }

            if (!exactly_once)
            {
                assertions.Add(doc.CreateElement("msmq", "MsmqBestEffort",
                                                 "http://schemas.microsoft.com/ws/06/2004/mspolicy/msmq"));
            }
        }
Exemple #28
0
        public void ExportPolicy()
        {
            ConnectionOrientedTransportBindingElement binding_element = new NamedPipeTransportBindingElement();

            binding_element.ChannelInitializationTimeout = TimeSpan.FromSeconds(3);
            binding_element.ConnectionBufferSize         = binding_element.ConnectionBufferSize / 2;
            binding_element.HostNameComparisonMode       = HostNameComparisonMode.WeakWildcard;
            binding_element.ManualAddressing             = !binding_element.ManualAddressing;
            binding_element.MaxBufferSize          = binding_element.MaxBufferSize / 2;
            binding_element.MaxBufferPoolSize      = binding_element.MaxBufferPoolSize / 2;
            binding_element.MaxOutputDelay         = TimeSpan.FromSeconds(3);
            binding_element.MaxPendingAccepts      = 3;
            binding_element.MaxPendingConnections  = 15;
            binding_element.MaxReceivedMessageSize = binding_element.MaxReceivedMessageSize / 2;
            binding_element.TransferMode           = TransferMode.Streamed;   // Causes an assertion with Streamed* values

            IPolicyExportExtension  export_extension   = binding_element as IPolicyExportExtension;
            PolicyConversionContext conversion_context = new CustomPolicyConversionContext();

            export_extension.ExportPolicy(new WsdlExporter(), conversion_context);

            PolicyAssertionCollection binding_assertions = conversion_context.GetBindingAssertions();
            BindingElementCollection  binding_elements   = conversion_context.BindingElements;

            Assert.AreEqual(3, binding_assertions.Count, "#A0");
            Assert.AreEqual(0, binding_elements.Count, "#A1");

            // msf:Streamed
            XmlNode streamed_node = FindAssertion(binding_assertions, "msf:Streamed");

            Assert.AreEqual(true, streamed_node != null, "#B0");
            Assert.AreEqual("Streamed", streamed_node.LocalName, "#B1");
            Assert.AreEqual("http://schemas.microsoft.com/ws/2006/05/framing/policy", streamed_node.NamespaceURI, "#B2");
            Assert.AreEqual(String.Empty, streamed_node.InnerText, "#B3");
            Assert.AreEqual(0, streamed_node.Attributes.Count, "#B4");
            Assert.AreEqual(0, streamed_node.ChildNodes.Count, "#B5");
        }
        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);
            }
        }
        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);
            }
        }
Exemple #31
0
		internal static XmlElement GetTransportBindingPolicy (PolicyAssertionCollection collection)
		{
			return FindAndRemove (collection, "TransportBinding", SecurityPolicyNS);
		}
Exemple #32
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;
		}
 internal static XmlElement GetTransportBindingPolicy(PolicyAssertionCollection collection)
 {
     return(FindAndRemove(collection, "TransportBinding", SecurityPolicyNS));
 }
 internal static XmlElement GetBinaryMessageEncodingPolicy(PolicyAssertionCollection collection)
 {
     return(FindAndRemove(collection, "BinaryEncoding", NetBinaryEncodingNS));
 }
Exemple #35
0
		internal static XmlElement GetMtomMessageEncodingPolicy (PolicyAssertionCollection collection)
		{
			return FindAndRemove (collection, "OptimizedMimeSerialization", MimeSerializationNS);
		}
        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;
        }
		// 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;
		}
 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;
 }
Exemple #39
0
		internal static XmlElement GetStreamedMessageFramingPolicy (PolicyAssertionCollection collection)
		{
			return FindAndRemove (collection, "Streamed", FramingPolicyNS);	
		}
Exemple #40
0
		internal static XmlElement GetBinaryMessageEncodingPolicy (PolicyAssertionCollection collection)
		{
			return FindAndRemove (collection, "BinaryEncoding", NetBinaryEncodingNS);
		}
		public CustomPolicyConversionContext (ServiceEndpoint endpoint)
			: base (endpoint)
		{
			assertions = new PolicyAssertionCollection ();
			binding_elements = endpoint.Binding.CreateBindingElements ();
		}
 internal static XmlElement GetMtomMessageEncodingPolicy(PolicyAssertionCollection collection)
 {
     return(FindAndRemove(collection, "OptimizedMimeSerialization", MimeSerializationNS));
 }
        public void ExportPolicy()
        {
            MsmqBindingElementBase binding_element = new MsmqTransportBindingElement();

            binding_element.CustomDeadLetterQueue = new Uri("msmq://custom");
            binding_element.DeadLetterQueue       = DeadLetterQueue.Custom;
            binding_element.Durable                = !binding_element.Durable;     // Volatile
            binding_element.ExactlyOnce            = !binding_element.ExactlyOnce; // BestEffort
            binding_element.ManualAddressing       = !binding_element.ManualAddressing;
            binding_element.MaxBufferPoolSize      = binding_element.MaxBufferPoolSize / 2;
            binding_element.MaxReceivedMessageSize = binding_element.MaxReceivedMessageSize / 2;
            binding_element.MaxRetryCycles         = binding_element.MaxRetryCycles / 2;
            binding_element.ReceiveRetryCount      = 10;
            binding_element.ReceiveErrorHandling   = ReceiveErrorHandling.Reject;
            binding_element.RetryCycleDelay        = TimeSpan.FromSeconds(5);
            binding_element.TimeToLive             = TimeSpan.FromSeconds(60);
            binding_element.UseMsmqTracing         = !binding_element.UseMsmqTracing;
            binding_element.UseSourceJournal       = !binding_element.UseSourceJournal;
#if NET_4_0
            // This ones haven't been implemented yet, so comment them for now.
            //binding_element.ReceiveContextEnabled = !binding_element.ReceiveContextEnabled;
            //binding_element.ValidityDuration = TimeSpan.FromSeconds (30);
#endif

            binding_element.MsmqTransportSecurity.MsmqAuthenticationMode  = MsmqAuthenticationMode.Certificate;
            binding_element.MsmqTransportSecurity.MsmqEncryptionAlgorithm = MsmqEncryptionAlgorithm.Aes;
            binding_element.MsmqTransportSecurity.MsmqProtectionLevel     = ProtectionLevel.EncryptAndSign;
            binding_element.MsmqTransportSecurity.MsmqSecureHashAlgorithm = MsmqSecureHashAlgorithm.Sha256;

            IPolicyExportExtension  export_extension   = binding_element as IPolicyExportExtension;
            PolicyConversionContext conversion_context = new CustomPolicyConversionContext();
            export_extension.ExportPolicy(new WsdlExporter(), conversion_context);

            PolicyAssertionCollection binding_assertions = conversion_context.GetBindingAssertions();
            BindingElementCollection  binding_elements   = conversion_context.BindingElements;
            Assert.AreEqual(5, binding_assertions.Count, "#A0");
            Assert.AreEqual(0, binding_elements.Count, "#A1");

            // msmq:MsmqVolatile
            XmlNode volatile_node = FindAssertion(binding_assertions, "msmq:MsmqVolatile");
            Assert.AreEqual(true, volatile_node != null, "#B0");
            Assert.AreEqual("MsmqVolatile", volatile_node.LocalName, "#B1");
            Assert.AreEqual("http://schemas.microsoft.com/ws/06/2004/mspolicy/msmq", volatile_node.NamespaceURI, "#B2");
            Assert.AreEqual(String.Empty, volatile_node.InnerText, "#B3");
            Assert.AreEqual(0, volatile_node.Attributes.Count, "#B4");
            Assert.AreEqual(0, volatile_node.ChildNodes.Count, "#B5");

            // msmq:MsmqBestEffort
            XmlNode best_effort_node = FindAssertion(binding_assertions, "msmq:MsmqBestEffort");
            Assert.AreEqual(true, best_effort_node != null, "#C0");
            Assert.AreEqual("MsmqBestEffort", best_effort_node.LocalName, "#C1");
            Assert.AreEqual("http://schemas.microsoft.com/ws/06/2004/mspolicy/msmq", best_effort_node.NamespaceURI, "#C2");
            Assert.AreEqual(String.Empty, best_effort_node.InnerText, "#C3");
            Assert.AreEqual(0, best_effort_node.Attributes.Count, "#C4");
            Assert.AreEqual(0, best_effort_node.ChildNodes.Count, "#C5");

            // Setting MsmqTransportSecurity.MsmqAuthenticationMode to a value other than WindowsDomain
            // causes the removal of the WindowsDomain policy.
            XmlNode domain_node = FindAssertion(binding_assertions, "msmq:WindowsDomain");
            Assert.AreEqual(true, domain_node == null, "#D0");
        }
 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>();
 }
        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);
            }
        }
 internal static XmlElement GetStreamedMessageFramingPolicy(PolicyAssertionCollection collection)
 {
     return(FindAndRemove(collection, "Streamed", FramingPolicyNS));
 }
Exemple #47
0
		public static void Dump (PolicyAssertionCollection assertions)
		{
			foreach (var assertion in assertions)
				Console.WriteLine ("ASSERTION: {0}", assertion.OuterXml);
		}
Exemple #48
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 ();
		}
 internal BindingOnlyPolicyConversionContext(ServiceEndpoint endpoint, IEnumerable<XmlElement> bindingPolicy)
     : base(endpoint)
 {
     this.bindingPolicy = new PolicyAssertionCollection(bindingPolicy);
 }