2 // System.Web.Configuration.FormsAuthenticationConfiguration
5 // Lluis Sanchez Gual (lluis@novell.com)
6 // Chris Toshok (toshok@ximian.com)
8 // (C) 2004-2005 Novell, Inc (http://www.novell.com)
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 using System.Configuration;
35 using System.ComponentModel;
37 namespace System.Web.Configuration
39 public sealed class FormsAuthenticationConfiguration: ConfigurationElement
41 static ConfigurationPropertyCollection properties;
43 static ConfigurationProperty cookielessProp;
44 static ConfigurationProperty credentialsProp;
45 static ConfigurationProperty defaultUrlProp;
46 static ConfigurationProperty domainProp;
47 static ConfigurationProperty enableCrossAppRedirectsProp;
48 static ConfigurationProperty loginUrlProp;
49 static ConfigurationProperty nameProp;
50 static ConfigurationProperty pathProp;
51 static ConfigurationProperty protectionProp;
52 static ConfigurationProperty requireSSLProp;
53 static ConfigurationProperty slidingExpirationProp;
54 static ConfigurationProperty timeoutProp;
56 static ConfigurationElementProperty elementProperty;
58 static FormsAuthenticationConfiguration ()
60 cookielessProp = new ConfigurationProperty ("cookieless", typeof (HttpCookieMode), HttpCookieMode.UseDeviceProfile,
61 new GenericEnumConverter (typeof (HttpCookieMode)), PropertyHelper.DefaultValidator,
62 ConfigurationPropertyOptions.None);
63 credentialsProp = new ConfigurationProperty ("credentials", typeof (FormsAuthenticationCredentials), null,
64 null, PropertyHelper.DefaultValidator,
65 ConfigurationPropertyOptions.None);
66 defaultUrlProp = new ConfigurationProperty ("defaultUrl", typeof (string), "default.aspx",
67 TypeDescriptor.GetConverter (typeof (string)),
68 PropertyHelper.NonEmptyStringValidator,
69 ConfigurationPropertyOptions.None);
70 domainProp = new ConfigurationProperty ("domain", typeof (string), "");
71 enableCrossAppRedirectsProp = new ConfigurationProperty ("enableCrossAppRedirects", typeof (bool), false);
72 loginUrlProp = new ConfigurationProperty ("loginUrl", typeof (string), "login.aspx",
73 TypeDescriptor.GetConverter (typeof (string)),
74 PropertyHelper.NonEmptyStringValidator,
75 ConfigurationPropertyOptions.None);
76 nameProp = new ConfigurationProperty ("name", typeof (string), ".ASPXAUTH",
77 TypeDescriptor.GetConverter (typeof (string)),
78 PropertyHelper.NonEmptyStringValidator,
79 ConfigurationPropertyOptions.None);
80 pathProp = new ConfigurationProperty ("path", typeof (string), "/",
81 TypeDescriptor.GetConverter (typeof (string)),
82 PropertyHelper.NonEmptyStringValidator,
83 ConfigurationPropertyOptions.None);
84 protectionProp = new ConfigurationProperty ("protection", typeof (FormsProtectionEnum), FormsProtectionEnum.All,
85 new GenericEnumConverter (typeof (FormsProtectionEnum)),
86 PropertyHelper.DefaultValidator,
87 ConfigurationPropertyOptions.None);
88 requireSSLProp = new ConfigurationProperty ("requireSSL", typeof (bool), false);
89 slidingExpirationProp = new ConfigurationProperty ("slidingExpiration", typeof (bool), true);
90 timeoutProp = new ConfigurationProperty ("timeout", typeof (TimeSpan), TimeSpan.FromMinutes (30),
91 PropertyHelper.TimeSpanMinutesConverter,
92 new TimeSpanValidator (new TimeSpan (0,0,0,0), TimeSpan.MaxValue),
93 ConfigurationPropertyOptions.None);
95 properties = new ConfigurationPropertyCollection ();
96 properties.Add (cookielessProp);
97 properties.Add (credentialsProp);
98 properties.Add (defaultUrlProp);
99 properties.Add (domainProp);
100 properties.Add (enableCrossAppRedirectsProp);
101 properties.Add (loginUrlProp);
102 properties.Add (nameProp);
103 properties.Add (pathProp);
104 properties.Add (protectionProp);
105 properties.Add (requireSSLProp);
106 properties.Add (slidingExpirationProp);
107 properties.Add (timeoutProp);
109 elementProperty = new ConfigurationElementProperty (new CallbackValidator (typeof (FormsAuthenticationConfiguration), ValidateElement));
112 public FormsAuthenticationConfiguration ()
117 static void ValidateElement (object o)
119 /* XXX do some sort of element validation here? */
122 protected override ConfigurationElementProperty ElementProperty {
123 get { return elementProperty; }
126 [ConfigurationProperty ("cookieless", DefaultValue = "UseDeviceProfile")]
127 public HttpCookieMode Cookieless {
128 get { return (HttpCookieMode)base[cookielessProp]; }
129 set { base[cookielessProp] = value; }
132 [ConfigurationProperty ("credentials")]
133 public FormsAuthenticationCredentials Credentials {
134 get { return (FormsAuthenticationCredentials) base[credentialsProp]; }
137 [StringValidator (MinLength = 1)]
138 [ConfigurationProperty ("defaultUrl", DefaultValue = "default.aspx")]
139 public string DefaultUrl {
140 get { return (string) base[defaultUrlProp]; }
141 set { base[defaultUrlProp] = value; }
144 [ConfigurationProperty ("domain", DefaultValue = "")]
145 public string Domain {
146 get { return (string) base[domainProp]; }
147 set { base[domainProp] = value; }
150 [ConfigurationProperty ("enableCrossAppRedirects", DefaultValue = "False")]
151 public bool EnableCrossAppRedirects {
152 get { return (bool) base[enableCrossAppRedirectsProp]; }
153 set { base[enableCrossAppRedirectsProp] = value; }
156 [StringValidator (MinLength = 1)]
157 [ConfigurationProperty ("loginUrl", DefaultValue = "login.aspx")]
158 public string LoginUrl {
159 get { return (string) base[loginUrlProp]; }
160 set { base[loginUrlProp] = value; }
163 [StringValidator (MinLength = 1)]
164 [ConfigurationProperty ("name", DefaultValue = ".ASPXAUTH")]
166 get { return (string) base[nameProp]; }
167 set { base[nameProp] = value; }
170 [StringValidator (MinLength = 1)]
171 [ConfigurationProperty ("path", DefaultValue = "/")]
173 get { return (string) base[pathProp]; }
174 set { base[pathProp] = value; }
177 [ConfigurationProperty ("protection", DefaultValue = "All")]
178 public FormsProtectionEnum Protection {
179 get { return (FormsProtectionEnum) base[protectionProp]; }
180 set { base[protectionProp] = value; }
183 [ConfigurationProperty ("requireSSL", DefaultValue = "False")]
184 public bool RequireSSL {
185 get { return (bool) base[requireSSLProp]; }
186 set { base[requireSSLProp] = value; }
189 [ConfigurationProperty ("slidingExpiration", DefaultValue = "True")]
190 public bool SlidingExpiration {
191 get { return (bool) base[slidingExpirationProp]; }
192 set { base[slidingExpirationProp] = value; }
195 [TypeConverter (typeof (TimeSpanMinutesConverter))]
196 [TimeSpanValidator (MinValueString = "00:00:00")]
197 [ConfigurationProperty ("timeout", DefaultValue = "00:30:00")]
198 public TimeSpan Timeout {
199 get { return (TimeSpan) base[timeoutProp]; }
200 set { base [timeoutProp] = value; }
203 protected override ConfigurationPropertyCollection Properties {
204 get { return properties; }