From eb3cac713b9d8d6f1f12f55df9e05c56ba64af41 Mon Sep 17 00:00:00 2001
From: "cbentzel@chromium.org"
 <cbentzel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>
Date: Fri, 26 Feb 2010 21:07:45 +0000
Subject: Added HttpAuthFilter.

Original patch by ahendrickson@chromium.org (http://codereview.chromium.org/646068)

BUG=29596
TEST=net_unittests.exe --gtest_filter="*HttpAuthFilterTest*"

Review URL: http://codereview.chromium.org/660193

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@40157 0039d316-1c4b-4281-b951-d872f2087c98
---
 chrome/browser/io_thread.cc      | 30 ++++++++++++++++++++++++++++--
 chrome/browser/io_thread.h       |  2 ++
 chrome/common/chrome_switches.cc |  3 +++
 chrome/common/chrome_switches.h  |  1 +
 4 files changed, 34 insertions(+), 2 deletions(-)

(limited to 'chrome')

diff --git a/chrome/browser/io_thread.cc b/chrome/browser/io_thread.cc
index f4d4698..cda63ef 100644
--- a/chrome/browser/io_thread.cc
+++ b/chrome/browser/io_thread.cc
@@ -17,6 +17,7 @@
 #include "net/base/host_resolver_impl.h"
 #include "net/base/net_util.h"
 #include "net/base/network_change_notifier.h"
+#include "net/http/http_auth_filter.h"
 #include "net/http/http_auth_handler_factory.h"
 #include "net/url_request/url_request.h"
 
@@ -127,8 +128,7 @@ void IOThread::Init() {
       net::NetworkChangeNotifier::CreateDefaultNetworkChangeNotifier());
   globals_->host_resolver =
       CreateGlobalHostResolver(globals_->network_change_notifier.get());
-  globals_->http_auth_handler_factory.reset(
-      net::HttpAuthHandlerFactory::CreateDefault());
+  globals_->http_auth_handler_factory.reset(CreateDefaultAuthHandlerFactory());
 }
 
 void IOThread::CleanUp() {
@@ -176,6 +176,32 @@ void IOThread::CleanUp() {
   BrowserProcessSubThread::CleanUp();
 }
 
+net::HttpAuthHandlerFactory* IOThread::CreateDefaultAuthHandlerFactory() {
+  net::HttpAuthHandlerRegistryFactory* registry_factory =
+      net::HttpAuthHandlerFactory::CreateDefault();
+
+  // Get the whitelist information from the command line, create an
+  // HttpAuthFilterWhitelist, and attach it to the HttpAuthHandlerFactory.
+  const CommandLine& command_line = *CommandLine::ForCurrentProcess();
+
+  // Set the NTLM and Negotiate filters (from the same whitelist)
+  if (command_line.HasSwitch(switches::kAuthServerWhitelist)) {
+    std::string ntlm_server_whitelist =
+        command_line.GetSwitchValueASCII(switches::kAuthServerWhitelist);
+    net::HttpAuthFilterWhitelist* ntlm_whitelist =
+        new net::HttpAuthFilterWhitelist();
+    net::HttpAuthFilterWhitelist* negotiate_whitelist =
+        new net::HttpAuthFilterWhitelist();
+
+    ntlm_whitelist->SetFilters(ntlm_server_whitelist);
+    negotiate_whitelist->SetFilters(ntlm_server_whitelist);
+    registry_factory->SetFilter("ntlm", ntlm_whitelist);
+    registry_factory->SetFilter("negotiate", negotiate_whitelist);
+  }
+
+  return registry_factory;
+}
+
 void IOThread::InitDnsMasterOnIOThread(
     bool prefetching_enabled,
     base::TimeDelta max_queue_delay,
diff --git a/chrome/browser/io_thread.h b/chrome/browser/io_thread.h
index c0b9ccd..6de1bae 100644
--- a/chrome/browser/io_thread.h
+++ b/chrome/browser/io_thread.h
@@ -60,6 +60,8 @@ class IOThread : public BrowserProcessSubThread {
   virtual void CleanUp();
 
  private:
+  net::HttpAuthHandlerFactory* CreateDefaultAuthHandlerFactory();
+
   void InitDnsMasterOnIOThread(
       bool prefetching_enabled,
       base::TimeDelta max_queue_delay,
diff --git a/chrome/common/chrome_switches.cc b/chrome/common/chrome_switches.cc
index 505b07b..c521395 100644
--- a/chrome/common/chrome_switches.cc
+++ b/chrome/common/chrome_switches.cc
@@ -39,6 +39,9 @@ const char kAppId[]                         = "app-id";
 // panel window.
 const char kAppLaunchAsPanel[]              = "app-launch-as-panel";
 
+// Authentication white list for servers
+const char kAuthServerWhitelist[]           = "auth-server-whitelist";
+
 // The value of this switch tells the app to listen for and broadcast
 // automation-related messages on IPC channel with the given ID.
 const char kAutomationClientChannelID[]     = "automation-channel";
diff --git a/chrome/common/chrome_switches.h b/chrome/common/chrome_switches.h
index 9af1ec9..0ce84a6 100644
--- a/chrome/common/chrome_switches.h
+++ b/chrome/common/chrome_switches.h
@@ -26,6 +26,7 @@ extern const char kAlwaysEnableDevTools[];
 extern const char kApp[];
 extern const char kAppId[];
 extern const char kAppLaunchAsPanel[];
+extern const char kAuthServerWhitelist[];
 extern const char kAutomationClientChannelID[];
 extern const char kBookmarkMenu[];
 extern const char kBrowserAssertTest[];
-- 
cgit v1.1