RoleManagerSection.cs 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. //
  2. // System.Web.Configuration.RoleManagerSection
  3. //
  4. // Authors:
  5. // Chris Toshok ([email protected])
  6. //
  7. // (C) 2005 Novell, Inc (http://www.novell.com)
  8. //
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining
  11. // a copy of this software and associated documentation files (the
  12. // "Software"), to deal in the Software without restriction, including
  13. // without limitation the rights to use, copy, modify, merge, publish,
  14. // distribute, sublicense, and/or sell copies of the Software, and to
  15. // permit persons to whom the Software is furnished to do so, subject to
  16. // the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. //
  29. using System;
  30. using System.ComponentModel;
  31. using System.Configuration;
  32. using System.Web.Security;
  33. #if NET_2_0
  34. namespace System.Web.Configuration {
  35. public sealed class RoleManagerSection : ConfigurationSection
  36. {
  37. static ConfigurationProperty cacheRolesInCookieProp;
  38. static ConfigurationProperty cookieNameProp;
  39. static ConfigurationProperty cookiePathProp;
  40. static ConfigurationProperty cookieProtectionProp;
  41. static ConfigurationProperty cookieRequireSSLProp;
  42. static ConfigurationProperty cookieSlidingExpirationProp;
  43. static ConfigurationProperty cookieTimeoutProp;
  44. static ConfigurationProperty createPersistentCookieProp;
  45. static ConfigurationProperty defaultProviderProp;
  46. static ConfigurationProperty domainProp;
  47. static ConfigurationProperty enabledProp;
  48. static ConfigurationProperty maxCachedResultsProp;
  49. static ConfigurationProperty providersProp;
  50. static ConfigurationPropertyCollection properties;
  51. static RoleManagerSection ()
  52. {
  53. cacheRolesInCookieProp = new ConfigurationProperty ("cacheRolesInCookie", typeof (bool), false);
  54. cookieNameProp = new ConfigurationProperty ("cookieName", typeof (string), ".ASPXROLES",
  55. PropertyHelper.WhiteSpaceTrimStringConverter,
  56. PropertyHelper.NonEmptyStringValidator,
  57. ConfigurationPropertyOptions.None);
  58. cookiePathProp = new ConfigurationProperty ("cookiePath", typeof (string), "/",
  59. PropertyHelper.WhiteSpaceTrimStringConverter,
  60. PropertyHelper.NonEmptyStringValidator,
  61. ConfigurationPropertyOptions.None);
  62. cookieProtectionProp = new ConfigurationProperty ("cookieProtection", typeof (CookieProtection), CookieProtection.All,
  63. new GenericEnumConverter (typeof (CookieProtection)),
  64. PropertyHelper.DefaultValidator,
  65. ConfigurationPropertyOptions.None);
  66. cookieRequireSSLProp = new ConfigurationProperty ("cookieRequireSSL", typeof (bool), false);
  67. cookieSlidingExpirationProp = new ConfigurationProperty ("cookieSlidingExpiration", typeof (bool), true);
  68. cookieTimeoutProp = new ConfigurationProperty ("cookieTimeout", typeof (TimeSpan), TimeSpan.FromMinutes (30),
  69. PropertyHelper.TimeSpanMinutesOrInfiniteConverter,
  70. PropertyHelper.PositiveTimeSpanValidator,
  71. ConfigurationPropertyOptions.None);
  72. createPersistentCookieProp = new ConfigurationProperty ("createPersistentCookie", typeof (bool), false);
  73. defaultProviderProp = new ConfigurationProperty ("defaultProvider", typeof (string), "AspNetSqlRoleProvider",
  74. /* XXX lame. MS decorates with WhiteSpaceTrimStringConverter but
  75. provides the normal string converter here */
  76. TypeDescriptor.GetConverter (typeof (string)),
  77. PropertyHelper.NonEmptyStringValidator,
  78. ConfigurationPropertyOptions.None);
  79. domainProp = new ConfigurationProperty ("domain", typeof (string));
  80. enabledProp = new ConfigurationProperty ("enabled", typeof (bool), false);
  81. maxCachedResultsProp = new ConfigurationProperty ("maxCachedResults", typeof (int), 25);
  82. providersProp = new ConfigurationProperty ("providers", typeof (ProviderSettingsCollection));
  83. properties = new ConfigurationPropertyCollection ();
  84. properties.Add (cacheRolesInCookieProp);
  85. properties.Add (cookieNameProp);
  86. properties.Add (cookiePathProp);
  87. properties.Add (cookieProtectionProp);
  88. properties.Add (cookieRequireSSLProp);
  89. properties.Add (cookieSlidingExpirationProp);
  90. properties.Add (cookieTimeoutProp);
  91. properties.Add (createPersistentCookieProp);
  92. properties.Add (defaultProviderProp);
  93. properties.Add (domainProp);
  94. properties.Add (enabledProp);
  95. properties.Add (maxCachedResultsProp);
  96. properties.Add (providersProp);
  97. }
  98. [ConfigurationProperty ("cacheRolesInCookie", DefaultValue = "False")]
  99. public bool CacheRolesInCookie {
  100. get { return (bool) base [cacheRolesInCookieProp];}
  101. set { base[cacheRolesInCookieProp] = value; }
  102. }
  103. [TypeConverter (typeof (WhiteSpaceTrimStringConverter))]
  104. [StringValidator (MinLength = 1)]
  105. [ConfigurationProperty ("cookieName", DefaultValue = ".ASPXROLES")]
  106. public string CookieName {
  107. get { return (string) base [cookieNameProp];}
  108. set { base[cookieNameProp] = value; }
  109. }
  110. [TypeConverter (typeof (WhiteSpaceTrimStringConverter))]
  111. [StringValidator (MinLength = 1)]
  112. [ConfigurationProperty ("cookiePath", DefaultValue = "/")]
  113. public string CookiePath {
  114. get { return (string) base [cookiePathProp];}
  115. set { base[cookiePathProp] = value; }
  116. }
  117. [ConfigurationProperty ("cookieProtection", DefaultValue = "All")]
  118. public CookieProtection CookieProtection {
  119. get { return (CookieProtection) base [cookieProtectionProp];}
  120. set { base[cookieProtectionProp] = value; }
  121. }
  122. [ConfigurationProperty ("cookieRequireSSL", DefaultValue = "False")]
  123. public bool CookieRequireSSL {
  124. get { return (bool) base [cookieRequireSSLProp];}
  125. set { base[cookieRequireSSLProp] = value; }
  126. }
  127. [ConfigurationProperty ("cookieSlidingExpiration", DefaultValue = "True")]
  128. public bool CookieSlidingExpiration {
  129. get { return (bool) base [cookieSlidingExpirationProp];}
  130. set { base[cookieSlidingExpirationProp] = value; }
  131. }
  132. [TypeConverter (typeof (TimeSpanMinutesOrInfiniteConverter))]
  133. [TimeSpanValidator (MinValueString = "00:00:00", MaxValueString = "10675199.02:48:05.4775807")]
  134. [ConfigurationProperty ("cookieTimeout", DefaultValue = "00:30:00")]
  135. public TimeSpan CookieTimeout {
  136. get { return (TimeSpan) base [cookieTimeoutProp];}
  137. set { base[cookieTimeoutProp] = value; }
  138. }
  139. [ConfigurationProperty ("createPersistentCookie", DefaultValue = "False")]
  140. public bool CreatePersistentCookie {
  141. get { return (bool) base [createPersistentCookieProp];}
  142. set { base[createPersistentCookieProp] = value; }
  143. }
  144. [TypeConverter (typeof (WhiteSpaceTrimStringConverter))]
  145. [StringValidator (MinLength = 1)]
  146. [ConfigurationProperty ("defaultProvider", DefaultValue = "AspNetSqlRoleProvider")]
  147. public string DefaultProvider {
  148. get { return (string) base [defaultProviderProp];}
  149. set { base[defaultProviderProp] = value; }
  150. }
  151. [ConfigurationProperty ("domain")]
  152. public string Domain {
  153. get { return (string) base [domainProp];}
  154. set { base[domainProp] = value; }
  155. }
  156. [ConfigurationProperty ("enabled", DefaultValue = "False")]
  157. public bool Enabled {
  158. get { return (bool) base [enabledProp];}
  159. set { base[enabledProp] = value; }
  160. }
  161. [ConfigurationProperty ("maxCachedResults", DefaultValue = "25")]
  162. public int MaxCachedResults {
  163. get { return (int) base [maxCachedResultsProp];}
  164. set { base[maxCachedResultsProp] = value; }
  165. }
  166. [ConfigurationProperty ("providers")]
  167. public ProviderSettingsCollection Providers {
  168. get { return (ProviderSettingsCollection) base [providersProp];}
  169. }
  170. protected override ConfigurationPropertyCollection Properties {
  171. get { return properties; }
  172. }
  173. }
  174. }
  175. #endif