SecureConversationServiceElement.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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.Security;
  10. using System.Xml;
  11. using System.IdentityModel.Tokens;
  12. using System.IdentityModel.Selectors;
  13. public sealed partial class SecureConversationServiceElement : ConfigurationElement
  14. {
  15. public SecureConversationServiceElement()
  16. {
  17. }
  18. [ConfigurationProperty(ConfigurationStrings.SecurityStateEncoderType, DefaultValue = "")]
  19. [StringValidator(MinLength = 0)]
  20. public string SecurityStateEncoderType
  21. {
  22. get { return (string)base[ConfigurationStrings.SecurityStateEncoderType]; }
  23. set
  24. {
  25. if (String.IsNullOrEmpty(value))
  26. {
  27. value = String.Empty;
  28. }
  29. base[ConfigurationStrings.SecurityStateEncoderType] = value;
  30. }
  31. }
  32. public void Copy(SecureConversationServiceElement 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.SecurityStateEncoderType = from.SecurityStateEncoderType;
  43. }
  44. internal void ApplyConfiguration(SecureConversationServiceCredential secureConversation)
  45. {
  46. if (secureConversation == null)
  47. {
  48. throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("secureConversation");
  49. }
  50. if (!string.IsNullOrEmpty(this.SecurityStateEncoderType))
  51. {
  52. Type type = System.Type.GetType(this.SecurityStateEncoderType, true);
  53. if (!typeof(SecurityStateEncoder).IsAssignableFrom(type))
  54. {
  55. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(
  56. SR.GetString(SR.ConfigInvalidSecurityStateEncoderType, this.SecurityStateEncoderType, typeof(SecurityStateEncoder).ToString())));
  57. }
  58. secureConversation.SecurityStateEncoder = (SecurityStateEncoder)Activator.CreateInstance(type);
  59. }
  60. }
  61. }
  62. }