//----------------------------------------------------------------------- // // Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------- namespace System.IdentityModel.Tokens { using System; using System.Collections.Generic; using System.IdentityModel.Configuration; using System.IdentityModel.Selectors; using System.Linq; using System.Text; /// /// A class which manages multiple named . /// public class SecurityTokenHandlerCollectionManager { private Dictionary collections = new Dictionary(); private string serviceName = ConfigurationStrings.DefaultServiceName; /// /// Initialize an instance of for a given named service. /// /// A indicating the name of the associated service. public SecurityTokenHandlerCollectionManager(string serviceName) { if (serviceName == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("serviceName"); } this.serviceName = serviceName; } /// /// Initialized with default service configuration. /// private SecurityTokenHandlerCollectionManager() : this(ConfigurationStrings.DefaultServiceName) { } /// /// Gets a count of the number of SecurityTokenHandlerCollections in this /// SecurityTokenHandlerCollectionManager. /// public int Count { get { return this.collections.Count; } } /// /// Gets the service name. /// public string ServiceName { get { return this.serviceName; } } /// /// Gets an enumeration over the SecurityTokenHandlerCollection list. /// public IEnumerable SecurityTokenHandlerCollections { get { return this.collections.Values; } } /// /// The SecurityTokenHandlerCollection for the specified usage. /// /// The usage name for the SecurityTokenHandlerCollection. /// A SecurityTokenHandlerCollection /// /// Behaves like a dictionary in that it will throw an exception if there is no /// value for the specified key. /// public SecurityTokenHandlerCollection this[string usage] { get { // Empty String is valid (Usage.Default) if (null == usage) { throw DiagnosticUtility.ThrowHelperArgumentNullOrEmptyString("usage"); } return this.collections[usage]; } set { // Empty String is valid (Usage.Default) if (null == usage) { throw DiagnosticUtility.ThrowHelperArgumentNullOrEmptyString("usage"); } this.collections[usage] = value; } } /// /// No token handlers are created. /// /// An empty token handler collection manager. public static SecurityTokenHandlerCollectionManager CreateEmptySecurityTokenHandlerCollectionManager() { return new SecurityTokenHandlerCollectionManager(ConfigurationStrings.DefaultConfigurationElementName); } /// /// Creates the default set of SecurityTokenHandlers. /// /// A SecurityTokenHandlerCollectionManager with a default collection of token handlers. public static SecurityTokenHandlerCollectionManager CreateDefaultSecurityTokenHandlerCollectionManager() { SecurityTokenHandlerCollection defaultHandlers = SecurityTokenHandlerCollection.CreateDefaultSecurityTokenHandlerCollection(); SecurityTokenHandlerCollectionManager defaultManager = new SecurityTokenHandlerCollectionManager(ConfigurationStrings.DefaultServiceName); defaultManager.collections.Clear(); defaultManager.collections.Add(SecurityTokenHandlerCollectionManager.Usage.Default, defaultHandlers); return defaultManager; } /// /// Checks if a SecurityTokenHandlerCollection exists for the given usage. /// /// A string that represents the usage of the SecurityTokenHandlerCollection. /// Whether or not a token handler collection exists for the given usage. public bool ContainsKey(string usage) { return this.collections.ContainsKey(usage); } /// /// Defines standard collection names used by the framework. /// public static class Usage { /// /// Used to reference the default collection of handlers. /// public const string Default = ""; /// /// Used to reference a collection of handlers for ActAs element processing. /// public const string ActAs = "ActAs"; /// /// Used to reference a collection of handlers for OnBehalfOf element processing. /// public const string OnBehalfOf = "OnBehalfOf"; } } }