Chromium Code Reviews| 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 static const char kBasic[] = "basic"; | |
|
Bernhard Bauer
2015/10/23 08:15:41
Static isn't necessary here, as const variables au
aberent
2015/10/23 15:40:33
Done.
| |
| 23 static const char kDigest[] = "digest"; | |
| 24 static const char kNtlm[] = "ntlm"; | |
| 25 static const char kNegotiate[] = "negotiate"; | |
| 26 | |
| 22 int HttpAuthHandlerFactory::CreateAuthHandlerFromString( | 27 int HttpAuthHandlerFactory::CreateAuthHandlerFromString( |
| 23 const std::string& challenge, | 28 const std::string& challenge, |
| 24 HttpAuth::Target target, | 29 HttpAuth::Target target, |
| 25 const GURL& origin, | 30 const GURL& origin, |
| 26 const BoundNetLog& net_log, | 31 const BoundNetLog& net_log, |
| 27 scoped_ptr<HttpAuthHandler>* handler) { | 32 scoped_ptr<HttpAuthHandler>* handler) { |
| 28 HttpAuthChallengeTokenizer props(challenge.begin(), challenge.end()); | 33 HttpAuthChallengeTokenizer props(challenge.begin(), challenge.end()); |
| 29 return CreateAuthHandler(&props, target, origin, CREATE_CHALLENGE, 1, | 34 return CreateAuthHandler(&props, target, origin, CREATE_CHALLENGE, 1, |
| 30 net_log, handler); | 35 net_log, handler); |
| 31 } | 36 } |
| 32 | 37 |
| 33 int HttpAuthHandlerFactory::CreatePreemptiveAuthHandlerFromString( | 38 int HttpAuthHandlerFactory::CreatePreemptiveAuthHandlerFromString( |
| 34 const std::string& challenge, | 39 const std::string& challenge, |
| 35 HttpAuth::Target target, | 40 HttpAuth::Target target, |
| 36 const GURL& origin, | 41 const GURL& origin, |
| 37 int digest_nonce_count, | 42 int digest_nonce_count, |
| 38 const BoundNetLog& net_log, | 43 const BoundNetLog& net_log, |
| 39 scoped_ptr<HttpAuthHandler>* handler) { | 44 scoped_ptr<HttpAuthHandler>* handler) { |
| 40 HttpAuthChallengeTokenizer props(challenge.begin(), challenge.end()); | 45 HttpAuthChallengeTokenizer props(challenge.begin(), challenge.end()); |
| 41 return CreateAuthHandler(&props, target, origin, CREATE_PREEMPTIVE, | 46 return CreateAuthHandler(&props, target, origin, CREATE_PREEMPTIVE, |
| 42 digest_nonce_count, net_log, handler); | 47 digest_nonce_count, net_log, handler); |
| 43 } | 48 } |
| 44 | 49 |
| 45 // static | 50 // static |
| 46 scoped_ptr<HttpAuthHandlerRegistryFactory> | 51 scoped_ptr<HttpAuthHandlerRegistryFactory> |
| 47 HttpAuthHandlerFactory::CreateDefault(HostResolver* host_resolver) { | 52 HttpAuthHandlerFactory::CreateDefault(HostResolver* host_resolver) { |
| 48 DCHECK(host_resolver); | 53 DCHECK(host_resolver); |
| 49 scoped_ptr<HttpAuthHandlerRegistryFactory> registry_factory = | 54 scoped_ptr<HttpAuthHandlerRegistryFactory> registry_factory = |
| 50 make_scoped_ptr(new HttpAuthHandlerRegistryFactory()); | 55 make_scoped_ptr(new HttpAuthHandlerRegistryFactory()); |
| 51 registry_factory->RegisterSchemeFactory( | 56 registry_factory->RegisterSchemeFactory(kBasic, |
| 52 "basic", new HttpAuthHandlerBasic::Factory()); | 57 new HttpAuthHandlerBasic::Factory()); |
| 53 registry_factory->RegisterSchemeFactory( | 58 registry_factory->RegisterSchemeFactory(kDigest, |
| 54 "digest", new HttpAuthHandlerDigest::Factory()); | 59 new HttpAuthHandlerDigest::Factory()); |
| 55 | 60 |
| 56 // On Android Chrome needs an account type configured to enable Kerberos, | 61 // On Android Chrome needs an account type configured to enable Kerberos, |
| 57 // so the default factory should not include Kerberos. | 62 // so the default factory should not include Kerberos. |
| 58 #if defined(USE_KERBEROS) && !defined(OS_ANDROID) | 63 #if defined(USE_KERBEROS) && !defined(OS_ANDROID) |
| 59 HttpAuthHandlerNegotiate::Factory* negotiate_factory = | 64 HttpAuthHandlerNegotiate::Factory* negotiate_factory = |
| 60 new HttpAuthHandlerNegotiate::Factory(); | 65 new HttpAuthHandlerNegotiate::Factory(); |
| 61 #if defined(OS_POSIX) | 66 #if defined(OS_POSIX) |
| 62 negotiate_factory->set_library(new GSSAPISharedLibrary(std::string())); | 67 negotiate_factory->set_library(new GSSAPISharedLibrary(std::string())); |
| 63 #elif defined(OS_WIN) | 68 #elif defined(OS_WIN) |
| 64 negotiate_factory->set_library(new SSPILibraryDefault()); | 69 negotiate_factory->set_library(new SSPILibraryDefault()); |
| 65 #endif | 70 #endif |
| 66 negotiate_factory->set_host_resolver(host_resolver); | 71 negotiate_factory->set_host_resolver(host_resolver); |
| 67 registry_factory->RegisterSchemeFactory("negotiate", negotiate_factory); | 72 registry_factory->RegisterSchemeFactory(kNegotiate, negotiate_factory); |
| 68 #endif // defined(USE_KERBEROS) && !defined(OS_ANDROID) | 73 #endif // defined(USE_KERBEROS) && !defined(OS_ANDROID) |
| 69 | 74 |
| 70 HttpAuthHandlerNTLM::Factory* ntlm_factory = | 75 HttpAuthHandlerNTLM::Factory* ntlm_factory = |
| 71 new HttpAuthHandlerNTLM::Factory(); | 76 new HttpAuthHandlerNTLM::Factory(); |
| 72 #if defined(OS_WIN) | 77 #if defined(OS_WIN) |
| 73 ntlm_factory->set_sspi_library(new SSPILibraryDefault()); | 78 ntlm_factory->set_sspi_library(new SSPILibraryDefault()); |
| 74 #endif | 79 #endif |
| 75 registry_factory->RegisterSchemeFactory("ntlm", ntlm_factory); | 80 registry_factory->RegisterSchemeFactory(kNtlm, ntlm_factory); |
| 76 return registry_factory; | 81 return registry_factory; |
| 77 } | 82 } |
| 78 | 83 |
| 79 namespace { | 84 namespace { |
| 80 | 85 |
| 81 bool IsSupportedScheme(const std::vector<std::string>& supported_schemes, | 86 bool IsSupportedScheme(const std::vector<std::string>& supported_schemes, |
| 82 const std::string& scheme) { | 87 const std::string& scheme) { |
| 83 std::vector<std::string>::const_iterator it = std::find( | 88 std::vector<std::string>::const_iterator it = std::find( |
| 84 supported_schemes.begin(), supported_schemes.end(), scheme); | 89 supported_schemes.begin(), supported_schemes.end(), scheme); |
| 85 return it != supported_schemes.end(); | 90 return it != supported_schemes.end(); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 123 FactoryMap::const_iterator it = factory_map_.find(lower_scheme); | 128 FactoryMap::const_iterator it = factory_map_.find(lower_scheme); |
| 124 if (it == factory_map_.end()) { | 129 if (it == factory_map_.end()) { |
| 125 return NULL; // |scheme| is not registered. | 130 return NULL; // |scheme| is not registered. |
| 126 } | 131 } |
| 127 return it->second; | 132 return it->second; |
| 128 } | 133 } |
| 129 | 134 |
| 130 // static | 135 // static |
| 131 HttpAuthHandlerRegistryFactory* HttpAuthHandlerRegistryFactory::Create( | 136 HttpAuthHandlerRegistryFactory* HttpAuthHandlerRegistryFactory::Create( |
| 132 const std::vector<std::string>& supported_schemes, | 137 const std::vector<std::string>& supported_schemes, |
| 133 URLSecurityManager* security_manager, | |
| 134 HostResolver* host_resolver, | 138 HostResolver* host_resolver, |
| 135 const std::string& gssapi_library_name, | 139 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 = | 140 HttpAuthHandlerRegistryFactory* registry_factory = |
| 140 new HttpAuthHandlerRegistryFactory(); | 141 new HttpAuthHandlerRegistryFactory(); |
| 141 if (IsSupportedScheme(supported_schemes, "basic")) | 142 if (IsSupportedScheme(supported_schemes, kBasic)) |
| 142 registry_factory->RegisterSchemeFactory( | 143 registry_factory->RegisterSchemeFactory( |
| 143 "basic", new HttpAuthHandlerBasic::Factory()); | 144 kBasic, new HttpAuthHandlerBasic::Factory()); |
| 144 if (IsSupportedScheme(supported_schemes, "digest")) | 145 if (IsSupportedScheme(supported_schemes, kDigest)) |
| 145 registry_factory->RegisterSchemeFactory( | 146 registry_factory->RegisterSchemeFactory( |
| 146 "digest", new HttpAuthHandlerDigest::Factory()); | 147 kDigest, new HttpAuthHandlerDigest::Factory()); |
| 147 if (IsSupportedScheme(supported_schemes, "ntlm")) { | 148 if (IsSupportedScheme(supported_schemes, kNtlm)) { |
| 148 HttpAuthHandlerNTLM::Factory* ntlm_factory = | 149 HttpAuthHandlerNTLM::Factory* ntlm_factory = |
| 149 new HttpAuthHandlerNTLM::Factory(); | 150 new HttpAuthHandlerNTLM::Factory(); |
| 150 ntlm_factory->set_url_security_manager(security_manager); | |
| 151 #if defined(OS_WIN) | 151 #if defined(OS_WIN) |
| 152 ntlm_factory->set_sspi_library(new SSPILibraryDefault()); | 152 ntlm_factory->set_sspi_library(new SSPILibraryDefault()); |
| 153 #endif | 153 #endif |
| 154 registry_factory->RegisterSchemeFactory("ntlm", ntlm_factory); | 154 registry_factory->RegisterSchemeFactory(kNtlm, ntlm_factory); |
| 155 } | 155 } |
| 156 #if defined(USE_KERBEROS) | 156 #if defined(USE_KERBEROS) |
| 157 if (IsSupportedScheme(supported_schemes, "negotiate")) { | 157 if (IsSupportedScheme(supported_schemes, kNegotiate)) { |
| 158 HttpAuthHandlerNegotiate::Factory* negotiate_factory = | 158 HttpAuthHandlerNegotiate::Factory* negotiate_factory = |
| 159 new HttpAuthHandlerNegotiate::Factory(); | 159 new HttpAuthHandlerNegotiate::Factory(); |
| 160 #if defined(OS_ANDROID) | 160 #if defined(OS_POSIX) && !defined(OS_ANDROID) |
| 161 negotiate_factory->set_library(&auth_android_negotiate_account_type); | |
| 162 #elif defined(OS_POSIX) | |
| 163 negotiate_factory->set_library( | 161 negotiate_factory->set_library( |
| 164 new GSSAPISharedLibrary(gssapi_library_name)); | 162 new GSSAPISharedLibrary(gssapi_library_name)); |
| 165 #elif defined(OS_WIN) | 163 #elif defined(OS_WIN) |
| 166 negotiate_factory->set_library(new SSPILibraryDefault()); | 164 negotiate_factory->set_library(new SSPILibraryDefault()); |
| 167 #endif | 165 #endif |
| 168 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(kNegotiate, negotiate_factory); |
| 172 negotiate_factory->set_use_port(negotiate_enable_port); | |
| 173 registry_factory->RegisterSchemeFactory("negotiate", negotiate_factory); | |
| 174 } | 168 } |
| 175 #endif // defined(USE_KERBEROS) | 169 #endif // defined(USE_KERBEROS) |
| 176 | 170 |
| 177 return registry_factory; | 171 return registry_factory; |
| 178 } | 172 } |
| 179 | 173 |
| 180 int HttpAuthHandlerRegistryFactory::CreateAuthHandler( | 174 int HttpAuthHandlerRegistryFactory::CreateAuthHandler( |
| 181 HttpAuthChallengeTokenizer* challenge, | 175 HttpAuthChallengeTokenizer* challenge, |
| 182 HttpAuth::Target target, | 176 HttpAuth::Target target, |
| 183 const GURL& origin, | 177 const GURL& origin, |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 194 FactoryMap::iterator it = factory_map_.find(lower_scheme); | 188 FactoryMap::iterator it = factory_map_.find(lower_scheme); |
| 195 if (it == factory_map_.end()) { | 189 if (it == factory_map_.end()) { |
| 196 handler->reset(); | 190 handler->reset(); |
| 197 return ERR_UNSUPPORTED_AUTH_SCHEME; | 191 return ERR_UNSUPPORTED_AUTH_SCHEME; |
| 198 } | 192 } |
| 199 DCHECK(it->second); | 193 DCHECK(it->second); |
| 200 return it->second->CreateAuthHandler(challenge, target, origin, reason, | 194 return it->second->CreateAuthHandler(challenge, target, origin, reason, |
| 201 digest_nonce_count, net_log, handler); | 195 digest_nonce_count, net_log, handler); |
| 202 } | 196 } |
| 203 | 197 |
| 198 void HttpAuthHandlerRegistryFactory::SetSecurityManager( | |
| 199 URLSecurityManager* security_manager) { | |
| 200 HttpAuthHandlerFactory* ntlm_factory = GetSchemeFactory(kNtlm); | |
| 201 if (ntlm_factory) | |
| 202 ntlm_factory->set_url_security_manager(security_manager); | |
| 203 HttpAuthHandlerFactory* negotiate_factory = GetSchemeFactory(kNegotiate); | |
| 204 if (negotiate_factory) | |
| 205 negotiate_factory->set_url_security_manager(security_manager); | |
| 206 } | |
| 207 | |
| 208 void HttpAuthHandlerRegistryFactory::SetAndroidAuthNegotiateAccountType( | |
| 209 const std::string& account_type) { | |
| 210 #if defined(OS_ANDROID) | |
| 211 auto negotiate_factory = static_cast<HttpAuthHandlerNegotiate::Factory*>( | |
| 212 GetSchemeFactory(kNegotiate)); | |
| 213 if (negotiate_factory) | |
| 214 negotiate_factory->set_library(&account_type); | |
| 215 #endif | |
| 216 } | |
| 217 | |
| 218 void HttpAuthHandlerRegistryFactory::SetNegotiateDisableCnameLookup( | |
| 219 bool negotiate_disable_cname_lookup) { | |
| 220 auto negotiate_factory = static_cast<HttpAuthHandlerNegotiate::Factory*>( | |
| 221 GetSchemeFactory(kNegotiate)); | |
| 222 if (negotiate_factory) | |
| 223 negotiate_factory->set_disable_cname_lookup(negotiate_disable_cname_lookup); | |
| 224 } | |
| 225 | |
| 226 void HttpAuthHandlerRegistryFactory::SetNegotiateEnablePort( | |
| 227 bool negotiate_enable_port) { | |
| 228 auto negotiate_factory = static_cast<HttpAuthHandlerNegotiate::Factory*>( | |
| 229 GetSchemeFactory(kNegotiate)); | |
| 230 if (negotiate_factory) | |
| 231 negotiate_factory->set_use_port(negotiate_enable_port); | |
| 232 } | |
| 233 | |
| 204 } // namespace net | 234 } // namespace net |
| OLD | NEW |