summaryrefslogtreecommitdiffstats
path: root/src/DotNetOpenAuth.OAuth/Configuration
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2012-01-29 14:32:45 -0800
committerAndrew Arnott <andrewarnott@gmail.com>2012-01-29 14:32:45 -0800
commit5fec515095ee10b522f414a03e78f282aaf520dc (patch)
tree204c75486639c23cdda2ef38b34d7e5050a1a2e3 /src/DotNetOpenAuth.OAuth/Configuration
parentf1a4155398635a4fd9f485eec817152627682704 (diff)
parent8f4165ee515728aca3faaa26e8354a40612e85e4 (diff)
downloadDotNetOpenAuth-5fec515095ee10b522f414a03e78f282aaf520dc.zip
DotNetOpenAuth-5fec515095ee10b522f414a03e78f282aaf520dc.tar.gz
DotNetOpenAuth-5fec515095ee10b522f414a03e78f282aaf520dc.tar.bz2
Merge branch 'splitDlls'.
DNOA now builds and (in some cases) ships as many distinct assemblies.
Diffstat (limited to 'src/DotNetOpenAuth.OAuth/Configuration')
-rw-r--r--src/DotNetOpenAuth.OAuth/Configuration/OAuthConsumerElement.cs34
-rw-r--r--src/DotNetOpenAuth.OAuth/Configuration/OAuthConsumerSecuritySettingsElement.cs35
-rw-r--r--src/DotNetOpenAuth.OAuth/Configuration/OAuthElement.cs64
-rw-r--r--src/DotNetOpenAuth.OAuth/Configuration/OAuthServiceProviderElement.cs49
-rw-r--r--src/DotNetOpenAuth.OAuth/Configuration/OAuthServiceProviderSecuritySettingsElement.cs75
5 files changed, 257 insertions, 0 deletions
diff --git a/src/DotNetOpenAuth.OAuth/Configuration/OAuthConsumerElement.cs b/src/DotNetOpenAuth.OAuth/Configuration/OAuthConsumerElement.cs
new file mode 100644
index 0000000..b15c3e3
--- /dev/null
+++ b/src/DotNetOpenAuth.OAuth/Configuration/OAuthConsumerElement.cs
@@ -0,0 +1,34 @@
+//-----------------------------------------------------------------------
+// <copyright file="OAuthConsumerElement.cs" company="Andrew Arnott">
+// Copyright (c) Andrew Arnott. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace DotNetOpenAuth.Configuration {
+ using System.Configuration;
+
+ /// <summary>
+ /// Represents the &lt;oauth/consumer&gt; element in the host's .config file.
+ /// </summary>
+ internal class OAuthConsumerElement : ConfigurationElement {
+ /// <summary>
+ /// Gets the name of the security sub-element.
+ /// </summary>
+ private const string SecuritySettingsConfigName = "security";
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="OAuthConsumerElement"/> class.
+ /// </summary>
+ internal OAuthConsumerElement() {
+ }
+
+ /// <summary>
+ /// Gets or sets the security settings.
+ /// </summary>
+ [ConfigurationProperty(SecuritySettingsConfigName)]
+ public OAuthConsumerSecuritySettingsElement SecuritySettings {
+ get { return (OAuthConsumerSecuritySettingsElement)this[SecuritySettingsConfigName] ?? new OAuthConsumerSecuritySettingsElement(); }
+ set { this[SecuritySettingsConfigName] = value; }
+ }
+ }
+}
diff --git a/src/DotNetOpenAuth.OAuth/Configuration/OAuthConsumerSecuritySettingsElement.cs b/src/DotNetOpenAuth.OAuth/Configuration/OAuthConsumerSecuritySettingsElement.cs
new file mode 100644
index 0000000..38a183a
--- /dev/null
+++ b/src/DotNetOpenAuth.OAuth/Configuration/OAuthConsumerSecuritySettingsElement.cs
@@ -0,0 +1,35 @@
+//-----------------------------------------------------------------------
+// <copyright file="OAuthConsumerSecuritySettingsElement.cs" company="Andrew Arnott">
+// Copyright (c) Andrew Arnott. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace DotNetOpenAuth.Configuration {
+ using System;
+ using System.Collections.Generic;
+ using System.Configuration;
+ using System.Diagnostics.CodeAnalysis;
+ using System.Linq;
+ using System.Text;
+ using DotNetOpenAuth.OAuth;
+
+ /// <summary>
+ /// Security settings that are applicable to consumers.
+ /// </summary>
+ internal class OAuthConsumerSecuritySettingsElement : ConfigurationElement {
+ /// <summary>
+ /// Initializes a new instance of the <see cref="OAuthConsumerSecuritySettingsElement"/> class.
+ /// </summary>
+ internal OAuthConsumerSecuritySettingsElement() {
+ }
+
+ /// <summary>
+ /// Initializes a programmatically manipulatable bag of these security settings with the settings from the config file.
+ /// </summary>
+ /// <returns>The newly created security settings object.</returns>
+ [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Justification = "By design")]
+ internal ConsumerSecuritySettings CreateSecuritySettings() {
+ return new ConsumerSecuritySettings();
+ }
+ }
+}
diff --git a/src/DotNetOpenAuth.OAuth/Configuration/OAuthElement.cs b/src/DotNetOpenAuth.OAuth/Configuration/OAuthElement.cs
new file mode 100644
index 0000000..59c5851
--- /dev/null
+++ b/src/DotNetOpenAuth.OAuth/Configuration/OAuthElement.cs
@@ -0,0 +1,64 @@
+//-----------------------------------------------------------------------
+// <copyright file="OAuthElement.cs" company="Andrew Arnott">
+// Copyright (c) Andrew Arnott. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace DotNetOpenAuth.Configuration {
+ using System.Configuration;
+ using System.Diagnostics.Contracts;
+
+ /// <summary>
+ /// Represents the &lt;oauth&gt; element in the host's .config file.
+ /// </summary>
+ internal class OAuthElement : ConfigurationSection {
+ /// <summary>
+ /// The name of the oauth section.
+ /// </summary>
+ private const string SectionName = DotNetOpenAuthSection.SectionName + "/oauth";
+
+ /// <summary>
+ /// The name of the &lt;consumer&gt; sub-element.
+ /// </summary>
+ private const string ConsumerElementName = "consumer";
+
+ /// <summary>
+ /// The name of the &lt;serviceProvider&gt; sub-element.
+ /// </summary>
+ private const string ServiceProviderElementName = "serviceProvider";
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="OAuthElement"/> class.
+ /// </summary>
+ internal OAuthElement() {
+ }
+
+ /// <summary>
+ /// Gets the configuration section from the .config file.
+ /// </summary>
+ public static OAuthElement Configuration {
+ get {
+ Contract.Ensures(Contract.Result<OAuthElement>() != null);
+ return (OAuthElement)ConfigurationManager.GetSection(SectionName) ?? new OAuthElement();
+ }
+ }
+
+ /// <summary>
+ /// Gets or sets the configuration specific for Consumers.
+ /// </summary>
+ [ConfigurationProperty(ConsumerElementName)]
+ internal OAuthConsumerElement Consumer {
+ get { return (OAuthConsumerElement)this[ConsumerElementName] ?? new OAuthConsumerElement(); }
+ set { this[ConsumerElementName] = value; }
+ }
+
+ /// <summary>
+ /// Gets or sets the configuration specific for Service Providers.
+ /// </summary>
+ [ConfigurationProperty(ServiceProviderElementName)]
+ internal OAuthServiceProviderElement ServiceProvider {
+ get { return (OAuthServiceProviderElement)this[ServiceProviderElementName] ?? new OAuthServiceProviderElement(); }
+ set { this[ServiceProviderElementName] = value; }
+ }
+ }
+}
diff --git a/src/DotNetOpenAuth.OAuth/Configuration/OAuthServiceProviderElement.cs b/src/DotNetOpenAuth.OAuth/Configuration/OAuthServiceProviderElement.cs
new file mode 100644
index 0000000..8e910a0
--- /dev/null
+++ b/src/DotNetOpenAuth.OAuth/Configuration/OAuthServiceProviderElement.cs
@@ -0,0 +1,49 @@
+//-----------------------------------------------------------------------
+// <copyright file="OAuthServiceProviderElement.cs" company="Andrew Arnott">
+// Copyright (c) Andrew Arnott. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace DotNetOpenAuth.Configuration {
+ using System.Configuration;
+ using DotNetOpenAuth.Messaging.Bindings;
+
+ /// <summary>
+ /// Represents the &lt;oauth/serviceProvider&gt; element in the host's .config file.
+ /// </summary>
+ internal class OAuthServiceProviderElement : ConfigurationElement {
+ /// <summary>
+ /// The name of the custom store sub-element.
+ /// </summary>
+ private const string StoreConfigName = "store";
+
+ /// <summary>
+ /// Gets the name of the security sub-element.
+ /// </summary>
+ private const string SecuritySettingsConfigName = "security";
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="OAuthServiceProviderElement"/> class.
+ /// </summary>
+ internal OAuthServiceProviderElement() {
+ }
+
+ /// <summary>
+ /// Gets or sets the type to use for storing application state.
+ /// </summary>
+ [ConfigurationProperty(StoreConfigName)]
+ public TypeConfigurationElement<INonceStore> ApplicationStore {
+ get { return (TypeConfigurationElement<INonceStore>)this[StoreConfigName] ?? new TypeConfigurationElement<INonceStore>(); }
+ set { this[StoreConfigName] = value; }
+ }
+
+ /// <summary>
+ /// Gets or sets the security settings.
+ /// </summary>
+ [ConfigurationProperty(SecuritySettingsConfigName)]
+ public OAuthServiceProviderSecuritySettingsElement SecuritySettings {
+ get { return (OAuthServiceProviderSecuritySettingsElement)this[SecuritySettingsConfigName] ?? new OAuthServiceProviderSecuritySettingsElement(); }
+ set { this[SecuritySettingsConfigName] = value; }
+ }
+ }
+}
diff --git a/src/DotNetOpenAuth.OAuth/Configuration/OAuthServiceProviderSecuritySettingsElement.cs b/src/DotNetOpenAuth.OAuth/Configuration/OAuthServiceProviderSecuritySettingsElement.cs
new file mode 100644
index 0000000..723b607
--- /dev/null
+++ b/src/DotNetOpenAuth.OAuth/Configuration/OAuthServiceProviderSecuritySettingsElement.cs
@@ -0,0 +1,75 @@
+//-----------------------------------------------------------------------
+// <copyright file="OAuthServiceProviderSecuritySettingsElement.cs" company="Andrew Arnott">
+// Copyright (c) Andrew Arnott. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace DotNetOpenAuth.Configuration {
+ using System;
+ using System.Collections.Generic;
+ using System.Configuration;
+ using System.Linq;
+ using System.Text;
+ using DotNetOpenAuth.OAuth;
+
+ /// <summary>
+ /// Security settings that are applicable to service providers.
+ /// </summary>
+ internal class OAuthServiceProviderSecuritySettingsElement : ConfigurationElement {
+ /// <summary>
+ /// Gets the name of the @minimumRequiredOAuthVersion attribute.
+ /// </summary>
+ private const string MinimumRequiredOAuthVersionConfigName = "minimumRequiredOAuthVersion";
+
+ /// <summary>
+ /// Gets the name of the @maxAuthorizationTime attribute.
+ /// </summary>
+ private const string MaximumRequestTokenTimeToLiveConfigName = "maxAuthorizationTime";
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="OAuthServiceProviderSecuritySettingsElement"/> class.
+ /// </summary>
+ internal OAuthServiceProviderSecuritySettingsElement() {
+ }
+
+ /// <summary>
+ /// Gets or sets the minimum OAuth version a Consumer is required to support in order for this library to interoperate with it.
+ /// </summary>
+ /// <remarks>
+ /// Although the earliest versions of OAuth are supported, for security reasons it may be desirable to require the
+ /// remote party to support a later version of OAuth.
+ /// </remarks>
+ [ConfigurationProperty(MinimumRequiredOAuthVersionConfigName, DefaultValue = "V10")]
+ public ProtocolVersion MinimumRequiredOAuthVersion {
+ get { return (ProtocolVersion)this[MinimumRequiredOAuthVersionConfigName]; }
+ set { this[MinimumRequiredOAuthVersionConfigName] = value; }
+ }
+
+ /// <summary>
+ /// Gets or sets the maximum time a user can take to complete authorization.
+ /// </summary>
+ /// <remarks>
+ /// This time limit serves as a security mitigation against brute force attacks to
+ /// compromise (unauthorized or authorized) request tokens.
+ /// Longer time limits is more friendly to slow users or consumers, while shorter
+ /// time limits provide better security.
+ /// </remarks>
+ [ConfigurationProperty(MaximumRequestTokenTimeToLiveConfigName, DefaultValue = "0:05")] // 5 minutes
+ [PositiveTimeSpanValidator]
+ public TimeSpan MaximumRequestTokenTimeToLive {
+ get { return (TimeSpan)this[MaximumRequestTokenTimeToLiveConfigName]; }
+ set { this[MaximumRequestTokenTimeToLiveConfigName] = value; }
+ }
+
+ /// <summary>
+ /// Initializes a programmatically manipulatable bag of these security settings with the settings from the config file.
+ /// </summary>
+ /// <returns>The newly created security settings object.</returns>
+ internal ServiceProviderSecuritySettings CreateSecuritySettings() {
+ return new ServiceProviderSecuritySettings {
+ MinimumRequiredOAuthVersion = this.MinimumRequiredOAuthVersion,
+ MaximumRequestTokenTimeToLive = this.MaximumRequestTokenTimeToLive,
+ };
+ }
+ }
+}