| 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" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 return CreateAuthHandler(&props, target, origin, CREATE_PREEMPTIVE, | 41 return CreateAuthHandler(&props, target, origin, CREATE_PREEMPTIVE, |
| 42 digest_nonce_count, net_log, handler); | 42 digest_nonce_count, net_log, handler); |
| 43 } | 43 } |
| 44 | 44 |
| 45 // static | 45 // static |
| 46 scoped_ptr<HttpAuthHandlerRegistryFactory> | 46 scoped_ptr<HttpAuthHandlerRegistryFactory> |
| 47 HttpAuthHandlerFactory::CreateDefault(HostResolver* host_resolver) { | 47 HttpAuthHandlerFactory::CreateDefault(HostResolver* host_resolver) { |
| 48 DCHECK(host_resolver); | 48 DCHECK(host_resolver); |
| 49 scoped_ptr<HttpAuthHandlerRegistryFactory> registry_factory = | 49 scoped_ptr<HttpAuthHandlerRegistryFactory> registry_factory = |
| 50 make_scoped_ptr(new HttpAuthHandlerRegistryFactory()); | 50 make_scoped_ptr(new HttpAuthHandlerRegistryFactory()); |
| 51 registry_factory->RegisterSchemeFactory( | 51 registry_factory->RegisterSchemeFactory(kBasicAuthScheme, |
| 52 "basic", new HttpAuthHandlerBasic::Factory()); | 52 new HttpAuthHandlerBasic::Factory()); |
| 53 registry_factory->RegisterSchemeFactory( | 53 registry_factory->RegisterSchemeFactory(kDigestAuthScheme, |
| 54 "digest", new HttpAuthHandlerDigest::Factory()); | 54 new HttpAuthHandlerDigest::Factory()); |
| 55 | 55 |
| 56 // On Android Chrome needs an account type configured to enable Kerberos, | 56 // On Android Chrome needs an account type configured to enable Kerberos, |
| 57 // so the default factory should not include Kerberos. | 57 // so the default factory should not include Kerberos. |
| 58 #if defined(USE_KERBEROS) && !defined(OS_ANDROID) | 58 #if defined(USE_KERBEROS) && !defined(OS_ANDROID) |
| 59 HttpAuthHandlerNegotiate::Factory* negotiate_factory = | 59 HttpAuthHandlerNegotiate::Factory* negotiate_factory = |
| 60 new HttpAuthHandlerNegotiate::Factory(); | 60 new HttpAuthHandlerNegotiate::Factory(); |
| 61 #if defined(OS_POSIX) | 61 #if defined(OS_WIN) |
| 62 negotiate_factory->set_library(new GSSAPISharedLibrary(std::string())); | 62 negotiate_factory->set_library(make_scoped_ptr(new SSPILibraryDefault())); |
| 63 #elif defined(OS_WIN) | 63 #elif defined(OS_POSIX) |
| 64 negotiate_factory->set_library(new SSPILibraryDefault()); | 64 negotiate_factory->set_library( |
| 65 make_scoped_ptr(new GSSAPISharedLibrary(std::string()))); |
| 65 #endif | 66 #endif |
| 66 negotiate_factory->set_host_resolver(host_resolver); | 67 negotiate_factory->set_host_resolver(host_resolver); |
| 67 registry_factory->RegisterSchemeFactory("negotiate", negotiate_factory); | 68 registry_factory->RegisterSchemeFactory(kNegotiateAuthScheme, |
| 69 negotiate_factory); |
| 68 #endif // defined(USE_KERBEROS) && !defined(OS_ANDROID) | 70 #endif // defined(USE_KERBEROS) && !defined(OS_ANDROID) |
| 69 | 71 |
| 70 HttpAuthHandlerNTLM::Factory* ntlm_factory = | 72 HttpAuthHandlerNTLM::Factory* ntlm_factory = |
| 71 new HttpAuthHandlerNTLM::Factory(); | 73 new HttpAuthHandlerNTLM::Factory(); |
| 72 #if defined(OS_WIN) | 74 #if defined(OS_WIN) |
| 73 ntlm_factory->set_sspi_library(new SSPILibraryDefault()); | 75 ntlm_factory->set_sspi_library(new SSPILibraryDefault()); |
| 74 #endif | 76 #endif |
| 75 registry_factory->RegisterSchemeFactory("ntlm", ntlm_factory); | 77 registry_factory->RegisterSchemeFactory(kNtlmAuthScheme, ntlm_factory); |
| 76 return registry_factory; | 78 return registry_factory; |
| 77 } | 79 } |
| 78 | 80 |
| 79 namespace { | 81 namespace { |
| 80 | 82 |
| 81 bool IsSupportedScheme(const std::vector<std::string>& supported_schemes, | 83 bool IsSupportedScheme(const std::vector<std::string>& supported_schemes, |
| 82 const std::string& scheme) { | 84 const std::string& scheme) { |
| 83 std::vector<std::string>::const_iterator it = std::find( | 85 std::vector<std::string>::const_iterator it = std::find( |
| 84 supported_schemes.begin(), supported_schemes.end(), scheme); | 86 supported_schemes.begin(), supported_schemes.end(), scheme); |
| 85 return it != supported_schemes.end(); | 87 return it != supported_schemes.end(); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 return NULL; // |scheme| is not registered. | 127 return NULL; // |scheme| is not registered. |
| 126 } | 128 } |
| 127 return it->second; | 129 return it->second; |
| 128 } | 130 } |
| 129 | 131 |
| 130 // static | 132 // static |
| 131 HttpAuthHandlerRegistryFactory* HttpAuthHandlerRegistryFactory::Create( | 133 HttpAuthHandlerRegistryFactory* HttpAuthHandlerRegistryFactory::Create( |
| 132 const std::vector<std::string>& supported_schemes, | 134 const std::vector<std::string>& supported_schemes, |
| 133 URLSecurityManager* security_manager, | 135 URLSecurityManager* security_manager, |
| 134 HostResolver* host_resolver, | 136 HostResolver* host_resolver, |
| 135 const std::string& gssapi_library_name, | 137 const std::string& gssapi_library_name) { |
| 136 const std::string& auth_android_negotiate_account_type, | |
| 137 bool negotiate_disable_cname_lookup, | |
| 138 bool negotiate_enable_port) { | |
| 139 HttpAuthHandlerRegistryFactory* registry_factory = | 138 HttpAuthHandlerRegistryFactory* registry_factory = |
| 140 new HttpAuthHandlerRegistryFactory(); | 139 new HttpAuthHandlerRegistryFactory(); |
| 141 if (IsSupportedScheme(supported_schemes, "basic")) | 140 if (IsSupportedScheme(supported_schemes, kBasicAuthScheme)) |
| 142 registry_factory->RegisterSchemeFactory( | 141 registry_factory->RegisterSchemeFactory( |
| 143 "basic", new HttpAuthHandlerBasic::Factory()); | 142 kBasicAuthScheme, new HttpAuthHandlerBasic::Factory()); |
| 144 if (IsSupportedScheme(supported_schemes, "digest")) | 143 if (IsSupportedScheme(supported_schemes, kDigestAuthScheme)) |
| 145 registry_factory->RegisterSchemeFactory( | 144 registry_factory->RegisterSchemeFactory( |
| 146 "digest", new HttpAuthHandlerDigest::Factory()); | 145 kDigestAuthScheme, new HttpAuthHandlerDigest::Factory()); |
| 147 if (IsSupportedScheme(supported_schemes, "ntlm")) { | 146 if (IsSupportedScheme(supported_schemes, kNtlmAuthScheme)) { |
| 148 HttpAuthHandlerNTLM::Factory* ntlm_factory = | 147 HttpAuthHandlerNTLM::Factory* ntlm_factory = |
| 149 new HttpAuthHandlerNTLM::Factory(); | 148 new HttpAuthHandlerNTLM::Factory(); |
| 150 ntlm_factory->set_url_security_manager(security_manager); | |
| 151 #if defined(OS_WIN) | 149 #if defined(OS_WIN) |
| 152 ntlm_factory->set_sspi_library(new SSPILibraryDefault()); | 150 ntlm_factory->set_sspi_library(new SSPILibraryDefault()); |
| 153 #endif | 151 #endif |
| 154 registry_factory->RegisterSchemeFactory("ntlm", ntlm_factory); | 152 ntlm_factory->set_url_security_manager(security_manager); |
| 153 registry_factory->RegisterSchemeFactory(kNtlmAuthScheme, ntlm_factory); |
| 155 } | 154 } |
| 156 #if defined(USE_KERBEROS) | 155 #if defined(USE_KERBEROS) |
| 157 if (IsSupportedScheme(supported_schemes, "negotiate")) { | 156 if (IsSupportedScheme(supported_schemes, kNegotiateAuthScheme)) { |
| 158 HttpAuthHandlerNegotiate::Factory* negotiate_factory = | 157 HttpAuthHandlerNegotiate::Factory* negotiate_factory = |
| 159 new HttpAuthHandlerNegotiate::Factory(); | 158 new HttpAuthHandlerNegotiate::Factory(); |
| 160 #if defined(OS_ANDROID) | 159 #if defined(OS_WIN) |
| 161 negotiate_factory->set_library(&auth_android_negotiate_account_type); | 160 negotiate_factory->set_library(make_scoped_ptr(new SSPILibraryDefault())); |
| 162 #elif defined(OS_POSIX) | 161 #elif defined(OS_POSIX) && !defined(OS_ANDROID) |
| 163 negotiate_factory->set_library( | 162 negotiate_factory->set_library( |
| 164 new GSSAPISharedLibrary(gssapi_library_name)); | 163 make_scoped_ptr(new GSSAPISharedLibrary(gssapi_library_name))); |
| 165 #elif defined(OS_WIN) | |
| 166 negotiate_factory->set_library(new SSPILibraryDefault()); | |
| 167 #endif | 164 #endif |
| 168 negotiate_factory->set_url_security_manager(security_manager); | 165 negotiate_factory->set_url_security_manager(security_manager); |
| 169 DCHECK(host_resolver || negotiate_disable_cname_lookup); | |
| 170 negotiate_factory->set_host_resolver(host_resolver); | 166 negotiate_factory->set_host_resolver(host_resolver); |
| 171 negotiate_factory->set_disable_cname_lookup(negotiate_disable_cname_lookup); | 167 registry_factory->RegisterSchemeFactory(kNegotiateAuthScheme, |
| 172 negotiate_factory->set_use_port(negotiate_enable_port); | 168 negotiate_factory); |
| 173 registry_factory->RegisterSchemeFactory("negotiate", negotiate_factory); | |
| 174 } | 169 } |
| 175 #endif // defined(USE_KERBEROS) | 170 #endif // defined(USE_KERBEROS) |
| 176 | 171 |
| 177 return registry_factory; | 172 return registry_factory; |
| 178 } | 173 } |
| 179 | 174 |
| 180 int HttpAuthHandlerRegistryFactory::CreateAuthHandler( | 175 int HttpAuthHandlerRegistryFactory::CreateAuthHandler( |
| 181 HttpAuthChallengeTokenizer* challenge, | 176 HttpAuthChallengeTokenizer* challenge, |
| 182 HttpAuth::Target target, | 177 HttpAuth::Target target, |
| 183 const GURL& origin, | 178 const GURL& origin, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 194 FactoryMap::iterator it = factory_map_.find(lower_scheme); | 189 FactoryMap::iterator it = factory_map_.find(lower_scheme); |
| 195 if (it == factory_map_.end()) { | 190 if (it == factory_map_.end()) { |
| 196 handler->reset(); | 191 handler->reset(); |
| 197 return ERR_UNSUPPORTED_AUTH_SCHEME; | 192 return ERR_UNSUPPORTED_AUTH_SCHEME; |
| 198 } | 193 } |
| 199 DCHECK(it->second); | 194 DCHECK(it->second); |
| 200 return it->second->CreateAuthHandler(challenge, target, origin, reason, | 195 return it->second->CreateAuthHandler(challenge, target, origin, reason, |
| 201 digest_nonce_count, net_log, handler); | 196 digest_nonce_count, net_log, handler); |
| 202 } | 197 } |
| 203 | 198 |
| 199 void HttpAuthHandlerRegistryFactory::SetAndroidAuthNegotiateAccountType( |
| 200 const std::string& account_type) { |
| 201 #if defined(OS_ANDROID) |
| 202 for (std::pair<std::string, HttpAuthHandlerFactory*> map_entry : |
| 203 factory_map_) { |
| 204 map_entry.second->SetAndroidAuthNegotiateAccountType(account_type); |
| 205 } |
| 206 #endif |
| 207 } |
| 208 |
| 209 void HttpAuthHandlerRegistryFactory::SetNegotiateDisableCnameLookup( |
| 210 bool negotiate_disable_cname_lookup) { |
| 211 for (std::pair<std::string, HttpAuthHandlerFactory*> map_entry : |
| 212 factory_map_) { |
| 213 map_entry.second->SetNegotiateDisableCnameLookup( |
| 214 negotiate_disable_cname_lookup); |
| 215 } |
| 216 } |
| 217 |
| 218 void HttpAuthHandlerRegistryFactory::SetNegotiateEnablePort( |
| 219 bool negotiate_enable_port) { |
| 220 for (std::pair<std::string, HttpAuthHandlerFactory*> map_entry : |
| 221 factory_map_) { |
| 222 map_entry.second->SetNegotiateEnablePort(negotiate_enable_port); |
| 223 } |
| 224 } |
| 225 |
| 204 } // namespace net | 226 } // namespace net |
| OLD | NEW |