diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2009-05-16 11:22:19 -0700 |
---|---|---|
committer | Andrew Arnott <andrewarnott@gmail.com> | 2009-05-16 11:22:19 -0700 |
commit | 467b2cbb3ad9fd8ea3948d4fc89f4090dc442526 (patch) | |
tree | b2ab421dc3d935538ff128f0198a983ffa94c4d9 /src | |
parent | faafbcf5bb51c1b695f47a3e0984547f8e3ad7ac (diff) | |
download | DotNetOpenAuth-467b2cbb3ad9fd8ea3948d4fc89f4090dc442526.zip DotNetOpenAuth-467b2cbb3ad9fd8ea3948d4fc89f4090dc442526.tar.gz DotNetOpenAuth-467b2cbb3ad9fd8ea3948d4fc89f4090dc442526.tar.bz2 |
Adds option to change out the XRI proxy resolver to use or even disable XRI resolution altogether.
Resolves Trac ticket 62.
Diffstat (limited to 'src')
-rw-r--r-- | src/DotNetOpenAuth/Configuration/HostNameElement.cs | 14 | ||||
-rw-r--r-- | src/DotNetOpenAuth/Configuration/OpenIdElement.cs | 14 | ||||
-rw-r--r-- | src/DotNetOpenAuth/Configuration/XriResolverElement.cs | 65 | ||||
-rw-r--r-- | src/DotNetOpenAuth/DotNetOpenAuth.csproj | 1 | ||||
-rw-r--r-- | src/DotNetOpenAuth/OpenId/OpenIdStrings.Designer.cs | 9 | ||||
-rw-r--r-- | src/DotNetOpenAuth/OpenId/OpenIdStrings.resx | 3 | ||||
-rw-r--r-- | src/DotNetOpenAuth/OpenId/XriIdentifier.cs | 14 |
7 files changed, 117 insertions, 3 deletions
diff --git a/src/DotNetOpenAuth/Configuration/HostNameElement.cs b/src/DotNetOpenAuth/Configuration/HostNameElement.cs index f252d6f..9df218e 100644 --- a/src/DotNetOpenAuth/Configuration/HostNameElement.cs +++ b/src/DotNetOpenAuth/Configuration/HostNameElement.cs @@ -19,6 +19,20 @@ namespace DotNetOpenAuth.Configuration { private const string NameConfigName = "name"; /// <summary> + /// Initializes a new instance of the <see cref="HostNameElement"/> class. + /// </summary> + internal HostNameElement() { + } + + /// <summary> + /// Initializes a new instance of the <see cref="HostNameElement"/> class. + /// </summary> + /// <param name="name">The default value of the <see cref="Name"/> property.</param> + internal HostNameElement(string name) { + this.Name = name; + } + + /// <summary> /// Gets or sets the name of the host on the white or black list. /// </summary> [ConfigurationProperty(NameConfigName, IsRequired = true, IsKey = true)] diff --git a/src/DotNetOpenAuth/Configuration/OpenIdElement.cs b/src/DotNetOpenAuth/Configuration/OpenIdElement.cs index 25e067e..3a58da1 100644 --- a/src/DotNetOpenAuth/Configuration/OpenIdElement.cs +++ b/src/DotNetOpenAuth/Configuration/OpenIdElement.cs @@ -32,6 +32,11 @@ namespace DotNetOpenAuth.Configuration { private const string ExtensionFactoriesElementName = "extensionFactories"; /// <summary> + /// The name of the <xriResolver> sub-element. + /// </summary> + private const string XriResolverElementName = "xriResolver"; + + /// <summary> /// Gets the name of the @maxAuthenticationTime attribute. /// </summary> private const string MaxAuthenticationTimePropertyName = "maxAuthenticationTime"; @@ -84,5 +89,14 @@ namespace DotNetOpenAuth.Configuration { get { return (TypeConfigurationCollection<IOpenIdExtensionFactory>)this[ExtensionFactoriesElementName] ?? new TypeConfigurationCollection<IOpenIdExtensionFactory>(); } set { this[ExtensionFactoriesElementName] = value; } } + + /// <summary> + /// Gets or sets the configuration for the XRI resolver. + /// </summary> + [ConfigurationProperty(XriResolverElementName)] + internal XriResolverElement XriResolver { + get { return (XriResolverElement)this[XriResolverElementName] ?? new XriResolverElement(); } + set { this[XriResolverElementName] = value; } + } } } diff --git a/src/DotNetOpenAuth/Configuration/XriResolverElement.cs b/src/DotNetOpenAuth/Configuration/XriResolverElement.cs new file mode 100644 index 0000000..cdc2ff5 --- /dev/null +++ b/src/DotNetOpenAuth/Configuration/XriResolverElement.cs @@ -0,0 +1,65 @@ +//----------------------------------------------------------------------- +// <copyright file="XriResolverElement.cs" company="Andrew Arnott"> +// Copyright (c) Andrew Arnott. All rights reserved. +// </copyright> +//----------------------------------------------------------------------- + +namespace DotNetOpenAuth.Configuration { + using System.Configuration; + + /// <summary> + /// Represents the <xriResolver> element in the host's .config file. + /// </summary> + internal class XriResolverElement : ConfigurationElement { + /// <summary> + /// Gets the name of the @enabled attribute. + /// </summary> + private const string EnabledAttributeName = "enabled"; + + /// <summary> + /// The default value for <see cref="Enabled"/>. + /// </summary> + private const bool EnabledDefaultValue = true; + + /// <summary> + /// The name of the <proxy> sub-element. + /// </summary> + private const string ProxyElementName = "proxy"; + + /// <summary> + /// The default XRI proxy resolver to use. + /// </summary> + private static readonly HostNameElement ProxyDefault = new HostNameElement("xri.net"); + + /// <summary> + /// Initializes a new instance of the <see cref="XriResolverElement"/> class. + /// </summary> + internal XriResolverElement() { + } + + /// <summary> + /// Gets or sets a value indicating whether this XRI resolution is enabled. + /// </summary> + /// <value>The default value is <c>true</c>.</value> + [ConfigurationProperty(EnabledAttributeName, DefaultValue = EnabledDefaultValue)] + internal bool Enabled { + get { return (bool)this[EnabledAttributeName]; } + set { this[EnabledAttributeName] = value; } + } + + /// <summary> + /// Gets or sets the proxy to use for resolving XRIs. + /// </summary> + [ConfigurationProperty(ProxyElementName)] + internal HostNameElement Proxy { + get { + var host = (HostNameElement)this[ProxyElementName] ?? ProxyDefault; + return string.IsNullOrEmpty(host.Name.Trim()) ? ProxyDefault : host; + } + + set { + this[ProxyElementName] = value; + } + } + } +} diff --git a/src/DotNetOpenAuth/DotNetOpenAuth.csproj b/src/DotNetOpenAuth/DotNetOpenAuth.csproj index a1afd2b..9197cee 100644 --- a/src/DotNetOpenAuth/DotNetOpenAuth.csproj +++ b/src/DotNetOpenAuth/DotNetOpenAuth.csproj @@ -187,6 +187,7 @@ <Compile Include="Configuration\UntrustedWebRequestElement.cs" /> <Compile Include="Configuration\HostNameOrRegexCollection.cs" /> <Compile Include="Configuration\HostNameElement.cs" /> + <Compile Include="Configuration\XriResolverElement.cs" /> <Compile Include="InfoCard\ClaimType.cs" /> <Compile Include="InfoCard\ReceivingTokenEventArgs.cs" /> <Compile Include="InfoCard\TokenProcessingErrorEventArgs.cs" /> diff --git a/src/DotNetOpenAuth/OpenId/OpenIdStrings.Designer.cs b/src/DotNetOpenAuth/OpenId/OpenIdStrings.Designer.cs index 07348db..dc8c0ee 100644 --- a/src/DotNetOpenAuth/OpenId/OpenIdStrings.Designer.cs +++ b/src/DotNetOpenAuth/OpenId/OpenIdStrings.Designer.cs @@ -641,6 +641,15 @@ namespace DotNetOpenAuth.OpenId { } /// <summary> + /// Looks up a localized string similar to XRI support has been disabled at this site.. + /// </summary> + internal static string XriResolutionDisabled { + get { + return ResourceManager.GetString("XriResolutionDisabled", resourceCulture); + } + } + + /// <summary> /// Looks up a localized string similar to XRI resolution failed.. /// </summary> internal static string XriResolutionFailed { diff --git a/src/DotNetOpenAuth/OpenId/OpenIdStrings.resx b/src/DotNetOpenAuth/OpenId/OpenIdStrings.resx index 87ed517..331e502 100644 --- a/src/DotNetOpenAuth/OpenId/OpenIdStrings.resx +++ b/src/DotNetOpenAuth/OpenId/OpenIdStrings.resx @@ -316,4 +316,7 @@ Discovered endpoint info: <data name="DelegatingIdentifiersNotAllowed" xml:space="preserve"> <value>Only OpenIDs issued directly by their OpenID Provider are allowed here.</value> </data> + <data name="XriResolutionDisabled" xml:space="preserve"> + <value>XRI support has been disabled at this site.</value> + </data> </root>
\ No newline at end of file diff --git a/src/DotNetOpenAuth/OpenId/XriIdentifier.cs b/src/DotNetOpenAuth/OpenId/XriIdentifier.cs index 1bb03ee..3c6cde2 100644 --- a/src/DotNetOpenAuth/OpenId/XriIdentifier.cs +++ b/src/DotNetOpenAuth/OpenId/XriIdentifier.cs @@ -7,10 +7,10 @@ namespace DotNetOpenAuth.OpenId { using System; using System.Collections.Generic; - using System.Diagnostics.CodeAnalysis; using System.Diagnostics.Contracts; using System.Globalization; using System.Xml; + using DotNetOpenAuth.Configuration; using DotNetOpenAuth.Messaging; using DotNetOpenAuth.OpenId.RelyingParty; using DotNetOpenAuth.Xrds; @@ -43,7 +43,7 @@ namespace DotNetOpenAuth.OpenId { /// The ssl=true parameter tells the proxy resolver to accept only SSL connections /// when resolving community i-names. /// </remarks> - private const string XriResolverProxyTemplate = "https://xri.net/{0}?_xrd_r=application/xrd%2Bxml;sep=false"; + private const string XriResolverProxyTemplate = "https://{1}/{0}?_xrd_r=application/xrd%2Bxml;sep=false"; /// <summary> /// The XRI proxy resolver to use for finding XRDS documents from an XRI. @@ -106,7 +106,15 @@ namespace DotNetOpenAuth.OpenId { /// Gets the URL from which this XRI's XRDS document may be downloaded. /// </summary> private Uri XrdsUrl { - get { return new Uri(string.Format(CultureInfo.InvariantCulture, this.xriResolverProxy, this)); } + get { + ErrorUtilities.VerifyProtocol(DotNetOpenAuthSection.Configuration.OpenId.XriResolver.Enabled, OpenIdStrings.XriResolutionDisabled); + return new Uri( + string.Format( + CultureInfo.InvariantCulture, + this.xriResolverProxy, + this, + DotNetOpenAuthSection.Configuration.OpenId.XriResolver.Proxy.Name)); + } } /// <summary> |