SecurityHeader.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. //----------------------------------------------------------
  2. // Copyright (c) Microsoft Corporation. All rights reserved.
  3. //------------------------------------------------------------
  4. namespace System.ServiceModel.Security
  5. {
  6. using System.Globalization;
  7. using System.ServiceModel.Channels;
  8. using System.ServiceModel;
  9. using System.ServiceModel.Description;
  10. using System.Xml;
  11. using DictionaryManager = System.IdentityModel.DictionaryManager;
  12. using ISecurityElement = System.IdentityModel.ISecurityElement;
  13. abstract class SecurityHeader : MessageHeader
  14. {
  15. readonly string actor;
  16. readonly SecurityAlgorithmSuite algorithmSuite;
  17. bool encryptedKeyContainsReferenceList = true;
  18. Message message;
  19. readonly bool mustUnderstand;
  20. readonly bool relay;
  21. bool requireMessageProtection = true;
  22. bool processingStarted;
  23. bool maintainSignatureConfirmationState;
  24. readonly SecurityStandardsManager standardsManager;
  25. MessageDirection transferDirection;
  26. SecurityHeaderLayout layout = SecurityHeaderLayout.Strict;
  27. public SecurityHeader(Message message,
  28. string actor, bool mustUnderstand, bool relay,
  29. SecurityStandardsManager standardsManager, SecurityAlgorithmSuite algorithmSuite,
  30. MessageDirection transferDirection)
  31. {
  32. if (message == null)
  33. {
  34. throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("message");
  35. }
  36. if (actor == null)
  37. {
  38. throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("actor");
  39. }
  40. if (standardsManager == null)
  41. {
  42. throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("standardsManager");
  43. }
  44. if (algorithmSuite == null)
  45. {
  46. throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("algorithmSuite");
  47. }
  48. this.message = message;
  49. this.actor = actor;
  50. this.mustUnderstand = mustUnderstand;
  51. this.relay = relay;
  52. this.standardsManager = standardsManager;
  53. this.algorithmSuite = algorithmSuite;
  54. this.transferDirection = transferDirection;
  55. }
  56. public override string Actor
  57. {
  58. get { return this.actor; }
  59. }
  60. public SecurityAlgorithmSuite AlgorithmSuite
  61. {
  62. get { return this.algorithmSuite; }
  63. }
  64. public bool EncryptedKeyContainsReferenceList
  65. {
  66. get { return this.encryptedKeyContainsReferenceList; }
  67. set
  68. {
  69. ThrowIfProcessingStarted();
  70. this.encryptedKeyContainsReferenceList = value;
  71. }
  72. }
  73. public bool RequireMessageProtection
  74. {
  75. get { return this.requireMessageProtection; }
  76. set
  77. {
  78. ThrowIfProcessingStarted();
  79. this.requireMessageProtection = value;
  80. }
  81. }
  82. public bool MaintainSignatureConfirmationState
  83. {
  84. get { return this.maintainSignatureConfirmationState; }
  85. set
  86. {
  87. ThrowIfProcessingStarted();
  88. this.maintainSignatureConfirmationState = value;
  89. }
  90. }
  91. protected Message Message
  92. {
  93. get { return this.message; }
  94. set { this.message = value; }
  95. }
  96. public override bool MustUnderstand
  97. {
  98. get { return this.mustUnderstand; }
  99. }
  100. public override bool Relay
  101. {
  102. get { return this.relay; }
  103. }
  104. public SecurityHeaderLayout Layout
  105. {
  106. get
  107. {
  108. return this.layout;
  109. }
  110. set
  111. {
  112. ThrowIfProcessingStarted();
  113. this.layout = value;
  114. }
  115. }
  116. public SecurityStandardsManager StandardsManager
  117. {
  118. get { return this.standardsManager; }
  119. }
  120. public MessageDirection MessageDirection
  121. {
  122. get { return this.transferDirection; }
  123. }
  124. protected MessageVersion Version
  125. {
  126. get { return this.message.Version; }
  127. }
  128. protected void SetProcessingStarted()
  129. {
  130. this.processingStarted = true;
  131. }
  132. protected void ThrowIfProcessingStarted()
  133. {
  134. if (this.processingStarted)
  135. {
  136. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.OperationCannotBeDoneAfterProcessingIsStarted)));
  137. }
  138. }
  139. public override string ToString()
  140. {
  141. return string.Format(CultureInfo.InvariantCulture, "{0}(Actor = '{1}')", GetType().Name, this.Actor);
  142. }
  143. }
  144. }