//-----------------------------------------------------------------------
//
// Copyright (c) Outercurve Foundation. All rights reserved.
//
//-----------------------------------------------------------------------
namespace DotNetOpenAuth.Configuration {
using System;
using System.Configuration;
using DotNetOpenAuth.OpenId;
using DotNetOpenAuth.OpenId.RelyingParty;
///
/// The section in the .config file that allows customization of OpenID Relying Party behaviors.
///
internal class OpenIdRelyingPartyElement : ConfigurationElement {
///
/// The name of the custom store sub-element.
///
private const string StoreConfigName = "store";
///
/// The name of the <relyingParty> sub-element.
///
private const string RelyingPartyElementName = "relyingParty";
///
/// The name of the attribute that specifies whether dnoa.userSuppliedIdentifier is tacked onto the openid.return_to URL.
///
private const string PreserveUserSuppliedIdentifierConfigName = "preserveUserSuppliedIdentifier";
///
/// Gets the name of the security sub-element.
///
private const string SecuritySettingsConfigName = "security";
///
/// The name of the <behaviors> sub-element.
///
private const string BehaviorsElementName = "behaviors";
///
/// The name of the <discoveryServices> sub-element.
///
private const string DiscoveryServicesElementName = "discoveryServices";
///
/// The name of the <hostMetaDiscovery> sub-element.
///
private const string HostMetaDiscoveryElementName = "hostMetaDiscovery";
///
/// The built-in set of identifier discovery services.
///
private static readonly TypeConfigurationCollection defaultDiscoveryServices =
new TypeConfigurationCollection(new Type[] { typeof(UriDiscoveryService), typeof(XriDiscoveryProxyService) });
///
/// Initializes a new instance of the class.
///
public OpenIdRelyingPartyElement() {
}
///
/// Gets or sets a value indicating whether "dnoa.userSuppliedIdentifier" is tacked onto the openid.return_to URL in order to preserve what the user typed into the OpenID box.
///
///
/// The default value is true.
///
[ConfigurationProperty(PreserveUserSuppliedIdentifierConfigName, DefaultValue = true)]
public bool PreserveUserSuppliedIdentifier {
get { return (bool)this[PreserveUserSuppliedIdentifierConfigName]; }
set { this[PreserveUserSuppliedIdentifierConfigName] = value; }
}
///
/// Gets or sets the security settings.
///
[ConfigurationProperty(SecuritySettingsConfigName)]
public OpenIdRelyingPartySecuritySettingsElement SecuritySettings {
get { return (OpenIdRelyingPartySecuritySettingsElement)this[SecuritySettingsConfigName] ?? new OpenIdRelyingPartySecuritySettingsElement(); }
set { this[SecuritySettingsConfigName] = value; }
}
///
/// Gets or sets the special behaviors to apply.
///
[ConfigurationProperty(BehaviorsElementName, IsDefaultCollection = false)]
[ConfigurationCollection(typeof(TypeConfigurationCollection))]
public TypeConfigurationCollection Behaviors {
get { return (TypeConfigurationCollection)this[BehaviorsElementName] ?? new TypeConfigurationCollection(); }
set { this[BehaviorsElementName] = value; }
}
///
/// Gets or sets the type to use for storing application state.
///
[ConfigurationProperty(StoreConfigName)]
public TypeConfigurationElement ApplicationStore {
get { return (TypeConfigurationElement)this[StoreConfigName] ?? new TypeConfigurationElement(); }
set { this[StoreConfigName] = value; }
}
///
/// Gets or sets the host meta discovery configuration element.
///
[ConfigurationProperty(HostMetaDiscoveryElementName)]
internal HostMetaDiscoveryElement HostMetaDiscovery {
get { return (HostMetaDiscoveryElement)this[HostMetaDiscoveryElementName] ?? new HostMetaDiscoveryElement(); }
set { this[HostMetaDiscoveryElementName] = value; }
}
///
/// Gets or sets the services to use for discovering service endpoints for identifiers.
///
///
/// If no discovery services are defined in the (web) application's .config file,
/// the default set of discovery services built into the library are used.
///
[ConfigurationProperty(DiscoveryServicesElementName, IsDefaultCollection = false)]
[ConfigurationCollection(typeof(TypeConfigurationCollection))]
internal TypeConfigurationCollection DiscoveryServices {
get {
var configResult = (TypeConfigurationCollection)this[DiscoveryServicesElementName];
return configResult != null && configResult.Count > 0 ? configResult : defaultDiscoveryServices;
}
set {
this[DiscoveryServicesElementName] = value;
}
}
}
}