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 #include "net/http/http_auth_scheme.h" | |
| 15 | 16 |
| 16 #if defined(USE_KERBEROS) | 17 #if defined(USE_KERBEROS) |
| 17 #include "net/http/http_auth_handler_negotiate.h" | 18 #include "net/http/http_auth_handler_negotiate.h" |
| 18 #endif | 19 #endif |
| 19 | 20 |
| 20 namespace net { | 21 namespace net { |
| 21 | 22 |
| 22 int HttpAuthHandlerFactory::CreateAuthHandlerFromString( | 23 int HttpAuthHandlerFactory::CreateAuthHandlerFromString( |
| 23 const std::string& challenge, | 24 const std::string& challenge, |
| 24 HttpAuth::Target target, | 25 HttpAuth::Target target, |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 41 return CreateAuthHandler(&props, target, origin, CREATE_PREEMPTIVE, | 42 return CreateAuthHandler(&props, target, origin, CREATE_PREEMPTIVE, |
| 42 digest_nonce_count, net_log, handler); | 43 digest_nonce_count, net_log, handler); |
| 43 } | 44 } |
| 44 | 45 |
| 45 // static | 46 // static |
| 46 scoped_ptr<HttpAuthHandlerRegistryFactory> | 47 scoped_ptr<HttpAuthHandlerRegistryFactory> |
| 47 HttpAuthHandlerFactory::CreateDefault(HostResolver* host_resolver) { | 48 HttpAuthHandlerFactory::CreateDefault(HostResolver* host_resolver) { |
| 48 DCHECK(host_resolver); | 49 DCHECK(host_resolver); |
| 49 scoped_ptr<HttpAuthHandlerRegistryFactory> registry_factory = | 50 scoped_ptr<HttpAuthHandlerRegistryFactory> registry_factory = |
| 50 make_scoped_ptr(new HttpAuthHandlerRegistryFactory()); | 51 make_scoped_ptr(new HttpAuthHandlerRegistryFactory()); |
| 51 registry_factory->RegisterSchemeFactory( | 52 registry_factory->RegisterSchemeFactory(kBasicAuthScheme, |
| 52 "basic", new HttpAuthHandlerBasic::Factory()); | 53 new HttpAuthHandlerBasic::Factory()); |
| 53 registry_factory->RegisterSchemeFactory( | 54 registry_factory->RegisterSchemeFactory(kDigestAuthScheme, |
| 54 "digest", new HttpAuthHandlerDigest::Factory()); | 55 new HttpAuthHandlerDigest::Factory()); |
| 55 | 56 |
| 56 // On Android Chrome needs an account type configured to enable Kerberos, | 57 // On Android Chrome needs an account type configured to enable Kerberos, |
| 57 // so the default factory should not include Kerberos. | 58 // so the default factory should not include Kerberos. |
| 58 #if defined(USE_KERBEROS) && !defined(OS_ANDROID) | 59 #if defined(USE_KERBEROS) && !defined(OS_ANDROID) |
| 59 HttpAuthHandlerNegotiate::Factory* negotiate_factory = | 60 HttpAuthHandlerNegotiate::Factory* negotiate_factory = |
| 60 new HttpAuthHandlerNegotiate::Factory(); | 61 new HttpAuthHandlerNegotiate::Factory(); |
| 61 #if defined(OS_POSIX) | 62 #if defined(OS_WIN) |
| 62 negotiate_factory->set_library(new GSSAPISharedLibrary(std::string())); | 63 negotiate_factory->set_library(make_scoped_ptr(new SSPILibraryDefault())); |
| 63 #elif defined(OS_WIN) | 64 #elif defined(OS_POSIX) |
| 64 negotiate_factory->set_library(new SSPILibraryDefault()); | 65 negotiate_factory->set_library( |
| 66 make_scoped_ptr(new GSSAPISharedLibrary(std::string()))); | |
| 65 #endif | 67 #endif |
| 66 negotiate_factory->set_host_resolver(host_resolver); | 68 negotiate_factory->set_host_resolver(host_resolver); |
| 67 registry_factory->RegisterSchemeFactory("negotiate", negotiate_factory); | 69 registry_factory->RegisterSchemeFactory(kNegotiateAuthScheme, |
| 70 negotiate_factory); | |
| 68 #endif // defined(USE_KERBEROS) && !defined(OS_ANDROID) | 71 #endif // defined(USE_KERBEROS) && !defined(OS_ANDROID) |
| 69 | 72 |
| 70 HttpAuthHandlerNTLM::Factory* ntlm_factory = | 73 HttpAuthHandlerNTLM::Factory* ntlm_factory = |
| 71 new HttpAuthHandlerNTLM::Factory(); | 74 new HttpAuthHandlerNTLM::Factory(); |
| 72 #if defined(OS_WIN) | 75 #if defined(OS_WIN) |
| 73 ntlm_factory->set_sspi_library(new SSPILibraryDefault()); | 76 ntlm_factory->set_sspi_library(new SSPILibraryDefault()); |
| 74 #endif | 77 #endif |
| 75 registry_factory->RegisterSchemeFactory("ntlm", ntlm_factory); | 78 registry_factory->RegisterSchemeFactory(kNtlmAuthScheme, ntlm_factory); |
| 76 return registry_factory; | 79 return registry_factory; |
| 77 } | 80 } |
| 78 | 81 |
| 79 namespace { | 82 namespace { |
| 80 | 83 |
| 81 bool IsSupportedScheme(const std::vector<std::string>& supported_schemes, | 84 bool IsSupportedScheme(const std::vector<std::string>& supported_schemes, |
| 82 const std::string& scheme) { | 85 const std::string& scheme) { |
| 83 std::vector<std::string>::const_iterator it = std::find( | 86 std::vector<std::string>::const_iterator it = std::find( |
| 84 supported_schemes.begin(), supported_schemes.end(), scheme); | 87 supported_schemes.begin(), supported_schemes.end(), scheme); |
| 85 return it != supported_schemes.end(); | 88 return it != supported_schemes.end(); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 96 } | 99 } |
| 97 | 100 |
| 98 void HttpAuthHandlerRegistryFactory::SetURLSecurityManager( | 101 void HttpAuthHandlerRegistryFactory::SetURLSecurityManager( |
| 99 const std::string& scheme, | 102 const std::string& scheme, |
| 100 URLSecurityManager* security_manager) { | 103 URLSecurityManager* security_manager) { |
| 101 HttpAuthHandlerFactory* factory = GetSchemeFactory(scheme); | 104 HttpAuthHandlerFactory* factory = GetSchemeFactory(scheme); |
| 102 if (factory) | 105 if (factory) |
| 103 factory->set_url_security_manager(security_manager); | 106 factory->set_url_security_manager(security_manager); |
| 104 } | 107 } |
| 105 | 108 |
| 106 void HttpAuthHandlerRegistryFactory::RegisterSchemeFactory( | 109 void HttpAuthHandlerRegistryFactory::RegisterSchemeFactory( |
|
asanka
2015/11/10 15:48:06
This method should propagate dynamic properties wh
aberent
2015/11/13 17:46:32
Done.
| |
| 107 const std::string& scheme, | 110 const std::string& scheme, |
| 108 HttpAuthHandlerFactory* factory) { | 111 HttpAuthHandlerFactory* factory) { |
| 109 std::string lower_scheme = base::ToLowerASCII(scheme); | 112 std::string lower_scheme = base::ToLowerASCII(scheme); |
| 110 FactoryMap::iterator it = factory_map_.find(lower_scheme); | 113 FactoryMap::iterator it = factory_map_.find(lower_scheme); |
| 111 if (it != factory_map_.end()) { | 114 if (it != factory_map_.end()) { |
| 112 delete it->second; | 115 delete it->second; |
| 113 } | 116 } |
| 114 if (factory) | 117 if (factory) |
| 115 factory_map_[lower_scheme] = factory; | 118 factory_map_[lower_scheme] = factory; |
| 116 else | 119 else |
| 117 factory_map_.erase(it); | 120 factory_map_.erase(it); |
| 118 } | 121 } |
| 119 | 122 |
| 120 HttpAuthHandlerFactory* HttpAuthHandlerRegistryFactory::GetSchemeFactory( | 123 HttpAuthHandlerFactory* HttpAuthHandlerRegistryFactory::GetSchemeFactory( |
| 121 const std::string& scheme) const { | 124 const std::string& scheme) const { |
| 122 std::string lower_scheme = base::ToLowerASCII(scheme); | 125 std::string lower_scheme = base::ToLowerASCII(scheme); |
| 123 FactoryMap::const_iterator it = factory_map_.find(lower_scheme); | 126 FactoryMap::const_iterator it = factory_map_.find(lower_scheme); |
| 124 if (it == factory_map_.end()) { | 127 if (it == factory_map_.end()) { |
| 125 return NULL; // |scheme| is not registered. | 128 return NULL; // |scheme| is not registered. |
| 126 } | 129 } |
| 127 return it->second; | 130 return it->second; |
| 128 } | 131 } |
| 129 | 132 |
| 130 // static | 133 // static |
| 131 HttpAuthHandlerRegistryFactory* HttpAuthHandlerRegistryFactory::Create( | 134 HttpAuthHandlerRegistryFactory* HttpAuthHandlerRegistryFactory::Create( |
| 132 const std::vector<std::string>& supported_schemes, | 135 const std::vector<std::string>& supported_schemes, |
| 133 URLSecurityManager* security_manager, | 136 URLSecurityManager* security_manager, |
| 134 HostResolver* host_resolver, | 137 HostResolver* host_resolver, |
| 135 const std::string& gssapi_library_name, | 138 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 = | 139 HttpAuthHandlerRegistryFactory* registry_factory = |
| 140 new HttpAuthHandlerRegistryFactory(); | 140 new HttpAuthHandlerRegistryFactory(); |
| 141 if (IsSupportedScheme(supported_schemes, "basic")) | 141 if (IsSupportedScheme(supported_schemes, kBasicAuthScheme)) |
| 142 registry_factory->RegisterSchemeFactory( | 142 registry_factory->RegisterSchemeFactory( |
| 143 "basic", new HttpAuthHandlerBasic::Factory()); | 143 kBasicAuthScheme, new HttpAuthHandlerBasic::Factory()); |
| 144 if (IsSupportedScheme(supported_schemes, "digest")) | 144 if (IsSupportedScheme(supported_schemes, kDigestAuthScheme)) |
| 145 registry_factory->RegisterSchemeFactory( | 145 registry_factory->RegisterSchemeFactory( |
| 146 "digest", new HttpAuthHandlerDigest::Factory()); | 146 kDigestAuthScheme, new HttpAuthHandlerDigest::Factory()); |
| 147 if (IsSupportedScheme(supported_schemes, "ntlm")) { | 147 if (IsSupportedScheme(supported_schemes, kNtlmAuthScheme)) { |
| 148 HttpAuthHandlerNTLM::Factory* ntlm_factory = | 148 HttpAuthHandlerNTLM::Factory* ntlm_factory = |
| 149 new HttpAuthHandlerNTLM::Factory(); | 149 new HttpAuthHandlerNTLM::Factory(); |
| 150 ntlm_factory->set_url_security_manager(security_manager); | |
| 151 #if defined(OS_WIN) | 150 #if defined(OS_WIN) |
| 152 ntlm_factory->set_sspi_library(new SSPILibraryDefault()); | 151 ntlm_factory->set_sspi_library(new SSPILibraryDefault()); |
| 153 #endif | 152 #endif |
| 154 registry_factory->RegisterSchemeFactory("ntlm", ntlm_factory); | 153 ntlm_factory->set_url_security_manager(security_manager); |
| 154 registry_factory->RegisterSchemeFactory(kNtlmAuthScheme, 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, kNegotiateAuthScheme)) { |
| 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_WIN) |
| 161 negotiate_factory->set_library(&auth_android_negotiate_account_type); | 161 negotiate_factory->set_library(make_scoped_ptr(new SSPILibraryDefault())); |
| 162 #elif defined(OS_POSIX) | 162 #elif defined(OS_POSIX) && !defined(OS_ANDROID) |
| 163 negotiate_factory->set_library( | 163 negotiate_factory->set_library( |
| 164 new GSSAPISharedLibrary(gssapi_library_name)); | 164 make_scoped_ptr(new GSSAPISharedLibrary(gssapi_library_name))); |
| 165 #elif defined(OS_WIN) | |
| 166 negotiate_factory->set_library(new SSPILibraryDefault()); | |
| 167 #endif | 165 #endif |
| 168 negotiate_factory->set_url_security_manager(security_manager); | 166 negotiate_factory->set_url_security_manager(security_manager); |
| 169 DCHECK(host_resolver || negotiate_disable_cname_lookup); | |
| 170 negotiate_factory->set_host_resolver(host_resolver); | 167 negotiate_factory->set_host_resolver(host_resolver); |
| 171 negotiate_factory->set_disable_cname_lookup(negotiate_disable_cname_lookup); | 168 registry_factory->RegisterSchemeFactory(kNegotiateAuthScheme, |
| 172 negotiate_factory->set_use_port(negotiate_enable_port); | 169 negotiate_factory); |
| 173 registry_factory->RegisterSchemeFactory("negotiate", negotiate_factory); | |
| 174 } | 170 } |
| 175 #endif // defined(USE_KERBEROS) | 171 #endif // defined(USE_KERBEROS) |
| 176 | 172 |
| 177 return registry_factory; | 173 return registry_factory; |
| 178 } | 174 } |
| 179 | 175 |
| 180 int HttpAuthHandlerRegistryFactory::CreateAuthHandler( | 176 int HttpAuthHandlerRegistryFactory::CreateAuthHandler( |
| 181 HttpAuthChallengeTokenizer* challenge, | 177 HttpAuthChallengeTokenizer* challenge, |
| 182 HttpAuth::Target target, | 178 HttpAuth::Target target, |
| 183 const GURL& origin, | 179 const GURL& origin, |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 194 FactoryMap::iterator it = factory_map_.find(lower_scheme); | 190 FactoryMap::iterator it = factory_map_.find(lower_scheme); |
| 195 if (it == factory_map_.end()) { | 191 if (it == factory_map_.end()) { |
| 196 handler->reset(); | 192 handler->reset(); |
| 197 return ERR_UNSUPPORTED_AUTH_SCHEME; | 193 return ERR_UNSUPPORTED_AUTH_SCHEME; |
| 198 } | 194 } |
| 199 DCHECK(it->second); | 195 DCHECK(it->second); |
| 200 return it->second->CreateAuthHandler(challenge, target, origin, reason, | 196 return it->second->CreateAuthHandler(challenge, target, origin, reason, |
| 201 digest_nonce_count, net_log, handler); | 197 digest_nonce_count, net_log, handler); |
| 202 } | 198 } |
| 203 | 199 |
| 200 void HttpAuthHandlerRegistryFactory::SetAndroidAuthNegotiateAccountType( | |
| 201 const std::string& account_type) { | |
| 202 #if defined(OS_ANDROID) | |
|
asanka
2015/11/10 15:48:06
Can we comment out the entire method for !OS_ANDRO
aberent
2015/11/13 17:46:32
Method no longer exists. Methods for account type
| |
| 203 for (std::pair<std::string, HttpAuthHandlerFactory*> map_entry : | |
| 204 factory_map_) { | |
| 205 map_entry.second->SetAndroidAuthNegotiateAccountType(account_type); | |
| 206 } | |
| 207 #endif | |
| 208 } | |
| 209 | |
| 210 void HttpAuthHandlerRegistryFactory::SetNegotiateDisableCnameLookup( | |
| 211 bool negotiate_disable_cname_lookup) { | |
| 212 for (std::pair<std::string, HttpAuthHandlerFactory*> map_entry : | |
| 213 factory_map_) { | |
| 214 map_entry.second->SetNegotiateDisableCnameLookup( | |
| 215 negotiate_disable_cname_lookup); | |
| 216 } | |
| 217 } | |
| 218 | |
| 219 void HttpAuthHandlerRegistryFactory::SetNegotiateEnablePort( | |
| 220 bool negotiate_enable_port) { | |
| 221 for (std::pair<std::string, HttpAuthHandlerFactory*> map_entry : | |
| 222 factory_map_) { | |
| 223 map_entry.second->SetNegotiateEnablePort(negotiate_enable_port); | |
| 224 } | |
| 225 } | |
| 226 | |
| 204 } // namespace net | 227 } // namespace net |
| OLD | NEW |