WindowsClientElement.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. //------------------------------------------------------------------------------
  2. // Copyright (c) Microsoft Corporation. All rights reserved.
  3. //------------------------------------------------------------------------------
  4. namespace System.ServiceModel.Configuration
  5. {
  6. using System;
  7. using System.ServiceModel;
  8. using System.Configuration;
  9. using System.ServiceModel.Security;
  10. using System.ServiceModel.Channels;
  11. using System.Xml;
  12. using System.Security.Principal;
  13. using System.Security.Cryptography.X509Certificates;
  14. public sealed partial class WindowsClientElement : ConfigurationElement
  15. {
  16. public WindowsClientElement()
  17. {
  18. }
  19. [ConfigurationProperty(ConfigurationStrings.AllowNtlm, DefaultValue = SspiSecurityTokenProvider.DefaultAllowNtlm)]
  20. public bool AllowNtlm
  21. {
  22. get { return (bool)base[ConfigurationStrings.AllowNtlm]; }
  23. set { base[ConfigurationStrings.AllowNtlm] = value; }
  24. }
  25. [ConfigurationProperty(ConfigurationStrings.AllowedImpersonationLevel, DefaultValue = WindowsClientCredential.DefaultImpersonationLevel)]
  26. [ServiceModelEnumValidator(typeof(TokenImpersonationLevelHelper))]
  27. public TokenImpersonationLevel AllowedImpersonationLevel
  28. {
  29. get { return (TokenImpersonationLevel)base[ConfigurationStrings.AllowedImpersonationLevel]; }
  30. set { base[ConfigurationStrings.AllowedImpersonationLevel] = value; }
  31. }
  32. public void Copy(WindowsClientElement from)
  33. {
  34. if (this.IsReadOnly())
  35. {
  36. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(SR.GetString(SR.ConfigReadOnly)));
  37. }
  38. if (null == from)
  39. {
  40. throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("from");
  41. }
  42. this.AllowNtlm = from.AllowNtlm;
  43. this.AllowedImpersonationLevel = from.AllowedImpersonationLevel;
  44. }
  45. internal void ApplyConfiguration(WindowsClientCredential windows)
  46. {
  47. if (windows == null)
  48. {
  49. throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("windows");
  50. }
  51. // To suppress AllowNtlm warning.
  52. #pragma warning disable 618
  53. windows.AllowNtlm = this.AllowNtlm;
  54. #pragma warning restore 618
  55. windows.AllowedImpersonationLevel = this.AllowedImpersonationLevel;
  56. }
  57. }
  58. }