diff options
Diffstat (limited to 'src/DotNetOpenAuth.Messaging')
10 files changed, 66 insertions, 62 deletions
diff --git a/src/DotNetOpenAuth.Messaging/Configuration/DotNetOpenAuthSection.cs b/src/DotNetOpenAuth.Messaging/Configuration/DotNetOpenAuthSection.cs index d41460b..5e2a494 100644 --- a/src/DotNetOpenAuth.Messaging/Configuration/DotNetOpenAuthSection.cs +++ b/src/DotNetOpenAuth.Messaging/Configuration/DotNetOpenAuthSection.cs @@ -13,16 +13,11 @@ namespace DotNetOpenAuth.Configuration { /// this library's settings. /// </summary> [ContractVerification(true)] - public class DotNetOpenAuthSection : ConfigurationSection { + public class DotNetOpenAuthSection : ConfigurationSectionGroup { /// <summary> /// The name of the section under which this library's settings must be found. /// </summary> - private const string SectionName = "dotNetOpenAuth"; - - /// <summary> - /// The name of the <messaging> sub-element. - /// </summary> - private const string MessagingElementName = "messaging"; + internal const string SectionName = "dotNetOpenAuth"; /// <summary> /// The name of the <openid> sub-element. @@ -35,21 +30,9 @@ namespace DotNetOpenAuth.Configuration { private const string OAuthElementName = "oauth"; /// <summary> - /// The name of the <reporting> sub-element. - /// </summary> - private const string ReportingElementName = "reporting"; - - /// <summary> - /// The name of the <webResourceUrlProvider> sub-element. - /// </summary> - private const string WebResourceUrlProviderName = "webResourceUrlProvider"; - - /// <summary> /// Initializes a new instance of the <see cref="DotNetOpenAuthSection"/> class. /// </summary> internal DotNetOpenAuthSection() { - Contract.Assume(this.SectionInformation != null); - this.SectionInformation.AllowLocation = false; } /// <summary> @@ -62,43 +45,17 @@ namespace DotNetOpenAuth.Configuration { } } - /// <summary> - /// Gets or sets the configuration for the messaging framework. - /// </summary> - [ConfigurationProperty(MessagingElementName)] - public MessagingElement Messaging { - get { - Contract.Ensures(Contract.Result<MessagingElement>() != null); - return (MessagingElement)this[MessagingElementName] ?? new MessagingElement(); - } - - set { - this[MessagingElementName] = value; - } + public static MessagingElement Messaging { + get { return MessagingElement.Configuration; } } - /// <summary> - /// Gets or sets the configuration for reporting. - /// </summary> - [ConfigurationProperty(ReportingElementName)] - internal ReportingElement Reporting { - get { - Contract.Ensures(Contract.Result<ReportingElement>() != null); - return (ReportingElement)this[ReportingElementName] ?? new ReportingElement(); - } - - set { - this[ReportingElementName] = value; - } + internal TypeConfigurationElement<IEmbeddedResourceRetrieval> EmbeddedResourceRetrievalProvider { + get { return /*(TypeConfigurationElement<IEmbeddedResourceRetrieval>)this[WebResourceUrlProviderName] ??*/ new TypeConfigurationElement<IEmbeddedResourceRetrieval>(); } + set { /*this[WebResourceUrlProviderName] = value;*/ } } - /// <summary> - /// Gets or sets the type to use for obtaining URLs that fetch embedded resource streams. - /// </summary> - [ConfigurationProperty(WebResourceUrlProviderName)] - internal TypeConfigurationElement<IEmbeddedResourceRetrieval> EmbeddedResourceRetrievalProvider { - get { return (TypeConfigurationElement<IEmbeddedResourceRetrieval>)this[WebResourceUrlProviderName] ?? new TypeConfigurationElement<IEmbeddedResourceRetrieval>(); } - set { this[WebResourceUrlProviderName] = value; } + internal static ReportingElement Reporting { + get { return ReportingElement.Configuration; } } } } diff --git a/src/DotNetOpenAuth.Messaging/Configuration/MessagingElement.cs b/src/DotNetOpenAuth.Messaging/Configuration/MessagingElement.cs index 1c46bcf..cec2552 100644 --- a/src/DotNetOpenAuth.Messaging/Configuration/MessagingElement.cs +++ b/src/DotNetOpenAuth.Messaging/Configuration/MessagingElement.cs @@ -15,7 +15,7 @@ namespace DotNetOpenAuth.Configuration { /// Represents the <messaging> element in the host's .config file. /// </summary> [ContractVerification(true)] - public class MessagingElement : ConfigurationElement { + public class MessagingElement : ConfigurationSection { /// <summary> /// The name of the <untrustedWebRequest> sub-element. /// </summary> @@ -61,6 +61,21 @@ namespace DotNetOpenAuth.Configuration { private const string PrivateSecretMaximumAgeConfigName = "privateSecretMaximumAge"; /// <summary> + /// The name of the <messaging> sub-element. + /// </summary> + private const string MessagingElementName = DotNetOpenAuthSection.SectionName + "/messaging"; + + /// <summary> + /// Gets the configuration section from the .config file. + /// </summary> + public static MessagingElement Configuration { + get { + Contract.Ensures(Contract.Result<MessagingElement>() != null); + return (MessagingElement)ConfigurationManager.GetSection(MessagingElementName) ?? new MessagingElement(); + } + } + + /// <summary> /// Gets the actual maximum message lifetime that a program should allow. /// </summary> /// <value>The sum of the <see cref="MaximumMessageLifetime"/> and diff --git a/src/DotNetOpenAuth.Messaging/Configuration/ReportingElement.cs b/src/DotNetOpenAuth.Messaging/Configuration/ReportingElement.cs index 2374448..3cd0af1 100644 --- a/src/DotNetOpenAuth.Messaging/Configuration/ReportingElement.cs +++ b/src/DotNetOpenAuth.Messaging/Configuration/ReportingElement.cs @@ -10,11 +10,12 @@ namespace DotNetOpenAuth.Configuration { using System.Configuration; using System.Linq; using System.Text; + using System.Diagnostics.Contracts; /// <summary> /// Represents the <reporting> element in the host's .config file. /// </summary> - internal class ReportingElement : ConfigurationElement { + internal class ReportingElement : ConfigurationSection { /// <summary> /// The name of the @enabled attribute. /// </summary> @@ -51,6 +52,11 @@ namespace DotNetOpenAuth.Configuration { private const string IncludeCulturesAttributeName = "includeCultures"; /// <summary> + /// The name of the <reporting> sub-element. + /// </summary> + private const string ReportingElementName = DotNetOpenAuthSection.SectionName + "/reporting"; + + /// <summary> /// The default value for the @minimumFlushInterval attribute. /// </summary> #if DEBUG @@ -66,6 +72,16 @@ namespace DotNetOpenAuth.Configuration { } /// <summary> + /// Gets the configuration section from the .config file. + /// </summary> + public static ReportingElement Configuration { + get { + Contract.Ensures(Contract.Result<ReportingElement>() != null); + return (ReportingElement)ConfigurationManager.GetSection(ReportingElementName) ?? new ReportingElement(); + } + } + + /// <summary> /// Gets or sets a value indicating whether this reporting is enabled. /// </summary> /// <value><c>true</c> if enabled; otherwise, <c>false</c>.</value> diff --git a/src/DotNetOpenAuth.Messaging/Configuration/UntrustedWebRequestElement.cs b/src/DotNetOpenAuth.Messaging/Configuration/UntrustedWebRequestElement.cs index 89cd435..40a3d0c 100644 --- a/src/DotNetOpenAuth.Messaging/Configuration/UntrustedWebRequestElement.cs +++ b/src/DotNetOpenAuth.Messaging/Configuration/UntrustedWebRequestElement.cs @@ -7,12 +7,18 @@ namespace DotNetOpenAuth.Configuration { using System; using System.Configuration; + using System.Diagnostics.Contracts; /// <summary> /// Represents the section of a .config file where security policies regarding web requests /// to user-provided, untrusted servers is controlled. /// </summary> internal class UntrustedWebRequestElement : ConfigurationElement { + /// <summary> + /// The name of the <webResourceUrlProvider> sub-element. + /// </summary> + private const string WebResourceUrlProviderName = "webResourceUrlProvider"; + #region Attribute names /// <summary> @@ -58,6 +64,16 @@ namespace DotNetOpenAuth.Configuration { #endregion /// <summary> + /// Gets the configuration section from the .config file. + /// </summary> + public static UntrustedWebRequestElement Configuration { + get { + Contract.Ensures(Contract.Result<UntrustedWebRequestElement>() != null); + return (UntrustedWebRequestElement)ConfigurationManager.GetSection(WebResourceUrlProviderName) ?? new UntrustedWebRequestElement(); + } + } + + /// <summary> /// Gets or sets the read/write timeout after which an HTTP request will fail. /// </summary> [ConfigurationProperty(ReadWriteTimeoutConfigName, DefaultValue = "00:00:01.500")] diff --git a/src/DotNetOpenAuth.Messaging/Messaging/Bindings/StandardExpirationBindingElement.cs b/src/DotNetOpenAuth.Messaging/Messaging/Bindings/StandardExpirationBindingElement.cs index 4396c16..f8c8c6a 100644 --- a/src/DotNetOpenAuth.Messaging/Messaging/Bindings/StandardExpirationBindingElement.cs +++ b/src/DotNetOpenAuth.Messaging/Messaging/Bindings/StandardExpirationBindingElement.cs @@ -42,7 +42,7 @@ namespace DotNetOpenAuth.Messaging.Bindings { /// being discarded as too old. /// </summary> protected internal static TimeSpan MaximumMessageAge { - get { return Configuration.DotNetOpenAuthSection.Configuration.Messaging.MaximumMessageLifetime; } + get { return Configuration.DotNetOpenAuthSection.Messaging.MaximumMessageLifetime; } } #region IChannelBindingElement Methods @@ -92,7 +92,7 @@ namespace DotNetOpenAuth.Messaging.Bindings { // Mitigate HMAC attacks (just guessing the signature until they get it) by // disallowing post-dated messages. ErrorUtilities.VerifyProtocol( - creationDate <= DateTime.UtcNow + DotNetOpenAuthSection.Configuration.Messaging.MaximumClockSkew, + creationDate <= DateTime.UtcNow + DotNetOpenAuthSection.Messaging.MaximumClockSkew, MessagingStrings.MessageTimestampInFuture, creationDate); diff --git a/src/DotNetOpenAuth.Messaging/Messaging/Channel.cs b/src/DotNetOpenAuth.Messaging/Messaging/Channel.cs index bff395b..cb32ca3 100644 --- a/src/DotNetOpenAuth.Messaging/Messaging/Channel.cs +++ b/src/DotNetOpenAuth.Messaging/Messaging/Channel.cs @@ -134,7 +134,7 @@ namespace DotNetOpenAuth.Messaging { /// <summary> /// Backing field for the <see cref="MaximumIndirectMessageUrlLength"/> property. /// </summary> - private int maximumIndirectMessageUrlLength = Configuration.DotNetOpenAuthSection.Configuration.Messaging.MaximumIndirectMessageUrlLength; + private int maximumIndirectMessageUrlLength = Configuration.DotNetOpenAuthSection.Messaging.MaximumIndirectMessageUrlLength; /// <summary> /// Initializes a new instance of the <see cref="Channel"/> class. diff --git a/src/DotNetOpenAuth.Messaging/Messaging/MessagingUtilities.cs b/src/DotNetOpenAuth.Messaging/Messaging/MessagingUtilities.cs index 8fc691f..e88f2a9 100644 --- a/src/DotNetOpenAuth.Messaging/Messaging/MessagingUtilities.cs +++ b/src/DotNetOpenAuth.Messaging/Messaging/MessagingUtilities.cs @@ -89,7 +89,7 @@ namespace DotNetOpenAuth.Messaging { /// <summary> /// The default lifetime of a private secret. /// </summary> - private static readonly TimeSpan SymmetricSecretKeyLifespan = Configuration.DotNetOpenAuthSection.Configuration.Messaging.PrivateSecretMaximumAge; + private static readonly TimeSpan SymmetricSecretKeyLifespan = Configuration.DotNetOpenAuthSection.Messaging.PrivateSecretMaximumAge; /// <summary> /// A character array containing just the = character. diff --git a/src/DotNetOpenAuth.Messaging/Messaging/Reflection/MessagePart.cs b/src/DotNetOpenAuth.Messaging/Messaging/Reflection/MessagePart.cs index bf92803..e0e48fe 100644 --- a/src/DotNetOpenAuth.Messaging/Messaging/Reflection/MessagePart.cs +++ b/src/DotNetOpenAuth.Messaging/Messaging/Reflection/MessagePart.cs @@ -233,7 +233,7 @@ namespace DotNetOpenAuth.Messaging.Reflection { try { if (this.IsConstantValue) { string constantValue = this.GetValue(message); - var caseSensitivity = DotNetOpenAuthSection.Configuration.Messaging.Strict ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase; + var caseSensitivity = DotNetOpenAuthSection.Messaging.Strict ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase; if (!string.Equals(constantValue, value, caseSensitivity)) { throw new ArgumentException(string.Format( CultureInfo.CurrentCulture, diff --git a/src/DotNetOpenAuth.Messaging/Messaging/UntrustedWebRequestHandler.cs b/src/DotNetOpenAuth.Messaging/Messaging/UntrustedWebRequestHandler.cs index 838b7e8..a1a34a5 100644 --- a/src/DotNetOpenAuth.Messaging/Messaging/UntrustedWebRequestHandler.cs +++ b/src/DotNetOpenAuth.Messaging/Messaging/UntrustedWebRequestHandler.cs @@ -174,7 +174,7 @@ namespace DotNetOpenAuth.Messaging { /// Gets the configuration for this class that is specified in the host's .config file. /// </summary> private static UntrustedWebRequestElement Configuration { - get { return DotNetOpenAuthSection.Configuration.Messaging.UntrustedWebRequest; } + get { return DotNetOpenAuthSection.Messaging.UntrustedWebRequest; } } #region IDirectWebRequestHandler Members diff --git a/src/DotNetOpenAuth.Messaging/Reporting.cs b/src/DotNetOpenAuth.Messaging/Reporting.cs index fcd35c7..c528972 100644 --- a/src/DotNetOpenAuth.Messaging/Reporting.cs +++ b/src/DotNetOpenAuth.Messaging/Reporting.cs @@ -115,7 +115,7 @@ namespace DotNetOpenAuth { [SuppressMessage("Microsoft.Performance", "CA1810:InitializeReferenceTypeStaticFieldsInline", Justification = "We do more than field initialization here.")] [SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "Reporting MUST NOT cause unhandled exceptions.")] static Reporting() { - Enabled = DotNetOpenAuthSection.Configuration.Reporting.Enabled; + Enabled = DotNetOpenAuthSection.Reporting.Enabled; } /// <summary> @@ -150,7 +150,7 @@ namespace DotNetOpenAuth { /// Gets the configuration to use for reporting. /// </summary> internal static ReportingElement Configuration { - get { return DotNetOpenAuthSection.Configuration.Reporting; } + get { return DotNetOpenAuthSection.Reporting; } } /// <summary> |