NegotiationTokenAuthenticatorState.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) Microsoft Corporation. All rights reserved.
  3. //-----------------------------------------------------------------------------
  4. namespace System.ServiceModel.Security
  5. {
  6. using System;
  7. using System.ServiceModel;
  8. using System.Collections;
  9. using System.Collections.Generic;
  10. using System.IdentityModel.Claims;
  11. using System.IdentityModel.Policy;
  12. using System.ServiceModel.Security.Tokens;
  13. class NegotiationTokenAuthenticatorState : IDisposable
  14. {
  15. bool isNegotiationCompleted;
  16. SecurityContextSecurityToken serviceToken;
  17. Object thisLock;
  18. public NegotiationTokenAuthenticatorState()
  19. {
  20. thisLock = new Object();
  21. }
  22. public Object ThisLock
  23. {
  24. get
  25. {
  26. return thisLock;
  27. }
  28. }
  29. public bool IsNegotiationCompleted
  30. {
  31. get
  32. {
  33. return this.isNegotiationCompleted;
  34. }
  35. }
  36. public SecurityContextSecurityToken ServiceToken
  37. {
  38. get
  39. {
  40. CheckCompleted();
  41. return this.serviceToken;
  42. }
  43. }
  44. public virtual void Dispose() { }
  45. public void SetServiceToken(SecurityContextSecurityToken token)
  46. {
  47. if (token == null)
  48. {
  49. throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("token");
  50. }
  51. this.serviceToken = token;
  52. this.isNegotiationCompleted = true;
  53. }
  54. public virtual string GetRemoteIdentityName()
  55. {
  56. if (this.isNegotiationCompleted)
  57. {
  58. return SecurityUtils.GetIdentityNamesFromPolicies(this.serviceToken.AuthorizationPolicies);
  59. }
  60. return String.Empty;
  61. }
  62. void CheckCompleted()
  63. {
  64. if (!this.isNegotiationCompleted)
  65. {
  66. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.NegotiationIsNotCompleted)));
  67. }
  68. }
  69. }
  70. }