New test.
[mono.git] / mcs / class / System.Web / System.Web.Configuration_2.0 / FormsAuthenticationConfiguration.cs
1 //
2 // System.Web.Configuration.FormsAuthenticationConfiguration
3 //
4 // Authors:
5 //      Lluis Sanchez Gual (lluis@novell.com)
6 //      Chris Toshok (toshok@ximian.com)
7 //
8 // (C) 2004-2005 Novell, Inc (http://www.novell.com)
9 //
10
11 //
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:
19 // 
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
22 // 
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.
30 //
31
32 #if NET_2_0
33
34 using System.Configuration;
35 using System.ComponentModel;
36
37 namespace System.Web.Configuration
38 {
39         public sealed class FormsAuthenticationConfiguration: ConfigurationElement
40         {
41                 static ConfigurationPropertyCollection properties;
42
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;
55
56                 static ConfigurationElementProperty elementProperty;
57
58                 static FormsAuthenticationConfiguration ()
59                 {
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);
94
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);
108
109                         elementProperty = new ConfigurationElementProperty (new CallbackValidator (typeof (FormsAuthenticationConfiguration), ValidateElement));
110                 }
111
112                 public FormsAuthenticationConfiguration ()
113                 {
114                 }
115
116                 static void ValidateElement (object o)
117                 {
118                         /* XXX do some sort of element validation here? */
119                 }
120
121                 protected override ConfigurationElementProperty ElementProperty {
122                         get { return elementProperty; }
123                 }
124
125                 [ConfigurationProperty ("cookieless", DefaultValue = "UseDeviceProfile")]
126                 public HttpCookieMode Cookieless {
127                         get { return (HttpCookieMode)base[cookielessProp]; }
128                         set { base[cookielessProp] = value; }
129                 }
130
131                 [ConfigurationProperty ("credentials")]
132                 public FormsAuthenticationCredentials Credentials {
133                         get { return (FormsAuthenticationCredentials) base[credentialsProp]; }
134                 }
135
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; }
141                 }
142
143                 [ConfigurationProperty ("domain", DefaultValue = "")]
144                 public string Domain {
145                         get { return (string) base[domainProp]; }
146                         set { base[domainProp] = value; }
147                 }
148
149                 [ConfigurationProperty ("enableCrossAppRedirects", DefaultValue = "False")]
150                 public bool EnableCrossAppRedirects {
151                         get { return (bool) base[enableCrossAppRedirectsProp]; }
152                         set { base[enableCrossAppRedirectsProp] = value; }
153                 }
154
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; }
160                 }
161
162                 [StringValidator (MinLength = 1)]
163                 [ConfigurationProperty ("name", DefaultValue = ".ASPXAUTH")]
164                 public string Name {
165                         get { return (string) base[nameProp]; }
166                         set { base[nameProp] = value; }
167                 }
168
169                 [StringValidator (MinLength = 1)]
170                 [ConfigurationProperty ("path", DefaultValue = "/")]
171                 public string Path {
172                         get { return (string) base[pathProp]; }
173                         set { base[pathProp] = value; }
174                 }
175
176                 [ConfigurationProperty ("protection", DefaultValue = "All")]
177                 public FormsProtectionEnum Protection {
178                         get { return (FormsProtectionEnum) base[protectionProp]; }
179                         set { base[protectionProp] = value; }
180                 }
181
182                 [ConfigurationProperty ("requireSSL", DefaultValue = "False")]
183                 public bool RequireSSL {
184                         get { return (bool) base[requireSSLProp]; }
185                         set { base[requireSSLProp] = value; }
186                 }
187
188                 [ConfigurationProperty ("slidingExpiration", DefaultValue = "True")]
189                 public bool SlidingExpiration {
190                         get { return (bool) base[slidingExpirationProp]; }
191                         set { base[slidingExpirationProp] = value; }
192                 }
193
194                 [TypeConverter (typeof (TimeSpanMinutesConverter))]
195                 [TimeSpanValidator (MinValueString = "00:00:00")]
196                 [ConfigurationProperty ("timeout", DefaultValue = "00:30:00")]
197                 public TimeSpan Timeout {
198                         get { return (TimeSpan) base[timeoutProp]; }
199                         set { base [timeoutProp] = value; }
200                 }
201
202                 protected override ConfigurationPropertyCollection Properties {
203                         get { return properties; }
204                 }
205         }
206 }
207
208 #endif