X509RecipientCertificateServiceElement.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. //------------------------------------------------------------------------------
  2. // Copyright (c) Microsoft Corporation. All rights reserved.
  3. //------------------------------------------------------------------------------
  4. namespace System.ServiceModel.Configuration
  5. {
  6. using System;
  7. using System.ServiceModel;
  8. using System.Configuration;
  9. using System.ServiceModel.Channels;
  10. using System.ServiceModel.Security;
  11. using System.Xml;
  12. using System.Security.Cryptography.X509Certificates;
  13. public sealed partial class X509RecipientCertificateServiceElement : ConfigurationElement
  14. {
  15. public X509RecipientCertificateServiceElement()
  16. {
  17. }
  18. [ConfigurationProperty(ConfigurationStrings.FindValue, DefaultValue = "")]
  19. [StringValidator(MinLength = 0)]
  20. public string FindValue
  21. {
  22. get { return (string)base[ConfigurationStrings.FindValue]; }
  23. set
  24. {
  25. if (String.IsNullOrEmpty(value))
  26. {
  27. value = String.Empty;
  28. }
  29. base[ConfigurationStrings.FindValue] = value;
  30. }
  31. }
  32. [ConfigurationProperty(ConfigurationStrings.StoreLocation, DefaultValue = X509CertificateRecipientServiceCredential.DefaultStoreLocation)]
  33. [StandardRuntimeEnumValidator(typeof(StoreLocation))]
  34. public StoreLocation StoreLocation
  35. {
  36. get { return (StoreLocation)base[ConfigurationStrings.StoreLocation]; }
  37. set { base[ConfigurationStrings.StoreLocation] = value; }
  38. }
  39. [ConfigurationProperty(ConfigurationStrings.StoreName, DefaultValue = X509CertificateRecipientServiceCredential.DefaultStoreName)]
  40. [StandardRuntimeEnumValidator(typeof(StoreName))]
  41. public StoreName StoreName
  42. {
  43. get { return (StoreName)base[ConfigurationStrings.StoreName]; }
  44. set { base[ConfigurationStrings.StoreName] = value; }
  45. }
  46. [ConfigurationProperty(ConfigurationStrings.X509FindType, DefaultValue = X509CertificateRecipientServiceCredential.DefaultFindType)]
  47. [StandardRuntimeEnumValidator(typeof(X509FindType))]
  48. public X509FindType X509FindType
  49. {
  50. get { return (X509FindType)base[ConfigurationStrings.X509FindType]; }
  51. set { base[ConfigurationStrings.X509FindType] = value; }
  52. }
  53. public void Copy(X509RecipientCertificateServiceElement from)
  54. {
  55. if (this.IsReadOnly())
  56. {
  57. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(SR.GetString(SR.ConfigReadOnly)));
  58. }
  59. if (null == from)
  60. {
  61. throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("from");
  62. }
  63. this.FindValue = from.FindValue;
  64. this.StoreLocation = from.StoreLocation;
  65. this.StoreName = from.StoreName;
  66. this.X509FindType = from.X509FindType;
  67. }
  68. internal void ApplyConfiguration(X509CertificateRecipientServiceCredential cert)
  69. {
  70. if (cert == null)
  71. {
  72. throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("cert");
  73. }
  74. PropertyInformationCollection propertyInfo = this.ElementInformation.Properties;
  75. if (propertyInfo[ConfigurationStrings.StoreLocation].ValueOrigin != PropertyValueOrigin.Default
  76. || propertyInfo[ConfigurationStrings.StoreName].ValueOrigin != PropertyValueOrigin.Default
  77. || propertyInfo[ConfigurationStrings.X509FindType].ValueOrigin != PropertyValueOrigin.Default
  78. || propertyInfo[ConfigurationStrings.FindValue].ValueOrigin != PropertyValueOrigin.Default)
  79. {
  80. cert.SetCertificate(this.StoreLocation, this.StoreName, this.X509FindType, this.FindValue);
  81. }
  82. }
  83. }
  84. }