System.Web.Configuration.(AdapterDictionary,AuthenticationMode,MachineKeyValidation...
[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
33 using System.Configuration;
34 using System.ComponentModel;
35
36 namespace System.Web.Configuration
37 {
38         public sealed class FormsAuthenticationConfiguration: ConfigurationElement
39         {
40                 static ConfigurationPropertyCollection properties;
41
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;
54
55                 static ConfigurationElementProperty elementProperty;
56
57                 static FormsAuthenticationConfiguration ()
58                 {
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);
93
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);
107
108                         elementProperty = new ConfigurationElementProperty (new CallbackValidator (typeof (FormsAuthenticationConfiguration), ValidateElement));
109                 }
110
111                 public FormsAuthenticationConfiguration ()
112                 {
113                 }
114
115                 static void ValidateElement (object o)
116                 {
117                         /* XXX do some sort of element validation here? */
118                 }
119
120                 protected internal override ConfigurationElementProperty ElementProperty {
121                         get { return elementProperty; }
122                 }
123
124                 [ConfigurationProperty ("cookieless", DefaultValue = "UseDeviceProfile")]
125                 public HttpCookieMode Cookieless {
126                         get { return (HttpCookieMode)base[cookielessProp]; }
127                         set { base[cookielessProp] = value; }
128                 }
129
130                 [ConfigurationProperty ("credentials")]
131                 public FormsAuthenticationCredentials Credentials {
132                         get { return (FormsAuthenticationCredentials) base[credentialsProp]; }
133                 }
134
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; }
140                 }
141
142                 [ConfigurationProperty ("domain", DefaultValue = "")]
143                 public string Domain {
144                         get { return (string) base[domainProp]; }
145                         set { base[domainProp] = value; }
146                 }
147
148                 [ConfigurationProperty ("enableCrossAppRedirects", DefaultValue = "False")]
149                 public bool EnableCrossAppRedirects {
150                         get { return (bool) base[enableCrossAppRedirectsProp]; }
151                         set { base[enableCrossAppRedirectsProp] = value; }
152                 }
153
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; }
159                 }
160
161                 [StringValidator (MinLength = 1)]
162                 [ConfigurationProperty ("name", DefaultValue = ".ASPXAUTH")]
163                 public string Name {
164                         get { return (string) base[nameProp]; }
165                         set { base[nameProp] = value; }
166                 }
167
168                 [StringValidator (MinLength = 1)]
169                 [ConfigurationProperty ("path", DefaultValue = "/")]
170                 public string Path {
171                         get { return (string) base[pathProp]; }
172                         set { base[pathProp] = value; }
173                 }
174
175                 [ConfigurationProperty ("protection", DefaultValue = "All")]
176                 public FormsProtectionEnum Protection {
177                         get { return (FormsProtectionEnum) base[protectionProp]; }
178                         set { base[protectionProp] = value; }
179                 }
180
181                 [ConfigurationProperty ("requireSSL", DefaultValue = "False")]
182                 public bool RequireSSL {
183                         get { return (bool) base[requireSSLProp]; }
184                         set { base[requireSSLProp] = value; }
185                 }
186
187                 [ConfigurationProperty ("slidingExpiration", DefaultValue = "True")]
188                 public bool SlidingExpiration {
189                         get { return (bool) base[slidingExpirationProp]; }
190                         set { base[slidingExpirationProp] = value; }
191                 }
192
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; }
199                 }
200
201                 protected internal override ConfigurationPropertyCollection Properties {
202                         get { return properties; }
203                 }
204         }
205 }
206