| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System; |
| | | 5 | | using System.Net; |
| | | 6 | | using CoreWCF.Channels; |
| | | 7 | | using CoreWCF.Runtime; |
| | | 8 | | |
| | | 9 | | namespace CoreWCF |
| | | 10 | | { |
| | | 11 | | internal static class HttpTransportHelpers |
| | | 12 | | { |
| | | 13 | | private const string DefaultRealm = HttpTransportDefaults.Realm; |
| | | 14 | | |
| | | 15 | | internal static void ConfigureTransportProtectionAndAuthentication(HttpsTransportBindingElement https, HttpTrans |
| | | 16 | | { |
| | 22 | 17 | | ConfigureAuthentication(https, transportSecurity); |
| | 22 | 18 | | https.RequireClientCertificate = (transportSecurity.ClientCredentialType == HttpClientCredentialType.Certifi |
| | 22 | 19 | | } |
| | | 20 | | |
| | | 21 | | internal static void ConfigureTransportAuthentication(HttpTransportBindingElement http, HttpTransportSecurity tr |
| | | 22 | | { |
| | 124 | 23 | | if (transportSecurity.ClientCredentialType == HttpClientCredentialType.Certificate) |
| | | 24 | | { |
| | 0 | 25 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.CertificateUn |
| | | 26 | | } |
| | | 27 | | |
| | 124 | 28 | | ConfigureAuthentication(http, transportSecurity); |
| | 124 | 29 | | } |
| | | 30 | | |
| | | 31 | | internal static void DisableTransportAuthentication(HttpTransportBindingElement http) |
| | | 32 | | { |
| | 631 | 33 | | DisableAuthentication(http); |
| | 631 | 34 | | } |
| | | 35 | | |
| | | 36 | | private static void ConfigureAuthentication(HttpTransportBindingElement http, HttpTransportSecurity transportSec |
| | | 37 | | { |
| | 146 | 38 | | http.AuthenticationScheme = MapToAuthenticationScheme(transportSecurity.ClientCredentialType); |
| | 146 | 39 | | http.Realm = transportSecurity.Realm; |
| | 146 | 40 | | http.ExtendedProtectionPolicy = transportSecurity.ExtendedProtectionPolicy; |
| | 146 | 41 | | } |
| | | 42 | | |
| | | 43 | | private static AuthenticationSchemes MapToAuthenticationScheme(HttpClientCredentialType clientCredentialType) |
| | | 44 | | { |
| | | 45 | | AuthenticationSchemes result; |
| | | 46 | | switch (clientCredentialType) |
| | | 47 | | { |
| | | 48 | | case HttpClientCredentialType.Certificate: |
| | | 49 | | // fall through to None case |
| | | 50 | | case HttpClientCredentialType.None: |
| | 22 | 51 | | result = AuthenticationSchemes.Anonymous; |
| | 22 | 52 | | break; |
| | | 53 | | case HttpClientCredentialType.Basic: |
| | 0 | 54 | | result = AuthenticationSchemes.Basic; |
| | 0 | 55 | | break; |
| | | 56 | | case HttpClientCredentialType.Digest: |
| | 0 | 57 | | result = AuthenticationSchemes.Digest; |
| | 0 | 58 | | break; |
| | | 59 | | case HttpClientCredentialType.Ntlm: |
| | 0 | 60 | | result = AuthenticationSchemes.Ntlm; |
| | 0 | 61 | | break; |
| | | 62 | | case HttpClientCredentialType.Windows: |
| | 0 | 63 | | result = AuthenticationSchemes.Negotiate; |
| | 0 | 64 | | break; |
| | | 65 | | case HttpClientCredentialType.InheritedFromHost: |
| | 124 | 66 | | result = AuthenticationSchemes.None; |
| | 124 | 67 | | break; |
| | | 68 | | default: |
| | | 69 | | Fx.Assert("unsupported client credential type"); |
| | 0 | 70 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException()); |
| | | 71 | | } |
| | 146 | 72 | | return result; |
| | | 73 | | } |
| | | 74 | | |
| | | 75 | | private static void DisableAuthentication(HttpTransportBindingElement http) |
| | | 76 | | { |
| | 631 | 77 | | http.AuthenticationScheme = AuthenticationSchemes.Anonymous; |
| | 631 | 78 | | http.Realm = DefaultRealm; |
| | | 79 | | //ExtendedProtectionPolicy is always copied - even for security mode None, Message and TransportWithMessageC |
| | | 80 | | //because the settings for ExtendedProtectionPolicy are always below the <security><transport> element |
| | | 81 | | //http.ExtendedProtectionPolicy = extendedProtectionPolicy; |
| | 631 | 82 | | } |
| | | 83 | | } |
| | | 84 | | } |