Esempio n. 1
0
        public override T GetProperty <T>(BindingContext context)
        {
            if (context == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context");
            }
            if (typeof(T) == typeof(ISecurityCapabilities))
            {
                AuthenticationSchemes effectiveAuthenticationSchemes = HttpTransportBindingElement.GetEffectiveAuthenticationSchemes(this.AuthenticationScheme,
                                                                                                                                     context.BindingParameters);

                return((T)(object)new SecurityCapabilities(this.GetSupportsClientAuthenticationImpl(effectiveAuthenticationSchemes),
                                                           effectiveAuthenticationSchemes == AuthenticationSchemes.Negotiate,
                                                           this.GetSupportsClientWindowsIdentityImpl(effectiveAuthenticationSchemes),
                                                           ProtectionLevel.None,
                                                           ProtectionLevel.None));
            }
            else if (typeof(T) == typeof(IBindingDeliveryCapabilities))
            {
                return((T)(object)new BindingDeliveryCapabilitiesHelper());
            }
            else if (typeof(T) == typeof(TransferMode))
            {
                return((T)(object)this.TransferMode);
            }
            else if (typeof(T) == typeof(ExtendedProtectionPolicy))
            {
                return((T)(object)this.ExtendedProtectionPolicy);
            }
            else if (typeof(T) == typeof(IAnonymousUriPrefixMatcher))
            {
                if (this.anonymousUriPrefixMatcher == null)
                {
                    this.anonymousUriPrefixMatcher = new HttpAnonymousUriPrefixMatcher();
                }

                return((T)(object)this.anonymousUriPrefixMatcher);
            }
            else if (typeof(T) == typeof(ITransportCompressionSupport))
            {
                return((T)(object)new TransportCompressionSupportHelper());
            }
            else
            {
#pragma warning suppress 56506 // Microsoft, BindingContext.BindingParameters cannot be null
                if (context.BindingParameters.Find <MessageEncodingBindingElement>() == null)
                {
                    context.BindingParameters.Add(new TextMessageEncodingBindingElement());
                }
                return(base.GetProperty <T>(context));
            }
        }
Esempio n. 2
0
        protected void UpdateAuthenticationSchemes(BindingContext context)
        {
            if (context == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context");
            }
            AuthenticationSchemes effectiveAutheSchemes = HttpTransportBindingElement.GetEffectiveAuthenticationSchemes(this.AuthenticationScheme,
                                                                                                                        context.BindingParameters);

            if (effectiveAutheSchemes == AuthenticationSchemes.None)
            {
#pragma warning suppress 56506 // Microsoft, context.Binding will never be null.
                string bindingName = context.Binding.Name;

                if (this.AuthenticationScheme == AuthenticationSchemes.None)
                {
                    //can't inherit from host because none were configured.
                    //We are throwing a "NotSupportedException" to be consistent with the type of exception that was thrown in this scenario,
                    //before the multi-auth feature, in HostedAspNetEnvironment.ValidateHttpSettings.
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                              new NotSupportedException(SR.GetString(SR.AuthenticationSchemesCannotBeInheritedFromHost, bindingName)));
                }
                else
                {
                    //settings configured on the host and binding conflict.
                    AuthenticationSchemes hostSchemes;
                    if (!AuthenticationSchemesBindingParameter.TryExtract(context.BindingParameters, out hostSchemes))
                    {
                        //The host/binding settings can only conflict if host has settings specified, so we should never
                        //hit this line of code
                        DiagnosticUtility.DebugAssert("Failed to find AuthenticationSchemesBindingParameter");
                    }

                    //We are throwing a "NotSupportedException" to be consistent with the type of exception that was thrown in this scenario,
                    //before the multi-auth feature, in HostedAspNetEnvironment.ValidateHttpSettings.
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                              new NotSupportedException(SR.GetString(SR.AuthenticationSchemes_BindingAndHostConflict, hostSchemes, bindingName, this.AuthenticationScheme)));
                }
            }
            this.AuthenticationScheme = effectiveAutheSchemes;
        }
        public override T GetProperty <T>(BindingContext context)
        {
            if (context == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context");
            }
            if (typeof(T) == typeof(ISecurityCapabilities))
            {
                AuthenticationSchemes effectiveAuthenticationSchemes = HttpTransportBindingElement.GetEffectiveAuthenticationSchemes(this.AuthenticationScheme,
                                                                                                                                     context.BindingParameters);

                return((T)(object)new SecurityCapabilities(this.GetSupportsClientAuthenticationImpl(effectiveAuthenticationSchemes),
                                                           true,
                                                           this.GetSupportsClientWindowsIdentityImpl(effectiveAuthenticationSchemes),
                                                           ProtectionLevel.EncryptAndSign,
                                                           ProtectionLevel.EncryptAndSign));
            }
            else
            {
                return(base.GetProperty <T>(context));
            }
        }
Esempio n. 4
0
        internal virtual void OnExportPolicy(MetadataExporter exporter, PolicyConversionContext policyContext)
        {
            List <string>         assertionNames = new List <string>();
            AuthenticationSchemes effectiveAuthenticationSchemes = HttpTransportBindingElement.GetEffectiveAuthenticationSchemes(this.AuthenticationScheme,
                                                                                                                                 policyContext.BindingParameters);

            if (effectiveAuthenticationSchemes != AuthenticationSchemes.None && !(effectiveAuthenticationSchemes.IsSet(AuthenticationSchemes.Anonymous)))
            {
                // ATTENTION: The order of the if-statements below is essential! When importing WSDL svcutil is actually
                // using the first assertion - and the HTTP spec requires clients to use the most secure authentication
                // scheme supported by the client. (especially important for downlevel (3.5/4.0) clients
                if (effectiveAuthenticationSchemes.IsSet(AuthenticationSchemes.Negotiate))
                {
                    assertionNames.Add(TransportPolicyConstants.NegotiateHttpAuthenticationName);
                }

                if (effectiveAuthenticationSchemes.IsSet(AuthenticationSchemes.Ntlm))
                {
                    assertionNames.Add(TransportPolicyConstants.NtlmHttpAuthenticationName);
                }

                if (effectiveAuthenticationSchemes.IsSet(AuthenticationSchemes.Digest))
                {
                    assertionNames.Add(TransportPolicyConstants.DigestHttpAuthenticationName);
                }

                if (effectiveAuthenticationSchemes.IsSet(AuthenticationSchemes.Basic))
                {
                    assertionNames.Add(TransportPolicyConstants.BasicHttpAuthenticationName);
                }

                if (assertionNames != null && assertionNames.Count > 0)
                {
                    if (assertionNames.Count == 1)
                    {
                        policyContext.GetBindingAssertions().Add(new XmlDocument().CreateElement(TransportPolicyConstants.HttpTransportPrefix,
                                                                                                 assertionNames[0], TransportPolicyConstants.HttpTransportNamespace));
                    }
                    else
                    {
                        XmlDocument dummy = new XmlDocument();
                        XmlElement  root  = dummy.CreateElement(MetadataStrings.WSPolicy.Prefix,
                                                                MetadataStrings.WSPolicy.Elements.ExactlyOne,
                                                                exporter.PolicyVersion.Namespace);

                        foreach (string assertionName in assertionNames)
                        {
                            root.AppendChild(dummy.CreateElement(TransportPolicyConstants.HttpTransportPrefix,
                                                                 assertionName,
                                                                 TransportPolicyConstants.HttpTransportNamespace));
                        }

                        policyContext.GetBindingAssertions().Add(root);
                    }
                }
            }

            bool useWebSocketTransport = WebSocketHelper.UseWebSocketTransport(this.WebSocketSettings.TransportUsage, policyContext.Contract.IsDuplex());

            if (useWebSocketTransport && this.TransferMode != TransferMode.Buffered)
            {
                policyContext.GetBindingAssertions().Add(new XmlDocument().CreateElement(TransportPolicyConstants.WebSocketPolicyPrefix,
                                                                                         this.TransferMode.ToString(), TransportPolicyConstants.WebSocketPolicyNamespace));
            }
        }