PageRenderTime 16ms CodeModel.GetById 12ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/ExpressInteropBinding/Microsoft.ServiceModel.Interop/Configuration/InteropSecurityElement.cs

#
C# | 93 lines | 55 code | 12 blank | 26 comment | 4 complexity | 7e0bb68f039ddb117ee71561291caf4c MD5 | raw file
 1// <copyright file="InteropSecurityElement.cs" company="Microsoft Corporation">
 2// Copyright (c) Microsoft Corporation.  All rights reserved.
 3// </copyright>
 4
 5namespace Microsoft.ServiceModel.Interop.Configuration
 6{
 7    using System;
 8    using System.ComponentModel;
 9    using System.Configuration;
10    using System.ServiceModel.Security;
11
12    /// <summary>
13    /// Base class for the security configuration element that the rest of the service stacks derive
14    /// </summary>
15    public class InteropSecurityElement : ConfigurationElement
16    {
17        private const string EstablishSecurityContextProperty = "establishSecurityContext";
18        private const string AlgorithmSuiteProperty = "algorithmSuite";
19
20        /// <summary>
21        /// Initializes a new instance of the InteropSecurityElement class
22        /// </summary>
23        protected InteropSecurityElement()
24        {
25        }
26
27        /// <summary>
28        /// Gets or sets a value indicating whether a secure conversation must be established
29        /// </summary>
30        [ConfigurationProperty(EstablishSecurityContextProperty, IsRequired = false, DefaultValue = false)]
31        public bool EstablishSecurityContext
32        {
33            get { return (bool)base[EstablishSecurityContextProperty]; }
34            set { base[EstablishSecurityContextProperty] = value; }
35        }
36
37        /// <summary>
38        /// Gets or sets the security algorithm
39        /// </summary>
40        [TypeConverter(typeof(SecurityAlgorithmSuiteConverter)), ConfigurationProperty(AlgorithmSuiteProperty, DefaultValue = "Default")]
41        public SecurityAlgorithmSuite AlgorithmSuite
42        {
43            get { return (SecurityAlgorithmSuite)base[AlgorithmSuiteProperty]; }
44            set { base[AlgorithmSuiteProperty] = value; }
45        }
46
47        /// <summary>
48        /// Gets all the available configuration properties
49        /// </summary>
50        protected override ConfigurationPropertyCollection Properties
51        {
52            get
53            {
54                ConfigurationPropertyCollection properties = base.Properties;
55                properties.Add(new ConfigurationProperty(EstablishSecurityContextProperty, typeof(bool), false));
56                properties.Add(new ConfigurationProperty(AlgorithmSuiteProperty, typeof(SecurityAlgorithmSuite), "Default", new SecurityAlgorithmSuiteConverter(), null, ConfigurationPropertyOptions.None));
57
58                return properties;
59            }
60        }
61
62        /// <summary>
63        /// Applies this configuration instance to an existing security binding element
64        /// </summary>
65        /// <param name="security">Security binding element</param>
66        public virtual void ApplyConfiguration(InteropSecurity security)
67        {
68            if (security == null)
69            {
70                throw new ArgumentNullException("security");
71            }
72
73            security.AlgorithmSuite = this.AlgorithmSuite;
74            security.EstablishSecurityContext = this.EstablishSecurityContext;
75        }
76
77        /// <summary>
78        /// Initializes this security configuration from an existing security binding element
79        /// </summary>
80        /// <param name="security">Security binding element</param>
81        public virtual void InitializeFrom(InteropSecurity security)
82        {
83            if (security == null)
84            {
85                throw new ArgumentNullException("security");
86            }
87
88            this.AlgorithmSuite = security.AlgorithmSuite;
89            this.EstablishSecurityContext = security.EstablishSecurityContext;
90        }
91    }
92}
93