summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--net/http/http_auth_cache_unittest.cc22
-rw-r--r--net/http/http_auth_handler.cc13
-rw-r--r--net/http/http_auth_handler.h55
-rw-r--r--net/http/http_auth_handler_basic.cc19
-rw-r--r--net/http/http_auth_handler_basic.h16
-rw-r--r--net/http/http_auth_handler_basic_unittest.cc11
-rw-r--r--net/http/http_auth_handler_digest.cc25
-rw-r--r--net/http/http_auth_handler_digest.h17
-rw-r--r--net/http/http_auth_handler_negotiate.h16
-rw-r--r--net/http/http_auth_handler_negotiate_posix.cc17
-rw-r--r--net/http/http_auth_handler_negotiate_win.cc26
-rw-r--r--net/http/http_auth_handler_ntlm.cc23
-rw-r--r--net/http/http_auth_handler_ntlm.h16
-rw-r--r--net/http/http_auth_handler_ntlm_portable.cc9
-rw-r--r--net/http/http_auth_handler_ntlm_win.cc13
-rw-r--r--net/http/http_auth_sspi_win.cc1
-rw-r--r--net/http/http_auth_sspi_win.h1
-rw-r--r--net/http/http_network_transaction.cc20
-rw-r--r--net/http/http_network_transaction.h2
-rw-r--r--net/http/http_network_transaction_unittest.cc68
-rw-r--r--net/socket_stream/socket_stream.cc8
21 files changed, 168 insertions, 230 deletions
diff --git a/net/http/http_auth_cache_unittest.cc b/net/http/http_auth_cache_unittest.cc
index ced4e0a..4e2af9d 100644
--- a/net/http/http_auth_cache_unittest.cc
+++ b/net/http/http_auth_cache_unittest.cc
@@ -25,26 +25,20 @@ class MockAuthHandler : public HttpAuthHandler {
properties_ = 0;
}
- virtual int GenerateAuthToken(const std::wstring&,
- const std::wstring&,
- const HttpRequestInfo*,
- const ProxyInfo*,
- std::string* auth_token) {
- *auth_token = "mock-credentials";
- return OK;
+ protected:
+ virtual bool Init(HttpAuth::ChallengeTokenizer* challenge) {
+ return false; // Unused.
}
- virtual int GenerateDefaultAuthToken(const HttpRequestInfo*,
- const ProxyInfo*,
- std::string* auth_token) {
+ virtual int GenerateAuthTokenImpl(const std::wstring*,
+ const std::wstring*,
+ const HttpRequestInfo*,
+ CompletionCallback* callback,
+ std::string* auth_token) {
*auth_token = "mock-credentials";
return OK;
}
- protected:
- virtual bool Init(HttpAuth::ChallengeTokenizer* challenge) {
- return false; // Unused.
- }
private:
~MockAuthHandler() {}
diff --git a/net/http/http_auth_handler.cc b/net/http/http_auth_handler.cc
index 661fc64..cf690bc 100644
--- a/net/http/http_auth_handler.cc
+++ b/net/http/http_auth_handler.cc
@@ -32,6 +32,19 @@ bool HttpAuthHandler::InitFromChallenge(
return ok;
}
+int HttpAuthHandler::GenerateAuthToken(const std::wstring* username,
+ const std::wstring* password,
+ const HttpRequestInfo* request,
+ CompletionCallback* callback,
+ std::string* auth_token) {
+ // TODO(cbentzel): Enforce non-NULL callback+auth_token.
+ DCHECK(request);
+ DCHECK((username == NULL) == (password == NULL));
+ DCHECK(username != NULL || AllowsDefaultCredentials());
+ return GenerateAuthTokenImpl(username, password, request, callback,
+ auth_token);
+}
+
int HttpAuthHandler::ResolveCanonicalName(net::HostResolver* host_resolver,
CompletionCallback* callback) {
NOTREACHED();
diff --git a/net/http/http_auth_handler.h b/net/http/http_auth_handler.h
index 4aa8852..01d2639 100644
--- a/net/http/http_auth_handler.h
+++ b/net/http/http_auth_handler.h
@@ -34,6 +34,30 @@ class HttpAuthHandler {
const GURL& origin,
const BoundNetLog& net_log);
+ // Generates an authentication token, potentially asynchronously.
+ //
+ // When |username| and |password| are NULL, the default credentials for
+ // the currently logged in user are used. |AllowsDefaultCredentials()| MUST be
+ // true in this case.
+ //
+ // |request|, |callback|, and |auth_token| must be non-NULL.
+ //
+ // The return value is a net error code.
+ // If |OK| is returned, |*auth_token| is filled in with an authentication
+ // token which can be inserted in the HTTP request.
+ // If |ERR_IO_PENDING| is returned, |*auth_token| will be filled in
+ // asynchronously and |callback| will be invoked. The lifetime of
+ // |request|, |callback|, and |auth_token| must last until |callback| is
+ // invoked, but |username| and |password| are only used during the initial
+ // call.
+ // Otherwise, there was a problem generating a token synchronously, and the
+ // value of |*auth_token| is unspecified.
+ int GenerateAuthToken(const std::wstring* username,
+ const std::wstring* password,
+ const HttpRequestInfo* request,
+ CompletionCallback* callback,
+ std::string* auth_token);
+
// Lowercase name of the auth scheme
const std::string& scheme() const {
return scheme_;
@@ -96,28 +120,6 @@ class HttpAuthHandler {
// name when constructing the Kerberos SPN.
virtual bool NeedsCanonicalName() { return false; }
- // TODO(cbentzel): Separate providing credentials from generating the
- // authentication token in the API.
-
- // Generates an authentication token.
- // The return value is an error code. If the code is not |OK|, the value of
- // |*auth_token| is unspecified.
- // |auth_token| is a return value and must be non-NULL.
- virtual int GenerateAuthToken(const std::wstring& username,
- const std::wstring& password,
- const HttpRequestInfo* request,
- const ProxyInfo* proxy,
- std::string* auth_token) = 0;
-
- // Generates an authentication token using default credentials.
- // The return value is an error code. If the code is not |OK|, the value of
- // |*auth_token| is unspecified.
- // |auth_token| is a return value and must be non-NULL.
- // This should only be called if |SupportsDefaultCredentials| returns true.
- virtual int GenerateDefaultAuthToken(const HttpRequestInfo* request,
- const ProxyInfo* proxy,
- std::string* auth_token) = 0;
-
// Resolves the canonical name for the |origin_| host. The canonical
// name is used by the Negotiate scheme to generate a valid Kerberos
// SPN.
@@ -139,6 +141,15 @@ class HttpAuthHandler {
// scheme_, realm_, score_, properties_
virtual bool Init(HttpAuth::ChallengeTokenizer* challenge) = 0;
+ // |GenerateAuthTokenImpl()} is the auth-scheme specific implementation
+ // of generating the next auth token. Callers sohuld use |GenerateAuthToken()|
+ // which will in turn call |GenerateAuthTokenImpl()|
+ virtual int GenerateAuthTokenImpl(const std::wstring* username,
+ const std::wstring* password,
+ const HttpRequestInfo* request,
+ CompletionCallback* callback,
+ std::string* auth_token) = 0;
+
// The lowercase auth-scheme {"basic", "digest", "ntlm", "negotiate"}
std::string scheme_;
diff --git a/net/http/http_auth_handler_basic.cc b/net/http/http_auth_handler_basic.cc
index 21bfc44..efd8c5e 100644
--- a/net/http/http_auth_handler_basic.cc
+++ b/net/http/http_auth_handler_basic.cc
@@ -41,15 +41,15 @@ bool HttpAuthHandlerBasic::Init(HttpAuth::ChallengeTokenizer* challenge) {
return challenge->valid();
}
-int HttpAuthHandlerBasic::GenerateAuthToken(
- const std::wstring& username,
- const std::wstring& password,
+int HttpAuthHandlerBasic::GenerateAuthTokenImpl(
+ const std::wstring* username,
+ const std::wstring* password,
const HttpRequestInfo*,
- const ProxyInfo*,
+ CompletionCallback*,
std::string* auth_token) {
// TODO(eroman): is this the right encoding of username/password?
std::string base64_username_password;
- if (!base::Base64Encode(WideToUTF8(username) + ":" + WideToUTF8(password),
+ if (!base::Base64Encode(WideToUTF8(*username) + ":" + WideToUTF8(*password),
&base64_username_password)) {
LOG(ERROR) << "Unexpected problem Base64 encoding.";
return ERR_UNEXPECTED;
@@ -58,15 +58,6 @@ int HttpAuthHandlerBasic::GenerateAuthToken(
return OK;
}
-int HttpAuthHandlerBasic::GenerateDefaultAuthToken(
- const HttpRequestInfo* request,
- const ProxyInfo* proxy,
- std::string* auth_token) {
- NOTREACHED();
- LOG(ERROR) << ErrorToString(ERR_NOT_IMPLEMENTED);
- return ERR_NOT_IMPLEMENTED;
-}
-
HttpAuthHandlerBasic::Factory::Factory() {
}
diff --git a/net/http/http_auth_handler_basic.h b/net/http/http_auth_handler_basic.h
index 26003aa..6ecb80a 100644
--- a/net/http/http_auth_handler_basic.h
+++ b/net/http/http_auth_handler_basic.h
@@ -27,19 +27,15 @@ class HttpAuthHandlerBasic : public HttpAuthHandler {
scoped_ptr<HttpAuthHandler>* handler);
};
- virtual int GenerateAuthToken(const std::wstring& username,
- const std::wstring& password,
- const HttpRequestInfo*,
- const ProxyInfo*,
- std::string* auth_token);
-
- virtual int GenerateDefaultAuthToken(const HttpRequestInfo* request,
- const ProxyInfo* proxy,
- std::string* auth_token);
-
protected:
virtual bool Init(HttpAuth::ChallengeTokenizer* challenge);
+ virtual int GenerateAuthTokenImpl(const std::wstring* username,
+ const std::wstring* password,
+ const HttpRequestInfo* request,
+ CompletionCallback* callback,
+ std::string* auth_token);
+
private:
~HttpAuthHandlerBasic() {}
};
diff --git a/net/http/http_auth_handler_basic_unittest.cc b/net/http/http_auth_handler_basic_unittest.cc
index 16652d4..6b25deb 100644
--- a/net/http/http_auth_handler_basic_unittest.cc
+++ b/net/http/http_auth_handler_basic_unittest.cc
@@ -7,6 +7,7 @@
#include "base/basictypes.h"
#include "net/base/net_errors.h"
#include "net/http/http_auth_handler_basic.h"
+#include "net/http/http_request_info.h"
namespace net {
@@ -32,11 +33,11 @@ TEST(HttpAuthHandlerBasicTest, GenerateAuthToken) {
EXPECT_EQ(OK, factory.CreateAuthHandlerFromString(
challenge, HttpAuth::AUTH_SERVER, origin, BoundNetLog(), &basic));
std::string credentials;
- int rv = basic->GenerateAuthToken(tests[i].username,
- tests[i].password,
- NULL,
- NULL,
- &credentials);
+ std::wstring username(tests[i].username);
+ std::wstring password(tests[i].password);
+ HttpRequestInfo request_info;
+ int rv = basic->GenerateAuthToken(
+ &username, &password, &request_info, NULL, &credentials);
EXPECT_EQ(OK, rv);
EXPECT_STREQ(tests[i].expected_credentials, credentials.c_str());
}
diff --git a/net/http/http_auth_handler_digest.cc b/net/http/http_auth_handler_digest.cc
index b15d01b..90090a6 100644
--- a/net/http/http_auth_handler_digest.cc
+++ b/net/http/http_auth_handler_digest.cc
@@ -85,11 +85,11 @@ std::string HttpAuthHandlerDigest::AlgorithmToString(int algorithm) {
}
}
-int HttpAuthHandlerDigest::GenerateAuthToken(
- const std::wstring& username,
- const std::wstring& password,
+int HttpAuthHandlerDigest::GenerateAuthTokenImpl(
+ const std::wstring* username,
+ const std::wstring* password,
const HttpRequestInfo* request,
- const ProxyInfo* proxy,
+ CompletionCallback* callback,
std::string* auth_token) {
// Generate a random client nonce.
std::string cnonce = GenerateNonce();
@@ -98,32 +98,21 @@ int HttpAuthHandlerDigest::GenerateAuthToken(
// in certain cases, to be a hostname.
std::string method;
std::string path;
- GetRequestMethodAndPath(request, proxy, &method, &path);
+ GetRequestMethodAndPath(request, &method, &path);
*auth_token = AssembleCredentials(method, path,
// TODO(eroman): is this the right encoding?
- WideToUTF8(username),
- WideToUTF8(password),
+ WideToUTF8(*username),
+ WideToUTF8(*password),
cnonce, nonce_count_);
return OK;
}
-int HttpAuthHandlerDigest::GenerateDefaultAuthToken(
- const HttpRequestInfo* request,
- const ProxyInfo* proxy,
- std::string* auth_token) {
- NOTREACHED();
- LOG(ERROR) << ErrorToString(ERR_NOT_IMPLEMENTED);
- return ERR_NOT_IMPLEMENTED;
-}
-
void HttpAuthHandlerDigest::GetRequestMethodAndPath(
const HttpRequestInfo* request,
- const ProxyInfo* proxy,
std::string* method,
std::string* path) const {
DCHECK(request);
- DCHECK(proxy);
const GURL& url = request->url;
diff --git a/net/http/http_auth_handler_digest.h b/net/http/http_auth_handler_digest.h
index bebbd8a..2aa9028 100644
--- a/net/http/http_auth_handler_digest.h
+++ b/net/http/http_auth_handler_digest.h
@@ -30,21 +30,17 @@ class HttpAuthHandlerDigest : public HttpAuthHandler {
scoped_ptr<HttpAuthHandler>* handler);
};
- virtual int GenerateAuthToken(const std::wstring& username,
- const std::wstring& password,
- const HttpRequestInfo* request,
- const ProxyInfo* proxy,
- std::string* auth_token);
-
- virtual int GenerateDefaultAuthToken(const HttpRequestInfo* request,
- const ProxyInfo* proxy,
- std::string* auth_token);
-
protected:
virtual bool Init(HttpAuth::ChallengeTokenizer* challenge) {
return ParseChallenge(challenge);
}
+ virtual int GenerateAuthTokenImpl(const std::wstring* username,
+ const std::wstring* password,
+ const HttpRequestInfo* request,
+ CompletionCallback* callback,
+ std::string* auth_token);
+
private:
FRIEND_TEST(HttpAuthHandlerDigestTest, ParseChallenge);
FRIEND_TEST(HttpAuthHandlerDigestTest, AssembleCredentials);
@@ -94,7 +90,6 @@ class HttpAuthHandlerDigest : public HttpAuthHandler {
// Extract the method and path of the request, as needed by
// the 'A2' production. (path may be a hostname for proxy).
void GetRequestMethodAndPath(const HttpRequestInfo* request,
- const ProxyInfo* proxy,
std::string* method,
std::string* path) const;
diff --git a/net/http/http_auth_handler_negotiate.h b/net/http/http_auth_handler_negotiate.h
index c7fdd67..c1414ec 100644
--- a/net/http/http_auth_handler_negotiate.h
+++ b/net/http/http_auth_handler_negotiate.h
@@ -98,16 +98,6 @@ class HttpAuthHandlerNegotiate : public HttpAuthHandler {
virtual bool NeedsCanonicalName();
- virtual int GenerateAuthToken(const std::wstring& username,
- const std::wstring& password,
- const HttpRequestInfo* request,
- const ProxyInfo* proxy,
- std::string* auth_token);
-
- virtual int GenerateDefaultAuthToken(const HttpRequestInfo* request,
- const ProxyInfo* proxy,
- std::string* auth_token);
-
virtual int ResolveCanonicalName(HostResolver* host_resolver,
CompletionCallback* callback);
@@ -120,6 +110,12 @@ class HttpAuthHandlerNegotiate : public HttpAuthHandler {
protected:
virtual bool Init(HttpAuth::ChallengeTokenizer* challenge);
+ virtual int GenerateAuthTokenImpl(const std::wstring* username,
+ const std::wstring* password,
+ const HttpRequestInfo* request,
+ CompletionCallback* callback,
+ std::string* auth_token);
+
private:
#if defined(OS_WIN)
void OnResolveCanonicalName(int result);
diff --git a/net/http/http_auth_handler_negotiate_posix.cc b/net/http/http_auth_handler_negotiate_posix.cc
index 556307d..17ef690 100644
--- a/net/http/http_auth_handler_negotiate_posix.cc
+++ b/net/http/http_auth_handler_negotiate_posix.cc
@@ -45,20 +45,11 @@ bool HttpAuthHandlerNegotiate::Init(HttpAuth::ChallengeTokenizer* tok) {
return false;
}
-int HttpAuthHandlerNegotiate::GenerateAuthToken(
- const std::wstring& username,
- const std::wstring& password,
+int HttpAuthHandlerNegotiate::GenerateAuthTokenImpl(
+ const std::wstring* username,
+ const std::wstring* password,
const HttpRequestInfo* request,
- const ProxyInfo* proxy,
- std::string* auth_token) {
- NOTREACHED();
- LOG(ERROR) << ErrorToString(ERR_NOT_IMPLEMENTED);
- return ERR_NOT_IMPLEMENTED;
-}
-
-int HttpAuthHandlerNegotiate::GenerateDefaultAuthToken(
- const HttpRequestInfo* request,
- const ProxyInfo* proxy,
+ CompletionCallback* callback,
std::string* auth_token) {
NOTREACHED();
LOG(ERROR) << ErrorToString(ERR_NOT_IMPLEMENTED);
diff --git a/net/http/http_auth_handler_negotiate_win.cc b/net/http/http_auth_handler_negotiate_win.cc
index bfb8258..f29a9d8 100644
--- a/net/http/http_auth_handler_negotiate_win.cc
+++ b/net/http/http_auth_handler_negotiate_win.cc
@@ -31,18 +31,17 @@ HttpAuthHandlerNegotiate::HttpAuthHandlerNegotiate(
HttpAuthHandlerNegotiate::~HttpAuthHandlerNegotiate() {
}
-int HttpAuthHandlerNegotiate::GenerateAuthToken(
- const std::wstring& username,
- const std::wstring& password,
+int HttpAuthHandlerNegotiate::GenerateAuthTokenImpl(
+ const std::wstring* username,
+ const std::wstring* password,
const HttpRequestInfo* request,
- const ProxyInfo* proxy,
+ CompletionCallback* callback,
std::string* auth_token) {
return auth_sspi_.GenerateAuthToken(
- &username,
- &password,
+ username,
+ password,
spn_,
request,
- proxy,
auth_token);
}
@@ -165,19 +164,6 @@ std::wstring HttpAuthHandlerNegotiate::CreateSPN(
}
}
-int HttpAuthHandlerNegotiate::GenerateDefaultAuthToken(
- const HttpRequestInfo* request,
- const ProxyInfo* proxy,
- std::string* auth_token) {
- return auth_sspi_.GenerateAuthToken(
- NULL, // username
- NULL, // password
- spn_,
- request,
- proxy,
- auth_token);
-}
-
HttpAuthHandlerNegotiate::Factory::Factory()
: disable_cname_lookup_(false),
use_port_(false),
diff --git a/net/http/http_auth_handler_ntlm.cc b/net/http/http_auth_handler_ntlm.cc
index ed3eb3a..b50a0a9 100644
--- a/net/http/http_auth_handler_ntlm.cc
+++ b/net/http/http_auth_handler_ntlm.cc
@@ -13,19 +13,18 @@
namespace net {
-int HttpAuthHandlerNTLM::GenerateAuthToken(
- const std::wstring& username,
- const std::wstring& password,
+int HttpAuthHandlerNTLM::GenerateAuthTokenImpl(
+ const std::wstring* username,
+ const std::wstring* password,
const HttpRequestInfo* request,
- const ProxyInfo* proxy,
+ CompletionCallback* callback,
std::string* auth_token) {
#if defined(NTLM_SSPI)
return auth_sspi_.GenerateAuthToken(
- &username,
- &password,
+ username,
+ password,
CreateSPN(origin_),
request,
- proxy,
auth_token);
#else // !defined(NTLM_SSPI)
// TODO(wtc): See if we can use char* instead of void* for in_buf and
@@ -40,16 +39,16 @@ int HttpAuthHandlerNTLM::GenerateAuthToken(
// components.
std::wstring domain;
std::wstring user;
- size_t backslash_idx = username.find(L'\\');
+ size_t backslash_idx = username->find(L'\\');
if (backslash_idx == std::wstring::npos) {
- user = username;
+ user = *username;
} else {
- domain = username.substr(0, backslash_idx);
- user = username.substr(backslash_idx + 1);
+ domain = username->substr(0, backslash_idx);
+ user = username->substr(backslash_idx + 1);
}
domain_ = WideToUTF16(domain);
username_ = WideToUTF16(user);
- password_ = WideToUTF16(password);
+ password_ = WideToUTF16(*password);
// Initial challenge.
if (auth_data_.empty()) {
diff --git a/net/http/http_auth_handler_ntlm.h b/net/http/http_auth_handler_ntlm.h
index 4467932..f22a2b5 100644
--- a/net/http/http_auth_handler_ntlm.h
+++ b/net/http/http_auth_handler_ntlm.h
@@ -111,21 +111,17 @@ class HttpAuthHandlerNTLM : public HttpAuthHandler {
virtual bool AllowsDefaultCredentials();
- virtual int GenerateAuthToken(const std::wstring& username,
- const std::wstring& password,
- const HttpRequestInfo* request,
- const ProxyInfo* proxy,
- std::string* auth_token);
-
- virtual int GenerateDefaultAuthToken(const HttpRequestInfo* request,
- const ProxyInfo* proxy,
- std::string* auth_token);
-
protected:
virtual bool Init(HttpAuth::ChallengeTokenizer* tok) {
return ParseChallenge(tok);
}
+ virtual int GenerateAuthTokenImpl(const std::wstring* username,
+ const std::wstring* password,
+ const HttpRequestInfo* request,
+ CompletionCallback* callback,
+ std::string* auth_token);
+
// This function acquires a credentials handle in the SSPI implementation.
// It does nothing in the portable implementation.
int InitializeBeforeFirstChallenge();
diff --git a/net/http/http_auth_handler_ntlm_portable.cc b/net/http/http_auth_handler_ntlm_portable.cc
index 940768c..e16d32c 100644
--- a/net/http/http_auth_handler_ntlm_portable.cc
+++ b/net/http/http_auth_handler_ntlm_portable.cc
@@ -710,15 +710,6 @@ int HttpAuthHandlerNTLM::InitializeBeforeFirstChallenge() {
return OK;
}
-int HttpAuthHandlerNTLM::GenerateDefaultAuthToken(
- const HttpRequestInfo* request,
- const ProxyInfo* proxy,
- std::string* auth_token) {
- NOTREACHED();
- LOG(ERROR) << ErrorToString(ERR_NOT_IMPLEMENTED);
- return ERR_NOT_IMPLEMENTED;
-}
-
HttpAuthHandlerNTLM::Factory::Factory() {
}
diff --git a/net/http/http_auth_handler_ntlm_win.cc b/net/http/http_auth_handler_ntlm_win.cc
index 0bd1e71..0f67c68 100644
--- a/net/http/http_auth_handler_ntlm_win.cc
+++ b/net/http/http_auth_handler_ntlm_win.cc
@@ -47,19 +47,6 @@ bool HttpAuthHandlerNTLM::AllowsDefaultCredentials() {
return url_security_manager_->CanUseDefaultCredentials(origin_);
}
-int HttpAuthHandlerNTLM::GenerateDefaultAuthToken(
- const HttpRequestInfo* request,
- const ProxyInfo* proxy,
- std::string* auth_token) {
- return auth_sspi_.GenerateAuthToken(
- NULL, // username
- NULL, // password
- CreateSPN(origin_),
- request,
- proxy,
- auth_token);
-}
-
HttpAuthHandlerNTLM::Factory::Factory()
: max_token_length_(0),
first_creation_(true),
diff --git a/net/http/http_auth_sspi_win.cc b/net/http/http_auth_sspi_win.cc
index 1f3165d..381d7ab 100644
--- a/net/http/http_auth_sspi_win.cc
+++ b/net/http/http_auth_sspi_win.cc
@@ -163,7 +163,6 @@ int HttpAuthSSPI::GenerateAuthToken(const std::wstring* username,
const std::wstring* password,
const std::wstring& spn,
const HttpRequestInfo* request,
- const ProxyInfo* proxy,
std::string* auth_token) {
DCHECK((username == NULL) == (password == NULL));
diff --git a/net/http/http_auth_sspi_win.h b/net/http/http_auth_sspi_win.h
index 12808bf..164bd07 100644
--- a/net/http/http_auth_sspi_win.h
+++ b/net/http/http_auth_sspi_win.h
@@ -96,7 +96,6 @@ class HttpAuthSSPI {
const std::wstring* password,
const std::wstring& spn,
const HttpRequestInfo* request,
- const ProxyInfo* proxy,
std::string* auth_token);
private:
diff --git a/net/http/http_network_transaction.cc b/net/http/http_network_transaction.cc
index d5361ce..b6dda2d 100644
--- a/net/http/http_network_transaction.cc
+++ b/net/http/http_network_transaction.cc
@@ -1905,18 +1905,16 @@ void HttpNetworkTransaction::AddAuthorizationHeader(
DCHECK(HaveAuth(target));
// Add a Authorization/Proxy-Authorization header line.
- std::string auth_token;
- int rv;
- if (auth_identity_[target].source ==
- HttpAuth::IDENT_SRC_DEFAULT_CREDENTIALS) {
- rv = auth_handler_[target]->GenerateDefaultAuthToken(
- request_, &proxy_info_, &auth_token);
- } else {
- rv = auth_handler_[target]->GenerateAuthToken(
- auth_identity_[target].username,
- auth_identity_[target].password,
- request_, &proxy_info_, &auth_token);
+ const std::wstring* username = NULL;
+ const std::wstring* password = NULL;
+ const HttpAuth::Identity& identity = auth_identity_[target];
+ if (identity.source != HttpAuth::IDENT_SRC_DEFAULT_CREDENTIALS) {
+ username = &identity.username;
+ password = &identity.password;
}
+ std::string auth_token;
+ int rv = auth_handler_[target]->GenerateAuthToken(
+ username, password, request_, NULL, &auth_token);
if (rv == OK) {
authorization_headers->SetHeader(
HttpAuth::GetAuthorizationHeaderName(target), auth_token);
diff --git a/net/http/http_network_transaction.h b/net/http/http_network_transaction.h
index 277df2a..d97d2d78 100644
--- a/net/http/http_network_transaction.h
+++ b/net/http/http_network_transaction.h
@@ -290,6 +290,8 @@ class HttpNetworkTransaction : public HttpTransaction {
// The following three auth members are arrays of size two -- index 0 is
// for the proxy server, and index 1 is for the origin server.
// Use the enum HttpAuth::Target to index into them.
+ // TODO(cbentzel): Just use explicit proxy_auth_handler_ and
+ // server_auth_handler_ and move identity into the handler directly.
// auth_handler encapsulates the logic for the particular auth-scheme.
// This includes the challenge's parameters. If NULL, then there is no
diff --git a/net/http/http_network_transaction_unittest.cc b/net/http/http_network_transaction_unittest.cc
index 9b08622..aaa2a19 100644
--- a/net/http/http_network_transaction_unittest.cc
+++ b/net/http/http_network_transaction_unittest.cc
@@ -5456,38 +5456,6 @@ class MockAuthHandlerCanonical : public HttpAuthHandler {
return rv;
}
- void OnResolveCanonicalName() {
- EXPECT_EQ(RESOLVE_ASYNC, resolve_);
- EXPECT_TRUE(user_callback_ != NULL);
- resolve_ = RESOLVE_TESTED;
- CompletionCallback* callback = user_callback_;
- user_callback_ = NULL;
- callback->Run(OK);
- }
-
- virtual bool Init(HttpAuth::ChallengeTokenizer* challenge) {
- scheme_ = "mock";
- score_ = 1;
- properties_ = 0;
- return true;
- }
-
- virtual int GenerateAuthToken(const std::wstring& username,
- const std::wstring& password,
- const HttpRequestInfo* request,
- const ProxyInfo* proxy,
- std::string* auth_token) {
- auth_token->assign("Mock AUTH myserver.example.com");
- return OK;
- }
-
- virtual int GenerateDefaultAuthToken(const HttpRequestInfo* request,
- const ProxyInfo* proxy,
- std::string* auth_token) {
- auth_token->assign("Mock DEFAULT_AUTH myserver.example.com");
- return OK;
- }
-
// The Factory class simply returns the same handler each time
// CreateAuthHandler is called.
class Factory : public HttpAuthHandlerFactory {
@@ -5516,7 +5484,36 @@ class MockAuthHandlerCanonical : public HttpAuthHandler {
scoped_ptr<HttpAuthHandler> handler_;
};
+ protected:
+ virtual bool Init(HttpAuth::ChallengeTokenizer* challenge) {
+ scheme_ = "mock";
+ score_ = 1;
+ properties_ = 0;
+ return true;
+ }
+
+ virtual int GenerateAuthTokenImpl(const std::wstring* username,
+ const std::wstring* password,
+ const HttpRequestInfo* request,
+ CompletionCallback* callback,
+ std::string* auth_token) {
+ if (username == NULL)
+ auth_token->assign("Mock DEFAULT_AUTH myserver.example.com");
+ else
+ auth_token->assign("Mock AUTH myserver.example.com");
+ return OK;
+ }
+
private:
+ void OnResolveCanonicalName() {
+ EXPECT_EQ(RESOLVE_ASYNC, resolve_);
+ EXPECT_TRUE(user_callback_ != NULL);
+ resolve_ = RESOLVE_TESTED;
+ CompletionCallback* callback = user_callback_;
+ user_callback_ = NULL;
+ callback->Run(OK);
+ }
+
Resolve resolve_;
CompletionCallback* user_callback_;
ScopedRunnableMethodFactory<MockAuthHandlerCanonical> method_factory_;
@@ -5532,7 +5529,12 @@ TEST_F(HttpNetworkTransactionTest, ResolveCanonicalName) {
for (int i = 0; i < 2; ++i) {
MockAuthHandlerCanonical* auth_handler(new MockAuthHandlerCanonical());
- auth_handler->Init(NULL);
+ std::string auth_challenge = "Mock";
+ GURL origin("http://www.example.com");
+ HttpAuth::ChallengeTokenizer tokenizer(auth_challenge.begin(),
+ auth_challenge.end());
+ auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER,
+ origin, BoundNetLog());
auth_factory->set_mock_handler(auth_handler);
scoped_ptr<HttpTransaction> trans(
diff --git a/net/socket_stream/socket_stream.cc b/net/socket_stream/socket_stream.cc
index 05c0bc9..a79af32 100644
--- a/net/socket_stream/socket_stream.cc
+++ b/net/socket_stream/socket_stream.cc
@@ -19,6 +19,7 @@
#include "net/base/net_errors.h"
#include "net/base/net_util.h"
#include "net/http/http_auth_handler_factory.h"
+#include "net/http/http_request_info.h"
#include "net/http/http_response_headers.h"
#include "net/http/http_util.h"
#include "net/socket/client_socket_factory.h"
@@ -567,11 +568,12 @@ int SocketStream::DoWriteTunnelHeaders() {
// TODO(ukai): Add support other authentication scheme.
if (auth_handler_.get() && auth_handler_->scheme() == "basic") {
std::string auth_token;
+ HttpRequestInfo request_info;
int rv = auth_handler_->GenerateAuthToken(
- auth_identity_.username,
- auth_identity_.password,
+ &auth_identity_.username,
+ &auth_identity_.password,
+ &request_info,
NULL,
- &proxy_info_,
&auth_token);
// TODO(cbentzel): Should do something different if credentials
// can't be generated. In this case, only Basic is allowed which