summaryrefslogtreecommitdiffstats
path: root/src/DotNetOpenId/Configuration
diff options
context:
space:
mode:
Diffstat (limited to 'src/DotNetOpenId/Configuration')
-rw-r--r--src/DotNetOpenId/Configuration/ProviderSection.cs27
-rw-r--r--src/DotNetOpenId/Configuration/ProviderSecuritySettingsElement.cs38
-rw-r--r--src/DotNetOpenId/Configuration/RelyingPartySection.cs27
-rw-r--r--src/DotNetOpenId/Configuration/RelyingPartySecuritySettingsElement.cs45
-rw-r--r--src/DotNetOpenId/Configuration/StoreElement.cs24
-rw-r--r--src/DotNetOpenId/Configuration/UntrustedWebRequestSection.cs78
-rw-r--r--src/DotNetOpenId/Configuration/WhiteBlackListCollection.cs33
-rw-r--r--src/DotNetOpenId/Configuration/WhiteBlackListElement.cs13
8 files changed, 285 insertions, 0 deletions
diff --git a/src/DotNetOpenId/Configuration/ProviderSection.cs b/src/DotNetOpenId/Configuration/ProviderSection.cs
new file mode 100644
index 0000000..cfd6052
--- /dev/null
+++ b/src/DotNetOpenId/Configuration/ProviderSection.cs
@@ -0,0 +1,27 @@
+using System.Configuration;
+using DotNetOpenId.Provider;
+using IProviderAssociationStore = DotNetOpenId.IAssociationStore<DotNetOpenId.AssociationRelyingPartyType>;
+
+namespace DotNetOpenId.Configuration {
+ internal class ProviderSection : ConfigurationSection {
+ internal static ProviderSection Configuration {
+ get { return (ProviderSection)ConfigurationManager.GetSection("dotNetOpenId/provider") ?? new ProviderSection(); }
+ }
+
+ public ProviderSection() { }
+
+ const string securitySettingsConfigName = "security";
+ [ConfigurationProperty(securitySettingsConfigName)]
+ public ProviderSecuritySettingsElement SecuritySettings {
+ get { return (ProviderSecuritySettingsElement)this[securitySettingsConfigName] ?? new ProviderSecuritySettingsElement(); }
+ set { this[securitySettingsConfigName] = value; }
+ }
+
+ const string storeConfigName = "store";
+ [ConfigurationProperty(storeConfigName)]
+ public StoreConfigurationElement<IProviderAssociationStore> Store {
+ get { return (StoreConfigurationElement<IProviderAssociationStore>)this[storeConfigName] ?? new StoreConfigurationElement<IProviderAssociationStore>(); }
+ set { this[storeConfigName] = value; }
+ }
+ }
+}
diff --git a/src/DotNetOpenId/Configuration/ProviderSecuritySettingsElement.cs b/src/DotNetOpenId/Configuration/ProviderSecuritySettingsElement.cs
new file mode 100644
index 0000000..8f3ffb8
--- /dev/null
+++ b/src/DotNetOpenId/Configuration/ProviderSecuritySettingsElement.cs
@@ -0,0 +1,38 @@
+using System.Configuration;
+using DotNetOpenId.Provider;
+
+namespace DotNetOpenId.Configuration {
+ internal class ProviderSecuritySettingsElement : ConfigurationElement {
+ public ProviderSecuritySettingsElement() {
+ }
+
+ public ProviderSecuritySettings CreateSecuritySettings() {
+ ProviderSecuritySettings settings = new ProviderSecuritySettings();
+ settings.MinimumHashBitLength = MinimumHashBitLength;
+ settings.MaximumHashBitLength = MaximumHashBitLength;
+ settings.ProtectDownlevelReplayAttacks = ProtectDownlevelReplayAttacks;
+ return settings;
+ }
+
+ const string minimumHashBitLengthConfigName = "minimumHashBitLength";
+ [ConfigurationProperty(minimumHashBitLengthConfigName, DefaultValue = DotNetOpenId.SecuritySettings.minimumHashBitLengthDefault)]
+ public int MinimumHashBitLength {
+ get { return (int)this[minimumHashBitLengthConfigName]; }
+ set { this[minimumHashBitLengthConfigName] = value; }
+ }
+
+ const string maximumHashBitLengthConfigName = "maximumHashBitLength";
+ [ConfigurationProperty(maximumHashBitLengthConfigName, DefaultValue = DotNetOpenId.SecuritySettings.maximumHashBitLengthRPDefault)]
+ public int MaximumHashBitLength {
+ get { return (int)this[maximumHashBitLengthConfigName]; }
+ set { this[maximumHashBitLengthConfigName] = value; }
+ }
+
+ const string protectDownlevelReplayAttacksConfigName = "protectDownlevelReplayAttacks";
+ [ConfigurationProperty(protectDownlevelReplayAttacksConfigName, DefaultValue = false)]
+ public bool ProtectDownlevelReplayAttacks {
+ get { return (bool)this[protectDownlevelReplayAttacksConfigName]; }
+ set { this[protectDownlevelReplayAttacksConfigName] = value; }
+ }
+ }
+}
diff --git a/src/DotNetOpenId/Configuration/RelyingPartySection.cs b/src/DotNetOpenId/Configuration/RelyingPartySection.cs
new file mode 100644
index 0000000..100641c
--- /dev/null
+++ b/src/DotNetOpenId/Configuration/RelyingPartySection.cs
@@ -0,0 +1,27 @@
+using System.Configuration;
+using DotNetOpenId.RelyingParty;
+
+namespace DotNetOpenId.Configuration {
+ internal class RelyingPartySection : ConfigurationSection {
+ internal static RelyingPartySection Configuration {
+ get { return (RelyingPartySection)ConfigurationManager.GetSection("dotNetOpenId/relyingParty") ?? new RelyingPartySection(); }
+ }
+
+ public RelyingPartySection() {
+ }
+
+ const string securitySettingsConfigName = "security";
+ [ConfigurationProperty(securitySettingsConfigName)]
+ public RelyingPartySecuritySettingsElement SecuritySettings {
+ get { return (RelyingPartySecuritySettingsElement)this[securitySettingsConfigName] ?? new RelyingPartySecuritySettingsElement(); }
+ set { this[securitySettingsConfigName] = value; }
+ }
+
+ const string storeConfigName = "store";
+ [ConfigurationProperty(storeConfigName)]
+ public StoreConfigurationElement<IRelyingPartyApplicationStore> Store {
+ get { return (StoreConfigurationElement<IRelyingPartyApplicationStore>)this[storeConfigName] ?? new StoreConfigurationElement<IRelyingPartyApplicationStore>(); }
+ set { this[storeConfigName] = value; }
+ }
+ }
+}
diff --git a/src/DotNetOpenId/Configuration/RelyingPartySecuritySettingsElement.cs b/src/DotNetOpenId/Configuration/RelyingPartySecuritySettingsElement.cs
new file mode 100644
index 0000000..a76d993
--- /dev/null
+++ b/src/DotNetOpenId/Configuration/RelyingPartySecuritySettingsElement.cs
@@ -0,0 +1,45 @@
+using System.Configuration;
+using DotNetOpenId.RelyingParty;
+
+namespace DotNetOpenId.Configuration {
+ internal class RelyingPartySecuritySettingsElement : ConfigurationElement {
+ public RelyingPartySecuritySettingsElement() { }
+
+ public RelyingPartySecuritySettings CreateSecuritySettings() {
+ RelyingPartySecuritySettings settings = new RelyingPartySecuritySettings();
+ settings.RequireSsl = RequireSsl;
+ settings.MinimumRequiredOpenIdVersion = MinimumRequiredOpenIdVersion;
+ settings.MinimumHashBitLength = MinimumHashBitLength;
+ settings.MaximumHashBitLength = MaximumHashBitLength;
+ return settings;
+ }
+
+ const string requireSslConfigName = "requireSsl";
+ [ConfigurationProperty(requireSslConfigName, DefaultValue = false)]
+ public bool RequireSsl {
+ get { return (bool)this[requireSslConfigName]; }
+ set { this[requireSslConfigName] = value; }
+ }
+
+ const string minimumRequiredOpenIdVersionConfigName = "minimumRequiredOpenIdVersion";
+ [ConfigurationProperty(minimumRequiredOpenIdVersionConfigName, DefaultValue = "V10")]
+ public ProtocolVersion MinimumRequiredOpenIdVersion {
+ get { return (ProtocolVersion)this[minimumRequiredOpenIdVersionConfigName]; }
+ set { this[minimumRequiredOpenIdVersionConfigName] = value; }
+ }
+
+ const string minimumHashBitLengthConfigName = "minimumHashBitLength";
+ [ConfigurationProperty(minimumHashBitLengthConfigName, DefaultValue = DotNetOpenId.SecuritySettings.minimumHashBitLengthDefault)]
+ public int MinimumHashBitLength {
+ get { return (int)this[minimumHashBitLengthConfigName]; }
+ set { this[minimumHashBitLengthConfigName] = value; }
+ }
+
+ const string maximumHashBitLengthConfigName = "maximumHashBitLength";
+ [ConfigurationProperty(maximumHashBitLengthConfigName, DefaultValue = DotNetOpenId.SecuritySettings.maximumHashBitLengthRPDefault)]
+ public int MaximumHashBitLength {
+ get { return (int)this[maximumHashBitLengthConfigName]; }
+ set { this[maximumHashBitLengthConfigName] = value; }
+ }
+ }
+}
diff --git a/src/DotNetOpenId/Configuration/StoreElement.cs b/src/DotNetOpenId/Configuration/StoreElement.cs
new file mode 100644
index 0000000..d2c94cb
--- /dev/null
+++ b/src/DotNetOpenId/Configuration/StoreElement.cs
@@ -0,0 +1,24 @@
+using System;
+using System.Configuration;
+
+namespace DotNetOpenId.Configuration {
+ internal class StoreConfigurationElement<T> : ConfigurationElement {
+ public StoreConfigurationElement() { }
+
+ const string customStoreTypeConfigName = "type";
+ [ConfigurationProperty(customStoreTypeConfigName)]
+ //[SubclassTypeValidator(typeof(T))]
+ public string TypeName {
+ get { return (string)this[customStoreTypeConfigName]; }
+ set { this[customStoreTypeConfigName] = value; }
+ }
+
+ public Type CustomStoreType {
+ get { return string.IsNullOrEmpty(TypeName) ? null : Type.GetType(TypeName); }
+ }
+
+ public T CreateInstanceOfStore(T defaultValue) {
+ return CustomStoreType != null ? (T)Activator.CreateInstance(CustomStoreType) : defaultValue;
+ }
+ }
+}
diff --git a/src/DotNetOpenId/Configuration/UntrustedWebRequestSection.cs b/src/DotNetOpenId/Configuration/UntrustedWebRequestSection.cs
new file mode 100644
index 0000000..392acf8
--- /dev/null
+++ b/src/DotNetOpenId/Configuration/UntrustedWebRequestSection.cs
@@ -0,0 +1,78 @@
+using System;
+using System.Configuration;
+
+namespace DotNetOpenId.Configuration {
+ internal class UntrustedWebRequestSection : ConfigurationSection {
+ internal static UntrustedWebRequestSection Configuration {
+ get { return (UntrustedWebRequestSection)ConfigurationManager.GetSection("dotNetOpenId/untrustedWebRequest") ?? new UntrustedWebRequestSection(); }
+ }
+
+ public UntrustedWebRequestSection() {
+ SectionInformation.AllowLocation = false;
+ }
+
+ const string readWriteTimeoutConfigName = "readWriteTimeout";
+ [ConfigurationProperty(readWriteTimeoutConfigName, DefaultValue = "00:00:00.800")]
+ [PositiveTimeSpanValidator]
+ public TimeSpan ReadWriteTimeout {
+ get { return (TimeSpan)this[readWriteTimeoutConfigName]; }
+ set { this[readWriteTimeoutConfigName] = value; }
+ }
+
+ const string timeoutConfigName = "timeout";
+ [ConfigurationProperty(timeoutConfigName, DefaultValue = "00:00:10")]
+ [PositiveTimeSpanValidator]
+ public TimeSpan Timeout {
+ get { return (TimeSpan)this[timeoutConfigName]; }
+ set { this[timeoutConfigName] = value; }
+ }
+
+ const string maximumBytesToReadConfigName = "maximumBytesToRead";
+ [ConfigurationProperty(maximumBytesToReadConfigName, DefaultValue = 1024 * 1024)]
+ [IntegerValidator(MinValue = 2048)]
+ public int MaximumBytesToRead {
+ get { return (int)this[maximumBytesToReadConfigName]; }
+ set { this[maximumBytesToReadConfigName] = value; }
+ }
+
+ const string maximumRedirectionsConfigName = "maximumRedirections";
+ [ConfigurationProperty(maximumRedirectionsConfigName, DefaultValue = 10)]
+ [IntegerValidator(MinValue = 0)]
+ public int MaximumRedirections {
+ get { return (int)this[maximumRedirectionsConfigName]; }
+ set { this[maximumRedirectionsConfigName] = value; }
+ }
+
+ const string whitelistHostsConfigName = "whitelistHosts";
+ [ConfigurationProperty(whitelistHostsConfigName, IsDefaultCollection = false)]
+ [ConfigurationCollection(typeof(WhiteBlackListCollection))]
+ public WhiteBlackListCollection WhitelistHosts {
+ get { return (WhiteBlackListCollection)this[whitelistHostsConfigName] ?? new WhiteBlackListCollection(); }
+ set { this[whitelistHostsConfigName] = value; }
+ }
+
+ const string blacklistHostsConfigName = "blacklistHosts";
+ [ConfigurationProperty(blacklistHostsConfigName, IsDefaultCollection = false)]
+ [ConfigurationCollection(typeof(WhiteBlackListCollection))]
+ public WhiteBlackListCollection BlacklistHosts {
+ get { return (WhiteBlackListCollection)this[blacklistHostsConfigName] ?? new WhiteBlackListCollection(); }
+ set { this[blacklistHostsConfigName] = value; }
+ }
+
+ const string whitelistHostsRegexConfigName = "whitelistHostsRegex";
+ [ConfigurationProperty(whitelistHostsRegexConfigName, IsDefaultCollection = false)]
+ [ConfigurationCollection(typeof(WhiteBlackListCollection))]
+ public WhiteBlackListCollection WhitelistHostsRegex {
+ get { return (WhiteBlackListCollection)this[whitelistHostsRegexConfigName] ?? new WhiteBlackListCollection(); }
+ set { this[whitelistHostsRegexConfigName] = value; }
+ }
+
+ const string blacklistHostsRegexConfigName = "blacklistHostsRegex";
+ [ConfigurationProperty(blacklistHostsRegexConfigName, IsDefaultCollection = false)]
+ [ConfigurationCollection(typeof(WhiteBlackListCollection))]
+ public WhiteBlackListCollection BlacklistHostsRegex {
+ get { return (WhiteBlackListCollection)this[blacklistHostsRegexConfigName] ?? new WhiteBlackListCollection(); }
+ set { this[blacklistHostsRegexConfigName] = value; }
+ }
+ }
+}
diff --git a/src/DotNetOpenId/Configuration/WhiteBlackListCollection.cs b/src/DotNetOpenId/Configuration/WhiteBlackListCollection.cs
new file mode 100644
index 0000000..29485d1
--- /dev/null
+++ b/src/DotNetOpenId/Configuration/WhiteBlackListCollection.cs
@@ -0,0 +1,33 @@
+using System.Collections.Generic;
+using System.Configuration;
+using System.Text.RegularExpressions;
+
+namespace DotNetOpenId.Configuration {
+ internal class WhiteBlackListCollection : ConfigurationElementCollection {
+ public WhiteBlackListCollection() { }
+
+ protected override ConfigurationElement CreateNewElement() {
+ return new WhiteBlackListElement();
+ }
+
+ protected override object GetElementKey(ConfigurationElement element) {
+ return ((WhiteBlackListElement)element).Name;
+ }
+
+ internal IEnumerable<string> KeysAsStrings {
+ get {
+ foreach (WhiteBlackListElement element in this) {
+ yield return element.Name;
+ }
+ }
+ }
+
+ internal IEnumerable<Regex> KeysAsRegexs {
+ get {
+ foreach (WhiteBlackListElement element in this) {
+ yield return new Regex(element.Name);
+ }
+ }
+ }
+ }
+}
diff --git a/src/DotNetOpenId/Configuration/WhiteBlackListElement.cs b/src/DotNetOpenId/Configuration/WhiteBlackListElement.cs
new file mode 100644
index 0000000..02a909d
--- /dev/null
+++ b/src/DotNetOpenId/Configuration/WhiteBlackListElement.cs
@@ -0,0 +1,13 @@
+using System.Configuration;
+
+namespace DotNetOpenId.Configuration {
+ internal class WhiteBlackListElement : ConfigurationElement {
+ const string nameConfigName = "name";
+ [ConfigurationProperty(nameConfigName, IsRequired = true)]
+ //[StringValidator(MinLength = 1)]
+ public string Name {
+ get { return (string)this[nameConfigName]; }
+ set { this[nameConfigName] = value; }
+ }
+ }
+}