SendSecurityHeaderElementContainer.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. //------------------------------------------------------------
  2. // Copyright (c) Microsoft Corporation. All rights reserved.
  3. //------------------------------------------------------------
  4. namespace System.ServiceModel.Security
  5. {
  6. using System.IdentityModel.Claims;
  7. using System.ServiceModel;
  8. using System.IdentityModel.Policy;
  9. using System.IdentityModel.Tokens;
  10. using System.ServiceModel.Security.Tokens;
  11. using System.Xml;
  12. using System.Collections.Generic;
  13. using ISecurityElement = System.IdentityModel.ISecurityElement;
  14. class SendSecurityHeaderElementContainer
  15. {
  16. List<SecurityToken> signedSupportingTokens = null;
  17. List<SendSecurityHeaderElement> basicSupportingTokens = null;
  18. List<SecurityToken> endorsingSupportingTokens = null;
  19. List<SecurityToken> endorsingDerivedSupportingTokens = null;
  20. List<SecurityToken> signedEndorsingSupportingTokens = null;
  21. List<SecurityToken> signedEndorsingDerivedSupportingTokens = null;
  22. List<SendSecurityHeaderElement> signatureConfirmations = null;
  23. List<SendSecurityHeaderElement> endorsingSignatures = null;
  24. Dictionary<SecurityToken, SecurityKeyIdentifierClause> securityTokenMappedToIdentifierClause = null;
  25. public SecurityTimestamp Timestamp;
  26. public SecurityToken PrerequisiteToken;
  27. public SecurityToken SourceSigningToken;
  28. public SecurityToken DerivedSigningToken;
  29. public SecurityToken SourceEncryptionToken;
  30. public SecurityToken WrappedEncryptionToken;
  31. public SecurityToken DerivedEncryptionToken;
  32. public ISecurityElement ReferenceList;
  33. public SendSecurityHeaderElement PrimarySignature;
  34. void Add<T>(ref List<T> list, T item)
  35. {
  36. if (list == null)
  37. {
  38. list = new List<T>();
  39. }
  40. list.Add(item);
  41. }
  42. public SecurityToken[] GetSignedSupportingTokens()
  43. {
  44. return (this.signedSupportingTokens != null) ? this.signedSupportingTokens.ToArray() : null;
  45. }
  46. public void AddSignedSupportingToken(SecurityToken token)
  47. {
  48. Add<SecurityToken>(ref this.signedSupportingTokens, token);
  49. }
  50. public List<SecurityToken> EndorsingSupportingTokens
  51. {
  52. get { return this.endorsingSupportingTokens; }
  53. }
  54. public SendSecurityHeaderElement[] GetBasicSupportingTokens()
  55. {
  56. return (this.basicSupportingTokens != null) ? this.basicSupportingTokens.ToArray() : null;
  57. }
  58. public void AddBasicSupportingToken(SendSecurityHeaderElement tokenElement)
  59. {
  60. Add<SendSecurityHeaderElement>(ref this.basicSupportingTokens, tokenElement);
  61. }
  62. public SecurityToken[] GetSignedEndorsingSupportingTokens()
  63. {
  64. return (this.signedEndorsingSupportingTokens != null) ? this.signedEndorsingSupportingTokens.ToArray() : null;
  65. }
  66. public void AddSignedEndorsingSupportingToken(SecurityToken token)
  67. {
  68. Add<SecurityToken>(ref this.signedEndorsingSupportingTokens, token);
  69. }
  70. public SecurityToken[] GetSignedEndorsingDerivedSupportingTokens()
  71. {
  72. return (this.signedEndorsingDerivedSupportingTokens != null) ? this.signedEndorsingDerivedSupportingTokens.ToArray() : null;
  73. }
  74. public void AddSignedEndorsingDerivedSupportingToken(SecurityToken token)
  75. {
  76. Add<SecurityToken>(ref this.signedEndorsingDerivedSupportingTokens, token);
  77. }
  78. public SecurityToken[] GetEndorsingSupportingTokens()
  79. {
  80. return (this.endorsingSupportingTokens != null) ? this.endorsingSupportingTokens.ToArray() : null;
  81. }
  82. public void AddEndorsingSupportingToken(SecurityToken token)
  83. {
  84. Add<SecurityToken>(ref this.endorsingSupportingTokens, token);
  85. }
  86. public SecurityToken[] GetEndorsingDerivedSupportingTokens()
  87. {
  88. return (this.endorsingDerivedSupportingTokens != null) ? this.endorsingDerivedSupportingTokens.ToArray() : null;
  89. }
  90. public void AddEndorsingDerivedSupportingToken(SecurityToken token)
  91. {
  92. Add<SecurityToken>(ref this.endorsingDerivedSupportingTokens, token);
  93. }
  94. public SendSecurityHeaderElement[] GetSignatureConfirmations()
  95. {
  96. return (this.signatureConfirmations != null) ? this.signatureConfirmations.ToArray() : null;
  97. }
  98. public void AddSignatureConfirmation(SendSecurityHeaderElement confirmation)
  99. {
  100. Add<SendSecurityHeaderElement>(ref this.signatureConfirmations, confirmation);
  101. }
  102. public SendSecurityHeaderElement[] GetEndorsingSignatures()
  103. {
  104. return (this.endorsingSignatures != null) ? this.endorsingSignatures.ToArray() : null;
  105. }
  106. public void AddEndorsingSignature(SendSecurityHeaderElement signature)
  107. {
  108. Add<SendSecurityHeaderElement>(ref this.endorsingSignatures, signature);
  109. }
  110. public void MapSecurityTokenToStrClause(SecurityToken securityToken, SecurityKeyIdentifierClause keyIdentifierClause)
  111. {
  112. if (this.securityTokenMappedToIdentifierClause == null)
  113. {
  114. this.securityTokenMappedToIdentifierClause = new Dictionary<SecurityToken, SecurityKeyIdentifierClause>();
  115. }
  116. if (!this.securityTokenMappedToIdentifierClause.ContainsKey(securityToken))
  117. {
  118. this.securityTokenMappedToIdentifierClause.Add(securityToken, keyIdentifierClause);
  119. }
  120. }
  121. public bool TryGetIdentifierClauseFromSecurityToken(SecurityToken securityToken, out SecurityKeyIdentifierClause keyIdentifierClause)
  122. {
  123. keyIdentifierClause = null;
  124. if (securityToken == null
  125. || this.securityTokenMappedToIdentifierClause == null
  126. || !this.securityTokenMappedToIdentifierClause.TryGetValue(securityToken, out keyIdentifierClause))
  127. {
  128. return false;
  129. }
  130. return true;
  131. }
  132. }
  133. }