PeerCredentialElement.cs 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. //------------------------------------------------------------------------------
  2. // Copyright (c) Microsoft Corporation. All rights reserved.
  3. //------------------------------------------------------------------------------
  4. namespace System.ServiceModel.Configuration
  5. {
  6. using System;
  7. using System.Configuration;
  8. using System.ServiceModel.Channels;
  9. using System.ServiceModel.Security;
  10. using System.Xml;
  11. using System.Security.Cryptography.X509Certificates;
  12. public sealed partial class PeerCredentialElement : ConfigurationElement
  13. {
  14. public PeerCredentialElement()
  15. {
  16. }
  17. [ConfigurationProperty(ConfigurationStrings.Certificate)]
  18. public X509PeerCertificateElement Certificate
  19. {
  20. get { return (X509PeerCertificateElement)base[ConfigurationStrings.Certificate]; }
  21. }
  22. [ConfigurationProperty(ConfigurationStrings.PeerAuthentication)]
  23. public X509PeerCertificateAuthenticationElement PeerAuthentication
  24. {
  25. get { return (X509PeerCertificateAuthenticationElement)base[ConfigurationStrings.PeerAuthentication]; }
  26. }
  27. [ConfigurationProperty(ConfigurationStrings.MessageSenderAuthentication)]
  28. public X509PeerCertificateAuthenticationElement MessageSenderAuthentication
  29. {
  30. get { return (X509PeerCertificateAuthenticationElement)base[ConfigurationStrings.MessageSenderAuthentication]; }
  31. }
  32. public void Copy(PeerCredentialElement from)
  33. {
  34. if (this.IsReadOnly())
  35. {
  36. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(SR.GetString(SR.ConfigReadOnly)));
  37. }
  38. if (null == from)
  39. {
  40. throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("from");
  41. }
  42. this.Certificate.Copy(from.Certificate);
  43. this.PeerAuthentication.Copy(from.PeerAuthentication);
  44. this.MessageSenderAuthentication.Copy(from.MessageSenderAuthentication);
  45. }
  46. internal void ApplyConfiguration(PeerCredential creds)
  47. {
  48. if (creds == null)
  49. {
  50. throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("creds");
  51. }
  52. PropertyInformationCollection propertyInfo = this.ElementInformation.Properties;
  53. if (propertyInfo[ConfigurationStrings.Certificate].ValueOrigin != PropertyValueOrigin.Default)
  54. {
  55. this.Certificate.ApplyConfiguration(creds);
  56. }
  57. if (propertyInfo[ConfigurationStrings.PeerAuthentication].ValueOrigin != PropertyValueOrigin.Default)
  58. {
  59. this.PeerAuthentication.ApplyConfiguration(creds.PeerAuthentication);
  60. }
  61. if (propertyInfo[ConfigurationStrings.MessageSenderAuthentication].ValueOrigin != PropertyValueOrigin.Default)
  62. {
  63. this.MessageSenderAuthentication.ApplyConfiguration(creds.MessageSenderAuthentication);
  64. }
  65. }
  66. }
  67. }