RoleManagerSection.cs 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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), null,
  83. null, null, ConfigurationPropertyOptions.None);
  84. properties = new ConfigurationPropertyCollection ();
  85. properties.Add (cacheRolesInCookieProp);
  86. properties.Add (cookieNameProp);
  87. properties.Add (cookiePathProp);
  88. properties.Add (cookieProtectionProp);
  89. properties.Add (cookieRequireSSLProp);
  90. properties.Add (cookieSlidingExpirationProp);
  91. properties.Add (cookieTimeoutProp);
  92. properties.Add (createPersistentCookieProp);
  93. properties.Add (defaultProviderProp);
  94. properties.Add (domainProp);
  95. properties.Add (enabledProp);
  96. properties.Add (maxCachedResultsProp);
  97. properties.Add (providersProp);
  98. }
  99. [ConfigurationProperty ("cacheRolesInCookie", DefaultValue = "False")]
  100. public bool CacheRolesInCookie {
  101. get { return (bool) base [cacheRolesInCookieProp];}
  102. set { base[cacheRolesInCookieProp] = value; }
  103. }
  104. [TypeConverter (typeof (WhiteSpaceTrimStringConverter))]
  105. [StringValidator (MinLength = 1)]
  106. [ConfigurationProperty ("cookieName", DefaultValue = ".ASPXROLES")]
  107. public string CookieName {
  108. get { return (string) base [cookieNameProp];}
  109. set { base[cookieNameProp] = value; }
  110. }
  111. [TypeConverter (typeof (WhiteSpaceTrimStringConverter))]
  112. [StringValidator (MinLength = 1)]
  113. [ConfigurationProperty ("cookiePath", DefaultValue = "/")]
  114. public string CookiePath {
  115. get { return (string) base [cookiePathProp];}
  116. set { base[cookiePathProp] = value; }
  117. }
  118. [ConfigurationProperty ("cookieProtection", DefaultValue = "All")]
  119. public CookieProtection CookieProtection {
  120. get { return (CookieProtection) base [cookieProtectionProp];}
  121. set { base[cookieProtectionProp] = value; }
  122. }
  123. [ConfigurationProperty ("cookieRequireSSL", DefaultValue = "False")]
  124. public bool CookieRequireSSL {
  125. get { return (bool) base [cookieRequireSSLProp];}
  126. set { base[cookieRequireSSLProp] = value; }
  127. }
  128. [ConfigurationProperty ("cookieSlidingExpiration", DefaultValue = "True")]
  129. public bool CookieSlidingExpiration {
  130. get { return (bool) base [cookieSlidingExpirationProp];}
  131. set { base[cookieSlidingExpirationProp] = value; }
  132. }
  133. [TypeConverter (typeof (TimeSpanMinutesOrInfiniteConverter))]
  134. [TimeSpanValidator (MinValueString = "00:00:00", MaxValueString = "10675199.02:48:05.4775807")]
  135. [ConfigurationProperty ("cookieTimeout", DefaultValue = "00:30:00")]
  136. public TimeSpan CookieTimeout {
  137. get { return (TimeSpan) base [cookieTimeoutProp];}
  138. set { base[cookieTimeoutProp] = value; }
  139. }
  140. [ConfigurationProperty ("createPersistentCookie", DefaultValue = "False")]
  141. public bool CreatePersistentCookie {
  142. get { return (bool) base [createPersistentCookieProp];}
  143. set { base[createPersistentCookieProp] = value; }
  144. }
  145. [TypeConverter (typeof (WhiteSpaceTrimStringConverter))]
  146. [StringValidator (MinLength = 1)]
  147. [ConfigurationProperty ("defaultProvider", DefaultValue = "AspNetSqlRoleProvider")]
  148. public string DefaultProvider {
  149. get { return (string) base [defaultProviderProp];}
  150. set { base[defaultProviderProp] = value; }
  151. }
  152. [ConfigurationProperty ("domain")]
  153. public string Domain {
  154. get { return (string) base [domainProp];}
  155. set { base[domainProp] = value; }
  156. }
  157. [ConfigurationProperty ("enabled", DefaultValue = "False")]
  158. public bool Enabled {
  159. get { return (bool) base [enabledProp];}
  160. set { base[enabledProp] = value; }
  161. }
  162. [ConfigurationProperty ("maxCachedResults", DefaultValue = "25")]
  163. public int MaxCachedResults {
  164. get { return (int) base [maxCachedResultsProp];}
  165. set { base[maxCachedResultsProp] = value; }
  166. }
  167. [ConfigurationProperty ("providers")]
  168. public ProviderSettingsCollection Providers {
  169. get { return (ProviderSettingsCollection) base [providersProp];}
  170. }
  171. protected override ConfigurationPropertyCollection Properties {
  172. get { return properties; }
  173. }
  174. }
  175. }
  176. #endif