forked from aspnet/AspNetWebStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHttpTransportSecurityExtensionMethods.cs
More file actions
58 lines (48 loc) · 3.13 KB
/
HttpTransportSecurityExtensionMethods.cs
File metadata and controls
58 lines (48 loc) · 3.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Diagnostics.Contracts;
using System.Net;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.Web.Http.SelfHost.Properties;
namespace System.Web.Http.SelfHost.ServiceModel
{
internal static class HttpTransportSecurityExtensionMethods
{
internal static void ConfigureTransportProtectionAndAuthentication(this HttpTransportSecurity httpTransportSecurity, HttpsTransportBindingElement httpsTransportBindingElement)
{
Contract.Assert(httpTransportSecurity != null);
Contract.Assert(httpsTransportBindingElement != null);
httpTransportSecurity.ConfigureAuthentication(httpsTransportBindingElement);
httpsTransportBindingElement.RequireClientCertificate = httpTransportSecurity.ClientCredentialType == HttpClientCredentialType.Certificate;
}
internal static void ConfigureTransportAuthentication(this HttpTransportSecurity httpTransportSecurity, HttpTransportBindingElement httpTransportBindingElement)
{
Contract.Assert(httpTransportSecurity != null);
Contract.Assert(httpTransportBindingElement != null);
if (httpTransportSecurity.ClientCredentialType == HttpClientCredentialType.Certificate)
{
throw Error.InvalidOperation(SRResources.CertificateUnsupportedForHttpTransportCredentialOnly);
}
httpTransportSecurity.ConfigureAuthentication(httpTransportBindingElement);
}
internal static void DisableTransportAuthentication(this HttpTransportSecurity httpTransportSecurity, HttpTransportBindingElement httpTransportBindingElement)
{
Contract.Assert(httpTransportSecurity != null);
Contract.Assert(httpTransportBindingElement != null);
httpTransportBindingElement.AuthenticationScheme = AuthenticationSchemes.Anonymous;
httpTransportBindingElement.ProxyAuthenticationScheme = AuthenticationSchemes.Anonymous;
httpTransportBindingElement.Realm = String.Empty;
httpTransportBindingElement.ExtendedProtectionPolicy = httpTransportSecurity.ExtendedProtectionPolicy;
}
private static void ConfigureAuthentication(this HttpTransportSecurity httpTransportSecurity, HttpTransportBindingElement httpTransportBindingElement)
{
Contract.Assert(httpTransportSecurity != null);
Contract.Assert(httpTransportBindingElement != null);
httpTransportBindingElement.AuthenticationScheme = HttpClientCredentialTypeHelper.MapToAuthenticationScheme(httpTransportSecurity.ClientCredentialType);
httpTransportBindingElement.ProxyAuthenticationScheme = HttpProxyCredentialTypeHelper.MapToAuthenticationScheme(httpTransportSecurity.ProxyCredentialType);
httpTransportBindingElement.Realm = httpTransportSecurity.Realm;
httpTransportBindingElement.ExtendedProtectionPolicy = httpTransportSecurity.ExtendedProtectionPolicy;
}
}
}