2005-01-31 Zoltan Varga <vargaz@freemail.hu>
[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 //
9
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30
31 using System;
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
54                 internal AuthConfig (object parent)
55                 {
56                         if (parent is AuthConfig) {
57                                 has_parent = true;
58                                 AuthConfig p = (AuthConfig) parent;
59                                 mode = p.mode;
60                                 cookieName = p.cookieName;
61                                 cookiePath = p.cookiePath;
62                                 loginUrl = p.loginUrl;
63                                 protection = p.protection;
64                                 timeout = p.timeout;
65                                 pwdFormat = p.pwdFormat;
66 #if NET_1_1
67                                 requireSSL = p.requireSSL;
68                                 slidingExpiration = p.slidingExpiration;
69 #endif
70                                 credentialUsers = new Hashtable (p.CredentialUsers);
71                         }
72                 }
73
74                 internal void SetMode (string m)
75                 {
76                         if (m == null) {
77                                 // we default to Forms authentication mode, MS defaults to Windows
78                                 if (!has_parent)
79                                         Mode = AuthenticationMode.Forms;
80                                 return;
81                         }
82
83                         Mode = (AuthenticationMode) Enum.Parse (typeof (AuthenticationMode), m, true);
84                 }
85
86                 internal void SetProtection (string prot)
87                 {
88                         if (prot == null) {
89                                 if (!has_parent)
90                                         Protection = FormsProtectionEnum.All;
91                                 return;
92                         }
93
94                         Protection = (FormsProtectionEnum) Enum.Parse (typeof (FormsProtectionEnum),
95                                                                        prot,
96                                                                        true);
97                 }
98
99                 internal void SetTimeout (string minutes)
100                 {
101                         if (minutes != null) {
102                                 Timeout = Int32.Parse (minutes);
103                                 return;
104                         }
105
106                         if (!has_parent)
107                                 Timeout = 30;
108                 }
109
110                 internal void SetPasswordFormat (string pwdFormat)
111                 {
112                         if (pwdFormat == null) {
113                                 if (!has_parent)
114                                         PasswordFormat = FormsAuthPasswordFormat.Clear;
115                                 return;
116                         }
117
118                         PasswordFormat =
119                                 (FormsAuthPasswordFormat) Enum.Parse (typeof (FormsAuthPasswordFormat),
120                                                                       pwdFormat,
121                                                                       true);
122                 }
123
124                 internal AuthenticationMode Mode {
125                         get { return mode; }
126                         set { mode = value; }
127                 }
128
129                 internal string CookieName {
130                         get {
131                                 if (cookieName == null)
132                                         cookieName = ".ASPXAUTH";
133
134                                 return cookieName;
135                         }
136                         set {
137                                 if (value == null)
138                                         return;
139
140                                 cookieName = value;
141                         }
142                 }
143
144                 internal string CookiePath {
145                         get {
146                                 if (cookiePath == null)
147                                         cookiePath = "/";
148
149                                 return cookiePath;
150                         }
151                         set {
152                                 if (value == null)
153                                         return;
154
155                                 cookiePath = value;
156                         }
157                 }
158
159                 internal string LoginUrl {
160                         get {
161                                 if (loginUrl == null)
162                                         loginUrl = "login.aspx";
163
164                                 return loginUrl;
165                         }
166                         set {
167                                 if (value == null)
168                                         return;
169
170                                 loginUrl = value;
171                         }
172                 }
173
174                 internal FormsProtectionEnum Protection {
175                         get { return protection; }
176                         set { protection = value; }
177                 }
178
179                 internal int Timeout {
180                         get { return timeout; }
181                         set {
182                                 if (value <= 0)
183                                         throw new ArgumentException ("Timeout must be > 0", "value");
184
185                                 timeout = value;
186                         }
187                 }
188
189                 internal FormsAuthPasswordFormat PasswordFormat {
190                         get { return pwdFormat; }
191                         set { pwdFormat = value; }
192                 }
193
194                 internal Hashtable CredentialUsers {
195                         get {
196                                 if (credentialUsers == null)
197                                         credentialUsers = new Hashtable ();
198
199                                 return credentialUsers;
200                         }
201                 }
202
203 #if NET_1_1
204                 internal bool RequireSSL {
205                         get { return requireSSL; }
206                         set { requireSSL = value; }
207                 }
208
209                 internal bool SlidingExpiration {
210                         get { return slidingExpiration; }
211                         set { slidingExpiration = value; }
212                 }
213 #endif
214         }
215 }
216