public static bool DoesAuthTypeMatch(AuthenticationSchemes authScheme, string authType)
        {
            if ((authType == null) || (authType.Length == 0))
            {
                return(authScheme.IsSet(AuthenticationSchemes.Anonymous));
            }

            if (authType.Equals("kerberos", StringComparison.OrdinalIgnoreCase) ||
                authType.Equals("negotiate", StringComparison.OrdinalIgnoreCase))
            {
                return(authScheme.IsSet(AuthenticationSchemes.Negotiate));
            }
            else if (authType.Equals("ntlm", StringComparison.OrdinalIgnoreCase))
            {
                return(authScheme.IsSet(AuthenticationSchemes.Negotiate) ||
                       authScheme.IsSet(AuthenticationSchemes.Ntlm));
            }

            AuthenticationSchemes authTypeScheme;

            if (!Enum.TryParse <AuthenticationSchemes>(authType, true, out authTypeScheme))
            {
                return(false);
            }

            return(authScheme.IsSet(authTypeScheme));
        }
        public static bool DoesAuthTypeMatch(AuthenticationSchemes authScheme, string authType)
        {
            if ((authType == null) || (authType.Length == 0))
            {
                return authScheme.IsSet(AuthenticationSchemes.Anonymous);
            }

            if (authType.Equals("kerberos", StringComparison.OrdinalIgnoreCase) ||
                authType.Equals("negotiate", StringComparison.OrdinalIgnoreCase))
            {
                return authScheme.IsSet(AuthenticationSchemes.Negotiate);
            }
            else if (authType.Equals("ntlm", StringComparison.OrdinalIgnoreCase))
            {
                return authScheme.IsSet(AuthenticationSchemes.Negotiate) ||
                    authScheme.IsSet(AuthenticationSchemes.Ntlm);
            }

            AuthenticationSchemes authTypeScheme;
            if (!Enum.TryParse<AuthenticationSchemes>(authType, true, out authTypeScheme))
            {
                return false;
            }

            return authScheme.IsSet(authTypeScheme);
        }
예제 #3
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));
            }
        }