| | | 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 CoreWCF.Channels; |
| | | 6 | | |
| | | 7 | | namespace CoreWCF |
| | | 8 | | { |
| | | 9 | | public sealed class WebHttpSecurity |
| | | 10 | | { |
| | | 11 | | internal const WebHttpSecurityMode DefaultMode = WebHttpSecurityMode.None; |
| | | 12 | | private WebHttpSecurityMode _mode; |
| | | 13 | | private HttpTransportSecurity _transportSecurity; |
| | | 14 | | |
| | 45 | 15 | | public WebHttpSecurity() |
| | | 16 | | { |
| | 45 | 17 | | _transportSecurity = new HttpTransportSecurity(); |
| | 45 | 18 | | } |
| | | 19 | | |
| | | 20 | | public WebHttpSecurityMode Mode |
| | | 21 | | { |
| | 1534 | 22 | | get { return _mode; } |
| | | 23 | | set |
| | | 24 | | { |
| | 11 | 25 | | if (!WebHttpSecurityModeHelper.IsDefined(value)) |
| | | 26 | | { |
| | 0 | 27 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val |
| | | 28 | | } |
| | | 29 | | |
| | 11 | 30 | | _mode = value; |
| | 11 | 31 | | IsModeSet = true; |
| | 11 | 32 | | } |
| | | 33 | | } |
| | | 34 | | |
| | 11 | 35 | | internal bool IsModeSet { get; private set; } |
| | | 36 | | |
| | | 37 | | public HttpTransportSecurity Transport |
| | | 38 | | { |
| | 1556 | 39 | | get { return _transportSecurity; } |
| | | 40 | | set |
| | | 41 | | { |
| | 6 | 42 | | _transportSecurity = (value == null) ? new HttpTransportSecurity() : value; |
| | 6 | 43 | | } |
| | | 44 | | } |
| | | 45 | | |
| | | 46 | | internal void DisableTransportAuthentication(HttpTransportBindingElement http) |
| | | 47 | | { |
| | 631 | 48 | | HttpTransportHelpers.DisableTransportAuthentication(http); |
| | 631 | 49 | | } |
| | | 50 | | |
| | | 51 | | internal void EnableTransportAuthentication(HttpTransportBindingElement http) |
| | | 52 | | { |
| | 124 | 53 | | HttpTransportHelpers.ConfigureTransportAuthentication(http, _transportSecurity); |
| | 124 | 54 | | } |
| | | 55 | | |
| | | 56 | | internal void EnableTransportSecurity(HttpsTransportBindingElement https) |
| | | 57 | | { |
| | 22 | 58 | | HttpTransportHelpers.ConfigureTransportProtectionAndAuthentication(https, _transportSecurity); |
| | 22 | 59 | | } |
| | | 60 | | |
| | | 61 | | internal void ApplyAuthorizationPolicySupport(HttpTransportBindingElement httpTransport) |
| | | 62 | | { |
| | 777 | 63 | | httpTransport.AlwaysUseAuthorizationPolicySupport = |
| | 777 | 64 | | Transport.AlwaysUseAuthorizationPolicySupport |
| | 777 | 65 | | || Transport.ClientCredentialType == HttpClientCredentialType.InheritedFromHost; |
| | 777 | 66 | | } |
| | | 67 | | } |
| | | 68 | | } |