RoleManagerSection.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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. cookiePathProp = new ConfigurationProperty ("cookiePath", typeof (string), "/");
  56. cookieProtectionProp = new ConfigurationProperty ("cookieProtection", typeof (CookieProtection), CookieProtection.All);
  57. cookieRequireSSLProp = new ConfigurationProperty ("cookieRequireSSL", typeof (bool), false);
  58. cookieSlidingExpirationProp = new ConfigurationProperty ("cookieSlidingExpiration", typeof (bool), true);
  59. cookieTimeoutProp = new ConfigurationProperty ("cookieTimeout", typeof (TimeSpan), TimeSpan.FromMinutes (30));
  60. createPersistentCookieProp = new ConfigurationProperty ("createPersistentCookie", typeof (bool), false);
  61. defaultProviderProp = new ConfigurationProperty ("defaultProvider", typeof (string), "AspNetSqlRoleProvider");
  62. domainProp = new ConfigurationProperty ("domain", typeof (string));
  63. enabledProp = new ConfigurationProperty ("enabled", typeof (bool), false);
  64. maxCachedResultsProp = new ConfigurationProperty ("maxCachedResults", typeof (int), 25);
  65. providersProp = new ConfigurationProperty ("providers", typeof (ProviderSettingsCollection));
  66. properties = new ConfigurationPropertyCollection ();
  67. properties.Add (cacheRolesInCookieProp);
  68. properties.Add (cookieNameProp);
  69. properties.Add (cookiePathProp);
  70. properties.Add (cookieProtectionProp);
  71. properties.Add (cookieRequireSSLProp);
  72. properties.Add (cookieSlidingExpirationProp);
  73. properties.Add (cookieTimeoutProp);
  74. properties.Add (createPersistentCookieProp);
  75. properties.Add (defaultProviderProp);
  76. properties.Add (domainProp);
  77. properties.Add (enabledProp);
  78. properties.Add (maxCachedResultsProp);
  79. properties.Add (providersProp);
  80. }
  81. [ConfigurationProperty ("cacheRolesInCookie", DefaultValue = "False")]
  82. public bool CacheRolesInCookie {
  83. get { return (bool) base [cacheRolesInCookieProp];}
  84. set { base[cacheRolesInCookieProp] = value; }
  85. }
  86. [TypeConverter (typeof (WhiteSpaceTrimStringConverter))]
  87. [StringValidator (MinLength = 1)]
  88. [ConfigurationProperty ("cookieName", DefaultValue = ".ASPXROLES")]
  89. public string CookieName {
  90. get { return (string) base [cookieNameProp];}
  91. set { base[cookieNameProp] = value; }
  92. }
  93. [TypeConverter (typeof (WhiteSpaceTrimStringConverter))]
  94. [StringValidator (MinLength = 1)]
  95. [ConfigurationProperty ("cookiePath", DefaultValue = "/")]
  96. public string CookiePath {
  97. get { return (string) base [cookiePathProp];}
  98. set { base[cookiePathProp] = value; }
  99. }
  100. [ConfigurationProperty ("cookieProtection", DefaultValue = "All")]
  101. public CookieProtection CookieProtection {
  102. get { return (CookieProtection) base [cookieProtectionProp];}
  103. set { base[cookieProtectionProp] = value; }
  104. }
  105. [ConfigurationProperty ("cookieRequireSSL", DefaultValue = "False")]
  106. public bool CookieRequireSSL {
  107. get { return (bool) base [cookieRequireSSLProp];}
  108. set { base[cookieRequireSSLProp] = value; }
  109. }
  110. [ConfigurationProperty ("cookieSlidingExpiration", DefaultValue = "True")]
  111. public bool CookieSlidingExpiration {
  112. get { return (bool) base [cookieSlidingExpirationProp];}
  113. set { base[cookieSlidingExpirationProp] = value; }
  114. }
  115. [TypeConverter (typeof (TimeSpanMinutesOrInfiniteConverter))]
  116. [TimeSpanValidator (MinValueString = "00:00:00", MaxValueString = "10675199.02:48:05.4775807")]
  117. [ConfigurationProperty ("cookieTimeout", DefaultValue = "00:30:00")]
  118. public TimeSpan CookieTimeout {
  119. get { return (TimeSpan) base [cookieTimeoutProp];}
  120. set { base[cookieTimeoutProp] = value; }
  121. }
  122. [ConfigurationProperty ("createPersistentCookie", DefaultValue = "False")]
  123. public bool CreatePersistentCookie {
  124. get { return (bool) base [createPersistentCookieProp];}
  125. set { base[createPersistentCookieProp] = value; }
  126. }
  127. [TypeConverter (typeof (WhiteSpaceTrimStringConverter))]
  128. [StringValidator (MinLength = 1)]
  129. [ConfigurationProperty ("defaultProvider", DefaultValue = "AspNetSqlRoleProvider")]
  130. public string DefaultProvider {
  131. get { return (string) base [defaultProviderProp];}
  132. set { base[defaultProviderProp] = value; }
  133. }
  134. [ConfigurationProperty ("domain")]
  135. public string Domain {
  136. get { return (string) base [domainProp];}
  137. set { base[domainProp] = value; }
  138. }
  139. [ConfigurationProperty ("enabled", DefaultValue = "False")]
  140. public bool Enabled {
  141. get { return (bool) base [enabledProp];}
  142. set { base[enabledProp] = value; }
  143. }
  144. [ConfigurationProperty ("maxCachedResults", DefaultValue = "25")]
  145. public int MaxCachedResults {
  146. get { return (int) base [maxCachedResultsProp];}
  147. set { base[maxCachedResultsProp] = value; }
  148. }
  149. [ConfigurationProperty ("providers")]
  150. public ProviderSettingsCollection Providers {
  151. get { return (ProviderSettingsCollection) base [providersProp];}
  152. }
  153. protected override ConfigurationPropertyCollection Properties {
  154. get { return properties; }
  155. }
  156. }
  157. }
  158. #endif