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 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
|
//-----------------------------------------------------------------------
// <copyright file="SecurityTokenHandlerCollectionManager.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
namespace System.IdentityModel.Tokens
{
using System;
using System.Collections.Generic;
using System.IdentityModel.Configuration;
using System.IdentityModel.Selectors;
using System.Linq;
using System.Text;
/// <summary>
/// A class which manages multiple named <see cref="SecurityTokenHandlerCollection"/>.
/// </summary>
public class SecurityTokenHandlerCollectionManager
{
private Dictionary<string, SecurityTokenHandlerCollection> collections = new Dictionary<string, SecurityTokenHandlerCollection>();
private string serviceName = ConfigurationStrings.DefaultServiceName;
/// <summary>
/// Initialize an instance of <see cref="SecurityTokenHandlerCollectionManager"/> for a given named service.
/// </summary>
/// <param name="serviceName">A <see cref="String"/> indicating the name of the associated service.</param>
public SecurityTokenHandlerCollectionManager(string serviceName)
{
if (serviceName == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("serviceName");
}
this.serviceName = serviceName;
}
/// <summary>
/// Initialized with default service configuration.
/// </summary>
private SecurityTokenHandlerCollectionManager()
: this(ConfigurationStrings.DefaultServiceName)
{
}
/// <summary>
/// Gets a count of the number of SecurityTokenHandlerCollections in this
/// SecurityTokenHandlerCollectionManager.
/// </summary>
public int Count
{
get { return this.collections.Count; }
}
/// <summary>
/// Gets the service name.
/// </summary>
public string ServiceName
{
get { return this.serviceName; }
}
/// <summary>
/// Gets an enumeration over the SecurityTokenHandlerCollection list.
/// </summary>
public IEnumerable<SecurityTokenHandlerCollection> SecurityTokenHandlerCollections
{
get
{
return this.collections.Values;
}
}
/// <summary>
/// The SecurityTokenHandlerCollection for the specified usage.
/// </summary>
/// <param name="usage">The usage name for the SecurityTokenHandlerCollection.</param>
/// <returns>A SecurityTokenHandlerCollection</returns>
/// <remarks>
/// Behaves like a dictionary in that it will throw an exception if there is no
/// value for the specified key.
/// </remarks>
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;
}
}
/// <summary>
/// No token handlers are created.
/// </summary>
/// <returns>An empty token handler collection manager.</returns>
public static SecurityTokenHandlerCollectionManager CreateEmptySecurityTokenHandlerCollectionManager()
{
return new SecurityTokenHandlerCollectionManager(ConfigurationStrings.DefaultConfigurationElementName);
}
/// <summary>
/// Creates the default set of SecurityTokenHandlers.
/// </summary>
/// <returns>A SecurityTokenHandlerCollectionManager with a default collection of token handlers.</returns>
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;
}
/// <summary>
/// Checks if a SecurityTokenHandlerCollection exists for the given usage.
/// </summary>
/// <param name="usage">A string that represents the usage of the SecurityTokenHandlerCollection.</param>
/// <returns>Whether or not a token handler collection exists for the given usage.</returns>
public bool ContainsKey(string usage)
{
return this.collections.ContainsKey(usage);
}
/// <summary>
/// Defines standard collection names used by the framework.
/// </summary>
public static class Usage
{
/// <summary>
/// Used to reference the default collection of handlers.
/// </summary>
public const string Default = "";
/// <summary>
/// Used to reference a collection of handlers for ActAs element processing.
/// </summary>
public const string ActAs = "ActAs";
/// <summary>
/// Used to reference a collection of handlers for OnBehalfOf element processing.
/// </summary>
public const string OnBehalfOf = "OnBehalfOf";
}
}
}
|