WSHttpTransportSecurityElement.cs 3.7 KB

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