2010-01-13 Gonzalo Paniagua Javier <gonzalo@novell.com>
authorGonzalo Paniagua Javier <gonzalo.mono@gmail.com>
Wed, 13 Jan 2010 23:22:38 +0000 (23:22 -0000)
committerGonzalo Paniagua Javier <gonzalo.mono@gmail.com>
Wed, 13 Jan 2010 23:22:38 +0000 (23:22 -0000)
* HttpWebRequest.cs: when the server returns several different
authentication methods, pick the one that works.
Fixes bug #562043.

svn path=/trunk/mcs/; revision=149500

mcs/class/System/System.Net/ChangeLog
mcs/class/System/System.Net/HttpWebRequest.cs

index 5eb763aec470e5cea2783ab82e2ffdf1a7bb6a58..4b4184b92659a9419c5ec8b059e21761e54e5bf5 100644 (file)
@@ -1,3 +1,9 @@
+2010-01-13 Gonzalo Paniagua Javier <gonzalo@novell.com>
+
+       * HttpWebRequest.cs: when the server returns several different
+       authentication methods, pick the one that works.
+       Fixes bug #562043.
+
 2010-01-12  Sebastien Pouliot  <sebastien@ximian.com>
 
        * NetworkCredential.cs: Fix properties to never return null.
index afe0adc2a88e6d58fac098c10c3137fb7a8d5fe7..f35109c70005a248200efed867b2d08ade2aacf1 100644 (file)
@@ -1347,15 +1347,19 @@ namespace System.Net
                        if (isProxy && (proxy == null || proxy.Credentials == null))
                                return false;
 
-                       string authHeader = response.Headers [(isProxy) ? "Proxy-Authenticate" : "WWW-Authenticate"];
-                       if (authHeader == null)
+                       string [] authHeaders = response.Headers.GetValues ( (isProxy) ? "Proxy-Authenticate" : "WWW-Authenticate");
+                       if (authHeaders == null || authHeaders.Length == 0)
                                return false;
 
                        ICredentials creds = (!isProxy) ? credentials : proxy.Credentials;
-                       Authorization auth = AuthenticationManager.Authenticate (authHeader, this, creds);
+                       Authorization auth = null;
+                       foreach (string authHeader in authHeaders) {
+                               auth = AuthenticationManager.Authenticate (authHeader, this, creds);
+                               if (auth != null)
+                                       break;
+                       }
                        if (auth == null)
                                return false;
-
                        webHeaders [(isProxy) ? "Proxy-Authorization" : "Authorization"] = auth.Message;
                        authCompleted = auth.Complete;
                        is_ntlm_auth = (auth.Module.AuthenticationType == "NTLM");