ServicesSection.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. //------------------------------------------------------------------------------
  2. // Copyright (c) Microsoft Corporation. All rights reserved.
  3. //------------------------------------------------------------------------------
  4. namespace System.ServiceModel.Configuration
  5. {
  6. using System.Configuration;
  7. using System.Runtime;
  8. using System.Security;
  9. public sealed partial class ServicesSection : ConfigurationSection, IConfigurationContextProviderInternal
  10. {
  11. [Fx.Tag.SecurityNote(Critical = "Stores information used in a security decision.")]
  12. [SecurityCritical]
  13. EvaluationContextHelper contextHelper;
  14. public ServicesSection()
  15. {
  16. }
  17. [ConfigurationProperty(ConfigurationStrings.DefaultCollectionName, Options = ConfigurationPropertyOptions.IsDefaultCollection)]
  18. public ServiceElementCollection Services
  19. {
  20. get { return (ServiceElementCollection)this[ConfigurationStrings.DefaultCollectionName]; }
  21. }
  22. internal static ServicesSection GetSection()
  23. {
  24. return (ServicesSection)ConfigurationHelpers.GetSection(ConfigurationStrings.ServicesSectionPath);
  25. }
  26. [Fx.Tag.SecurityNote(Critical = "Calls SecurityCritical method UnsafeGetSection which elevates in order to load config."
  27. + "Caller must guard access to resultant config section.")]
  28. [SecurityCritical]
  29. internal static ServicesSection UnsafeGetSection()
  30. {
  31. return (ServicesSection)ConfigurationHelpers.UnsafeGetSection(ConfigurationStrings.ServicesSectionPath);
  32. }
  33. protected override void PostDeserialize()
  34. {
  35. this.ValidateSection();
  36. base.PostDeserialize();
  37. }
  38. void ValidateSection()
  39. {
  40. ContextInformation context = ConfigurationHelpers.GetEvaluationContext(this);
  41. if (context != null)
  42. {
  43. foreach (ServiceElement service in this.Services)
  44. {
  45. BehaviorsSection.ValidateServiceBehaviorReference(service.BehaviorConfiguration, context, service);
  46. foreach (ServiceEndpointElement endpoint in service.Endpoints)
  47. {
  48. if (string.IsNullOrEmpty(endpoint.Kind))
  49. {
  50. if (!string.IsNullOrEmpty(endpoint.EndpointConfiguration))
  51. {
  52. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(SR.GetString(SR.ConfigInvalidAttribute, "endpointConfiguration", "endpoint", "kind")));
  53. }
  54. if (string.IsNullOrEmpty(endpoint.Binding))
  55. {
  56. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(SR.GetString(SR.RequiredAttributeMissing, "binding", "endpoint")));
  57. }
  58. }
  59. if (string.IsNullOrEmpty(endpoint.Binding) && !string.IsNullOrEmpty(endpoint.BindingConfiguration))
  60. {
  61. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(SR.GetString(SR.ConfigInvalidAttribute, "bindingConfiguration", "endpoint", "binding")));
  62. }
  63. BehaviorsSection.ValidateEndpointBehaviorReference(endpoint.BehaviorConfiguration, context, endpoint);
  64. BindingsSection.ValidateBindingReference(endpoint.Binding, endpoint.BindingConfiguration, context, endpoint);
  65. StandardEndpointsSection.ValidateEndpointReference(endpoint.Kind, endpoint.EndpointConfiguration, context, endpoint);
  66. }
  67. }
  68. }
  69. }
  70. [Fx.Tag.SecurityNote(Critical = "Accesses critical field contextHelper.")]
  71. [SecurityCritical]
  72. protected override void Reset(ConfigurationElement parentElement)
  73. {
  74. this.contextHelper.OnReset(parentElement);
  75. base.Reset(parentElement);
  76. }
  77. ContextInformation IConfigurationContextProviderInternal.GetEvaluationContext()
  78. {
  79. return this.EvaluationContext;
  80. }
  81. [Fx.Tag.SecurityNote(Critical = "Accesses critical field contextHelper.",
  82. Miscellaneous = "RequiresReview -- the return value will be used for a security decision -- see comment in interface definition.")]
  83. [SecurityCritical]
  84. ContextInformation IConfigurationContextProviderInternal.GetOriginalEvaluationContext()
  85. {
  86. return this.contextHelper.GetOriginalContext(this);
  87. }
  88. }
  89. }