FormsAuthenticationConfiguration.cs 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. //
  2. // System.Web.Configuration.FormsAuthenticationConfiguration
  3. //
  4. // Authors:
  5. // Lluis Sanchez Gual ([email protected])
  6. // Chris Toshok ([email protected])
  7. //
  8. // (C) 2004-2005 Novell, Inc (http://www.novell.com)
  9. //
  10. //
  11. // Permission is hereby granted, free of charge, to any person obtaining
  12. // a copy of this software and associated documentation files (the
  13. // "Software"), to deal in the Software without restriction, including
  14. // without limitation the rights to use, copy, modify, merge, publish,
  15. // distribute, sublicense, and/or sell copies of the Software, and to
  16. // permit persons to whom the Software is furnished to do so, subject to
  17. // the following conditions:
  18. //
  19. // The above copyright notice and this permission notice shall be
  20. // included in all copies or substantial portions of the Software.
  21. //
  22. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  23. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  24. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  25. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  26. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  27. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  28. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  29. //
  30. #if NET_2_0
  31. using System.Configuration;
  32. using System.ComponentModel;
  33. namespace System.Web.Configuration
  34. {
  35. public sealed class FormsAuthenticationConfiguration: ConfigurationElement
  36. {
  37. static ConfigurationPropertyCollection properties;
  38. static ConfigurationProperty cookielessProp;
  39. static ConfigurationProperty credentialsProp;
  40. static ConfigurationProperty defaultUrlProp;
  41. static ConfigurationProperty domainProp;
  42. static ConfigurationProperty enableCrossAppRedirectsProp;
  43. static ConfigurationProperty loginUrlProp;
  44. static ConfigurationProperty nameProp;
  45. static ConfigurationProperty pathProp;
  46. static ConfigurationProperty protectionProp;
  47. static ConfigurationProperty requireSSLProp;
  48. static ConfigurationProperty slidingExpirationProp;
  49. static ConfigurationProperty timeoutProp;
  50. static ConfigurationElementProperty elementProperty;
  51. static FormsAuthenticationConfiguration ()
  52. {
  53. cookielessProp = new ConfigurationProperty ("cookieless", typeof (HttpCookieMode), HttpCookieMode.UseDeviceProfile,
  54. new GenericEnumConverter (typeof (HttpCookieMode)), PropertyHelper.DefaultValidator,
  55. ConfigurationPropertyOptions.None);
  56. credentialsProp = new ConfigurationProperty ("credentials", typeof (FormsAuthenticationCredentials), null,
  57. null, PropertyHelper.DefaultValidator,
  58. ConfigurationPropertyOptions.None);
  59. defaultUrlProp = new ConfigurationProperty ("defaultUrl", typeof (string), "default.aspx",
  60. TypeDescriptor.GetConverter (typeof (string)),
  61. PropertyHelper.NonEmptyStringValidator,
  62. ConfigurationPropertyOptions.None);
  63. domainProp = new ConfigurationProperty ("domain", typeof (string), "");
  64. enableCrossAppRedirectsProp = new ConfigurationProperty ("enableCrossAppRedirects", typeof (bool), false);
  65. loginUrlProp = new ConfigurationProperty ("loginUrl", typeof (string), "login.aspx",
  66. TypeDescriptor.GetConverter (typeof (string)),
  67. PropertyHelper.NonEmptyStringValidator,
  68. ConfigurationPropertyOptions.None);
  69. nameProp = new ConfigurationProperty ("name", typeof (string), ".ASPXAUTH",
  70. TypeDescriptor.GetConverter (typeof (string)),
  71. PropertyHelper.NonEmptyStringValidator,
  72. ConfigurationPropertyOptions.None);
  73. pathProp = new ConfigurationProperty ("path", typeof (string), "/",
  74. TypeDescriptor.GetConverter (typeof (string)),
  75. PropertyHelper.NonEmptyStringValidator,
  76. ConfigurationPropertyOptions.None);
  77. protectionProp = new ConfigurationProperty ("protection", typeof (FormsProtectionEnum), FormsProtectionEnum.All,
  78. new GenericEnumConverter (typeof (FormsProtectionEnum)),
  79. PropertyHelper.DefaultValidator,
  80. ConfigurationPropertyOptions.None);
  81. requireSSLProp = new ConfigurationProperty ("requireSSL", typeof (bool), false);
  82. slidingExpirationProp = new ConfigurationProperty ("slidingExpiration", typeof (bool), true);
  83. timeoutProp = new ConfigurationProperty ("timeout", typeof (TimeSpan), TimeSpan.FromMinutes (30),
  84. PropertyHelper.TimeSpanMinutesConverter,
  85. new TimeSpanValidator (new TimeSpan (0,0,0,0), TimeSpan.MaxValue),
  86. ConfigurationPropertyOptions.None);
  87. properties = new ConfigurationPropertyCollection ();
  88. properties.Add (cookielessProp);
  89. properties.Add (credentialsProp);
  90. properties.Add (defaultUrlProp);
  91. properties.Add (domainProp);
  92. properties.Add (enableCrossAppRedirectsProp);
  93. properties.Add (loginUrlProp);
  94. properties.Add (nameProp);
  95. properties.Add (pathProp);
  96. properties.Add (protectionProp);
  97. properties.Add (requireSSLProp);
  98. properties.Add (slidingExpirationProp);
  99. properties.Add (timeoutProp);
  100. elementProperty = new ConfigurationElementProperty (new CallbackValidator (typeof (FormsAuthenticationConfiguration), ValidateElement));
  101. }
  102. public FormsAuthenticationConfiguration ()
  103. {
  104. }
  105. [MonoTODO]
  106. static void ValidateElement (object o)
  107. {
  108. /* XXX do some sort of element validation here? */
  109. }
  110. protected override ConfigurationElementProperty ElementProperty {
  111. get { return elementProperty; }
  112. }
  113. [ConfigurationProperty ("cookieless", DefaultValue = "UseDeviceProfile")]
  114. public HttpCookieMode Cookieless {
  115. get { return (HttpCookieMode)base[cookielessProp]; }
  116. set { base[cookielessProp] = value; }
  117. }
  118. [ConfigurationProperty ("credentials")]
  119. public FormsAuthenticationCredentials Credentials {
  120. get { return (FormsAuthenticationCredentials) base[credentialsProp]; }
  121. }
  122. [StringValidator (MinLength = 1)]
  123. [ConfigurationProperty ("defaultUrl", DefaultValue = "default.aspx")]
  124. public string DefaultUrl {
  125. get { return (string) base[defaultUrlProp]; }
  126. set { base[defaultUrlProp] = value; }
  127. }
  128. [ConfigurationProperty ("domain", DefaultValue = "")]
  129. public string Domain {
  130. get { return (string) base[domainProp]; }
  131. set { base[domainProp] = value; }
  132. }
  133. [ConfigurationProperty ("enableCrossAppRedirects", DefaultValue = "False")]
  134. public bool EnableCrossAppRedirects {
  135. get { return (bool) base[enableCrossAppRedirectsProp]; }
  136. set { base[enableCrossAppRedirectsProp] = value; }
  137. }
  138. [StringValidator (MinLength = 1)]
  139. [ConfigurationProperty ("loginUrl", DefaultValue = "login.aspx")]
  140. public string LoginUrl {
  141. get { return (string) base[loginUrlProp]; }
  142. set { base[loginUrlProp] = value; }
  143. }
  144. [StringValidator (MinLength = 1)]
  145. [ConfigurationProperty ("name", DefaultValue = ".ASPXAUTH")]
  146. public string Name {
  147. get { return (string) base[nameProp]; }
  148. set { base[nameProp] = value; }
  149. }
  150. [StringValidator (MinLength = 1)]
  151. [ConfigurationProperty ("path", DefaultValue = "/")]
  152. public string Path {
  153. get { return (string) base[pathProp]; }
  154. set { base[pathProp] = value; }
  155. }
  156. [ConfigurationProperty ("protection", DefaultValue = "All")]
  157. public FormsProtectionEnum Protection {
  158. get { return (FormsProtectionEnum) base[protectionProp]; }
  159. set { base[protectionProp] = value; }
  160. }
  161. [ConfigurationProperty ("requireSSL", DefaultValue = "False")]
  162. public bool RequireSSL {
  163. get { return (bool) base[requireSSLProp]; }
  164. set { base[requireSSLProp] = value; }
  165. }
  166. [ConfigurationProperty ("slidingExpiration", DefaultValue = "True")]
  167. public bool SlidingExpiration {
  168. get { return (bool) base[slidingExpirationProp]; }
  169. set { base[slidingExpirationProp] = value; }
  170. }
  171. [TypeConverter (typeof (TimeSpanMinutesConverter))]
  172. [TimeSpanValidator (MinValueString = "00:00:00")]
  173. [ConfigurationProperty ("timeout", DefaultValue = "00:30:00")]
  174. public TimeSpan Timeout {
  175. get { return (TimeSpan) base[timeoutProp]; }
  176. set { base [timeoutProp] = value; }
  177. }
  178. protected override ConfigurationPropertyCollection Properties {
  179. get { return properties; }
  180. }
  181. }
  182. }
  183. #endif