| | | 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; |
| | | 5 | | using System.ComponentModel; |
| | | 6 | | using System.Configuration; |
| | | 7 | | using CoreWCF.Channels; |
| | | 8 | | |
| | | 9 | | namespace CoreWCF.Configuration |
| | | 10 | | { |
| | | 11 | | public sealed class LocalServiceSecuritySettingsElement : ServiceModelConfigurationElement |
| | | 12 | | { |
| | | 13 | | [ConfigurationProperty(ConfigurationStrings.DetectReplays, DefaultValue = SecurityBindingDefaults.DefaultDetectR |
| | | 14 | | public bool DetectReplays |
| | | 15 | | { |
| | 1 | 16 | | get { return (bool)base[ConfigurationStrings.DetectReplays]; } |
| | 0 | 17 | | set { base[ConfigurationStrings.DetectReplays] = value; } |
| | | 18 | | } |
| | | 19 | | |
| | | 20 | | [ConfigurationProperty(ConfigurationStrings.IssuedCookieLifetime, DefaultValue = SecurityBindingDefaults.Default |
| | | 21 | | [TypeConverter(typeof(TimeSpanOrInfiniteConverter))] |
| | | 22 | | public TimeSpan IssuedCookieLifetime |
| | | 23 | | { |
| | 1 | 24 | | get { return (TimeSpan)base[ConfigurationStrings.IssuedCookieLifetime]; } |
| | 0 | 25 | | set { base[ConfigurationStrings.IssuedCookieLifetime] = value; } |
| | | 26 | | } |
| | | 27 | | |
| | | 28 | | [ConfigurationProperty(ConfigurationStrings.MaxStatefulNegotiations, DefaultValue = SecurityBindingDefaults.Defa |
| | | 29 | | [IntegerValidator(MinValue = 0)] |
| | | 30 | | public int MaxStatefulNegotiations |
| | | 31 | | { |
| | 1 | 32 | | get { return (int)base[ConfigurationStrings.MaxStatefulNegotiations]; } |
| | 0 | 33 | | set { base[ConfigurationStrings.MaxStatefulNegotiations] = value; } |
| | | 34 | | } |
| | | 35 | | |
| | | 36 | | [ConfigurationProperty(ConfigurationStrings.ReplayCacheSize, DefaultValue = SecurityBindingDefaults.DefaultMaxCa |
| | | 37 | | [IntegerValidator(MinValue = 1)] |
| | | 38 | | public int ReplayCacheSize |
| | | 39 | | { |
| | 1 | 40 | | get { return (int)base[ConfigurationStrings.ReplayCacheSize]; } |
| | 0 | 41 | | set { base[ConfigurationStrings.ReplayCacheSize] = value; } |
| | | 42 | | } |
| | | 43 | | |
| | | 44 | | [ConfigurationProperty(ConfigurationStrings.MaxClockSkew, DefaultValue = SecurityBindingDefaults.DefaultMaxClock |
| | | 45 | | [TypeConverter(typeof(TimeSpanOrInfiniteConverter))] |
| | | 46 | | public TimeSpan MaxClockSkew |
| | | 47 | | { |
| | 1 | 48 | | get { return (TimeSpan)base[ConfigurationStrings.MaxClockSkew]; } |
| | 0 | 49 | | set { base[ConfigurationStrings.MaxClockSkew] = value; } |
| | | 50 | | } |
| | | 51 | | |
| | | 52 | | [ConfigurationProperty(ConfigurationStrings.NegotiationTimeout, DefaultValue = SecurityBindingDefaults.DefaultSe |
| | | 53 | | [TypeConverter(typeof(TimeSpanOrInfiniteConverter))] |
| | | 54 | | public TimeSpan NegotiationTimeout |
| | | 55 | | { |
| | 1 | 56 | | get { return (TimeSpan)base[ConfigurationStrings.NegotiationTimeout]; } |
| | 0 | 57 | | set { base[ConfigurationStrings.NegotiationTimeout] = value; } |
| | | 58 | | } |
| | | 59 | | |
| | | 60 | | [ConfigurationProperty(ConfigurationStrings.ReplayWindow, DefaultValue = SecurityBindingDefaults.DefaultReplayWi |
| | | 61 | | [TypeConverter(typeof(TimeSpanOrInfiniteConverter))] |
| | | 62 | | public TimeSpan ReplayWindow |
| | | 63 | | { |
| | 1 | 64 | | get { return (TimeSpan)base[ConfigurationStrings.ReplayWindow]; } |
| | 0 | 65 | | set { base[ConfigurationStrings.ReplayWindow] = value; } |
| | | 66 | | } |
| | | 67 | | |
| | | 68 | | [ConfigurationProperty(ConfigurationStrings.InactivityTimeout, DefaultValue = SecurityBindingDefaults.DefaultIna |
| | | 69 | | [TypeConverter(typeof(TimeSpanOrInfiniteConverter))] |
| | | 70 | | public TimeSpan InactivityTimeout |
| | | 71 | | { |
| | 1 | 72 | | get { return (TimeSpan)base[ConfigurationStrings.InactivityTimeout]; } |
| | 0 | 73 | | set { base[ConfigurationStrings.InactivityTimeout] = value; } |
| | | 74 | | } |
| | | 75 | | |
| | | 76 | | [ConfigurationProperty(ConfigurationStrings.SessionKeyRenewalInterval, DefaultValue = SecurityBindingDefaults.De |
| | | 77 | | [TypeConverter(typeof(TimeSpanOrInfiniteConverter))] |
| | | 78 | | public TimeSpan SessionKeyRenewalInterval |
| | | 79 | | { |
| | 1 | 80 | | get { return (TimeSpan)base[ConfigurationStrings.SessionKeyRenewalInterval]; } |
| | 0 | 81 | | set { base[ConfigurationStrings.SessionKeyRenewalInterval] = value; } |
| | | 82 | | } |
| | | 83 | | |
| | | 84 | | [ConfigurationProperty(ConfigurationStrings.SessionKeyRolloverInterval, DefaultValue = SecurityBindingDefaults.D |
| | | 85 | | [TypeConverter(typeof(TimeSpanOrInfiniteConverter))] |
| | | 86 | | public TimeSpan SessionKeyRolloverInterval |
| | | 87 | | { |
| | 1 | 88 | | get { return (TimeSpan)base[ConfigurationStrings.SessionKeyRolloverInterval]; } |
| | 0 | 89 | | set { base[ConfigurationStrings.SessionKeyRolloverInterval] = value; } |
| | | 90 | | } |
| | | 91 | | |
| | | 92 | | [ConfigurationProperty(ConfigurationStrings.ReconnectTransportOnFailure, DefaultValue = SecurityBindingDefaults. |
| | | 93 | | public bool ReconnectTransportOnFailure |
| | | 94 | | { |
| | 1 | 95 | | get { return (bool)base[ConfigurationStrings.ReconnectTransportOnFailure]; } |
| | 0 | 96 | | set { base[ConfigurationStrings.ReconnectTransportOnFailure] = value; } |
| | | 97 | | } |
| | | 98 | | |
| | | 99 | | [ConfigurationProperty(ConfigurationStrings.MaxPendingSessions, DefaultValue = SecurityBindingDefaults.DefaultMa |
| | | 100 | | [IntegerValidator(MinValue = 1)] |
| | | 101 | | public int MaxPendingSessions |
| | | 102 | | { |
| | 1 | 103 | | get { return (int)base[ConfigurationStrings.MaxPendingSessions]; } |
| | 0 | 104 | | set { base[ConfigurationStrings.MaxPendingSessions] = value; } |
| | | 105 | | } |
| | | 106 | | |
| | | 107 | | [ConfigurationProperty(ConfigurationStrings.MaxCachedCookies, DefaultValue = SecurityBindingDefaults.DefaultServ |
| | | 108 | | [IntegerValidator(MinValue = 0)] |
| | | 109 | | public int MaxCachedCookies |
| | | 110 | | { |
| | 1 | 111 | | get { return (int)base[ConfigurationStrings.MaxCachedCookies]; } |
| | 0 | 112 | | set { base[ConfigurationStrings.MaxCachedCookies] = value; } |
| | | 113 | | } |
| | | 114 | | |
| | | 115 | | [ConfigurationProperty(ConfigurationStrings.TimestampValidityDuration, DefaultValue = SecurityBindingDefaults.De |
| | | 116 | | [TypeConverter(typeof(TimeSpanOrInfiniteConverter))] |
| | | 117 | | public TimeSpan TimestampValidityDuration |
| | | 118 | | { |
| | 1 | 119 | | get { return (TimeSpan)base[ConfigurationStrings.TimestampValidityDuration]; } |
| | 0 | 120 | | set { base[ConfigurationStrings.TimestampValidityDuration] = value; } |
| | | 121 | | } |
| | | 122 | | |
| | | 123 | | internal void ApplyConfiguration(LocalServiceSecuritySettings settings) |
| | | 124 | | { |
| | 1 | 125 | | if (settings == null) |
| | | 126 | | { |
| | 0 | 127 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(settings)); |
| | | 128 | | } |
| | 1 | 129 | | if (PropertyValueOrigin.Default != ElementInformation.Properties[ConfigurationStrings.DetectReplays].ValueOr |
| | 1 | 130 | | settings.DetectReplays = DetectReplays; |
| | 1 | 131 | | settings.IssuedCookieLifetime = IssuedCookieLifetime; |
| | 1 | 132 | | settings.MaxClockSkew = MaxClockSkew; |
| | 1 | 133 | | settings.MaxPendingSessions = MaxPendingSessions; |
| | 1 | 134 | | settings.MaxStatefulNegotiations = MaxStatefulNegotiations; |
| | 1 | 135 | | settings.NegotiationTimeout = NegotiationTimeout; |
| | 1 | 136 | | settings.ReconnectTransportOnFailure = ReconnectTransportOnFailure; |
| | 1 | 137 | | settings.ReplayCacheSize = ReplayCacheSize; |
| | 1 | 138 | | settings.ReplayWindow = ReplayWindow; |
| | 1 | 139 | | settings.SessionKeyRenewalInterval = SessionKeyRenewalInterval; |
| | 1 | 140 | | settings.SessionKeyRolloverInterval = SessionKeyRolloverInterval; |
| | 1 | 141 | | settings.InactivityTimeout = InactivityTimeout; |
| | 1 | 142 | | settings.TimestampValidityDuration = TimestampValidityDuration; |
| | 1 | 143 | | settings.MaxCachedCookies = MaxCachedCookies; |
| | 1 | 144 | | } |
| | | 145 | | |
| | | 146 | | internal void InitializeFrom(LocalServiceSecuritySettings settings) |
| | | 147 | | { |
| | 0 | 148 | | if (settings == null) |
| | | 149 | | { |
| | 0 | 150 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(settings)); |
| | | 151 | | } |
| | 0 | 152 | | DetectReplays = settings.DetectReplays; // can't use default value optimization here because runtime default |
| | 0 | 153 | | SetPropertyValueIfNotDefaultValue(ConfigurationStrings.IssuedCookieLifetime, settings.IssuedCookieLifetime); |
| | 0 | 154 | | SetPropertyValueIfNotDefaultValue(ConfigurationStrings.MaxClockSkew, settings.MaxClockSkew); |
| | 0 | 155 | | SetPropertyValueIfNotDefaultValue(ConfigurationStrings.MaxPendingSessions, settings.MaxPendingSessions); |
| | 0 | 156 | | SetPropertyValueIfNotDefaultValue(ConfigurationStrings.MaxStatefulNegotiations, settings.MaxStatefulNegotiat |
| | 0 | 157 | | SetPropertyValueIfNotDefaultValue(ConfigurationStrings.NegotiationTimeout, settings.NegotiationTimeout); |
| | 0 | 158 | | SetPropertyValueIfNotDefaultValue(ConfigurationStrings.ReconnectTransportOnFailure, settings.ReconnectTransp |
| | 0 | 159 | | SetPropertyValueIfNotDefaultValue(ConfigurationStrings.ReplayCacheSize, settings.ReplayCacheSize); |
| | 0 | 160 | | SetPropertyValueIfNotDefaultValue(ConfigurationStrings.ReplayWindow, settings.ReplayWindow); |
| | 0 | 161 | | SetPropertyValueIfNotDefaultValue(ConfigurationStrings.SessionKeyRenewalInterval, settings.SessionKeyRenewal |
| | 0 | 162 | | SetPropertyValueIfNotDefaultValue(ConfigurationStrings.SessionKeyRolloverInterval, settings.SessionKeyRollov |
| | 0 | 163 | | SetPropertyValueIfNotDefaultValue(ConfigurationStrings.InactivityTimeout, settings.InactivityTimeout); |
| | 0 | 164 | | SetPropertyValueIfNotDefaultValue(ConfigurationStrings.TimestampValidityDuration, settings.TimestampValidity |
| | 0 | 165 | | SetPropertyValueIfNotDefaultValue(ConfigurationStrings.MaxCachedCookies, settings.MaxCachedCookies); |
| | 0 | 166 | | } |
| | | 167 | | |
| | | 168 | | internal void CopyFrom(LocalServiceSecuritySettingsElement source) |
| | | 169 | | { |
| | 0 | 170 | | if (source == null) |
| | | 171 | | { |
| | 0 | 172 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(source)); |
| | | 173 | | } |
| | 0 | 174 | | if (PropertyValueOrigin.Default != source.ElementInformation.Properties[ConfigurationStrings.DetectReplays]. |
| | 0 | 175 | | DetectReplays = source.DetectReplays; |
| | 0 | 176 | | IssuedCookieLifetime = source.IssuedCookieLifetime; |
| | 0 | 177 | | MaxClockSkew = source.MaxClockSkew; |
| | 0 | 178 | | MaxPendingSessions = source.MaxPendingSessions; |
| | 0 | 179 | | MaxStatefulNegotiations = source.MaxStatefulNegotiations; |
| | 0 | 180 | | NegotiationTimeout = source.NegotiationTimeout; |
| | 0 | 181 | | ReconnectTransportOnFailure = source.ReconnectTransportOnFailure; |
| | 0 | 182 | | ReplayCacheSize = source.ReplayCacheSize; |
| | 0 | 183 | | ReplayWindow = source.ReplayWindow; |
| | 0 | 184 | | SessionKeyRenewalInterval = source.SessionKeyRenewalInterval; |
| | 0 | 185 | | SessionKeyRolloverInterval = source.SessionKeyRolloverInterval; |
| | 0 | 186 | | InactivityTimeout = source.InactivityTimeout; |
| | 0 | 187 | | TimestampValidityDuration = source.TimestampValidityDuration; |
| | 0 | 188 | | MaxCachedCookies = source.MaxCachedCookies; |
| | 0 | 189 | | } |
| | | 190 | | } |
| | | 191 | | } |