TcpTransportSecurityElement.cs 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 TcpTransportSecurityElement : ServiceModelConfigurationElement
  16. {
  17. [ConfigurationProperty(ConfigurationStrings.ClientCredentialType, DefaultValue = TcpTransportSecurity.DefaultClientCredentialType)]
  18. [ServiceModelEnumValidator(typeof(TcpClientCredentialTypeHelper))]
  19. public TcpClientCredentialType ClientCredentialType
  20. {
  21. get { return (TcpClientCredentialType)base[ConfigurationStrings.ClientCredentialType]; }
  22. set { base[ConfigurationStrings.ClientCredentialType] = value; }
  23. }
  24. [ConfigurationProperty(ConfigurationStrings.ProtectionLevel, DefaultValue = TcpTransportSecurity.DefaultProtectionLevel)]
  25. [ServiceModelEnumValidator(typeof(ProtectionLevelHelper))]
  26. public ProtectionLevel ProtectionLevel
  27. {
  28. get { return (ProtectionLevel)base[ConfigurationStrings.ProtectionLevel]; }
  29. set { base[ConfigurationStrings.ProtectionLevel] = 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. internal void ApplyConfiguration(TcpTransportSecurity security)
  38. {
  39. if (security == null)
  40. {
  41. throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("security");
  42. }
  43. security.ClientCredentialType = this.ClientCredentialType;
  44. security.ProtectionLevel = this.ProtectionLevel;
  45. security.ExtendedProtectionPolicy = ChannelBindingUtility.BuildPolicy(this.ExtendedProtectionPolicy);
  46. }
  47. internal void InitializeFrom(TcpTransportSecurity security)
  48. {
  49. if (security == null)
  50. {
  51. throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("security");
  52. }
  53. SetPropertyValueIfNotDefaultValue(ConfigurationStrings.ClientCredentialType, security.ClientCredentialType);
  54. SetPropertyValueIfNotDefaultValue(ConfigurationStrings.ProtectionLevel, security.ProtectionLevel);
  55. ChannelBindingUtility.InitializeFrom(security.ExtendedProtectionPolicy, this.ExtendedProtectionPolicy);
  56. }
  57. }
  58. }