2 // System.Web.Configuration.RoleManagerSection
5 // Chris Toshok (toshok@ximian.com)
7 // (C) 2005 Novell, Inc (http://www.novell.com)
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:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
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.
32 using System.ComponentModel;
33 using System.Configuration;
34 using System.Web.Security;
38 namespace System.Web.Configuration {
40 public sealed class RoleManagerSection : ConfigurationSection
42 static ConfigurationProperty cacheRolesInCookieProp;
43 static ConfigurationProperty cookieNameProp;
44 static ConfigurationProperty cookiePathProp;
45 static ConfigurationProperty cookieProtectionProp;
46 static ConfigurationProperty cookieRequireSSLProp;
47 static ConfigurationProperty cookieSlidingExpirationProp;
48 static ConfigurationProperty cookieTimeoutProp;
49 static ConfigurationProperty createPersistentCookieProp;
50 static ConfigurationProperty defaultProviderProp;
51 static ConfigurationProperty domainProp;
52 static ConfigurationProperty enabledProp;
53 static ConfigurationProperty maxCachedResultsProp;
54 static ConfigurationProperty providersProp;
55 static ConfigurationPropertyCollection properties;
57 static RoleManagerSection ()
59 cacheRolesInCookieProp = new ConfigurationProperty ("cacheRolesInCookie", typeof (bool), false);
60 cookieNameProp = new ConfigurationProperty ("cookieName", typeof (string), ".ASPXROLES",
61 PropertyHelper.WhiteSpaceTrimStringConverter,
62 PropertyHelper.NonEmptyStringValidator,
63 ConfigurationPropertyOptions.None);
64 cookiePathProp = new ConfigurationProperty ("cookiePath", typeof (string), "/",
65 PropertyHelper.WhiteSpaceTrimStringConverter,
66 PropertyHelper.NonEmptyStringValidator,
67 ConfigurationPropertyOptions.None);
68 cookieProtectionProp = new ConfigurationProperty ("cookieProtection", typeof (CookieProtection), CookieProtection.All,
69 new GenericEnumConverter (typeof (CookieProtection)),
70 PropertyHelper.DefaultValidator,
71 ConfigurationPropertyOptions.None);
72 cookieRequireSSLProp = new ConfigurationProperty ("cookieRequireSSL", typeof (bool), false);
73 cookieSlidingExpirationProp = new ConfigurationProperty ("cookieSlidingExpiration", typeof (bool), true);
74 cookieTimeoutProp = new ConfigurationProperty ("cookieTimeout", typeof (TimeSpan), TimeSpan.FromMinutes (30),
75 PropertyHelper.TimeSpanMinutesOrInfiniteConverter,
76 PropertyHelper.PositiveTimeSpanValidator,
77 ConfigurationPropertyOptions.None);
78 createPersistentCookieProp = new ConfigurationProperty ("createPersistentCookie", typeof (bool), false);
79 defaultProviderProp = new ConfigurationProperty ("defaultProvider", typeof (string), "AspNetSqlRoleProvider",
80 /* XXX lame. MS decorates with WhiteSpaceTrimStringConverter but
81 provides the normal string converter here */
82 TypeDescriptor.GetConverter (typeof (string)),
83 PropertyHelper.NonEmptyStringValidator,
84 ConfigurationPropertyOptions.None);
85 domainProp = new ConfigurationProperty ("domain", typeof (string));
86 enabledProp = new ConfigurationProperty ("enabled", typeof (bool), false);
87 maxCachedResultsProp = new ConfigurationProperty ("maxCachedResults", typeof (int), 25);
88 providersProp = new ConfigurationProperty ("providers", typeof (ProviderSettingsCollection));
89 properties = new ConfigurationPropertyCollection ();
91 properties.Add (cacheRolesInCookieProp);
92 properties.Add (cookieNameProp);
93 properties.Add (cookiePathProp);
94 properties.Add (cookieProtectionProp);
95 properties.Add (cookieRequireSSLProp);
96 properties.Add (cookieSlidingExpirationProp);
97 properties.Add (cookieTimeoutProp);
98 properties.Add (createPersistentCookieProp);
99 properties.Add (defaultProviderProp);
100 properties.Add (domainProp);
101 properties.Add (enabledProp);
102 properties.Add (maxCachedResultsProp);
103 properties.Add (providersProp);
106 [ConfigurationProperty ("cacheRolesInCookie", DefaultValue = "False")]
107 public bool CacheRolesInCookie {
108 get { return (bool) base [cacheRolesInCookieProp];}
109 set { base[cacheRolesInCookieProp] = value; }
112 [TypeConverter (typeof (WhiteSpaceTrimStringConverter))]
113 [StringValidator (MinLength = 1)]
114 [ConfigurationProperty ("cookieName", DefaultValue = ".ASPXROLES")]
115 public string CookieName {
116 get { return (string) base [cookieNameProp];}
117 set { base[cookieNameProp] = value; }
120 [TypeConverter (typeof (WhiteSpaceTrimStringConverter))]
121 [StringValidator (MinLength = 1)]
122 [ConfigurationProperty ("cookiePath", DefaultValue = "/")]
123 public string CookiePath {
124 get { return (string) base [cookiePathProp];}
125 set { base[cookiePathProp] = value; }
128 [ConfigurationProperty ("cookieProtection", DefaultValue = "All")]
129 public CookieProtection CookieProtection {
130 get { return (CookieProtection) base [cookieProtectionProp];}
131 set { base[cookieProtectionProp] = value; }
134 [ConfigurationProperty ("cookieRequireSSL", DefaultValue = "False")]
135 public bool CookieRequireSSL {
136 get { return (bool) base [cookieRequireSSLProp];}
137 set { base[cookieRequireSSLProp] = value; }
140 [ConfigurationProperty ("cookieSlidingExpiration", DefaultValue = "True")]
141 public bool CookieSlidingExpiration {
142 get { return (bool) base [cookieSlidingExpirationProp];}
143 set { base[cookieSlidingExpirationProp] = value; }
146 [TypeConverter (typeof (TimeSpanMinutesOrInfiniteConverter))]
147 [TimeSpanValidator (MinValueString = "00:00:00", MaxValueString = "10675199.02:48:05.4775807")]
148 [ConfigurationProperty ("cookieTimeout", DefaultValue = "00:30:00")]
149 public TimeSpan CookieTimeout {
150 get { return (TimeSpan) base [cookieTimeoutProp];}
151 set { base[cookieTimeoutProp] = value; }
154 [ConfigurationProperty ("createPersistentCookie", DefaultValue = "False")]
155 public bool CreatePersistentCookie {
156 get { return (bool) base [createPersistentCookieProp];}
157 set { base[createPersistentCookieProp] = value; }
160 [TypeConverter (typeof (WhiteSpaceTrimStringConverter))]
161 [StringValidator (MinLength = 1)]
162 [ConfigurationProperty ("defaultProvider", DefaultValue = "AspNetSqlRoleProvider")]
163 public string DefaultProvider {
164 get { return (string) base [defaultProviderProp];}
165 set { base[defaultProviderProp] = value; }
168 [ConfigurationProperty ("domain")]
169 public string Domain {
170 get { return (string) base [domainProp];}
171 set { base[domainProp] = value; }
174 [ConfigurationProperty ("enabled", DefaultValue = "False")]
175 public bool Enabled {
176 get { return (bool) base [enabledProp];}
177 set { base[enabledProp] = value; }
180 [ConfigurationProperty ("maxCachedResults", DefaultValue = "25")]
181 public int MaxCachedResults {
182 get { return (int) base [maxCachedResultsProp];}
183 set { base[maxCachedResultsProp] = value; }
186 [ConfigurationProperty ("providers")]
187 public ProviderSettingsCollection Providers {
188 get { return (ProviderSettingsCollection) base [providersProp];}
191 protected override ConfigurationPropertyCollection Properties {
192 get { return properties; }