summaryrefslogtreecommitdiffstats
path: root/src/DotNetOpenAuth.Core/Configuration/TrustedProviderConfigurationCollection.cs
blob: de70f640060e72a1cf77afb425ca3c5d3b804dfb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//-----------------------------------------------------------------------
// <copyright file="TrustedProviderConfigurationCollection.cs" company="Outercurve Foundation">
//     Copyright (c) Outercurve Foundation. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

namespace DotNetOpenAuth.Configuration {
	using System;
	using System.Collections.Generic;
	using System.Configuration;
	using System.Diagnostics.CodeAnalysis;
	using Validation;

	/// <summary>
	/// A configuration collection of trusted OP Endpoints.
	/// </summary>
	internal class TrustedProviderConfigurationCollection : ConfigurationElementCollection {
		/// <summary>
		/// The name of the "rejectAssertionsFromUntrustedProviders" element.
		/// </summary>
		private const string RejectAssertionsFromUntrustedProvidersConfigName = "rejectAssertionsFromUntrustedProviders";

		/// <summary>
		/// Initializes a new instance of the <see cref="TrustedProviderConfigurationCollection"/> class.
		/// </summary>
		internal TrustedProviderConfigurationCollection() {
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="TrustedProviderConfigurationCollection"/> class.
		/// </summary>
		/// <param name="elements">The elements to initialize the collection with.</param>
		[SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors", Justification = "Seems unavoidable")]
		internal TrustedProviderConfigurationCollection(IEnumerable<TrustedProviderEndpointConfigurationElement> elements) {
			Requires.NotNull(elements, "elements");

			foreach (TrustedProviderEndpointConfigurationElement element in elements) {
				this.BaseAdd(element);
			}
		}

		/// <summary>
		/// Gets or sets a value indicating whether any login attempt coming from an OpenID Provider Endpoint that is not on this
		/// whitelist of trusted OP Endpoints will be rejected.  If the trusted providers list is empty and this value
		/// is true, all assertions are rejected.
		/// </summary>
		[ConfigurationProperty(RejectAssertionsFromUntrustedProvidersConfigName, DefaultValue = false)]
		internal bool RejectAssertionsFromUntrustedProviders {
			get { return (bool)this[RejectAssertionsFromUntrustedProvidersConfigName]; }
			set { this[RejectAssertionsFromUntrustedProvidersConfigName] = value; }
		}

		/// <summary>
		/// When overridden in a derived class, creates a new <see cref="T:System.Configuration.ConfigurationElement"/>.
		/// </summary>
		/// <returns>
		/// A new <see cref="T:System.Configuration.ConfigurationElement"/>.
		/// </returns>
		protected override ConfigurationElement CreateNewElement() {
			return new TrustedProviderEndpointConfigurationElement();
		}

		/// <summary>
		/// Gets the element key for a specified configuration element when overridden in a derived class.
		/// </summary>
		/// <param name="element">The <see cref="T:System.Configuration.ConfigurationElement"/> to return the key for.</param>
		/// <returns>
		/// An <see cref="T:System.Object"/> that acts as the key for the specified <see cref="T:System.Configuration.ConfigurationElement"/>.
		/// </returns>
		protected override object GetElementKey(ConfigurationElement element) {
			return ((TrustedProviderEndpointConfigurationElement)element).ProviderEndpoint;
		}
	}
}