Skip to content
This repository was archived by the owner on Mar 20, 2019. It is now read-only.

Commit d54af69

Browse files
committed
Trying to fix up configuration section code.
1 parent 6643055 commit d54af69

26 files changed

Lines changed: 89 additions & 81 deletions

File tree

projecttemplates/RelyingPartyLogic/NonceDbStore.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public bool StoreNonce(string context, string nonce, DateTime timestampUtc) {
6464
Context = context,
6565
Code = nonce,
6666
IssuedUtc = timestampUtc,
67-
ExpiresUtc = timestampUtc + DotNetOpenAuthSection.Configuration.Messaging.MaximumMessageLifetime,
67+
ExpiresUtc = timestampUtc + DotNetOpenAuthSection.Messaging.MaximumMessageLifetime,
6868
};
6969

7070
// The database columns [context] and [code] MUST be using

samples/OpenIdProviderWebForms/Code/CustomStore.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public bool StoreNonce(string context, string nonce, DateTime timestampUtc) {
6767
return false;
6868
}
6969

70-
TimeSpan maxMessageAge = DotNetOpenAuthSection.Configuration.Messaging.MaximumMessageLifetime;
70+
TimeSpan maxMessageAge = DotNetOpenAuthSection.Messaging.MaximumMessageLifetime;
7171
dataSet.Nonce.AddNonceRow(context, nonce, timestampUtc, timestampUtc + maxMessageAge);
7272
return true;
7373
}

samples/OpenIdRelyingPartyWebForms/Code/CustomStore.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public bool StoreNonce(string context, string nonce, DateTime timestampUtc) {
6868
return false;
6969
}
7070

71-
TimeSpan maxMessageAge = DotNetOpenAuthSection.Configuration.Messaging.MaximumMessageLifetime;
71+
TimeSpan maxMessageAge = DotNetOpenAuthSection.Messaging.MaximumMessageLifetime;
7272
dataSet.Nonce.AddNonceRow(context, nonce, timestampUtc, timestampUtc + maxMessageAge);
7373
return true;
7474
}

samples/OpenIdRelyingPartyWebForms/Web.config

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
<configSections>
44
<section name="uri" type="System.Configuration.UriSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
55
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler" requirePermission="false" />
6-
<section name="dotNetOpenAuth" type="DotNetOpenAuth.Configuration.DotNetOpenAuthSection" requirePermission="false" allowLocation="true"/>
6+
<sectionGroup name="dotNetOpenAuth" type="DotNetOpenAuth.Configuration.DotNetOpenAuthSection">
7+
<section name="openid" type="DotNetOpenAuth.Configuration.OpenIdElement" requirePermission="false" allowLocation="true" />
8+
<section name="messaging" type="DotNetOpenAuth.Configuration.MessagingElement" requirePermission="false" allowLocation="true" />
9+
<section name="reporting" type="DotNetOpenAuth.Configuration.ReportingElement" requirePermission="false" allowLocation="true" />
10+
</sectionGroup>
711
</configSections>
812

913
<!-- The uri section is necessary to turn on .NET 3.5 support for IDN (international domain names),
@@ -37,7 +41,7 @@
3741
<behaviors>
3842
<!-- The following OPTIONAL behavior allows RPs to use SREG only, but be compatible
3943
with OPs that use Attribute Exchange (in various formats). -->
40-
<add type="DotNetOpenAuth.OpenId.Behaviors.AXFetchAsSregTransform, DotNetOpenAuth" />
44+
<add type="DotNetOpenAuth.OpenId.Behaviors.AXFetchAsSregTransform, DotNetOpenAuth.OpenId" />
4145
<!--<add type="DotNetOpenAuth.OpenId.Behaviors.GsaIcamProfile, DotNetOpenAuth" />-->
4246
</behaviors>
4347
<!-- Uncomment the following to activate the sample custom store. -->

samples/OpenIdRelyingPartyWebForms/login.aspx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<%@ Page Language="C#" AutoEventWireup="True" CodeBehind="login.aspx.cs" Inherits="OpenIdRelyingPartyWebForms.login"
22
ValidateRequest="false" MasterPageFile="~/Site.Master" %>
33

4-
<%@ Register Assembly="DotNetOpenAuth" Namespace="DotNetOpenAuth.OpenId.RelyingParty" TagPrefix="rp" %>
5-
<%@ Register Assembly="DotNetOpenAuth" Namespace="DotNetOpenAuth.OpenId.Extensions.SimpleRegistration" TagPrefix="sreg" %>
4+
<%@ Register Assembly="DotNetOpenAuth.OpenId" Namespace="DotNetOpenAuth.OpenId.RelyingParty" TagPrefix="rp" %>
5+
<%@ Register Assembly="DotNetOpenAuth.OpenId" Namespace="DotNetOpenAuth.OpenId.Extensions.SimpleRegistration" TagPrefix="sreg" %>
66
<asp:Content runat="server" ContentPlaceHolderID="Main">
77
<h2>Login Page </h2>
88
<rp:OpenIdLogin ID="OpenIdLogin1" runat="server" CssClass="openid_login" RequestCountry="Request"

src/DotNetOpenAuth.InfoCard/InfoCard/Token/TokenUtility.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ internal static class TokenUtility {
3535
/// Gets the maximum amount the token can be out of sync with time.
3636
/// </summary>
3737
internal static TimeSpan MaximumClockSkew {
38-
get { return DotNetOpenAuth.Configuration.DotNetOpenAuthSection.Configuration.Messaging.MaximumClockSkew; }
38+
get { return DotNetOpenAuth.Configuration.DotNetOpenAuthSection.Messaging.MaximumClockSkew; }
3939
}
4040

4141
/// <summary>

src/DotNetOpenAuth.Messaging/Configuration/DotNetOpenAuthSection.cs

Lines changed: 9 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,11 @@ namespace DotNetOpenAuth.Configuration {
1313
/// this library's settings.
1414
/// </summary>
1515
[ContractVerification(true)]
16-
public class DotNetOpenAuthSection : ConfigurationSection {
16+
public class DotNetOpenAuthSection : ConfigurationSectionGroup {
1717
/// <summary>
1818
/// The name of the section under which this library's settings must be found.
1919
/// </summary>
20-
private const string SectionName = "dotNetOpenAuth";
21-
22-
/// <summary>
23-
/// The name of the &lt;messaging&gt; sub-element.
24-
/// </summary>
25-
private const string MessagingElementName = "messaging";
20+
internal const string SectionName = "dotNetOpenAuth";
2621

2722
/// <summary>
2823
/// The name of the &lt;openid&gt; sub-element.
@@ -34,22 +29,10 @@ public class DotNetOpenAuthSection : ConfigurationSection {
3429
/// </summary>
3530
private const string OAuthElementName = "oauth";
3631

37-
/// <summary>
38-
/// The name of the &lt;reporting&gt; sub-element.
39-
/// </summary>
40-
private const string ReportingElementName = "reporting";
41-
42-
/// <summary>
43-
/// The name of the &lt;webResourceUrlProvider&gt; sub-element.
44-
/// </summary>
45-
private const string WebResourceUrlProviderName = "webResourceUrlProvider";
46-
4732
/// <summary>
4833
/// Initializes a new instance of the <see cref="DotNetOpenAuthSection"/> class.
4934
/// </summary>
5035
internal DotNetOpenAuthSection() {
51-
Contract.Assume(this.SectionInformation != null);
52-
this.SectionInformation.AllowLocation = false;
5336
}
5437

5538
/// <summary>
@@ -62,43 +45,17 @@ public static DotNetOpenAuthSection Configuration {
6245
}
6346
}
6447

65-
/// <summary>
66-
/// Gets or sets the configuration for the messaging framework.
67-
/// </summary>
68-
[ConfigurationProperty(MessagingElementName)]
69-
public MessagingElement Messaging {
70-
get {
71-
Contract.Ensures(Contract.Result<MessagingElement>() != null);
72-
return (MessagingElement)this[MessagingElementName] ?? new MessagingElement();
73-
}
74-
75-
set {
76-
this[MessagingElementName] = value;
77-
}
48+
public static MessagingElement Messaging {
49+
get { return MessagingElement.Configuration; }
7850
}
7951

80-
/// <summary>
81-
/// Gets or sets the configuration for reporting.
82-
/// </summary>
83-
[ConfigurationProperty(ReportingElementName)]
84-
internal ReportingElement Reporting {
85-
get {
86-
Contract.Ensures(Contract.Result<ReportingElement>() != null);
87-
return (ReportingElement)this[ReportingElementName] ?? new ReportingElement();
88-
}
89-
90-
set {
91-
this[ReportingElementName] = value;
92-
}
52+
internal TypeConfigurationElement<IEmbeddedResourceRetrieval> EmbeddedResourceRetrievalProvider {
53+
get { return /*(TypeConfigurationElement<IEmbeddedResourceRetrieval>)this[WebResourceUrlProviderName] ??*/ new TypeConfigurationElement<IEmbeddedResourceRetrieval>(); }
54+
set { /*this[WebResourceUrlProviderName] = value;*/ }
9355
}
9456

95-
/// <summary>
96-
/// Gets or sets the type to use for obtaining URLs that fetch embedded resource streams.
97-
/// </summary>
98-
[ConfigurationProperty(WebResourceUrlProviderName)]
99-
internal TypeConfigurationElement<IEmbeddedResourceRetrieval> EmbeddedResourceRetrievalProvider {
100-
get { return (TypeConfigurationElement<IEmbeddedResourceRetrieval>)this[WebResourceUrlProviderName] ?? new TypeConfigurationElement<IEmbeddedResourceRetrieval>(); }
101-
set { this[WebResourceUrlProviderName] = value; }
57+
internal static ReportingElement Reporting {
58+
get { return ReportingElement.Configuration; }
10259
}
10360
}
10461
}

src/DotNetOpenAuth.Messaging/Configuration/MessagingElement.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace DotNetOpenAuth.Configuration {
1515
/// Represents the &lt;messaging&gt; element in the host's .config file.
1616
/// </summary>
1717
[ContractVerification(true)]
18-
public class MessagingElement : ConfigurationElement {
18+
public class MessagingElement : ConfigurationSection {
1919
/// <summary>
2020
/// The name of the &lt;untrustedWebRequest&gt; sub-element.
2121
/// </summary>
@@ -60,6 +60,21 @@ public class MessagingElement : ConfigurationElement {
6060
/// </summary>
6161
private const string PrivateSecretMaximumAgeConfigName = "privateSecretMaximumAge";
6262

63+
/// <summary>
64+
/// The name of the &lt;messaging&gt; sub-element.
65+
/// </summary>
66+
private const string MessagingElementName = DotNetOpenAuthSection.SectionName + "/messaging";
67+
68+
/// <summary>
69+
/// Gets the configuration section from the .config file.
70+
/// </summary>
71+
public static MessagingElement Configuration {
72+
get {
73+
Contract.Ensures(Contract.Result<MessagingElement>() != null);
74+
return (MessagingElement)ConfigurationManager.GetSection(MessagingElementName) ?? new MessagingElement();
75+
}
76+
}
77+
6378
/// <summary>
6479
/// Gets the actual maximum message lifetime that a program should allow.
6580
/// </summary>

src/DotNetOpenAuth.Messaging/Configuration/ReportingElement.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ namespace DotNetOpenAuth.Configuration {
1010
using System.Configuration;
1111
using System.Linq;
1212
using System.Text;
13+
using System.Diagnostics.Contracts;
1314

1415
/// <summary>
1516
/// Represents the &lt;reporting&gt; element in the host's .config file.
1617
/// </summary>
17-
internal class ReportingElement : ConfigurationElement {
18+
internal class ReportingElement : ConfigurationSection {
1819
/// <summary>
1920
/// The name of the @enabled attribute.
2021
/// </summary>
@@ -50,6 +51,11 @@ internal class ReportingElement : ConfigurationElement {
5051
/// </summary>
5152
private const string IncludeCulturesAttributeName = "includeCultures";
5253

54+
/// <summary>
55+
/// The name of the &lt;reporting&gt; sub-element.
56+
/// </summary>
57+
private const string ReportingElementName = DotNetOpenAuthSection.SectionName + "/reporting";
58+
5359
/// <summary>
5460
/// The default value for the @minimumFlushInterval attribute.
5561
/// </summary>
@@ -65,6 +71,16 @@ internal class ReportingElement : ConfigurationElement {
6571
internal ReportingElement() {
6672
}
6773

74+
/// <summary>
75+
/// Gets the configuration section from the .config file.
76+
/// </summary>
77+
public static ReportingElement Configuration {
78+
get {
79+
Contract.Ensures(Contract.Result<ReportingElement>() != null);
80+
return (ReportingElement)ConfigurationManager.GetSection(ReportingElementName) ?? new ReportingElement();
81+
}
82+
}
83+
6884
/// <summary>
6985
/// Gets or sets a value indicating whether this reporting is enabled.
7086
/// </summary>

src/DotNetOpenAuth.Messaging/Configuration/UntrustedWebRequestElement.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,18 @@
77
namespace DotNetOpenAuth.Configuration {
88
using System;
99
using System.Configuration;
10+
using System.Diagnostics.Contracts;
1011

1112
/// <summary>
1213
/// Represents the section of a .config file where security policies regarding web requests
1314
/// to user-provided, untrusted servers is controlled.
1415
/// </summary>
1516
internal class UntrustedWebRequestElement : ConfigurationElement {
17+
/// <summary>
18+
/// The name of the &lt;webResourceUrlProvider&gt; sub-element.
19+
/// </summary>
20+
private const string WebResourceUrlProviderName = "webResourceUrlProvider";
21+
1622
#region Attribute names
1723

1824
/// <summary>
@@ -57,6 +63,16 @@ internal class UntrustedWebRequestElement : ConfigurationElement {
5763

5864
#endregion
5965

66+
/// <summary>
67+
/// Gets the configuration section from the .config file.
68+
/// </summary>
69+
public static UntrustedWebRequestElement Configuration {
70+
get {
71+
Contract.Ensures(Contract.Result<UntrustedWebRequestElement>() != null);
72+
return (UntrustedWebRequestElement)ConfigurationManager.GetSection(WebResourceUrlProviderName) ?? new UntrustedWebRequestElement();
73+
}
74+
}
75+
6076
/// <summary>
6177
/// Gets or sets the read/write timeout after which an HTTP request will fail.
6278
/// </summary>

0 commit comments

Comments
 (0)