void IPolicyImportExtension.ImportPolicy(MetadataImporter importer, PolicyConversionContext context)
 {
     if (importer == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("importer");
     }
     if (context == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context");
     }
     XmlElement element = PolicyConversionContext.FindAssertion(context.GetBindingAssertions(), "OneWay", "http://schemas.microsoft.com/ws/2005/05/routing/policy", true);
     if (element != null)
     {
         OneWayBindingElement item = new OneWayBindingElement();
         context.BindingElements.Add(item);
         for (int i = 0; i < element.ChildNodes.Count; i++)
         {
             System.Xml.XmlNode node = element.ChildNodes[i];
             if (((node != null) && (node.NodeType == XmlNodeType.Element)) && ((node.NamespaceURI == "http://schemas.microsoft.com/ws/2005/05/routing/policy") && (node.LocalName == "PacketRoutable")))
             {
                 item.PacketRoutable = true;
                 return;
             }
         }
     }
     else if (WsdlImporter.WSAddressingHelper.DetermineSupportedAddressingMode(importer, context) == SupportedAddressingMode.NonAnonymous)
     {
         context.BindingElements.Add(new OneWayBindingElement());
     }
 }
        internal void OnImportPolicy(MetadataImporter importer, PolicyConversionContext context)
        {
            XmlElement element = PolicyConversionContext.FindAssertion(context.GetBindingAssertions(),
                                    PeerTransportPolicyConstants.PeerTransportSecurityMode,
                                    TransportPolicyConstants.PeerTransportUri, true);

            this.Mode = SecurityMode.Transport;
            if (element != null)
            {
                switch (element.InnerText)
                {
                    case PeerTransportPolicyConstants.PeerTransportSecurityModeNone:
                        this.Mode = SecurityMode.None;
                        break;
                    case PeerTransportPolicyConstants.PeerTransportSecurityModeTransport:
                        this.Mode = SecurityMode.Transport;
                        break;
                    case PeerTransportPolicyConstants.PeerTransportSecurityModeMessage:
                        this.Mode = SecurityMode.Message;
                        break;
                    case PeerTransportPolicyConstants.PeerTransportSecurityModeTransportWithMessageCredential:
                        this.Mode = SecurityMode.TransportWithMessageCredential;
                        break;
                    default:
                        break;
                }
            }
            transportSecurity.OnImportPolicy(importer, context);
        }
		protected virtual void OnImportPolicy (XmlElement assertion,
			MessageVersion messageVersion,
			MetadataImporter exporter,
			PolicyConversionContext context)
		{
			throw new NotImplementedException ();
		}
 internal void OnImportPolicy(MetadataImporter importer, PolicyConversionContext context)
 {
     string str;
     XmlElement element = PolicyConversionContext.FindAssertion(context.GetBindingAssertions(), "PeerTransportSecurityMode", "http://schemas.microsoft.com/soap/peer", true);
     this.Mode = SecurityMode.Transport;
     if ((element != null) && ((str = element.InnerText) != null))
     {
         if (!(str == "PeerTransportSecurityModeNone"))
         {
             if (str == "PeerTransportSecurityModeTransport")
             {
                 this.Mode = SecurityMode.Transport;
             }
             else if (str == "PeerTransportSecurityModeMessage")
             {
                 this.Mode = SecurityMode.Message;
             }
             else if (str == "PeerTransportSecurityModeTransportWithMessageCredential")
             {
                 this.Mode = SecurityMode.TransportWithMessageCredential;
             }
         }
         else
         {
             this.Mode = SecurityMode.None;
         }
     }
     this.transportSecurity.OnImportPolicy(importer, context);
 }
        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);
            }
        }
        void IPolicyImportExtension.ImportPolicy(MetadataImporter importer, PolicyConversionContext context)
        {
            if (importer == null)
            {
                throw new ArgumentNullException("importer");
            }

            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            ICollection<XmlElement> assertions = context.GetBindingAssertions();
            foreach (XmlElement assertion in assertions)
            {
                if ((assertion.NamespaceURI == GZipMessageEncodingPolicyConstants.GZipEncodingNamespace) &&
                    (assertion.LocalName == GZipMessageEncodingPolicyConstants.GZipEncodingName)
                    )
                {
                    assertions.Remove(assertion);
                    context.BindingElements.Add(new GZipMessageEncodingBindingElement());
                    break;
                }
            }
        }
        void IPolicyImportExtension.ImportPolicy(MetadataImporter importer, PolicyConversionContext policyContext)
        {
            if (policyContext == null)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("policyContext");

            XmlElement privacyNoticeAssertion = PolicyConversionContext.FindAssertion(policyContext.GetBindingAssertions(),
                PrivacyNoticePolicyStrings.PrivacyNoticeName, PrivacyNoticePolicyStrings.PrivacyNoticeNamespace, true);
            if (privacyNoticeAssertion != null)
            {
                PrivacyNoticeBindingElement settings =
                    policyContext.BindingElements.Find<PrivacyNoticeBindingElement>();

                if (null == settings)
                {
                    settings = new PrivacyNoticeBindingElement();
                    policyContext.BindingElements.Add(settings);
                }

                settings.Url = new Uri(privacyNoticeAssertion.InnerText);
                string versionString = privacyNoticeAssertion.GetAttribute(PrivacyNoticePolicyStrings.PrivacyNoticeVersionAttributeName, PrivacyNoticePolicyStrings.PrivacyNoticeNamespace);
                if (string.IsNullOrEmpty(versionString))
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.CannotImportPrivacyNoticeElementWithoutVersionAttribute)));
                }

                int version = 0;
                if (!Int32.TryParse(versionString, out version))
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.PrivacyNoticeElementVersionAttributeInvalid)));
                }
                settings.Version = version;
            }
        }
 public override bool TryImportWsspHttpsTokenAssertion(MetadataImporter importer, ICollection<XmlElement> assertions, HttpsTransportBindingElement httpsBinding)
 {
     XmlElement element;
     if (assertions == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("assertions");
     }
     if (this.TryImportWsspAssertion(assertions, "HttpsToken", out element))
     {
         bool flag = true;
         string attribute = element.GetAttribute("RequireClientCertificate");
         try
         {
             httpsBinding.RequireClientCertificate = XmlUtil.IsTrue(attribute);
         }
         catch (Exception exception)
         {
             if (Fx.IsFatal(exception))
             {
                 throw;
             }
             if (exception is NullReferenceException)
             {
                 throw;
             }
             importer.Errors.Add(new MetadataConversionError(System.ServiceModel.SR.GetString("UnsupportedBooleanAttribute", new object[] { "RequireClientCertificate", exception.Message }), false));
             flag = false;
         }
         return flag;
     }
     return false;
 }
 void IPolicyImportExtension.ImportPolicy(MetadataImporter importer, PolicyConversionContext policyContext)
 {
     if (policyContext == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("policyContext");
     }
     XmlElement element = PolicyConversionContext.FindAssertion(policyContext.GetBindingAssertions(), "PrivacyNotice", "http://schemas.xmlsoap.org/ws/2005/05/identity", true);
     if (element != null)
     {
         PrivacyNoticeBindingElement item = policyContext.BindingElements.Find<PrivacyNoticeBindingElement>();
         if (item == null)
         {
             item = new PrivacyNoticeBindingElement();
             policyContext.BindingElements.Add(item);
         }
         item.Url = new Uri(element.InnerText);
         string attribute = element.GetAttribute("Version", "http://schemas.xmlsoap.org/ws/2005/05/identity");
         if (string.IsNullOrEmpty(attribute))
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("CannotImportPrivacyNoticeElementWithoutVersionAttribute")));
         }
         int result = 0;
         if (!int.TryParse(attribute, out result))
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("PrivacyNoticeElementVersionAttributeInvalid")));
         }
         item.Version = result;
     }
 }
 private static void ProcessReliableSession11Assertion(MetadataImporter importer, XmlElement element, ReliableSessionBindingElement settings)
 {
     settings.ReliableMessagingVersion = ReliableMessagingVersion.WSReliableMessaging11;
     IEnumerator nodes = element.ChildNodes.GetEnumerator();
     System.Xml.XmlNode node = SkipToNode(nodes);
     ProcessWsrm11Policy(importer, node, settings);
     node = SkipToNode(nodes);
     State inactivityTimeout = State.InactivityTimeout;
     while (node != null)
     {
         if ((inactivityTimeout == State.InactivityTimeout) && Is11Assertion(node, "InactivityTimeout"))
         {
             SetInactivityTimeout(settings, ReadMillisecondsAttribute(node, true), node.LocalName);
             inactivityTimeout = State.AcknowledgementInterval;
             node = SkipToNode(nodes);
         }
         else
         {
             if (Is11Assertion(node, "AcknowledgementInterval"))
             {
                 SetAcknowledgementInterval(settings, ReadMillisecondsAttribute(node, true), node.LocalName);
                 return;
             }
             if (inactivityTimeout == State.AcknowledgementInterval)
             {
                 return;
             }
             node = SkipToNode(nodes);
         }
     }
 }
        void IPolicyImportExtension.ImportPolicy(MetadataImporter importer, PolicyConversionContext context)
        {
            if (importer == null)
            {
                throw new ArgumentNullException("importer");
            }

            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            ICollection<XmlElement> assertions = context.GetBindingAssertions();

            foreach (XmlElement assertion in assertions)
            {
                if (assertion.NamespaceURI == MakeConnectionConstants.Namespace)
                {
                    if (assertion.LocalName == MakeConnectionConstants.Policy.Assertion)
                    {
                        assertions.Remove(assertion);
                        context.BindingElements.Insert(0, new MakeConnectionBindingElement());
                        return;
                    }
                }
            }
        }
        public override bool TryImportWsspHttpsTokenAssertion(MetadataImporter importer, ICollection<XmlElement> assertions, HttpsTransportBindingElement httpsBinding)
        {
            if (assertions == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("assertions");
            }

            bool result = true;
            XmlElement assertion;

            if (TryImportWsspAssertion(assertions, HttpsTokenName, out assertion))
            {
                XmlElement policyElement = null;
                foreach (XmlNode node in assertion.ChildNodes)
                {
                    if (node is XmlElement && node.LocalName == WSSecurityPolicy.PolicyName && (node.NamespaceURI == WSSecurityPolicy.WspNamespace || node.NamespaceURI == WSSecurityPolicy.Wsp15Namespace))
                    {
                        policyElement = (XmlElement)node;
                        break;
                    }
                }

                if (policyElement != null)
                {
                    foreach (XmlNode node in policyElement.ChildNodes)
                    {
                        if (node is XmlElement && node.NamespaceURI == this.WsspNamespaceUri)
                        {
                            if (node.LocalName == WSSecurityPolicy.RequireClientCertificateName)
                            {
                                httpsBinding.RequireClientCertificate = true;
                            }
                            else if (node.LocalName == WSSecurityPolicy.HttpBasicAuthenticationName)
                            {
                                httpsBinding.AuthenticationScheme = AuthenticationSchemes.Basic;
                            }
                            else if (node.LocalName == WSSecurityPolicy.HttpDigestAuthenticationName)
                            {
                                httpsBinding.AuthenticationScheme = AuthenticationSchemes.Digest;
                            }
                        }
                    }
                }
            }
            else
            {
                result = false;
            }

            return result;
        }
        public void ImportPolicy(MetadataImporter importer, PolicyConversionContext context)
        {
            XmlQualifiedName wsdlBindingQName;
            string transportUri = WsdlImporter.SoapInPolicyWorkaroundHelper.FindAdHocPolicy(context, this.udpTransportUriKey, out wsdlBindingQName);

            if (transportUri != null && transportUri.Equals(UdpConstants.WsdlSoapUdpTransportUri, StringComparison.Ordinal) && !context.BindingElements.Contains(typeof(TransportBindingElement)))
            {
                UdpTransportBindingElement transport = new UdpTransportBindingElement();
                ((ITransportPolicyImport)transport).ImportPolicy(importer, context);

                StateHelper.RegisterTransportBindingElement(importer, wsdlBindingQName);
                context.BindingElements.Add(transport);
            }
        }
        void IPolicyImportExtension.ImportPolicy(MetadataImporter importer, PolicyConversionContext context)
        {
            if (importer == null)
            {
                throw new ArgumentNullException("importer");
            }

            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            ICollection<XmlElement> bindingAssertions = context.GetBindingAssertions();
            List<XmlElement> processedAssertions = new List<XmlElement>();
            UdpTransportBindingElement udpBindingElement = null;
            bool multicast = false;
            foreach (XmlElement assertion in bindingAssertions)
            {
                if (assertion.NamespaceURI != UdpPolicyStrings.UdpNamespace)
                {
                    continue;
                }

                switch (assertion.LocalName)
                {
                    case UdpPolicyStrings.TransportAssertion:
                        udpBindingElement = new UdpTransportBindingElement();
                        break;
                    case UdpPolicyStrings.MulticastAssertion:
                        multicast = true;
                        break;
                    default:
                        continue;
                }

                processedAssertions.Add(assertion);
            }

            if (udpBindingElement != null)
            {
                udpBindingElement.Multicast = multicast;
                context.BindingElements.Add(udpBindingElement);
            }

            for (int i = 0; i < processedAssertions.Count; i++)
            {
                bindingAssertions.Remove(processedAssertions[i]);
            }
        }
 void IPolicyImportExtension.ImportPolicy(MetadataImporter importer, PolicyConversionContext context)
 {
     if (importer == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("importer");
     }
     if (context == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context");
     }
     if ((PolicyConversionContext.FindAssertion(context.GetBindingAssertions(), "CompositeDuplex", "http://schemas.microsoft.com/net/2006/06/duplex", true) != null) || (WsdlImporter.WSAddressingHelper.DetermineSupportedAddressingMode(importer, context) == SupportedAddressingMode.NonAnonymous))
     {
         context.BindingElements.Add(new CompositeDuplexBindingElement());
     }
 }
        void ImportOperationScopeSupportingTokensPolicy(MetadataImporter importer, PolicyConversionContext policyContext, SecurityBindingElement binding)
        {
            foreach (OperationDescription operation in policyContext.Contract.Operations)
            {
                string requestAction = null;
                foreach (MessageDescription message in operation.Messages)
                {
                    if (message.Direction == MessageDirection.Input)
                    {
                        requestAction = message.Action;
                        break;
                    }
                }

                SupportingTokenParameters requirements = new SupportingTokenParameters();
                SupportingTokenParameters optionalRequirements = new SupportingTokenParameters();
                ICollection<XmlElement> operationBindingAssertions = policyContext.GetOperationBindingAssertions(operation);
                this.ImportSupportingTokenAssertions(importer, policyContext, operationBindingAssertions, requirements, optionalRequirements);
                if (requirements.Endorsing.Count > 0
                    || requirements.Signed.Count > 0
                    || requirements.SignedEncrypted.Count > 0
                    || requirements.SignedEndorsing.Count > 0)
                {
                    if (requestAction != null)
                    {
                        binding.OperationSupportingTokenParameters[requestAction] = requirements;
                    }
                    else
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.CannotImportSupportingTokensForOperationWithoutRequestAction)));
                    }
                }
                if (optionalRequirements.Endorsing.Count > 0
                    || optionalRequirements.Signed.Count > 0
                    || optionalRequirements.SignedEncrypted.Count > 0
                    || optionalRequirements.SignedEndorsing.Count > 0)
                {
                    if (requestAction != null)
                    {
                        binding.OptionalOperationSupportingTokenParameters[requestAction] = optionalRequirements;
                    }
                    else
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.CannotImportSupportingTokensForOperationWithoutRequestAction)));
                    }
                }
            }
        }
        void IPolicyImportExtension.ImportPolicy(MetadataImporter importer, PolicyConversionContext policyContext)
        {
            if (policyContext == null)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("policyContext");

            XmlElement useManagedPresentationAssertion = PolicyConversionContext.FindAssertion(policyContext.GetBindingAssertions(),
                UseManagedPresentationPolicyStrings.RequireFederatedIdentityProvisioningName, UseManagedPresentationPolicyStrings.UseManagedPresentationNamespace, true);
            if (useManagedPresentationAssertion != null)
            {
                UseManagedPresentationBindingElement settings =
                    policyContext.BindingElements.Find<UseManagedPresentationBindingElement>();

                if (null == settings)
                {
                    settings = new UseManagedPresentationBindingElement();
                    policyContext.BindingElements.Add(settings);
                }
            }

        }
		void IPolicyImportExtension.ImportPolicy (MetadataImporter importer,
			PolicyConversionContext context)
		{
			var assertions = context.GetBindingAssertions ();

			var mtom = PolicyImportHelper.GetMtomMessageEncodingPolicy (assertions);
			if (mtom != null) {
				// http://www.w3.org/Submission/WS-MTOMPolicy/
				context.BindingElements.Add (new MtomMessageEncodingBindingElement ());
				return;
			}

			var binary = PolicyImportHelper.GetBinaryMessageEncodingPolicy (assertions);
			if (binary != null) {
				context.BindingElements.Add (new BinaryMessageEncodingBindingElement ());
				return;
			}

			context.BindingElements.Add (new TextMessageEncodingBindingElement ());
		}
        void IPolicyImportExtension.ImportPolicy(MetadataImporter importer, PolicyConversionContext context)
        {
            if (importer == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("importer");
            }

            if (context == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context");
            }

            bool gotAssertion = false;

            XmlElement reliableSessionAssertion = PolicyConversionContext.FindAssertion(context.GetBindingAssertions(),
                ReliableSessionPolicyStrings.ReliableSessionName,
                ReliableSessionPolicyStrings.ReliableSessionFebruary2005Namespace, true);

            if (reliableSessionAssertion != null)
            {
                ProcessReliableSessionFeb2005Assertion(reliableSessionAssertion, GetReliableSessionBindingElement(context));
                gotAssertion = true;
            }

            reliableSessionAssertion = PolicyConversionContext.FindAssertion(context.GetBindingAssertions(),
                ReliableSessionPolicyStrings.ReliableSessionName,
                ReliableSessionPolicyStrings.ReliableSession11Namespace, true);

            if (reliableSessionAssertion != null)
            {
                if (gotAssertion)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidChannelBindingException(
                        SR.GetString(SR.MultipleVersionsFoundInPolicy,
                        ReliableSessionPolicyStrings.ReliableSessionName)));
                }

                ProcessReliableSession11Assertion(importer, reliableSessionAssertion,
                    GetReliableSessionBindingElement(context));
            }
        }
 private void ImportEndpointScopeMessageBindingAssertions(MetadataImporter importer, PolicyConversionContext policyContext, SecurityBindingElement binding)
 {
     XmlElement assertion = null;
     WSSecurityPolicy policy;
     this.ImportSupportingTokenAssertions(importer, policyContext, policyContext.GetBindingAssertions(), binding.EndpointSupportingTokenParameters, binding.OptionalEndpointSupportingTokenParameters);
     if (WSSecurityPolicy.TryGetSecurityPolicyDriver(policyContext.GetBindingAssertions(), out policy))
     {
         if (!policy.TryImportWsspWssAssertion(importer, policyContext.GetBindingAssertions(), binding, out assertion) && (assertion != null))
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("UnsupportedSecurityPolicyAssertion", new object[] { assertion.OuterXml })));
         }
         if (!policy.TryImportWsspTrustAssertion(importer, policyContext.GetBindingAssertions(), binding, out assertion) && (assertion != null))
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("UnsupportedSecurityPolicyAssertion", new object[] { assertion.OuterXml })));
         }
     }
     if (assertion == null)
     {
         binding.DoNotEmitTrust = true;
     }
 }
        void IPolicyImportExtension.ImportPolicy(MetadataImporter importer, PolicyConversionContext context)
        {
            if (importer == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("importer");
            }

            if (context == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context");
            }

            XmlElement compositeDuplexAssertion = PolicyConversionContext.FindAssertion(context.GetBindingAssertions(),
                TransportPolicyConstants.CompositeDuplex, TransportPolicyConstants.CompositeDuplexNamespace, true);

            if (compositeDuplexAssertion != null
                || WsdlImporter.WSAddressingHelper.DetermineSupportedAddressingMode(importer, context) == SupportedAddressingMode.NonAnonymous)
            {
                context.BindingElements.Add(new CompositeDuplexBindingElement());
            }
        }
 internal void OnImportPolicy(MetadataImporter importer, PolicyConversionContext context)
 {
     string str;
     XmlElement element = PolicyConversionContext.FindAssertion(context.GetBindingAssertions(), "PeerTransportCredentialType", "http://schemas.microsoft.com/soap/peer", true);
     PeerTransportCredentialType password = PeerTransportCredentialType.Password;
     if ((element != null) && ((str = element.InnerText) != null))
     {
         if (!(str == "PeerTransportCredentialTypePassword"))
         {
             if (str == "PeerTransportCredentialTypeCertificate")
             {
                 password = PeerTransportCredentialType.Certificate;
             }
         }
         else
         {
             password = PeerTransportCredentialType.Password;
         }
     }
     this.CredentialType = password;
 }
 internal void OnImportPolicy(MetadataImporter importer, PolicyConversionContext context)
 {
     XmlElement element = PolicyConversionContext.FindAssertion(context.GetBindingAssertions(),
                             PeerTransportPolicyConstants.PeerTransportCredentialType,
                             TransportPolicyConstants.PeerTransportUri, true);
     PeerTransportCredentialType credentialType = PeerTransportCredentialType.Password;
     if (element != null)
     {
         switch (element.InnerText)
         {
             case PeerTransportPolicyConstants.PeerTransportCredentialTypePassword:
                 credentialType = PeerTransportCredentialType.Password;
                 break;
             case PeerTransportPolicyConstants.PeerTransportCredentialTypeCertificate:
                 credentialType = PeerTransportCredentialType.Certificate;
                 break;
             default:
                 break;
         }
     }
     this.CredentialType = credentialType;
 }
        void IPolicyImportExtension.ImportPolicy(MetadataImporter importer, PolicyConversionContext context)
        {
            if (importer == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("importer");
            }

            if (context == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context");
            }

            XmlElement oneWayAssertion = PolicyConversionContext.FindAssertion(context.GetBindingAssertions(),
                OneWayPolicyConstants.OneWay, OneWayPolicyConstants.Namespace, true);

            if (oneWayAssertion != null)
            {
                OneWayBindingElement bindingElement = new OneWayBindingElement();
                context.BindingElements.Add(bindingElement);

                for (int i = 0; i < oneWayAssertion.ChildNodes.Count; i++)
                {
                    XmlNode currentNode = oneWayAssertion.ChildNodes[i];
                    if (currentNode != null
                        && currentNode.NodeType == XmlNodeType.Element
                        && currentNode.NamespaceURI == OneWayPolicyConstants.Namespace
                        && currentNode.LocalName == OneWayPolicyConstants.PacketRoutable)
                    {
                        bindingElement.PacketRoutable = true;
                        break;
                    }
                }
            }
            else if (WsdlImporter.WSAddressingHelper.DetermineSupportedAddressingMode(importer, context) == SupportedAddressingMode.NonAnonymous)
            {
                context.BindingElements.Add(new OneWayBindingElement());
            }
        }
        void IPolicyImportExtension.ImportPolicy(MetadataImporter importer, 
            PolicyConversionContext context)
        {
            foreach (XmlElement assertion in context.GetBindingAssertions())
            {
                if (assertion.Name == HttpCookiePolicyStrings.HttpCookiePolicyElement
                    && assertion.NamespaceURI == HttpCookiePolicyStrings.Namespace)
                {
                    HttpCookieSessionBindingElement bindingElement =
                        new HttpCookieSessionBindingElement();

                    XmlAttribute attribute =
                        assertion.Attributes[HttpCookiePolicyStrings.ExchangeTerminateAttribute];

                    if(attribute != null)
                    {
                        bindingElement.ExchangeTerminateMessage = true;
                    }

                    context.BindingElements.Add(bindingElement);
                    break;
                }
            }
        }
        public override bool TryImportWsspHttpsTokenAssertion(MetadataImporter importer, ICollection<XmlElement> assertions, HttpsTransportBindingElement httpsBinding)
        {
            if (assertions == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("assertions");
            }

            bool result;
            XmlElement assertion;

            if (TryImportWsspAssertion(assertions, HttpsTokenName, out assertion))
            {
                result = true;
                string v = assertion.GetAttribute(RequireClientCertificateName);
                try 
                {
                    httpsBinding.RequireClientCertificate = XmlUtil.IsTrue(v);
                }
                catch (Exception e)
                {
                    if (Fx.IsFatal(e))
                        throw;
                    if (e is NullReferenceException)
                        throw;

                    importer.Errors.Add(new MetadataConversionError(SR.GetString(SR.UnsupportedBooleanAttribute, RequireClientCertificateName, e.Message), false));
                    result = false;
                }
            }
            else
            {
                result = false;
            }

            return result;
        }
        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);
            }
        }
        protected bool TryImportWsspTrustAssertion(string trustName, MetadataImporter importer, ICollection<XmlElement> assertions, SecurityBindingElement binding, out XmlElement assertion)
        {
            if (binding == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("binding");
            }
            if (assertions == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("assertions");
            }

            bool result = true;
            Collection<Collection<XmlElement>> alternatives;

            if (TryImportWsspAssertion(assertions, trustName, out assertion)
                && TryGetNestedPolicyAlternatives(importer, assertion, out alternatives))
            {
                foreach (Collection<XmlElement> alternative in alternatives)
                {
                    TryImportWsspAssertion(alternative, MustSupportIssuedTokensName);
                    bool requireClientEntropy = TryImportWsspAssertion(alternative, RequireClientEntropyName);
                    bool requireServerEntropy = TryImportWsspAssertion(alternative, RequireServerEntropyName);
                    if (trustName == Trust13Name)
                    {
                        // We are just reading this optional element.
                        TryImportWsspAssertion(alternative, RequireAppliesTo);
                    }
                    if (alternative.Count == 0)
                    {
                        if (requireClientEntropy)
                        {
                            if (requireServerEntropy)
                            {
                                binding.KeyEntropyMode = SecurityKeyEntropyMode.CombinedEntropy;
                            }
                            else
                            {
                                binding.KeyEntropyMode = SecurityKeyEntropyMode.ClientEntropy;
                            }
                        }
                        else if (requireServerEntropy)
                        {
                            binding.KeyEntropyMode = SecurityKeyEntropyMode.ServerEntropy;
                        }

                        result = true;
                        break;
                    }
                    else
                    {
                        result = false;
                    }
                }
            }

            return result;
        }
 public abstract bool TryImportWsspTrustAssertion(MetadataImporter importer, ICollection<XmlElement> assertions, SecurityBindingElement binding, out XmlElement assertion);
        public virtual bool TryImportWsspWssAssertion(MetadataImporter importer, ICollection<XmlElement> assertions, SecurityBindingElement binding, out XmlElement assertion)
        {
            if (binding == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("binding");
            }
            if (assertions == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("assertions");
            }

            bool result = true;
            Collection<Collection<XmlElement>> alternatives;

            if (TryImportWsspAssertion(assertions, Wss10Name, out assertion))
            {
                if (TryGetNestedPolicyAlternatives(importer, assertion, out alternatives))
                {
                    foreach (Collection<XmlElement> alternative in alternatives)
                    {
                        TryImportWsspAssertion(alternative, MustSupportRefKeyIdentifierName);
                        TryImportWsspAssertion(alternative, MustSupportRefIssuerSerialName);
                        if (alternative.Count == 0)
                        {
                            binding.MessageSecurityVersion = this.GetSupportedMessageSecurityVersion(SecurityVersion.WSSecurity10);
                            result = true;
                            break;
                        }
                        else
                        {
                            result = false;
                        }
                    }
                }
            }
            else if (TryImportWsspAssertion(assertions, Wss11Name, out assertion))
            {
                if (TryGetNestedPolicyAlternatives(importer, assertion, out alternatives))
                {
                    foreach (Collection<XmlElement> alternative in alternatives)
                    {
                        TryImportWsspAssertion(alternative, MustSupportRefKeyIdentifierName);
                        TryImportWsspAssertion(alternative, MustSupportRefIssuerSerialName);
                        TryImportWsspAssertion(alternative, MustSupportRefThumbprintName);
                        TryImportWsspAssertion(alternative, MustSupportRefEncryptedKeyName);
                        bool requireSignatureConfirmation = TryImportWsspAssertion(alternative, RequireSignatureConfirmationName);
                        if (alternative.Count == 0)
                        {
                            binding.MessageSecurityVersion = this.GetSupportedMessageSecurityVersion(SecurityVersion.WSSecurity11);
                            if (binding is SymmetricSecurityBindingElement)
                            {
                                ((SymmetricSecurityBindingElement)binding).RequireSignatureConfirmation = requireSignatureConfirmation;
                            }
                            else if (binding is AsymmetricSecurityBindingElement)
                            {
                                ((AsymmetricSecurityBindingElement)binding).RequireSignatureConfirmation = requireSignatureConfirmation;
                            }
                            result = true;
                            break;
                        }
                        else
                        {
                            result = false;
                        }
                    }
                }
            }

            return result;
        }
Beispiel #31
0
 internal YieldLimiter(int maxYields, MetadataImporter metadataImporter)
 {
     this.metadataImporter = metadataImporter;
     this.yieldsHit        = 0;
     this.maxYields        = maxYields;
 }
Beispiel #32
0
 internal YieldLimiter(int maxYields, MetadataImporter metadataImporter)
 {
     _metadataImporter = metadataImporter;
     _yieldsHit        = 0;
     _maxYields        = maxYields;
 }
Beispiel #33
0
 internal PolicyReader(MetadataImporter metadataImporter)
 {
     _metadataImporter = metadataImporter;
 }