SspiNegotiationTokenAuthenticatorState.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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.Security.Principal;
  10. using System.Security.Cryptography;
  11. using System.Security.Cryptography.X509Certificates;
  12. using System.Collections.Generic;
  13. using System.ServiceModel.Channels;
  14. using System.Runtime.Serialization;
  15. using System.Net;
  16. using System.Diagnostics;
  17. class SspiNegotiationTokenAuthenticatorState : NegotiationTokenAuthenticatorState
  18. {
  19. ISspiNegotiation sspiNegotiation;
  20. HashAlgorithm negotiationDigest;
  21. string context;
  22. int requestedKeySize;
  23. EndpointAddress appliesTo;
  24. DataContractSerializer appliesToSerializer;
  25. public SspiNegotiationTokenAuthenticatorState(ISspiNegotiation sspiNegotiation)
  26. : base()
  27. {
  28. if (sspiNegotiation == null)
  29. {
  30. throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("sspiNegotiation");
  31. }
  32. this.sspiNegotiation = sspiNegotiation;
  33. this.negotiationDigest = CryptoHelper.NewSha1HashAlgorithm();
  34. }
  35. public ISspiNegotiation SspiNegotiation
  36. {
  37. get
  38. {
  39. return this.sspiNegotiation;
  40. }
  41. }
  42. internal int RequestedKeySize
  43. {
  44. get
  45. {
  46. return this.requestedKeySize;
  47. }
  48. set
  49. {
  50. this.requestedKeySize = value;
  51. }
  52. }
  53. internal HashAlgorithm NegotiationDigest
  54. {
  55. get
  56. {
  57. return this.negotiationDigest;
  58. }
  59. }
  60. internal string Context
  61. {
  62. get
  63. {
  64. return this.context;
  65. }
  66. set
  67. {
  68. this.context = value;
  69. }
  70. }
  71. internal EndpointAddress AppliesTo
  72. {
  73. get
  74. {
  75. return this.appliesTo;
  76. }
  77. set
  78. {
  79. this.appliesTo = value;
  80. }
  81. }
  82. internal DataContractSerializer AppliesToSerializer
  83. {
  84. get
  85. {
  86. return this.appliesToSerializer;
  87. }
  88. set
  89. {
  90. this.appliesToSerializer = value;
  91. }
  92. }
  93. public override string GetRemoteIdentityName()
  94. {
  95. if (this.sspiNegotiation != null && !this.IsNegotiationCompleted)
  96. {
  97. return this.sspiNegotiation.GetRemoteIdentityName();
  98. }
  99. return base.GetRemoteIdentityName();
  100. }
  101. public override void Dispose()
  102. {
  103. try
  104. {
  105. lock (ThisLock)
  106. {
  107. if (this.sspiNegotiation != null)
  108. {
  109. this.sspiNegotiation.Dispose();
  110. }
  111. if (this.negotiationDigest != null)
  112. {
  113. ((IDisposable)this.negotiationDigest).Dispose();
  114. }
  115. }
  116. }
  117. finally
  118. {
  119. base.Dispose();
  120. }
  121. }
  122. }
  123. }