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,1,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 ()
116 static void ValidateElement (object o
)
118 /* XXX do some sort of element validation here? */
121 protected override ConfigurationElementProperty ElementProperty
{
122 get { return elementProperty; }
125 [ConfigurationProperty ("cookieless", DefaultValue
= "UseDeviceProfile")]
126 public HttpCookieMode Cookieless
{
127 get { return (HttpCookieMode)base[cookielessProp]; }
128 set { base[cookielessProp] = value; }
131 [ConfigurationProperty ("credentials")]
132 public FormsAuthenticationCredentials Credentials
{
133 get { return (FormsAuthenticationCredentials) base[credentialsProp]; }
136 [StringValidator (MinLength
= 1)]
137 [ConfigurationProperty ("defaultUrl", DefaultValue
= "default.aspx")]
138 public string DefaultUrl
{
139 get { return (string) base[defaultUrlProp]; }
140 set { base[defaultUrlProp] = value; }
143 [ConfigurationProperty ("domain", DefaultValue
= "")]
144 public string Domain
{
145 get { return (string) base[domainProp]; }
146 set { base[domainProp] = value; }
149 [ConfigurationProperty ("enableCrossAppRedirects", DefaultValue
= "False")]
150 public bool EnableCrossAppRedirects
{
151 get { return (bool) base[enableCrossAppRedirectsProp]; }
152 set { base[enableCrossAppRedirectsProp] = value; }
155 [StringValidator (MinLength
= 1)]
156 [ConfigurationProperty ("loginUrl", DefaultValue
= "login.aspx")]
157 public string LoginUrl
{
158 get { return (string) base[loginUrlProp]; }
159 set { base[loginUrlProp] = value; }
162 [StringValidator (MinLength
= 1)]
163 [ConfigurationProperty ("name", DefaultValue
= ".ASPXAUTH")]
165 get { return (string) base[nameProp]; }
166 set { base[nameProp] = value; }
169 [StringValidator (MinLength
= 1)]
170 [ConfigurationProperty ("path", DefaultValue
= "/")]
172 get { return (string) base[pathProp]; }
173 set { base[pathProp] = value; }
176 [ConfigurationProperty ("protection", DefaultValue
= "All")]
177 public FormsProtectionEnum Protection
{
178 get { return (FormsProtectionEnum) base[protectionProp]; }
179 set { base[protectionProp] = value; }
182 [ConfigurationProperty ("requireSSL", DefaultValue
= "False")]
183 public bool RequireSSL
{
184 get { return (bool) base[requireSSLProp]; }
185 set { base[requireSSLProp] = value; }
188 [ConfigurationProperty ("slidingExpiration", DefaultValue
= "True")]
189 public bool SlidingExpiration
{
190 get { return (bool) base[slidingExpirationProp]; }
191 set { base[slidingExpirationProp] = value; }
194 [TypeConverter (typeof (TimeSpanMinutesConverter
))]
195 [TimeSpanValidator (MinValueString
= "00:01:00")]
196 [ConfigurationProperty ("timeout", DefaultValue
= "00:30:00")]
197 public TimeSpan Timeout
{
198 get { return (TimeSpan) base[timeoutProp]; }
199 set { base [timeoutProp] = value; }
202 protected override ConfigurationPropertyCollection Properties
{
203 get { return properties; }