OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/http/http_auth_handler_factory.h" | 5 #include "net/http/http_auth_handler_factory.h" |
6 | 6 |
7 #include "base/stl_util.h" | 7 #include "base/stl_util.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "net/base/net_errors.h" | 9 #include "net/base/net_errors.h" |
10 #include "net/http/http_auth_challenge_tokenizer.h" | 10 #include "net/http/http_auth_challenge_tokenizer.h" |
11 #include "net/http/http_auth_filter.h" | 11 #include "net/http/http_auth_filter.h" |
12 #include "net/http/http_auth_handler_basic.h" | 12 #include "net/http/http_auth_handler_basic.h" |
13 #include "net/http/http_auth_handler_digest.h" | 13 #include "net/http/http_auth_handler_digest.h" |
14 #include "net/http/http_auth_handler_ntlm.h" | 14 #include "net/http/http_auth_handler_ntlm.h" |
15 | 15 |
16 #if defined(USE_KERBEROS) | 16 #if defined(USE_KERBEROS) |
17 #include "net/http/http_auth_handler_negotiate.h" | 17 #include "net/http/http_auth_handler_negotiate.h" |
18 #endif | 18 #endif |
19 | 19 |
20 namespace net { | 20 namespace net { |
21 | 21 |
22 int HttpAuthHandlerFactory::CreateAuthHandlerFromString( | |
23 const std::string& challenge, | |
24 HttpAuth::Target target, | |
25 const GURL& origin, | |
26 const BoundNetLog& net_log, | |
27 scoped_ptr<HttpAuthHandler>* handler) { | |
28 HttpAuthChallengeTokenizer props(challenge.begin(), challenge.end()); | |
29 return CreateAuthHandler(props, target, origin, CREATE_CHALLENGE, 1, net_log, | |
30 handler); | |
31 } | |
32 | |
33 int HttpAuthHandlerFactory::CreatePreemptiveAuthHandlerFromString( | |
34 const std::string& challenge, | |
35 HttpAuth::Target target, | |
36 const GURL& origin, | |
37 int digest_nonce_count, | |
38 const BoundNetLog& net_log, | |
39 scoped_ptr<HttpAuthHandler>* handler) { | |
40 HttpAuthChallengeTokenizer props(challenge.begin(), challenge.end()); | |
41 return CreateAuthHandler(props, target, origin, CREATE_PREEMPTIVE, | |
42 digest_nonce_count, net_log, handler); | |
43 } | |
44 | |
45 // static | 22 // static |
46 scoped_ptr<HttpAuthHandlerRegistryFactory> | 23 scoped_ptr<HttpAuthHandlerRegistryFactory> |
47 HttpAuthHandlerFactory::CreateDefault(HostResolver* host_resolver) { | 24 HttpAuthHandlerFactory::CreateDefault(HostResolver* host_resolver) { |
48 DCHECK(host_resolver); | 25 DCHECK(host_resolver); |
49 scoped_ptr<HttpAuthHandlerRegistryFactory> registry_factory = | 26 scoped_ptr<HttpAuthHandlerRegistryFactory> registry_factory = |
50 make_scoped_ptr(new HttpAuthHandlerRegistryFactory()); | 27 make_scoped_ptr(new HttpAuthHandlerRegistryFactory()); |
51 registry_factory->RegisterSchemeFactory( | 28 registry_factory->RegisterSchemeFactory( |
52 "basic", new HttpAuthHandlerBasic::Factory()); | 29 "basic", new HttpAuthHandlerBasic::Factory()); |
53 registry_factory->RegisterSchemeFactory( | 30 registry_factory->RegisterSchemeFactory( |
54 "digest", new HttpAuthHandlerDigest::Factory()); | 31 "digest", new HttpAuthHandlerDigest::Factory()); |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 negotiate_factory->set_host_resolver(host_resolver); | 147 negotiate_factory->set_host_resolver(host_resolver); |
171 negotiate_factory->set_disable_cname_lookup(negotiate_disable_cname_lookup); | 148 negotiate_factory->set_disable_cname_lookup(negotiate_disable_cname_lookup); |
172 negotiate_factory->set_use_port(negotiate_enable_port); | 149 negotiate_factory->set_use_port(negotiate_enable_port); |
173 registry_factory->RegisterSchemeFactory("negotiate", negotiate_factory); | 150 registry_factory->RegisterSchemeFactory("negotiate", negotiate_factory); |
174 } | 151 } |
175 #endif // defined(USE_KERBEROS) | 152 #endif // defined(USE_KERBEROS) |
176 | 153 |
177 return registry_factory; | 154 return registry_factory; |
178 } | 155 } |
179 | 156 |
180 int HttpAuthHandlerRegistryFactory::CreateAuthHandler( | 157 scoped_ptr<HttpAuthHandler> |
181 const HttpAuthChallengeTokenizer& challenge, | 158 HttpAuthHandlerRegistryFactory::CreateAuthHandlerForScheme( |
| 159 const std::string& scheme) { |
| 160 const auto it = factory_map_.find(scheme); |
| 161 if (it == factory_map_.end()) |
| 162 return scoped_ptr<HttpAuthHandler>(); |
| 163 DCHECK(it->second); |
| 164 return it->second->CreateAuthHandlerForScheme(scheme); |
| 165 } |
| 166 |
| 167 scoped_ptr<HttpAuthHandler> |
| 168 HttpAuthHandlerRegistryFactory::CreateAndInitPreemptiveAuthHandler( |
| 169 HttpAuthCache::Entry* cache_entry, |
| 170 const HttpAuthChallengeTokenizer& tokenizer, |
182 HttpAuth::Target target, | 171 HttpAuth::Target target, |
183 const GURL& origin, | 172 const BoundNetLog& net_log) { |
184 CreateReason reason, | 173 std::string scheme_name = cache_entry->scheme(); |
185 int digest_nonce_count, | 174 const auto it = factory_map_.find(scheme_name); |
186 const BoundNetLog& net_log, | 175 if (it == factory_map_.end()) |
187 scoped_ptr<HttpAuthHandler>* handler) { | 176 return scoped_ptr<HttpAuthHandler>(); |
188 std::string scheme = challenge.NormalizedScheme(); | |
189 if (scheme.empty()) { | |
190 handler->reset(); | |
191 return ERR_INVALID_RESPONSE; | |
192 } | |
193 FactoryMap::iterator it = factory_map_.find(scheme); | |
194 if (it == factory_map_.end()) { | |
195 handler->reset(); | |
196 return ERR_UNSUPPORTED_AUTH_SCHEME; | |
197 } | |
198 DCHECK(it->second); | 177 DCHECK(it->second); |
199 return it->second->CreateAuthHandler(challenge, target, origin, reason, | 178 return it->second->CreateAndInitPreemptiveAuthHandler(cache_entry, tokenizer, |
200 digest_nonce_count, net_log, handler); | 179 target, net_log); |
201 } | 180 } |
202 | 181 |
203 } // namespace net | 182 } // namespace net |
OLD | NEW |