SecureConversationSecurityTokenParameters.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. //
  2. // SecureConversationSecurityTokenParameters.cs
  3. //
  4. // Author:
  5. // Atsushi Enomoto <[email protected]>
  6. //
  7. // Copyright (C) 2006-2007 Novell, Inc. http://www.novell.com
  8. //
  9. // Permission is hereby granted, free of charge, to any person obtaining
  10. // a copy of this software and associated documentation files (the
  11. // "Software"), to deal in the Software without restriction, including
  12. // without limitation the rights to use, copy, modify, merge, publish,
  13. // distribute, sublicense, and/or sell copies of the Software, and to
  14. // permit persons to whom the Software is furnished to do so, subject to
  15. // the following conditions:
  16. //
  17. // The above copyright notice and this permission notice shall be
  18. // included in all copies or substantial portions of the Software.
  19. //
  20. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  21. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  22. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  23. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  24. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  25. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  26. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27. //
  28. using System.IdentityModel.Selectors;
  29. using System.IdentityModel.Tokens;
  30. using System.ServiceModel.Channels;
  31. using System.ServiceModel.Security;
  32. using ReqType = System.ServiceModel.Security.Tokens.ServiceModelSecurityTokenRequirement;
  33. namespace System.ServiceModel.Security.Tokens
  34. {
  35. public class SecureConversationSecurityTokenParameters : SecurityTokenParameters
  36. {
  37. static readonly ChannelProtectionRequirements default_channel_protection_requirements;
  38. static readonly BindingContext dummy_context;
  39. static SecureConversationSecurityTokenParameters ()
  40. {
  41. ChannelProtectionRequirements r =
  42. new ChannelProtectionRequirements ();
  43. r.IncomingSignatureParts.ChannelParts.IsBodyIncluded = true;
  44. r.OutgoingSignatureParts.ChannelParts.IsBodyIncluded = true;
  45. r.IncomingEncryptionParts.ChannelParts.IsBodyIncluded = true;
  46. r.OutgoingEncryptionParts.ChannelParts.IsBodyIncluded = true;
  47. r.MakeReadOnly ();
  48. default_channel_protection_requirements = r;
  49. dummy_context = new BindingContext (
  50. new CustomBinding (),
  51. new BindingParameterCollection ());
  52. }
  53. SecurityBindingElement element;
  54. ChannelProtectionRequirements requirements;
  55. bool cancellable;
  56. public SecureConversationSecurityTokenParameters ()
  57. : this ((SecurityBindingElement) null)
  58. {
  59. }
  60. public SecureConversationSecurityTokenParameters (
  61. SecurityBindingElement element)
  62. : this (element, true)
  63. {
  64. }
  65. public SecureConversationSecurityTokenParameters (
  66. SecurityBindingElement element,
  67. bool requireCancellation)
  68. : this (element, requireCancellation, null)
  69. {
  70. }
  71. public SecureConversationSecurityTokenParameters (
  72. SecurityBindingElement element,
  73. bool requireCancellation,
  74. ChannelProtectionRequirements requirements)
  75. {
  76. this.element = element;
  77. this.cancellable = requireCancellation;
  78. if (requirements == null)
  79. this.requirements = new ChannelProtectionRequirements (default_channel_protection_requirements);
  80. else
  81. this.requirements = new ChannelProtectionRequirements (requirements);
  82. }
  83. protected SecureConversationSecurityTokenParameters (SecureConversationSecurityTokenParameters source)
  84. : base (source)
  85. {
  86. this.element = (SecurityBindingElement) source.element.Clone ();
  87. this.cancellable = source.cancellable;
  88. this.requirements = new ChannelProtectionRequirements (default_channel_protection_requirements);
  89. }
  90. public bool RequireCancellation {
  91. get { return cancellable; }
  92. set { cancellable = value; }
  93. }
  94. public SecurityBindingElement BootstrapSecurityBindingElement {
  95. get { return element; }
  96. set { element = value; }
  97. }
  98. public ChannelProtectionRequirements BootstrapProtectionRequirements {
  99. get { return requirements; }
  100. }
  101. // SecurityTokenParameters
  102. protected override bool HasAsymmetricKey {
  103. get { return false; }
  104. }
  105. protected override bool SupportsClientAuthentication {
  106. get { return element.GetProperty<ISecurityCapabilities> (dummy_context).SupportsClientAuthentication; }
  107. }
  108. protected override bool SupportsClientWindowsIdentity {
  109. get { return element.GetProperty<ISecurityCapabilities> (dummy_context).SupportsClientWindowsIdentity; }
  110. }
  111. protected override bool SupportsServerAuthentication {
  112. get { return element.GetProperty<ISecurityCapabilities> (dummy_context).SupportsServerAuthentication; }
  113. }
  114. protected override SecurityTokenParameters CloneCore ()
  115. {
  116. return new SecureConversationSecurityTokenParameters (this);
  117. }
  118. [MonoTODO]
  119. protected override SecurityKeyIdentifierClause CreateKeyIdentifierClause (
  120. SecurityToken token, SecurityTokenReferenceStyle referenceStyle)
  121. {
  122. throw new NotImplementedException ();
  123. }
  124. [MonoTODO]
  125. protected override void InitializeSecurityTokenRequirement (SecurityTokenRequirement requirement)
  126. {
  127. // .NET somehow causes NRE. dunno why.
  128. requirement.TokenType = ServiceModelSecurityTokenTypes.SecureConversation;
  129. requirement.RequireCryptographicToken = true;
  130. requirement.Properties [ReqType.SupportSecurityContextCancellationProperty] = RequireCancellation;
  131. requirement.Properties [ReqType.SecureConversationSecurityBindingElementProperty] =
  132. BootstrapSecurityBindingElement;
  133. requirement.Properties [ReqType.IssuedSecurityTokenParametersProperty] = this.Clone ();
  134. requirement.KeyType = SecurityKeyType.SymmetricKey;
  135. }
  136. [MonoTODO]
  137. public override string ToString ()
  138. {
  139. return base.ToString ();
  140. }
  141. }
  142. }