ServiceAuthenticationElement.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. 
  2. namespace System.ServiceModel.Configuration
  3. {
  4. using System.Collections.Generic;
  5. using System.ComponentModel;
  6. using System.Configuration;
  7. using System.IdentityModel.Claims;
  8. using System.IdentityModel.Policy;
  9. using System.Net;
  10. using System.ServiceModel.Channels;
  11. using System.ServiceModel;
  12. using System.ServiceModel.Description;
  13. public sealed partial class ServiceAuthenticationElement : BehaviorExtensionElement
  14. {
  15. public ServiceAuthenticationElement()
  16. {
  17. }
  18. [ConfigurationProperty(ConfigurationStrings.ServiceAuthenticationManagerType, DefaultValue = "")]
  19. [StringValidator(MinLength = 0)]
  20. public string ServiceAuthenticationManagerType
  21. {
  22. get { return (string)base[ConfigurationStrings.ServiceAuthenticationManagerType]; }
  23. set
  24. {
  25. if (String.IsNullOrEmpty(value))
  26. {
  27. value = String.Empty;
  28. }
  29. base[ConfigurationStrings.ServiceAuthenticationManagerType] = value;
  30. }
  31. }
  32. [ConfigurationProperty(ConfigurationStrings.AuthenticationSchemes, DefaultValue = AuthenticationSchemes.None)]
  33. [StandardRuntimeFlagEnumValidator(typeof(AuthenticationSchemes))]
  34. public AuthenticationSchemes AuthenticationSchemes
  35. {
  36. get { return (AuthenticationSchemes)base[ConfigurationStrings.AuthenticationSchemes]; }
  37. set
  38. {
  39. base[ConfigurationStrings.AuthenticationSchemes] = value;
  40. }
  41. }
  42. public override Type BehaviorType
  43. {
  44. get { return typeof(ServiceAuthenticationBehavior); }
  45. }
  46. protected internal override object CreateBehavior()
  47. {
  48. ServiceAuthenticationBehavior behavior = new ServiceAuthenticationBehavior();
  49. string serviceAuthenticationManagerType = this.ServiceAuthenticationManagerType;
  50. if (!String.IsNullOrEmpty(serviceAuthenticationManagerType))
  51. {
  52. Type type = Type.GetType(serviceAuthenticationManagerType, true);
  53. if (!typeof(ServiceAuthenticationManager).IsAssignableFrom(type))
  54. {
  55. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(
  56. SR.GetString(SR.ConfigInvalidServiceAuthenticationManagerType, serviceAuthenticationManagerType, typeof(ServiceAuthenticationManager))));
  57. }
  58. behavior.ServiceAuthenticationManager = (ServiceAuthenticationManager)Activator.CreateInstance(type);
  59. }
  60. if (this.AuthenticationSchemes != AuthenticationSchemes.None)
  61. {
  62. behavior.AuthenticationSchemes = this.AuthenticationSchemes;
  63. }
  64. return behavior;
  65. }
  66. }
  67. }