PeerSecurityElement.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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.ServiceModel;
  12. using System.ServiceModel.Security;
  13. using System.ComponentModel;
  14. public sealed partial class PeerSecurityElement : ServiceModelConfigurationElement
  15. {
  16. [ConfigurationProperty(ConfigurationStrings.Mode, DefaultValue = PeerSecuritySettings.DefaultMode)]
  17. [ServiceModelEnumValidator(typeof(SecurityModeHelper))]
  18. public SecurityMode Mode
  19. {
  20. get { return (SecurityMode)base[ConfigurationStrings.Mode]; }
  21. set { base[ConfigurationStrings.Mode] = value; }
  22. }
  23. [ConfigurationProperty(ConfigurationStrings.Transport)]
  24. public PeerTransportSecurityElement Transport
  25. {
  26. get { return (PeerTransportSecurityElement)base[ConfigurationStrings.Transport]; }
  27. }
  28. internal void ApplyConfiguration(PeerSecuritySettings security)
  29. {
  30. if (security == null)
  31. {
  32. throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("security");
  33. }
  34. security.Mode = this.Mode;
  35. if (security.Mode != SecurityMode.None)
  36. {
  37. this.Transport.ApplyConfiguration(security.Transport);
  38. }
  39. }
  40. internal void InitializeFrom(PeerSecuritySettings security)
  41. {
  42. if (security == null)
  43. {
  44. throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("security");
  45. }
  46. SetPropertyValueIfNotDefaultValue(ConfigurationStrings.Mode, security.Mode);
  47. if (security.Mode != SecurityMode.None)
  48. {
  49. this.Transport.InitializeFrom(security.Transport);
  50. }
  51. }
  52. internal void CopyFrom(PeerSecurityElement source)
  53. {
  54. if (source == null)
  55. {
  56. throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("security");
  57. }
  58. this.Mode = source.Mode;
  59. if (source.Mode != SecurityMode.None)
  60. {
  61. this.Transport.CopyFrom(source.Transport);
  62. }
  63. }
  64. }
  65. }