The Labs \ Source Viewer \ SSCLI \ System.Configuration \ ProtectedConfiguration

  1. //------------------------------------------------------------------------------
  2. // <copyright file="ProtectedConfiguration.cs" company="Microsoft">
  3. //
  4. // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
  5. //
  6. // The use and distribution terms for this software are contained in the file
  7. // named license.txt, which can be found in the root of this distribution.
  8. // By using this software in any fashion, you are agreeing to be bound by the
  9. // terms of this license.
  10. //
  11. // You must not remove this notice, or any other, from this software.
  12. //
  13. // </copyright>
  14. //------------------------------------------------------------------------------
  15. namespace System.Configuration
  16. {
  17.     using System.Collections;
  18.     using System.Collections.Specialized;
  19.     using System.Runtime.Serialization;
  20.     using System.Configuration.Provider;
  21.     using System.Xml;
  22.     using System.Security.Permissions;
  23.    
  24.     [PermissionSet(SecurityAction.LinkDemand, Name = "FullTrust")]
  25.     public static class ProtectedConfiguration
  26.     {
  27.         public static ProtectedConfigurationProviderCollection Providers {
  28.             get {
  29.                 ProtectedConfigurationSection config = PrivilegedConfigurationManager.GetSection(BaseConfigurationRecord.RESERVED_SECTION_PROTECTED_CONFIGURATION) as ProtectedConfigurationSection;
  30.                 if (config == null)
  31.                     return new ProtectedConfigurationProviderCollection();
  32.                
  33.                 return config.GetAllProviders();
  34.             }
  35.         }
  36.        
  37.         public const string RsaProviderName = "RsaProtectedConfigurationProvider";
  38.         public const string DataProtectionProviderName = "DataProtectionConfigurationProvider";
  39.         public const string ProtectedDataSectionName = BaseConfigurationRecord.RESERVED_SECTION_PROTECTED_CONFIGURATION;
  40.        
  41.         public static string DefaultProvider {
  42.             get {
  43.                 ProtectedConfigurationSection config = PrivilegedConfigurationManager.GetSection(BaseConfigurationRecord.RESERVED_SECTION_PROTECTED_CONFIGURATION) as ProtectedConfigurationSection;
  44.                 if (config != null)
  45.                     return config.DefaultProvider;
  46.                
  47.                 return "";
  48.             }
  49.         }
  50.        
  51.        
  52.         ///////////////////////////////////////////////////////////////////////////
  53.         ///////////////////////////////////////////////////////////////////////////
  54.         ///////////////////////////////////////////////////////////////////////////
  55.         #if CACHE_PROVIDERS_IN_STATIC
  56.         private static void InstantiateProviders()
  57.         {
  58.             if (_Providers != null)
  59.                 return;
  60.            
  61.             lock (_Lock) {
  62.                 if (_Providers != null)
  63.                     return;
  64.                
  65.                 ProtectedConfigurationProviderCollection providers = new ProtectedConfigurationProviderCollection();
  66.                 ProtectedConfigurationSection config = PrivilegedConfigurationManager.GetSection(BaseConfigurationRecord.RESERVED_SECTION_PROTECTED_CONFIGURATION) as ProtectedConfigurationSection;
  67.                
  68.                 if (config != null) {
  69.                     foreach (DictionaryEntry de in config.ProviderNodes) {
  70.                         ProviderNode pn = de.Value as ProviderNode;
  71.                        
  72.                         if (pn == null)
  73.                             continue;
  74.                        
  75.                         providers.Add(pn.Provider);
  76.                     }
  77.                 }
  78.                
  79.                 _Providers = providers;
  80.             }
  81.         }
  82.         private static object _Lock = new object();
  83.         private static ProtectedConfigurationProviderCollection _Providers = null;
  84.         #endif
  85.        
  86.     }
  87. }

Developer Fusion