The Labs \ Source Viewer \ SSCLI \ System.Net.Configuration \ AuthenticationModulesSection

  1. //------------------------------------------------------------------------------
  2. // <copyright file="AuthenticationModulesSection.cs" company="Microsoft Corporation">
  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.Net.Configuration
  16. {
  17.     using System.Configuration;
  18.     using System.Collections.Generic;
  19.     using System.Globalization;
  20.     using System.Net;
  21.     using System.Threading;
  22.    
  23.     public sealed class AuthenticationModulesSection : ConfigurationSection
  24.     {
  25.         public AuthenticationModulesSection()
  26.         {
  27.             this.properties.Add(this.authenticationModules);
  28.         }
  29.        
  30.         protected override void PostDeserialize()
  31.         {
  32.             // Perf optimization. If the configuration is coming from machine.config
  33.             // It is safe and we don't need to check for permissions.
  34.             if (EvaluationContext.IsMachineLevel)
  35.                 return;
  36.            
  37.             try {
  38.                 ExceptionHelper.UnmanagedPermission.Demand();
  39.             }
  40.             catch (Exception exception) {
  41.                 throw new ConfigurationErrorsException(SR.GetString(SR.net_config_section_permission, ConfigurationStrings.AuthenticationModulesSectionName), exception);
  42.             }
  43.         }
  44.        
  45.         [ConfigurationProperty("", IsDefaultCollection = true)]
  46.         public AuthenticationModuleElementCollection AuthenticationModules {
  47.             get { return (AuthenticationModuleElementCollection)this[this.authenticationModules]; }
  48.         }
  49.        
  50.         protected override void InitializeDefault()
  51.         {
  52.         }
  53.        
  54.         protected override ConfigurationPropertyCollection Properties {
  55.             get { return this.properties; }
  56.         }
  57.        
  58.         ConfigurationPropertyCollection properties = new ConfigurationPropertyCollection();
  59.        
  60.         readonly ConfigurationProperty authenticationModules = new ConfigurationProperty(null, typeof(AuthenticationModuleElementCollection), null, ConfigurationPropertyOptions.IsDefaultCollection);
  61.     }
  62.    
  63.     internal sealed class AuthenticationModulesSectionInternal
  64.     {
  65.         internal AuthenticationModulesSectionInternal(AuthenticationModulesSection section)
  66.         {
  67.             if (section.AuthenticationModules.Count > 0) {
  68.                 this.authenticationModules = new List<Type>(section.AuthenticationModules.Count);
  69.                 foreach (AuthenticationModuleElement authenticationModuleElement in section.AuthenticationModules) {
  70.                     Type type = null;
  71.                    
  72.                     try {
  73.                         type = Type.GetType(authenticationModuleElement.Type, true, true);
  74.                        
  75.                         // verify that its of the proper type of object
  76.                         if (!typeof(IAuthenticationModule).IsAssignableFrom(type)) {
  77.                             throw new InvalidCastException(SR.GetString(SR.net_invalid_cast, type.FullName, "IAuthenticationModule"));
  78.                         }
  79.                     }
  80.                     catch (Exception exception) {
  81.                         if (NclUtilities.IsFatal(exception))
  82.                             throw;
  83.                        
  84.                         throw new ConfigurationErrorsException(SR.GetString(SR.net_config_authenticationmodules), exception);
  85.                     }
  86.                     catch {
  87.                         throw new ConfigurationErrorsException(SR.GetString(SR.net_config_authenticationmodules), new Exception(SR.GetString(SR.net_nonClsCompliantException)));
  88.                     }
  89.                    
  90.                     this.authenticationModules.Add(type);
  91.                 }
  92.             }
  93.         }
  94.        
  95.         internal List<Type> AuthenticationModules {
  96.             get {
  97.                 List<Type> retval = this.authenticationModules;
  98.                 if (retval == null) {
  99.                     retval = new List<Type>(0);
  100.                 }
  101.                 return retval;
  102.             }
  103.         }
  104.        
  105.         static internal object ClassSyncObject {
  106.             get {
  107.                 if (classSyncObject == null) {
  108.                     object o = new object();
  109.                     Interlocked.CompareExchange(ref classSyncObject, o, null);
  110.                 }
  111.                 return classSyncObject;
  112.             }
  113.         }
  114.        
  115.         static internal AuthenticationModulesSectionInternal GetSection()
  116.         {
  117.             lock (AuthenticationModulesSectionInternal.ClassSyncObject) {
  118.                 AuthenticationModulesSection section = PrivilegedConfigurationManager.GetSection(ConfigurationStrings.AuthenticationModulesSectionPath) as AuthenticationModulesSection;
  119.                 if (section == null)
  120.                     return null;
  121.                
  122.                 return new AuthenticationModulesSectionInternal(section);
  123.             }
  124.         }
  125.        
  126.         List<Type> authenticationModules = null;
  127.         static object classSyncObject = null;
  128.     }
  129. }

Developer Fusion