1
//-----------------------------------------------------------------------
2 // <copyright file="ProviderSecuritySettingsElement.cs" company="Andrew Arnott">
3 // Copyright (c) Andrew Arnott. All rights reserved.
5 //-----------------------------------------------------------------------
7 namespace DotNetOpenAuth
.Configuration
{
8 using System
.Configuration
;
9 using DotNetOpenAuth
.OpenId
;
10 using DotNetOpenAuth
.OpenId
.Provider
;
13 /// Represents the .config file element that allows for setting the security policies of the Provider.
15 internal class ProviderSecuritySettingsElement
: ConfigurationElement
{
17 /// Gets the name of the @protectDownlevelReplayAttacks attribute.
19 private const string ProtectDownlevelReplayAttacksConfigName
= "protectDownlevelReplayAttacks";
22 /// Gets the name of the @minimumHashBitLength attribute.
24 private const string MinimumHashBitLengthConfigName
= "minimumHashBitLength";
27 /// Gets the name of the @maximumHashBitLength attribute.
29 private const string MaximumHashBitLengthConfigName
= "maximumHashBitLength";
32 /// The name of the associations collection sub-element.
34 private const string AssociationsConfigName
= "associations";
37 /// Initializes a new instance of the <see cref="ProviderSecuritySettingsElement"/> class.
39 public ProviderSecuritySettingsElement() {
43 /// Gets or sets the minimum length of the hash that protects the protocol from hijackers.
45 [ConfigurationProperty(MinimumHashBitLengthConfigName
, DefaultValue
= SecuritySettings
.MinimumHashBitLengthDefault
)]
46 public int MinimumHashBitLength
{
47 get { return (int)this[MinimumHashBitLengthConfigName]; }
48 set { this[MinimumHashBitLengthConfigName] = value; }
52 /// Gets or sets the maximum length of the hash that protects the protocol from hijackers.
54 [ConfigurationProperty(MaximumHashBitLengthConfigName
, DefaultValue
= SecuritySettings
.MaximumHashBitLengthRPDefault
)]
55 public int MaximumHashBitLength
{
56 get { return (int)this[MaximumHashBitLengthConfigName]; }
57 set { this[MaximumHashBitLengthConfigName] = value; }
61 /// Gets or sets a value indicating whether the Provider should take special care to protect OpenID 1.x relying parties
62 /// against replay attacks.
64 [ConfigurationProperty(ProtectDownlevelReplayAttacksConfigName
, DefaultValue
= false)]
65 public bool ProtectDownlevelReplayAttacks
{
66 get { return (bool)this[ProtectDownlevelReplayAttacksConfigName]; }
67 set { this[ProtectDownlevelReplayAttacksConfigName] = value; }
71 /// Gets or sets the configured lifetimes of the various association types.
73 [ConfigurationProperty(AssociationsConfigName
, IsDefaultCollection
= false)]
74 [ConfigurationCollection(typeof(AssociationTypeCollection
))]
75 public AssociationTypeCollection AssociationLifetimes
{
76 get { return (AssociationTypeCollection)this[AssociationsConfigName] ?? new AssociationTypeCollection(); }
77 set { this[AssociationsConfigName] = value; }
81 /// Initializes a programmatically manipulatable bag of these security settings with the settings from the config file.
83 /// <returns>The newly created security settings object.</returns>
84 public ProviderSecuritySettings
CreateSecuritySettings() {
85 ProviderSecuritySettings settings
= new ProviderSecuritySettings();
86 settings
.MinimumHashBitLength
= this.MinimumHashBitLength
;
87 settings
.MaximumHashBitLength
= this.MaximumHashBitLength
;
88 settings
.ProtectDownlevelReplayAttacks
= this.ProtectDownlevelReplayAttacks
;
89 foreach (AssociationTypeElement element
in this.AssociationLifetimes
) {
90 settings
.AssociationLifetimes
.Add(element
.AssociationType
, element
.MaximumLifetime
);