FormsAuthenticationConfiguration.cs 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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 FormsAuthenticationConfiguration ()
  51. {
  52. cookielessProp = new ConfigurationProperty ("cookieless", typeof (HttpCookieMode), HttpCookieMode.UseDeviceProfile,
  53. new GenericEnumConverter (typeof (HttpCookieMode)), PropertyHelper.DefaultValidator,
  54. ConfigurationPropertyOptions.None);
  55. credentialsProp = new ConfigurationProperty ("credentials", typeof (FormsAuthenticationCredentials), null,
  56. null, PropertyHelper.DefaultValidator,
  57. ConfigurationPropertyOptions.None);
  58. defaultUrlProp = new ConfigurationProperty ("defaultUrl", typeof (string), "default.aspx",
  59. TypeDescriptor.GetConverter (typeof (string)),
  60. PropertyHelper.NonEmptyStringValidator,
  61. ConfigurationPropertyOptions.None);
  62. domainProp = new ConfigurationProperty ("domain", typeof (string), "");
  63. enableCrossAppRedirectsProp = new ConfigurationProperty ("enableCrossAppRedirects", typeof (bool), false);
  64. loginUrlProp = new ConfigurationProperty ("loginUrl", typeof (string), "login.aspx",
  65. TypeDescriptor.GetConverter (typeof (string)),
  66. PropertyHelper.NonEmptyStringValidator,
  67. ConfigurationPropertyOptions.None);
  68. nameProp = new ConfigurationProperty ("name", typeof (string), ".ASPXAUTH",
  69. TypeDescriptor.GetConverter (typeof (string)),
  70. PropertyHelper.NonEmptyStringValidator,
  71. ConfigurationPropertyOptions.None);
  72. pathProp = new ConfigurationProperty ("path", typeof (string), "/",
  73. TypeDescriptor.GetConverter (typeof (string)),
  74. PropertyHelper.NonEmptyStringValidator,
  75. ConfigurationPropertyOptions.None);
  76. protectionProp = new ConfigurationProperty ("protection", typeof (FormsProtectionEnum), FormsProtectionEnum.All,
  77. new GenericEnumConverter (typeof (FormsProtectionEnum)),
  78. PropertyHelper.DefaultValidator,
  79. ConfigurationPropertyOptions.None);
  80. requireSSLProp = new ConfigurationProperty ("requireSSL", typeof (bool), false);
  81. slidingExpirationProp = new ConfigurationProperty ("slidingExpiration", typeof (bool), true);
  82. timeoutProp = new ConfigurationProperty ("timeout", typeof (TimeSpan), TimeSpan.FromMinutes (30),
  83. PropertyHelper.TimeSpanMinutesConverter,
  84. new TimeSpanValidator (new TimeSpan (0,0,0,0), TimeSpan.MaxValue),
  85. ConfigurationPropertyOptions.None);
  86. properties = new ConfigurationPropertyCollection ();
  87. properties.Add (cookielessProp);
  88. properties.Add (credentialsProp);
  89. properties.Add (defaultUrlProp);
  90. properties.Add (domainProp);
  91. properties.Add (enableCrossAppRedirectsProp);
  92. properties.Add (loginUrlProp);
  93. properties.Add (nameProp);
  94. properties.Add (pathProp);
  95. properties.Add (protectionProp);
  96. properties.Add (requireSSLProp);
  97. properties.Add (slidingExpirationProp);
  98. properties.Add (timeoutProp);
  99. }
  100. public FormsAuthenticationConfiguration ()
  101. {
  102. }
  103. [ConfigurationProperty ("cookieless", DefaultValue = "UseDeviceProfile")]
  104. public HttpCookieMode Cookieless {
  105. get { return (HttpCookieMode)base[cookielessProp]; }
  106. set { base[cookielessProp] = value; }
  107. }
  108. [ConfigurationProperty ("credentials")]
  109. public FormsAuthenticationCredentials Credentials {
  110. get { return (FormsAuthenticationCredentials) base[credentialsProp]; }
  111. }
  112. [StringValidator (MinLength = 1)]
  113. [ConfigurationProperty ("defaultUrl", DefaultValue = "default.aspx")]
  114. public string DefaultUrl {
  115. get { return (string) base[defaultUrlProp]; }
  116. set { base[defaultUrlProp] = value; }
  117. }
  118. [ConfigurationProperty ("domain", DefaultValue = "")]
  119. public string Domain {
  120. get { return (string) base[domainProp]; }
  121. set { base[domainProp] = value; }
  122. }
  123. [ConfigurationProperty ("enableCrossAppRedirects", DefaultValue = "False")]
  124. public bool EnableCrossAppRedirects {
  125. get { return (bool) base[enableCrossAppRedirectsProp]; }
  126. set { base[enableCrossAppRedirectsProp] = value; }
  127. }
  128. [StringValidator (MinLength = 1)]
  129. [ConfigurationProperty ("loginUrl", DefaultValue = "login.aspx")]
  130. public string LoginUrl {
  131. get { return (string) base[loginUrlProp]; }
  132. set { base[loginUrlProp] = value; }
  133. }
  134. [StringValidator (MinLength = 1)]
  135. [ConfigurationProperty ("name", DefaultValue = ".ASPXAUTH")]
  136. public string Name {
  137. get { return (string) base[nameProp]; }
  138. set { base[nameProp] = value; }
  139. }
  140. [StringValidator (MinLength = 1)]
  141. [ConfigurationProperty ("path", DefaultValue = "/")]
  142. public string Path {
  143. get { return (string) base[pathProp]; }
  144. set { base[pathProp] = value; }
  145. }
  146. [ConfigurationProperty ("protection", DefaultValue = "All")]
  147. public FormsProtectionEnum Protection {
  148. get { return (FormsProtectionEnum) base[protectionProp]; }
  149. set { base[protectionProp] = value; }
  150. }
  151. [ConfigurationProperty ("requireSSL", DefaultValue = "False")]
  152. public bool RequireSSL {
  153. get { return (bool) base[requireSSLProp]; }
  154. set { base[requireSSLProp] = value; }
  155. }
  156. [ConfigurationProperty ("slidingExpiration", DefaultValue = "True")]
  157. public bool SlidingExpiration {
  158. get { return (bool) base[slidingExpirationProp]; }
  159. set { base[slidingExpirationProp] = value; }
  160. }
  161. [TypeConverter (typeof (TimeSpanMinutesConverter))]
  162. [TimeSpanValidator (MinValueString = "00:00:00")]
  163. [ConfigurationProperty ("timeout", DefaultValue = "00:30:00")]
  164. public TimeSpan Timeout {
  165. get { return (TimeSpan) base[timeoutProp]; }
  166. set { base [timeoutProp] = value; }
  167. }
  168. protected override ConfigurationPropertyCollection Properties {
  169. get { return properties; }
  170. }
  171. #if notyet
  172. [MonoTODO]
  173. protected override ConfigurationElementProperty ElementProperty {
  174. get { throw new NotImplementedException (); }
  175. }
  176. #endif
  177. }
  178. }
  179. #endif