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 
37 namespace System.Web.Configuration {
38 
39 	public sealed class RoleManagerSection : ConfigurationSection
40 	{
41 		static ConfigurationProperty cacheRolesInCookieProp;
42 		static ConfigurationProperty cookieNameProp;
43 		static ConfigurationProperty cookiePathProp;
44 		static ConfigurationProperty cookieProtectionProp;
45 		static ConfigurationProperty cookieRequireSSLProp;
46 		static ConfigurationProperty cookieSlidingExpirationProp;
47 		static ConfigurationProperty cookieTimeoutProp;
48 		static ConfigurationProperty createPersistentCookieProp;
49 		static ConfigurationProperty defaultProviderProp;
50 		static ConfigurationProperty domainProp;
51 		static ConfigurationProperty enabledProp;
52 		static ConfigurationProperty maxCachedResultsProp;
53 		static ConfigurationProperty providersProp;
54 
55 		static ConfigurationPropertyCollection properties;
56 
RoleManagerSection()57 		static RoleManagerSection ()
58 		{
59 			cacheRolesInCookieProp = new ConfigurationProperty ("cacheRolesInCookie", typeof (bool), false);
60 			cookieNameProp = new ConfigurationProperty ("cookieName", typeof (string), ".ASPXROLES");
61 			cookiePathProp = new ConfigurationProperty ("cookiePath", typeof (string), "/");
62 			cookieProtectionProp = new ConfigurationProperty ("cookieProtection", typeof (CookieProtection),
63 									  CookieProtection.All);
64 			cookieRequireSSLProp = new ConfigurationProperty ("cookieRequireSSL", typeof (bool), false);
65 			cookieSlidingExpirationProp = new ConfigurationProperty ("cookieSlidingExpiration", typeof (bool), true);
66 			cookieTimeoutProp = new ConfigurationProperty ("cookieTimeout", typeof (TimeSpan), TimeSpan.FromMinutes (30),
67 								       PropertyHelper.TimeSpanMinutesOrInfiniteConverter,
68 								       PropertyHelper.PositiveTimeSpanValidator,
69 								       ConfigurationPropertyOptions.None);
70 			createPersistentCookieProp = new ConfigurationProperty ("createPersistentCookie", typeof (bool), false);
71 			defaultProviderProp = new ConfigurationProperty ("defaultProvider", typeof (string), "AspNetSqlRoleProvider");
72 			domainProp = new ConfigurationProperty ("domain", typeof (string), "");
73 			enabledProp = new ConfigurationProperty ("enabled", typeof (bool), false);
74 			maxCachedResultsProp = new ConfigurationProperty ("maxCachedResults", typeof (int), 25);
75 			providersProp = new ConfigurationProperty ("providers", typeof (ProviderSettingsCollection));
76 
77 			properties = new ConfigurationPropertyCollection ();
78 			properties.Add (cacheRolesInCookieProp);
79 			properties.Add (cookieNameProp);
80 			properties.Add (cookiePathProp);
81 			properties.Add (cookieProtectionProp);
82 			properties.Add (cookieRequireSSLProp);
83 			properties.Add (cookieSlidingExpirationProp);
84 			properties.Add (cookieTimeoutProp);
85 			properties.Add (createPersistentCookieProp);
86 			properties.Add (defaultProviderProp);
87 			properties.Add (domainProp);
88 			properties.Add (enabledProp);
89 			properties.Add (maxCachedResultsProp);
90 			properties.Add (providersProp);
91 		}
92 
93 		[ConfigurationProperty ("cacheRolesInCookie", DefaultValue = false)]
94 		public bool CacheRolesInCookie {
95 			get { return (bool) base [cacheRolesInCookieProp]; }
96 			set { base [cacheRolesInCookieProp] = value; }
97 		}
98 
99 		[TypeConverter (typeof (WhiteSpaceTrimStringConverter))]
100 		[StringValidator (MinLength = 1)]
101 		[ConfigurationProperty ("cookieName", DefaultValue = ".ASPXROLES")]
102 		public string CookieName {
103 			get { return (string) base [cookieNameProp]; }
104 			set { base [cookieNameProp] = value; }
105 		}
106 
107 		[TypeConverter (typeof (WhiteSpaceTrimStringConverter))]
108 		[StringValidator (MinLength = 1)]
109 		[ConfigurationProperty ("cookiePath", DefaultValue = "/")]
110 		public string CookiePath {
111 			get { return (string) base [cookiePathProp]; }
112 			set { base [cookiePathProp] = value; }
113 		}
114 
115 		[ConfigurationProperty ("cookieProtection", DefaultValue = "All")]
116 		public CookieProtection CookieProtection {
117 			get { return (CookieProtection) base [cookieProtectionProp]; }
118 			set { base [cookieProtectionProp] = value; }
119 		}
120 
121 		[ConfigurationProperty ("cookieRequireSSL", DefaultValue = false)]
122 		public bool CookieRequireSSL {
123 			get { return (bool) base [cookieRequireSSLProp]; }
124 			set { base [cookieRequireSSLProp] = value; }
125 		}
126 
127 		[ConfigurationProperty ("cookieSlidingExpiration", DefaultValue = true)]
128 		public bool CookieSlidingExpiration {
129 			get { return (bool) base [cookieSlidingExpirationProp]; }
130 			set { base [cookieSlidingExpirationProp] = value; }
131 		}
132 
133 		[TimeSpanValidatorAttribute(MinValueString = "00:00:00", MaxValueString = "10675199.02:48:05.4775807")]
134 		[ConfigurationPropertyAttribute("cookieTimeout", DefaultValue = "00:30:00")]
135 		[TypeConverterAttribute(typeof(TimeSpanMinutesOrInfiniteConverter))]
136 		public TimeSpan CookieTimeout {
137 			get { return (TimeSpan) base [cookieTimeoutProp]; }
138 			set { base [cookieTimeoutProp] = value; }
139 		}
140 
141 		[ConfigurationProperty ("createPersistentCookie", DefaultValue = false)]
142 		public bool CreatePersistentCookie {
143 			get { return (bool) base [createPersistentCookieProp]; }
144 			set { base [createPersistentCookieProp] = value; }
145 		}
146 
147 		[TypeConverter (typeof (WhiteSpaceTrimStringConverter))]
148 		[StringValidator (MinLength = 1)]
149 		[ConfigurationProperty ("defaultProvider", DefaultValue = "AspNetSqlRoleProvider")]
150 		public string DefaultProvider {
151 			get { return (string) base [defaultProviderProp]; }
152 			set { base [defaultProviderProp] = value; }
153 		}
154 
155 		[ConfigurationProperty ("domain")]
156 		public string Domain {
157 			get { return (string) base [domainProp]; }
158 			set { base [domainProp] = value; }
159 		}
160 
161 		[ConfigurationProperty ("enabled", DefaultValue = false)]
162 		public bool Enabled {
163 			get { return (bool) base [enabledProp]; }
164 			set { base [enabledProp] = value; }
165 		}
166 
167 		[ConfigurationProperty ("maxCachedResults", DefaultValue = 25)]
168 		public int MaxCachedResults {
169 			get { return (int) base [maxCachedResultsProp]; }
170 			set { base [maxCachedResultsProp] = value; }
171 		}
172 
173 		[ConfigurationProperty ("providers")]
174 		public ProviderSettingsCollection Providers {
175 			get { return (ProviderSettingsCollection) base [providersProp]; }
176 		}
177 
178 		protected internal override ConfigurationPropertyCollection Properties {
179 			get { return properties; }
180 		}
181 	}
182 }
183 
184