1 //------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation.  All rights reserved.
3 //------------------------------------------------------------
4 namespace System.ServiceModel
5 {
6     using System.Runtime;
7     using System.ServiceModel.Channels;
8     using System.ComponentModel;
9 
10     public sealed class WebHttpSecurity
11     {
12         internal const WebHttpSecurityMode DefaultMode = WebHttpSecurityMode.None;
13         WebHttpSecurityMode mode;
14         HttpTransportSecurity transportSecurity;
15         bool isModeSet;
16 
WebHttpSecurity()17         public WebHttpSecurity()
18         {
19             this.transportSecurity = new HttpTransportSecurity();
20         }
21 
22         public WebHttpSecurityMode Mode
23         {
24             get { return this.mode; }
25             set
26             {
27                 if (!WebHttpSecurityModeHelper.IsDefined(value))
28                 {
29                     throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value"));
30                 }
31                 this.mode = value;
32                 this.isModeSet = true;
33             }
34         }
35 
36         internal bool IsModeSet
37         {
38             get { return this.isModeSet; }
39         }
40 
41         public HttpTransportSecurity Transport
42         {
43             get { return this.transportSecurity; }
44             set
45             {
46                 this.transportSecurity = (value == null) ? new HttpTransportSecurity() : value;
47             }
48         }
49 
DisableTransportAuthentication(HttpTransportBindingElement http)50         internal void DisableTransportAuthentication(HttpTransportBindingElement http)
51         {
52             this.transportSecurity.DisableTransportAuthentication(http);
53         }
54 
EnableTransportAuthentication(HttpTransportBindingElement http)55         internal void EnableTransportAuthentication(HttpTransportBindingElement http)
56         {
57             this.transportSecurity.ConfigureTransportAuthentication(http);
58         }
59 
EnableTransportSecurity(HttpsTransportBindingElement https)60         internal void EnableTransportSecurity(HttpsTransportBindingElement https)
61         {
62             this.transportSecurity.ConfigureTransportProtectionAndAuthentication(https);
63         }
64 
InternalShouldSerialize()65         internal bool InternalShouldSerialize()
66         {
67             return this.ShouldSerializeMode()
68                 || this.ShouldSerializeTransport();
69         }
70 
71         [EditorBrowsable(EditorBrowsableState.Never)]
ShouldSerializeMode()72         public bool ShouldSerializeMode()
73         {
74             return this.Mode != DefaultMode;
75         }
76 
77         [EditorBrowsable(EditorBrowsableState.Never)]
ShouldSerializeTransport()78         public bool ShouldSerializeTransport()
79         {
80             return this.Transport.InternalShouldSerialize();
81         }
82 
83 
84     }
85 }
86