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.
33 using System.Configuration;
34 using System.ComponentModel;
36 namespace System.Web.Configuration
38 public sealed class FormsAuthenticationConfiguration: ConfigurationElement
40 static ConfigurationPropertyCollection properties;
42 static ConfigurationProperty cookielessProp;
43 static ConfigurationProperty credentialsProp;
44 static ConfigurationProperty defaultUrlProp;
45 static ConfigurationProperty domainProp;
46 static ConfigurationProperty enableCrossAppRedirectsProp;
47 static ConfigurationProperty loginUrlProp;
48 static ConfigurationProperty nameProp;
49 static ConfigurationProperty pathProp;
50 static ConfigurationProperty protectionProp;
51 static ConfigurationProperty requireSSLProp;
52 static ConfigurationProperty slidingExpirationProp;
53 static ConfigurationProperty timeoutProp;
55 static ConfigurationElementProperty elementProperty;
57 static FormsAuthenticationConfiguration ()
59 cookielessProp = new ConfigurationProperty ("cookieless", typeof (HttpCookieMode), HttpCookieMode.UseDeviceProfile,
60 new GenericEnumConverter (typeof (HttpCookieMode)), PropertyHelper.DefaultValidator,
61 ConfigurationPropertyOptions.None);
62 credentialsProp = new ConfigurationProperty ("credentials", typeof (FormsAuthenticationCredentials), null,
63 null, PropertyHelper.DefaultValidator,
64 ConfigurationPropertyOptions.None);
65 defaultUrlProp = new ConfigurationProperty ("defaultUrl", typeof (string), "default.aspx",
66 TypeDescriptor.GetConverter (typeof (string)),
67 PropertyHelper.NonEmptyStringValidator,
68 ConfigurationPropertyOptions.None);
69 domainProp = new ConfigurationProperty ("domain", typeof (string), "");
70 enableCrossAppRedirectsProp = new ConfigurationProperty ("enableCrossAppRedirects", typeof (bool), false);
71 loginUrlProp = new ConfigurationProperty ("loginUrl", typeof (string), "login.aspx",
72 TypeDescriptor.GetConverter (typeof (string)),
73 PropertyHelper.NonEmptyStringValidator,
74 ConfigurationPropertyOptions.None);
75 nameProp = new ConfigurationProperty ("name", typeof (string), ".ASPXAUTH",
76 TypeDescriptor.GetConverter (typeof (string)),
77 PropertyHelper.NonEmptyStringValidator,
78 ConfigurationPropertyOptions.None);
79 pathProp = new ConfigurationProperty ("path", typeof (string), "/",
80 TypeDescriptor.GetConverter (typeof (string)),
81 PropertyHelper.NonEmptyStringValidator,
82 ConfigurationPropertyOptions.None);
83 protectionProp = new ConfigurationProperty ("protection", typeof (FormsProtectionEnum), FormsProtectionEnum.All,
84 new GenericEnumConverter (typeof (FormsProtectionEnum)),
85 PropertyHelper.DefaultValidator,
86 ConfigurationPropertyOptions.None);
87 requireSSLProp = new ConfigurationProperty ("requireSSL", typeof (bool), false);
88 slidingExpirationProp = new ConfigurationProperty ("slidingExpiration", typeof (bool), true);
89 timeoutProp = new ConfigurationProperty ("timeout", typeof (TimeSpan), TimeSpan.FromMinutes (30),
90 PropertyHelper.TimeSpanMinutesConverter,
91 new TimeSpanValidator (new TimeSpan (0,1,0), TimeSpan.MaxValue),
92 ConfigurationPropertyOptions.None);
94 properties = new ConfigurationPropertyCollection ();
95 properties.Add (cookielessProp);
96 properties.Add (credentialsProp);
97 properties.Add (defaultUrlProp);
98 properties.Add (domainProp);
99 properties.Add (enableCrossAppRedirectsProp);
100 properties.Add (loginUrlProp);
101 properties.Add (nameProp);
102 properties.Add (pathProp);
103 properties.Add (protectionProp);
104 properties.Add (requireSSLProp);
105 properties.Add (slidingExpirationProp);
106 properties.Add (timeoutProp);
108 elementProperty = new ConfigurationElementProperty (new CallbackValidator (typeof (FormsAuthenticationConfiguration), ValidateElement));
111 public FormsAuthenticationConfiguration ()
115 static void ValidateElement (object o)
117 /* XXX do some sort of element validation here? */
120 protected internal override ConfigurationElementProperty ElementProperty {
121 get { return elementProperty; }
124 [ConfigurationProperty ("cookieless", DefaultValue = "UseDeviceProfile")]
125 public HttpCookieMode Cookieless {
126 get { return (HttpCookieMode)base[cookielessProp]; }
127 set { base[cookielessProp] = value; }
130 [ConfigurationProperty ("credentials")]
131 public FormsAuthenticationCredentials Credentials {
132 get { return (FormsAuthenticationCredentials) base[credentialsProp]; }
135 [StringValidator (MinLength = 1)]
136 [ConfigurationProperty ("defaultUrl", DefaultValue = "default.aspx")]
137 public string DefaultUrl {
138 get { return (string) base[defaultUrlProp]; }
139 set { base[defaultUrlProp] = value; }
142 [ConfigurationProperty ("domain", DefaultValue = "")]
143 public string Domain {
144 get { return (string) base[domainProp]; }
145 set { base[domainProp] = value; }
148 [ConfigurationProperty ("enableCrossAppRedirects", DefaultValue = "False")]
149 public bool EnableCrossAppRedirects {
150 get { return (bool) base[enableCrossAppRedirectsProp]; }
151 set { base[enableCrossAppRedirectsProp] = value; }
154 [StringValidator (MinLength = 1)]
155 [ConfigurationProperty ("loginUrl", DefaultValue = "login.aspx")]
156 public string LoginUrl {
157 get { return (string) base[loginUrlProp]; }
158 set { base[loginUrlProp] = value; }
161 [StringValidator (MinLength = 1)]
162 [ConfigurationProperty ("name", DefaultValue = ".ASPXAUTH")]
164 get { return (string) base[nameProp]; }
165 set { base[nameProp] = value; }
168 [StringValidator (MinLength = 1)]
169 [ConfigurationProperty ("path", DefaultValue = "/")]
171 get { return (string) base[pathProp]; }
172 set { base[pathProp] = value; }
175 [ConfigurationProperty ("protection", DefaultValue = "All")]
176 public FormsProtectionEnum Protection {
177 get { return (FormsProtectionEnum) base[protectionProp]; }
178 set { base[protectionProp] = value; }
181 [ConfigurationProperty ("requireSSL", DefaultValue = "False")]
182 public bool RequireSSL {
183 get { return (bool) base[requireSSLProp]; }
184 set { base[requireSSLProp] = value; }
187 [ConfigurationProperty ("slidingExpiration", DefaultValue = "True")]
188 public bool SlidingExpiration {
189 get { return (bool) base[slidingExpirationProp]; }
190 set { base[slidingExpirationProp] = value; }
193 [TypeConverter (typeof (TimeSpanMinutesConverter))]
194 [TimeSpanValidator (MinValueString = "00:01:00")]
195 [ConfigurationProperty ("timeout", DefaultValue = "00:30:00")]
196 public TimeSpan Timeout {
197 get { return (TimeSpan) base[timeoutProp]; }
198 set { base [timeoutProp] = value; }
201 protected internal override ConfigurationPropertyCollection Properties {
202 get { return properties; }