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( | 22 int HttpAuthHandlerFactory::CreateAuthHandlerFromString( |
23 const std::string& challenge, | 23 const std::string& challenge, |
24 HttpAuth::Target target, | 24 HttpAuth::Target target, |
25 const GURL& origin, | 25 const GURL& origin, |
26 const BoundNetLog& net_log, | 26 const BoundNetLog& net_log, |
27 scoped_ptr<HttpAuthHandler>* handler) { | 27 scoped_ptr<HttpAuthHandler>* handler) { |
28 HttpAuthChallengeTokenizer props(challenge.begin(), challenge.end()); | 28 HttpAuthChallengeTokenizer props(challenge.begin(), challenge.end()); |
29 return CreateAuthHandler(&props, target, origin, CREATE_CHALLENGE, 1, | 29 return CreateAuthHandler( |
30 net_log, handler); | 30 &props, target, origin, CREATE_CHALLENGE, 1, net_log, handler); |
31 } | 31 } |
32 | 32 |
33 int HttpAuthHandlerFactory::CreatePreemptiveAuthHandlerFromString( | 33 int HttpAuthHandlerFactory::CreatePreemptiveAuthHandlerFromString( |
34 const std::string& challenge, | 34 const std::string& challenge, |
35 HttpAuth::Target target, | 35 HttpAuth::Target target, |
36 const GURL& origin, | 36 const GURL& origin, |
37 int digest_nonce_count, | 37 int digest_nonce_count, |
38 const BoundNetLog& net_log, | 38 const BoundNetLog& net_log, |
39 scoped_ptr<HttpAuthHandler>* handler) { | 39 scoped_ptr<HttpAuthHandler>* handler) { |
40 HttpAuthChallengeTokenizer props(challenge.begin(), challenge.end()); | 40 HttpAuthChallengeTokenizer props(challenge.begin(), challenge.end()); |
41 return CreateAuthHandler(&props, target, origin, CREATE_PREEMPTIVE, | 41 return CreateAuthHandler(&props, |
42 digest_nonce_count, net_log, handler); | 42 target, |
| 43 origin, |
| 44 CREATE_PREEMPTIVE, |
| 45 digest_nonce_count, |
| 46 net_log, |
| 47 handler); |
43 } | 48 } |
44 | 49 |
45 // static | 50 // static |
46 HttpAuthHandlerRegistryFactory* HttpAuthHandlerFactory::CreateDefault( | 51 HttpAuthHandlerRegistryFactory* HttpAuthHandlerFactory::CreateDefault( |
47 HostResolver* host_resolver) { | 52 HostResolver* host_resolver) { |
48 DCHECK(host_resolver); | 53 DCHECK(host_resolver); |
49 HttpAuthHandlerRegistryFactory* registry_factory = | 54 HttpAuthHandlerRegistryFactory* registry_factory = |
50 new HttpAuthHandlerRegistryFactory(); | 55 new HttpAuthHandlerRegistryFactory(); |
51 registry_factory->RegisterSchemeFactory( | 56 registry_factory->RegisterSchemeFactory("basic", |
52 "basic", new HttpAuthHandlerBasic::Factory()); | 57 new HttpAuthHandlerBasic::Factory()); |
53 registry_factory->RegisterSchemeFactory( | 58 registry_factory->RegisterSchemeFactory("digest", |
54 "digest", new HttpAuthHandlerDigest::Factory()); | 59 new HttpAuthHandlerDigest::Factory()); |
55 | 60 |
56 #if defined(USE_KERBEROS) | 61 #if defined(USE_KERBEROS) |
57 HttpAuthHandlerNegotiate::Factory* negotiate_factory = | 62 HttpAuthHandlerNegotiate::Factory* negotiate_factory = |
58 new HttpAuthHandlerNegotiate::Factory(); | 63 new HttpAuthHandlerNegotiate::Factory(); |
59 #if defined(OS_POSIX) | 64 #if defined(OS_POSIX) |
60 negotiate_factory->set_library(new GSSAPISharedLibrary(std::string())); | 65 negotiate_factory->set_library(new GSSAPISharedLibrary(std::string())); |
61 #elif defined(OS_WIN) | 66 #elif defined(OS_WIN) |
62 negotiate_factory->set_library(new SSPILibraryDefault()); | 67 negotiate_factory->set_library(new SSPILibraryDefault()); |
63 #endif | 68 #endif |
64 negotiate_factory->set_host_resolver(host_resolver); | 69 negotiate_factory->set_host_resolver(host_resolver); |
65 registry_factory->RegisterSchemeFactory("negotiate", negotiate_factory); | 70 registry_factory->RegisterSchemeFactory("negotiate", negotiate_factory); |
66 #endif // defined(USE_KERBEROS) | 71 #endif // defined(USE_KERBEROS) |
67 | 72 |
68 HttpAuthHandlerNTLM::Factory* ntlm_factory = | 73 HttpAuthHandlerNTLM::Factory* ntlm_factory = |
69 new HttpAuthHandlerNTLM::Factory(); | 74 new HttpAuthHandlerNTLM::Factory(); |
70 #if defined(OS_WIN) | 75 #if defined(OS_WIN) |
71 ntlm_factory->set_sspi_library(new SSPILibraryDefault()); | 76 ntlm_factory->set_sspi_library(new SSPILibraryDefault()); |
72 #endif | 77 #endif |
73 registry_factory->RegisterSchemeFactory("ntlm", ntlm_factory); | 78 registry_factory->RegisterSchemeFactory("ntlm", ntlm_factory); |
74 return registry_factory; | 79 return registry_factory; |
75 } | 80 } |
76 | 81 |
77 namespace { | 82 namespace { |
78 | 83 |
79 bool IsSupportedScheme(const std::vector<std::string>& supported_schemes, | 84 bool IsSupportedScheme(const std::vector<std::string>& supported_schemes, |
80 const std::string& scheme) { | 85 const std::string& scheme) { |
81 std::vector<std::string>::const_iterator it = std::find( | 86 std::vector<std::string>::const_iterator it = |
82 supported_schemes.begin(), supported_schemes.end(), scheme); | 87 std::find(supported_schemes.begin(), supported_schemes.end(), scheme); |
83 return it != supported_schemes.end(); | 88 return it != supported_schemes.end(); |
84 } | 89 } |
85 | 90 |
86 } // namespace | 91 } // namespace |
87 | 92 |
88 HttpAuthHandlerRegistryFactory::HttpAuthHandlerRegistryFactory() { | 93 HttpAuthHandlerRegistryFactory::HttpAuthHandlerRegistryFactory() { |
89 } | 94 } |
90 | 95 |
91 HttpAuthHandlerRegistryFactory::~HttpAuthHandlerRegistryFactory() { | 96 HttpAuthHandlerRegistryFactory::~HttpAuthHandlerRegistryFactory() { |
92 STLDeleteContainerPairSecondPointers(factory_map_.begin(), | 97 STLDeleteContainerPairSecondPointers(factory_map_.begin(), |
(...skipping 20 matching lines...) Expand all Loading... |
113 factory_map_[lower_scheme] = factory; | 118 factory_map_[lower_scheme] = factory; |
114 else | 119 else |
115 factory_map_.erase(it); | 120 factory_map_.erase(it); |
116 } | 121 } |
117 | 122 |
118 HttpAuthHandlerFactory* HttpAuthHandlerRegistryFactory::GetSchemeFactory( | 123 HttpAuthHandlerFactory* HttpAuthHandlerRegistryFactory::GetSchemeFactory( |
119 const std::string& scheme) const { | 124 const std::string& scheme) const { |
120 std::string lower_scheme = StringToLowerASCII(scheme); | 125 std::string lower_scheme = StringToLowerASCII(scheme); |
121 FactoryMap::const_iterator it = factory_map_.find(lower_scheme); | 126 FactoryMap::const_iterator it = factory_map_.find(lower_scheme); |
122 if (it == factory_map_.end()) { | 127 if (it == factory_map_.end()) { |
123 return NULL; // |scheme| is not registered. | 128 return NULL; // |scheme| is not registered. |
124 } | 129 } |
125 return it->second; | 130 return it->second; |
126 } | 131 } |
127 | 132 |
128 // static | 133 // static |
129 HttpAuthHandlerRegistryFactory* HttpAuthHandlerRegistryFactory::Create( | 134 HttpAuthHandlerRegistryFactory* HttpAuthHandlerRegistryFactory::Create( |
130 const std::vector<std::string>& supported_schemes, | 135 const std::vector<std::string>& supported_schemes, |
131 URLSecurityManager* security_manager, | 136 URLSecurityManager* security_manager, |
132 HostResolver* host_resolver, | 137 HostResolver* host_resolver, |
133 const std::string& gssapi_library_name, | 138 const std::string& gssapi_library_name, |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 handler->reset(); | 190 handler->reset(); |
186 return ERR_INVALID_RESPONSE; | 191 return ERR_INVALID_RESPONSE; |
187 } | 192 } |
188 std::string lower_scheme = StringToLowerASCII(scheme); | 193 std::string lower_scheme = StringToLowerASCII(scheme); |
189 FactoryMap::iterator it = factory_map_.find(lower_scheme); | 194 FactoryMap::iterator it = factory_map_.find(lower_scheme); |
190 if (it == factory_map_.end()) { | 195 if (it == factory_map_.end()) { |
191 handler->reset(); | 196 handler->reset(); |
192 return ERR_UNSUPPORTED_AUTH_SCHEME; | 197 return ERR_UNSUPPORTED_AUTH_SCHEME; |
193 } | 198 } |
194 DCHECK(it->second); | 199 DCHECK(it->second); |
195 return it->second->CreateAuthHandler(challenge, target, origin, reason, | 200 return it->second->CreateAuthHandler( |
196 digest_nonce_count, net_log, handler); | 201 challenge, target, origin, reason, digest_nonce_count, net_log, handler); |
197 } | 202 } |
198 | 203 |
199 } // namespace net | 204 } // namespace net |
OLD | NEW |