In System.Web.Configuration.Internal:
[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                 [MonoTODO]
117                 static void ValidateElement (object o)
118                 {
119                         /* XXX do some sort of element validation here? */
120                 }
121
122                 protected override ConfigurationElementProperty ElementProperty {
123                         get { return elementProperty; }
124                 }
125
126                 [ConfigurationProperty ("cookieless", DefaultValue = "UseDeviceProfile")]
127                 public HttpCookieMode Cookieless {
128                         get { return (HttpCookieMode)base[cookielessProp]; }
129                         set { base[cookielessProp] = value; }
130                 }
131
132                 [ConfigurationProperty ("credentials")]
133                 public FormsAuthenticationCredentials Credentials {
134                         get { return (FormsAuthenticationCredentials) base[credentialsProp]; }
135                 }
136
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; }
142                 }
143
144                 [ConfigurationProperty ("domain", DefaultValue = "")]
145                 public string Domain {
146                         get { return (string) base[domainProp]; }
147                         set { base[domainProp] = value; }
148                 }
149
150                 [ConfigurationProperty ("enableCrossAppRedirects", DefaultValue = "False")]
151                 public bool EnableCrossAppRedirects {
152                         get { return (bool) base[enableCrossAppRedirectsProp]; }
153                         set { base[enableCrossAppRedirectsProp] = value; }
154                 }
155
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; }
161                 }
162
163                 [StringValidator (MinLength = 1)]
164                 [ConfigurationProperty ("name", DefaultValue = ".ASPXAUTH")]
165                 public string Name {
166                         get { return (string) base[nameProp]; }
167                         set { base[nameProp] = value; }
168                 }
169
170                 [StringValidator (MinLength = 1)]
171                 [ConfigurationProperty ("path", DefaultValue = "/")]
172                 public string Path {
173                         get { return (string) base[pathProp]; }
174                         set { base[pathProp] = value; }
175                 }
176
177                 [ConfigurationProperty ("protection", DefaultValue = "All")]
178                 public FormsProtectionEnum Protection {
179                         get { return (FormsProtectionEnum) base[protectionProp]; }
180                         set { base[protectionProp] = value; }
181                 }
182
183                 [ConfigurationProperty ("requireSSL", DefaultValue = "False")]
184                 public bool RequireSSL {
185                         get { return (bool) base[requireSSLProp]; }
186                         set { base[requireSSLProp] = value; }
187                 }
188
189                 [ConfigurationProperty ("slidingExpiration", DefaultValue = "True")]
190                 public bool SlidingExpiration {
191                         get { return (bool) base[slidingExpirationProp]; }
192                         set { base[slidingExpirationProp] = value; }
193                 }
194
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; }
201                 }
202
203                 protected override ConfigurationPropertyCollection Properties {
204                         get { return properties; }
205                 }
206         }
207 }
208
209 #endif