PageRenderTime 8ms CodeModel.GetById 2ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/ExpressInteropBinding/Microsoft.ServiceModel.Interop/Metro/MetroSecurity.cs

#
C# | 63 lines | 39 code | 10 blank | 14 comment | 5 complexity | b9b0a4cb18da0ba5de9ad61d37408f16 MD5 | raw file
 1// <copyright file="MetroSecurity.cs" company="Microsoft Corporation">
 2// Copyright (c) Microsoft Corporation.  All rights reserved.
 3// </copyright>
 4
 5namespace Microsoft.ServiceModel.Interop.Metro
 6{
 7    using System.ServiceModel;
 8
 9    /// <summary>
10    /// Security binding element for Metro
11    /// </summary>
12    public class MetroSecurity : InteropSecurity
13    {
14        private MetroSecurityMode mode;
15
16        /// <summary>
17        /// Initializes a new instance of the MetroSecurity class
18        /// </summary>
19        /// <param name="security">Security binding element</param>
20        /// <param name="mode">Security Mode</param>
21        public MetroSecurity(WSHttpSecurity security, MetroSecurityMode mode)
22            : base(security)
23        {
24            this.InnerSecurity.Mode = SecurityMode.Message;
25            this.InnerSecurity.Message.NegotiateServiceCredential = false;
26
27            this.mode = mode;
28
29            this.ConfigureSecurity();
30        }
31
32        /// <summary>
33        /// Gets or sets the security mode
34        /// </summary>
35        public MetroSecurityMode Mode
36        {
37            get
38            {
39                return this.mode;
40            }
41
42            set
43            {
44                this.mode = value;
45
46                this.ConfigureSecurity();
47            }
48        }
49
50        private void ConfigureSecurity()
51        {
52            if (this.Mode == MetroSecurityMode.UserNameOverCertificate)
53            {
54                this.InnerSecurity.Message.ClientCredentialType = MessageCredentialType.UserName;
55            }
56            else if (this.Mode == MetroSecurityMode.MutualCertificate)
57            {
58                this.InnerSecurity.Message.ClientCredentialType = MessageCredentialType.Certificate;
59            }
60        }
61    }
62}
63