move the WriteClientScriptIncludes to the top of the form, according to the MSDN
[mono.git] / mcs / class / System.Web / System.Web.Configuration / AuthConfig.cs
1 //
2 // System.Web.Configuration.AuthConfig
3 //
4 // Authors:
5 //      Gonzalo Paniagua Javier (gonzalo@ximian.com)
6 //
7 // (C) 2002 Ximian, Inc (http://www.ximian.com)
8 // Copyright (c) 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 using System.Collections;
33 using System.Configuration;
34 using System.Xml;
35
36 namespace System.Web.Configuration
37 {
38         class AuthConfig
39         {
40                 AuthenticationMode mode;
41                 string cookieName;
42                 string cookiePath;
43                 string loginUrl;
44                 FormsProtectionEnum protection;
45                 int timeout;
46                 FormsAuthPasswordFormat pwdFormat;
47                 Hashtable credentialUsers;
48                 bool has_parent;
49 #if NET_1_1
50                 bool requireSSL;
51                 bool slidingExpiration;
52 #endif
53 #if NET_2_0
54                 string cookie_domain;
55                 HttpCookieMode cookie_mode;
56                 bool cookies_supported;
57                 string default_url;
58                 bool enable_crossapp_redirects;
59 #endif
60
61                 internal AuthConfig (object parent)
62                 {
63                         if (parent is AuthConfig) {
64                                 has_parent = true;
65                                 AuthConfig p = (AuthConfig) parent;
66                                 mode = p.mode;
67                                 cookieName = p.cookieName;
68                                 cookiePath = p.cookiePath;
69                                 loginUrl = p.loginUrl;
70                                 protection = p.protection;
71                                 timeout = p.timeout;
72                                 pwdFormat = p.pwdFormat;
73 #if NET_1_1
74                                 requireSSL = p.requireSSL;
75                                 slidingExpiration = p.slidingExpiration;
76 #endif
77 #if NET_2_0
78                                 cookie_domain = p.cookie_domain;
79                                 cookie_mode = p.cookie_mode;
80                                 cookies_supported = p.cookies_supported;
81                                 default_url = p.default_url;
82                                 enable_crossapp_redirects = p.enable_crossapp_redirects;
83 #endif
84                                 credentialUsers = new Hashtable (p.CredentialUsers);
85                         }
86                 }
87
88                 internal void SetMode (string m)
89                 {
90                         if (m == null) {
91                                 // we default to Forms authentication mode, MS defaults to Windows
92                                 if (!has_parent)
93                                         Mode = AuthenticationMode.Forms;
94                                 return;
95                         }
96
97                         Mode = (AuthenticationMode) Enum.Parse (typeof (AuthenticationMode), m, true);
98                 }
99
100                 internal void SetProtection (string prot)
101                 {
102                         if (prot == null) {
103                                 if (!has_parent)
104                                         Protection = FormsProtectionEnum.All;
105                                 return;
106                         }
107
108                         Protection = (FormsProtectionEnum) Enum.Parse (typeof (FormsProtectionEnum),
109                                                                        prot,
110                                                                        true);
111                 }
112
113                 internal void SetTimeout (string minutes)
114                 {
115                         if (minutes != null) {
116                                 Timeout = Int32.Parse (minutes);
117                                 return;
118                         }
119
120                         if (!has_parent)
121                                 Timeout = 30;
122                 }
123
124                 internal void SetPasswordFormat (string pwdFormat)
125                 {
126                         if (pwdFormat == null) {
127                                 if (!has_parent)
128                                         PasswordFormat = FormsAuthPasswordFormat.Clear;
129                                 return;
130                         }
131
132                         PasswordFormat =
133                                 (FormsAuthPasswordFormat) Enum.Parse (typeof (FormsAuthPasswordFormat),
134                                                                       pwdFormat,
135                                                                       true);
136                 }
137
138                 internal AuthenticationMode Mode {
139                         get { return mode; }
140                         set { mode = value; }
141                 }
142
143                 internal string CookieName {
144                         get {
145                                 if (cookieName == null)
146                                         cookieName = ".ASPXAUTH";
147
148                                 return cookieName;
149                         }
150                         set {
151                                 if (value == null)
152                                         return;
153
154                                 cookieName = value;
155                         }
156                 }
157
158                 internal string CookiePath {
159                         get {
160                                 if (cookiePath == null)
161                                         cookiePath = "/";
162
163                                 return cookiePath;
164                         }
165                         set {
166                                 if (value == null)
167                                         return;
168
169                                 cookiePath = value;
170                         }
171                 }
172
173                 internal string LoginUrl {
174                         get {
175                                 if (loginUrl == null)
176                                         loginUrl = "login.aspx";
177
178                                 return loginUrl;
179                         }
180                         set {
181                                 if (value == null)
182                                         return;
183
184                                 loginUrl = value;
185                         }
186                 }
187
188                 internal FormsProtectionEnum Protection {
189                         get { return protection; }
190                         set { protection = value; }
191                 }
192
193                 internal int Timeout {
194                         get { return timeout; }
195                         set {
196                                 if (value <= 0)
197                                         throw new ArgumentException ("Timeout must be > 0", "value");
198
199                                 timeout = value;
200                         }
201                 }
202
203                 internal FormsAuthPasswordFormat PasswordFormat {
204                         get { return pwdFormat; }
205                         set { pwdFormat = value; }
206                 }
207
208                 internal Hashtable CredentialUsers {
209                         get {
210                                 if (credentialUsers == null)
211                                         credentialUsers = new Hashtable ();
212
213                                 return credentialUsers;
214                         }
215                 }
216
217 #if NET_1_1
218                 internal bool RequireSSL {
219                         get { return requireSSL; }
220                         set { requireSSL = value; }
221                 }
222
223                 internal bool SlidingExpiration {
224                         get { return slidingExpiration; }
225                         set { slidingExpiration = value; }
226                 }
227 #endif
228
229 #if NET_2_0
230                 internal string CookieDomain {
231                         get { return cookie_domain; }
232                         set { cookie_domain = value; }
233                 }
234
235                 internal HttpCookieMode CookieMode {
236                         get { return cookie_mode; }
237                         set { cookie_mode = value; }
238                 }
239
240                 internal bool CookiesSupported {
241                         get { return cookies_supported; }
242                         set { cookies_supported = value; }
243                 }
244
245                 internal string DefaultUrl {
246                         get { return default_url; }
247                         set { default_url = value; }
248                 }
249
250                 internal bool EnableCrossAppRedirects {
251                         get { return enable_crossapp_redirects; }
252                         set { enable_crossapp_redirects = value; }
253                 }
254 #endif
255         }
256 }
257