2
0

HttpTransportSecurityElement.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. //------------------------------------------------------------------------------
  2. // Copyright (c) Microsoft Corporation. All rights reserved.
  3. //------------------------------------------------------------------------------
  4. namespace System.ServiceModel.Configuration
  5. {
  6. using System.Configuration;
  7. using System.Diagnostics.CodeAnalysis;
  8. using System.ServiceModel.Channels;
  9. using System.Globalization;
  10. using System.Net;
  11. using System.Net.Security;
  12. using System.Runtime;
  13. using System.Security.Authentication.ExtendedProtection.Configuration;
  14. using System.ServiceModel;
  15. using System.ServiceModel.Security;
  16. using System.ComponentModel;
  17. public sealed partial class HttpTransportSecurityElement : ServiceModelConfigurationElement
  18. {
  19. [ConfigurationProperty(ConfigurationStrings.ClientCredentialType, DefaultValue = HttpTransportSecurity.DefaultClientCredentialType)]
  20. [ServiceModelEnumValidator(typeof(HttpClientCredentialTypeHelper))]
  21. public HttpClientCredentialType ClientCredentialType
  22. {
  23. get { return (HttpClientCredentialType)base[ConfigurationStrings.ClientCredentialType]; }
  24. set { base[ConfigurationStrings.ClientCredentialType] = value; }
  25. }
  26. [ConfigurationProperty(ConfigurationStrings.ProxyCredentialType, DefaultValue = HttpTransportSecurity.DefaultProxyCredentialType)]
  27. [ServiceModelEnumValidator(typeof(HttpProxyCredentialTypeHelper))]
  28. public HttpProxyCredentialType ProxyCredentialType
  29. {
  30. get { return (HttpProxyCredentialType)base[ConfigurationStrings.ProxyCredentialType]; }
  31. set { base[ConfigurationStrings.ProxyCredentialType] = value; }
  32. }
  33. [ConfigurationProperty(ConfigurationStrings.ExtendedProtectionPolicy)]
  34. public ExtendedProtectionPolicyElement ExtendedProtectionPolicy
  35. {
  36. get { return (ExtendedProtectionPolicyElement)base[ConfigurationStrings.ExtendedProtectionPolicy]; }
  37. private set { base[ConfigurationStrings.ExtendedProtectionPolicy] = value; }
  38. }
  39. [ConfigurationProperty(ConfigurationStrings.Realm, DefaultValue = HttpTransportSecurity.DefaultRealm)]
  40. [StringValidator(MinLength = 0)]
  41. public string Realm
  42. {
  43. get { return (string)base[ConfigurationStrings.Realm]; }
  44. set
  45. {
  46. if (String.IsNullOrEmpty(value))
  47. {
  48. value = String.Empty;
  49. }
  50. base[ConfigurationStrings.Realm] = value;
  51. }
  52. }
  53. internal void ApplyConfiguration(HttpTransportSecurity security)
  54. {
  55. if (security == null)
  56. {
  57. throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("security");
  58. }
  59. security.ClientCredentialType = this.ClientCredentialType;
  60. security.ProxyCredentialType = this.ProxyCredentialType;
  61. security.Realm = this.Realm;
  62. security.ExtendedProtectionPolicy = ChannelBindingUtility.BuildPolicy(this.ExtendedProtectionPolicy);
  63. }
  64. internal void InitializeFrom(HttpTransportSecurity security)
  65. {
  66. if (security == null)
  67. {
  68. throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("security");
  69. }
  70. SetPropertyValueIfNotDefaultValue(ConfigurationStrings.ClientCredentialType, security.ClientCredentialType);
  71. SetPropertyValueIfNotDefaultValue(ConfigurationStrings.ProxyCredentialType, security.ProxyCredentialType);
  72. SetPropertyValueIfNotDefaultValue(ConfigurationStrings.Realm, security.Realm);
  73. ChannelBindingUtility.InitializeFrom(security.ExtendedProtectionPolicy, this.ExtendedProtectionPolicy);
  74. }
  75. }
  76. }