| | | 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.Collections.Generic; |
| | | 5 | | using System.Configuration; |
| | | 6 | | using System.Security.Authentication.ExtendedProtection; |
| | | 7 | | |
| | | 8 | | namespace CoreWCF.Configuration |
| | | 9 | | { |
| | | 10 | | public sealed class ExtendedProtectionPolicyElement : ConfigurationElement |
| | | 11 | | { |
| | 6 | 12 | | public ExtendedProtectionPolicyElement() |
| | | 13 | | { |
| | 6 | 14 | | _properties.Add(_policyEnforcement); |
| | 6 | 15 | | _properties.Add(_protectionScenario); |
| | 6 | 16 | | _properties.Add(_customServiceNames); |
| | 6 | 17 | | } |
| | | 18 | | |
| | | 19 | | protected override ConfigurationPropertyCollection Properties |
| | | 20 | | { |
| | 2 | 21 | | get { return _properties; } |
| | | 22 | | } |
| | | 23 | | |
| | | 24 | | [ConfigurationProperty(ExtendedProtectionConfigurationStrings.PolicyEnforcement)] |
| | | 25 | | public PolicyEnforcement PolicyEnforcement |
| | | 26 | | { |
| | | 27 | | get |
| | | 28 | | { |
| | 2 | 29 | | return (PolicyEnforcement)this[_policyEnforcement]; |
| | | 30 | | } |
| | | 31 | | set |
| | | 32 | | { |
| | 0 | 33 | | this[_policyEnforcement] = value; |
| | 0 | 34 | | } |
| | | 35 | | } |
| | | 36 | | |
| | | 37 | | [ConfigurationProperty(ExtendedProtectionConfigurationStrings.ProtectionScenario, DefaultValue = ProtectionScena |
| | | 38 | | public ProtectionScenario ProtectionScenario |
| | | 39 | | { |
| | | 40 | | get |
| | | 41 | | { |
| | 1 | 42 | | return (ProtectionScenario)this[_protectionScenario]; |
| | | 43 | | } |
| | | 44 | | set |
| | | 45 | | { |
| | 0 | 46 | | this[_protectionScenario] = value; |
| | 0 | 47 | | } |
| | | 48 | | } |
| | | 49 | | |
| | | 50 | | [ConfigurationProperty(ExtendedProtectionConfigurationStrings.CustomServiceNames)] |
| | | 51 | | public ServiceNameElementCollection CustomServiceNames |
| | | 52 | | { |
| | | 53 | | get |
| | | 54 | | { |
| | 1 | 55 | | return (ServiceNameElementCollection)this[_customServiceNames]; |
| | | 56 | | } |
| | | 57 | | } |
| | | 58 | | |
| | | 59 | | public ExtendedProtectionPolicy BuildPolicy() |
| | | 60 | | { |
| | 1 | 61 | | if (PolicyEnforcement == PolicyEnforcement.Never) |
| | | 62 | | { |
| | 0 | 63 | | return new ExtendedProtectionPolicy(PolicyEnforcement.Never); |
| | | 64 | | } |
| | | 65 | | |
| | 1 | 66 | | ServiceNameCollection spns = null; |
| | | 67 | | |
| | 1 | 68 | | ServiceNameElementCollection spnCollection = CustomServiceNames; |
| | 1 | 69 | | if (spnCollection != null && spnCollection.Count > 0) |
| | | 70 | | { |
| | 1 | 71 | | List<string> spnList = new List<string>(spnCollection.Count); |
| | 4 | 72 | | foreach (ServiceNameElement element in spnCollection) |
| | | 73 | | { |
| | 1 | 74 | | spnList.Add(element.Name); |
| | | 75 | | } |
| | 1 | 76 | | spns = new ServiceNameCollection(spnList); |
| | | 77 | | } |
| | | 78 | | |
| | 1 | 79 | | return new ExtendedProtectionPolicy(PolicyEnforcement, ProtectionScenario, spns); |
| | | 80 | | } |
| | | 81 | | |
| | 6 | 82 | | private readonly ConfigurationPropertyCollection _properties = new ConfigurationPropertyCollection(); |
| | | 83 | | |
| | | 84 | | private static PolicyEnforcement DefaultPolicyEnforcement |
| | | 85 | | { |
| | | 86 | | get |
| | | 87 | | { |
| | 6 | 88 | | return PolicyEnforcement.Never; |
| | | 89 | | } |
| | | 90 | | } |
| | | 91 | | |
| | 6 | 92 | | private readonly ConfigurationProperty _policyEnforcement = |
| | 6 | 93 | | new ConfigurationProperty(ExtendedProtectionConfigurationStrings.PolicyEnforcement, |
| | 6 | 94 | | typeof(PolicyEnforcement), DefaultPolicyEnforcement, |
| | 6 | 95 | | ConfigurationPropertyOptions.None); |
| | | 96 | | |
| | 6 | 97 | | private readonly ConfigurationProperty _protectionScenario = |
| | 6 | 98 | | new ConfigurationProperty(ExtendedProtectionConfigurationStrings.ProtectionScenario, |
| | 6 | 99 | | typeof(ProtectionScenario), ProtectionScenario.TransportSelected, |
| | 6 | 100 | | ConfigurationPropertyOptions.None); |
| | | 101 | | |
| | 6 | 102 | | private readonly ConfigurationProperty _customServiceNames = |
| | 6 | 103 | | new ConfigurationProperty(ExtendedProtectionConfigurationStrings.CustomServiceNames, |
| | 6 | 104 | | typeof(ServiceNameElementCollection), null, |
| | 6 | 105 | | ConfigurationPropertyOptions.None); |
| | | 106 | | } |
| | | 107 | | |
| | | 108 | | internal static class ExtendedProtectionConfigurationStrings |
| | | 109 | | { |
| | | 110 | | internal const string ExtendedProtectionPolicy = "extendedProtectionPolicy"; |
| | | 111 | | internal const string PolicyEnforcement = "policyEnforcement"; |
| | | 112 | | internal const string ProtectionScenario = "protectionScenario"; |
| | | 113 | | internal const string CustomServiceNames = "customServiceNames"; |
| | | 114 | | internal const string Name = "name"; |
| | | 115 | | } |
| | | 116 | | } |