//-----------------------------------------------------------------------
//
// Copyright (c) Outercurve Foundation. All rights reserved.
//
//-----------------------------------------------------------------------
namespace DotNetOpenAuth.Configuration {
using System;
using System.Collections.Generic;
using System.Configuration;
using DotNetOpenAuth.OpenId.ChannelElements;
using DotNetOpenAuth.OpenId.Messages;
using Validation;
///
/// Represents the <openid> element in the host's .config file.
///
internal class OpenIdElement : ConfigurationSection {
///
/// The name of the section under which this library's settings must be found.
///
private const string SectionName = DotNetOpenAuthSection.SectionName + "/openid";
///
/// The name of the <relyingParty> sub-element.
///
private const string RelyingPartyElementName = "relyingParty";
///
/// The name of the <provider> sub-element.
///
private const string ProviderElementName = "provider";
///
/// The name of the <extensions> sub-element.
///
private const string ExtensionFactoriesElementName = "extensionFactories";
///
/// The name of the <xriResolver> sub-element.
///
private const string XriResolverElementName = "xriResolver";
///
/// The name of the @maxAuthenticationTime attribute.
///
private const string MaxAuthenticationTimePropertyName = "maxAuthenticationTime";
///
/// The name of the @cacheDiscovery attribute.
///
private const string CacheDiscoveryPropertyName = "cacheDiscovery";
///
/// Initializes a new instance of the class.
///
internal OpenIdElement() {
}
///
/// Gets the configuration section from the .config file.
///
public static OpenIdElement Configuration {
get {
return (OpenIdElement)ConfigurationManager.GetSection(SectionName) ?? new OpenIdElement();
}
}
///
/// Gets or sets the maximum time a user can take to complete authentication.
///
///
/// This time limit allows the library to decide how long to cache certain values
/// necessary to complete authentication. The lower the time, the less demand on
/// the server. But too short a time can frustrate the user.
///
[ConfigurationProperty(MaxAuthenticationTimePropertyName, DefaultValue = "0:05")] // 5 minutes
[PositiveTimeSpanValidator]
internal TimeSpan MaxAuthenticationTime {
get {
TimeSpan result = (TimeSpan)this[MaxAuthenticationTimePropertyName];
Assumes.True(result > TimeSpan.Zero); // our PositiveTimeSpanValidator should take care of this
return result;
}
set {
Requires.Range(value > TimeSpan.Zero, "value");
this[MaxAuthenticationTimePropertyName] = value;
}
}
///
/// Gets or sets a value indicating whether the results of Identifier discovery
/// should be cached.
///
///
/// Use true to allow identifier discovery to immediately return cached results when available;
/// otherwise, use false.to force fresh results every time at the cost of slightly slower logins.
/// The default value is true.
///
///
/// When enabled, caching is done according to HTTP standards.
///
[ConfigurationProperty(CacheDiscoveryPropertyName, DefaultValue = true)]
internal bool CacheDiscovery {
get { return (bool)this[CacheDiscoveryPropertyName]; }
set { this[CacheDiscoveryPropertyName] = value; }
}
///
/// Gets or sets the configuration specific for Relying Parties.
///
[ConfigurationProperty(RelyingPartyElementName)]
internal OpenIdRelyingPartyElement RelyingParty {
get { return (OpenIdRelyingPartyElement)this[RelyingPartyElementName] ?? new OpenIdRelyingPartyElement(); }
set { this[RelyingPartyElementName] = value; }
}
///
/// Gets or sets the configuration specific for Providers.
///
[ConfigurationProperty(ProviderElementName)]
internal OpenIdProviderElement Provider {
get { return (OpenIdProviderElement)this[ProviderElementName] ?? new OpenIdProviderElement(); }
set { this[ProviderElementName] = value; }
}
///
/// Gets or sets the registered OpenID extension factories.
///
[ConfigurationProperty(ExtensionFactoriesElementName, IsDefaultCollection = false)]
[ConfigurationCollection(typeof(TypeConfigurationCollection))]
internal TypeConfigurationCollection ExtensionFactories {
get { return (TypeConfigurationCollection)this[ExtensionFactoriesElementName] ?? new TypeConfigurationCollection(); }
set { this[ExtensionFactoriesElementName] = value; }
}
///
/// Gets or sets the configuration for the XRI resolver.
///
[ConfigurationProperty(XriResolverElementName)]
internal XriResolverElement XriResolver {
get { return (XriResolverElement)this[XriResolverElementName] ?? new XriResolverElement(); }
set { this[XriResolverElementName] = value; }
}
}
}