HttpDigestClientCredential.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) Microsoft Corporation. All rights reserved.
  3. //-----------------------------------------------------------------------------
  4. namespace System.ServiceModel.Security
  5. {
  6. using System.Net;
  7. using System.Security.Principal;
  8. using System.ServiceModel;
  9. public sealed class HttpDigestClientCredential
  10. {
  11. TokenImpersonationLevel allowedImpersonationLevel = WindowsClientCredential.DefaultImpersonationLevel;
  12. NetworkCredential digestCredentials;
  13. bool isReadOnly;
  14. internal HttpDigestClientCredential()
  15. {
  16. this.digestCredentials = new NetworkCredential();
  17. }
  18. internal HttpDigestClientCredential(HttpDigestClientCredential other)
  19. {
  20. this.allowedImpersonationLevel = other.allowedImpersonationLevel;
  21. this.digestCredentials = SecurityUtils.GetNetworkCredentialsCopy(other.digestCredentials);
  22. this.isReadOnly = other.isReadOnly;
  23. }
  24. public TokenImpersonationLevel AllowedImpersonationLevel
  25. {
  26. get
  27. {
  28. return this.allowedImpersonationLevel;
  29. }
  30. set
  31. {
  32. ThrowIfImmutable();
  33. this.allowedImpersonationLevel = value;
  34. }
  35. }
  36. public NetworkCredential ClientCredential
  37. {
  38. get
  39. {
  40. return this.digestCredentials;
  41. }
  42. set
  43. {
  44. ThrowIfImmutable();
  45. this.digestCredentials = value;
  46. }
  47. }
  48. internal void MakeReadOnly()
  49. {
  50. this.isReadOnly = true;
  51. }
  52. void ThrowIfImmutable()
  53. {
  54. if (this.isReadOnly)
  55. {
  56. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.ObjectIsReadOnly)));
  57. }
  58. }
  59. }
  60. }