[#7258][Web]: Support multiple proxy auth methods.
[mono.git] / mcs / class / System / System.Net / NetworkCredential.cs
1 //
2 // System.Net.NetworkCredential.cs
3 //
4 // Author: Duncan Mak (duncan@ximian.com)
5 // Author: Rolf Bjarne KVinge (rolf@xamarin.com)
6 //
7 // (C) Ximian, Inc.
8 // Copyright (C) 2010 Novell, Inc (http://www.novell.com)
9 // Copyright (C) 2011 Xamarin Inc (http://www.xamarin.com)
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.Security;
32
33 namespace System.Net
34 {
35         public class NetworkCredential : ICredentials
36 #if !MOONLIGHT
37                                         , ICredentialsByHost
38 #endif
39         {
40                 // Fields
41                 string userName;
42                 string password;
43                 string domain;
44                 
45 #if NET_4_0
46                 SecureString securePassword;
47 #endif
48
49                 // Constructors
50                 public NetworkCredential ()
51                 {
52                 }
53
54                 public NetworkCredential (string userName, string password)
55                 {
56                         this.userName = userName;
57                         this.password = password;
58                 }
59
60                 public NetworkCredential (string userName, string password, string domain)
61                 {
62                         this.userName = userName;
63                         this.password = password;
64                         this.domain = domain;
65                 }
66
67                 // Properties
68
69                 public string Domain {
70                         get { return domain ?? String.Empty; }
71                         set { domain = value; }
72                 }
73
74                 public string UserName {
75                         get { return userName ?? String.Empty; }
76                         set { userName = value; }                       
77                 }
78
79                 public string Password {
80                         get { return password ?? String.Empty; }
81                         set { password = value; }
82                 }
83
84 #if NET_4_0
85                 public SecureString SecurePassword {
86                         get { return securePassword; }
87                         set {
88                                 if (value == null) {
89                                         securePassword = new SecureString ();
90                                 } else {
91                                         securePassword = value;
92                                 }
93                         }
94                 }
95 #endif
96
97                 public NetworkCredential GetCredential (Uri uri, string authType)
98                 {
99                         return this;
100                 }
101
102 #if !MOONLIGHT
103                 public NetworkCredential GetCredential (string host, int port, string authenticationType)
104                 {
105                         return this;
106                 }
107 #endif
108         }
109 }