summaryrefslogtreecommitdiffstats
path: root/net/http/http_auth_handler_basic.cc
diff options
context:
space:
mode:
authorcbentzel@chromium.org <cbentzel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-15 14:25:50 +0000
committercbentzel@chromium.org <cbentzel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-15 14:25:50 +0000
commitfa55e1931013409ddbce59ed39f8b12a351fd0c4 (patch)
tree1ff77c48d22f36173c1fa63ae8acb1faf896aa0d /net/http/http_auth_handler_basic.cc
parente8da0a0066695284dbf698c9900617b3b159f33b (diff)
downloadchromium_src-fa55e1931013409ddbce59ed39f8b12a351fd0c4.zip
chromium_src-fa55e1931013409ddbce59ed39f8b12a351fd0c4.tar.gz
chromium_src-fa55e1931013409ddbce59ed39f8b12a351fd0c4.tar.bz2
Added factories for HttpAuthHandler.
The driving rationale for this change was to prevent choosing an AuthHandler when it is not supported on the system due to a missing runtime component (such as not being able to locate a gssapi shared library when seeing a Negotiate scheme). It also has the advantage (currently unused) of determining some per-auth-scheme properties only the first time that a challenge for that scheme is seen (such as maximum token length for the SSPI implementation of NTLM). Finally, it may make unit tests easier to generate since the factory can be easily mocked. BUG=34795 TEST=New unit test for HttpAuthHandlerDispatchFactory. Review URL: http://codereview.chromium.org/582007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@39065 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/http/http_auth_handler_basic.cc')
-rw-r--r--net/http/http_auth_handler_basic.cc35
1 files changed, 26 insertions, 9 deletions
diff --git a/net/http/http_auth_handler_basic.cc b/net/http/http_auth_handler_basic.cc
index 2c70577..3510ee2 100644
--- a/net/http/http_auth_handler_basic.cc
+++ b/net/http/http_auth_handler_basic.cc
@@ -21,25 +21,23 @@ namespace net {
//
// We allow it to be compatibility with certain embedded webservers that don't
// include a realm (see http://crbug.com/20984.)
-bool HttpAuthHandlerBasic::Init(std::string::const_iterator challenge_begin,
- std::string::const_iterator challenge_end) {
+bool HttpAuthHandlerBasic::Init(HttpAuth::ChallengeTokenizer* challenge) {
scheme_ = "basic";
score_ = 1;
properties_ = 0;
// Verify the challenge's auth-scheme.
- HttpAuth::ChallengeTokenizer challenge_tok(challenge_begin, challenge_end);
- if (!challenge_tok.valid() ||
- !LowerCaseEqualsASCII(challenge_tok.scheme(), "basic"))
+ if (!challenge->valid() ||
+ !LowerCaseEqualsASCII(challenge->scheme(), "basic"))
return false;
// Extract the realm (may be missing).
- while (challenge_tok.GetNext()) {
- if (LowerCaseEqualsASCII(challenge_tok.name(), "realm"))
- realm_ = challenge_tok.unquoted_value();
+ while (challenge->GetNext()) {
+ if (LowerCaseEqualsASCII(challenge->name(), "realm"))
+ realm_ = challenge->unquoted_value();
}
- return challenge_tok.valid();
+ return challenge->valid();
}
int HttpAuthHandlerBasic::GenerateAuthToken(
@@ -68,5 +66,24 @@ int HttpAuthHandlerBasic::GenerateDefaultAuthToken(
return ERR_NOT_IMPLEMENTED;
}
+HttpAuthHandlerBasic::Factory::Factory() {
+}
+
+HttpAuthHandlerBasic::Factory::~Factory() {
+}
+
+int HttpAuthHandlerBasic::Factory::CreateAuthHandler(
+ HttpAuth::ChallengeTokenizer* challenge,
+ HttpAuth::Target target,
+ const GURL& origin,
+ scoped_refptr<HttpAuthHandler>* handler) {
+ // TODO(cbentzel): Move towards model of parsing in the factory
+ // method and only constructing when valid.
+ scoped_refptr<HttpAuthHandler> tmp_handler(new HttpAuthHandlerBasic());
+ if (!tmp_handler->InitFromChallenge(challenge, target, origin))
+ return ERR_INVALID_RESPONSE;
+ handler->swap(tmp_handler);
+ return OK;
+}
} // namespace net