New test.
[mono.git] / mcs / class / System.Web / System.Web.Configuration_2.0 / RoleManagerSection.cs
1 //
2 // System.Web.Configuration.RoleManagerSection
3 //
4 // Authors:
5 //      Chris Toshok (toshok@ximian.com)
6 //
7 // (C) 2005 Novell, Inc (http://www.novell.com)
8 //
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
31 using System;
32 using System.ComponentModel;
33 using System.Configuration;
34 using System.Web.Security;
35
36 #if NET_2_0
37
38 namespace System.Web.Configuration {
39
40         public sealed class RoleManagerSection : ConfigurationSection
41         {
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;
56
57                 static RoleManagerSection ()
58                 {
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), null,
89                                                                    null, null, ConfigurationPropertyOptions.None);
90                         properties = new ConfigurationPropertyCollection ();
91
92                         properties.Add (cacheRolesInCookieProp);
93                         properties.Add (cookieNameProp);
94                         properties.Add (cookiePathProp);
95                         properties.Add (cookieProtectionProp);
96                         properties.Add (cookieRequireSSLProp);
97                         properties.Add (cookieSlidingExpirationProp);
98                         properties.Add (cookieTimeoutProp);
99                         properties.Add (createPersistentCookieProp);
100                         properties.Add (defaultProviderProp);
101                         properties.Add (domainProp);
102                         properties.Add (enabledProp);
103                         properties.Add (maxCachedResultsProp);
104                         properties.Add (providersProp);
105                 }
106
107                 [ConfigurationProperty ("cacheRolesInCookie", DefaultValue = "False")]
108                 public bool CacheRolesInCookie {
109                         get { return (bool) base [cacheRolesInCookieProp];}
110                         set { base[cacheRolesInCookieProp] = value; }
111                 }
112
113                 [TypeConverter (typeof (WhiteSpaceTrimStringConverter))]
114                 [StringValidator (MinLength = 1)]
115                 [ConfigurationProperty ("cookieName", DefaultValue = ".ASPXROLES")]
116                 public string CookieName {
117                         get { return (string) base [cookieNameProp];}
118                         set { base[cookieNameProp] = value; }
119                 }
120
121                 [TypeConverter (typeof (WhiteSpaceTrimStringConverter))]
122                 [StringValidator (MinLength = 1)]
123                 [ConfigurationProperty ("cookiePath", DefaultValue = "/")]
124                 public string CookiePath {
125                         get { return (string) base [cookiePathProp];}
126                         set { base[cookiePathProp] = value; }
127                 }
128
129                 [ConfigurationProperty ("cookieProtection", DefaultValue = "All")]
130                 public CookieProtection CookieProtection {
131                         get { return (CookieProtection) base [cookieProtectionProp];}
132                         set { base[cookieProtectionProp] = value; }
133                 }
134
135                 [ConfigurationProperty ("cookieRequireSSL", DefaultValue = "False")]
136                 public bool CookieRequireSSL {
137                         get { return (bool) base [cookieRequireSSLProp];}
138                         set { base[cookieRequireSSLProp] = value; }
139                 }
140
141                 [ConfigurationProperty ("cookieSlidingExpiration", DefaultValue = "True")]
142                 public bool CookieSlidingExpiration {
143                         get { return (bool) base [cookieSlidingExpirationProp];}
144                         set { base[cookieSlidingExpirationProp] = value; }
145                 }
146
147                 [TypeConverter (typeof (TimeSpanMinutesOrInfiniteConverter))]
148                 [TimeSpanValidator (MinValueString = "00:00:00", MaxValueString = "10675199.02:48:05.4775807")]
149                 [ConfigurationProperty ("cookieTimeout", DefaultValue = "00:30:00")]
150                 public TimeSpan CookieTimeout {
151                         get { return (TimeSpan) base [cookieTimeoutProp];}
152                         set { base[cookieTimeoutProp] = value; }
153                 }
154
155                 [ConfigurationProperty ("createPersistentCookie", DefaultValue = "False")]
156                 public bool CreatePersistentCookie {
157                         get { return (bool) base [createPersistentCookieProp];}
158                         set { base[createPersistentCookieProp] = value; }
159                 }
160
161                 [TypeConverter (typeof (WhiteSpaceTrimStringConverter))]
162                 [StringValidator (MinLength = 1)]
163                 [ConfigurationProperty ("defaultProvider", DefaultValue = "AspNetSqlRoleProvider")]
164                 public string DefaultProvider {
165                         get { return (string) base [defaultProviderProp];}
166                         set { base[defaultProviderProp] = value; }
167                 }
168
169                 [ConfigurationProperty ("domain")]
170                 public string Domain {
171                         get { return (string) base [domainProp];}
172                         set { base[domainProp] = value; }
173                 }
174
175                 [ConfigurationProperty ("enabled", DefaultValue = "False")]
176                 public bool Enabled {
177                         get { return (bool) base [enabledProp];}
178                         set { base[enabledProp] = value; }
179                 }
180
181                 [ConfigurationProperty ("maxCachedResults", DefaultValue = "25")]
182                 public int MaxCachedResults {
183                         get { return (int) base [maxCachedResultsProp];}
184                         set { base[maxCachedResultsProp] = value; }
185                 }
186
187                 [ConfigurationProperty ("providers")]
188                 public ProviderSettingsCollection Providers {
189                         get { return (ProviderSettingsCollection) base [providersProp];}
190                 }
191
192                 protected override ConfigurationPropertyCollection Properties {
193                         get { return properties; }
194                 }
195         }
196 }
197
198 #endif