| 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_preferences.h" | 15 #include "net/http/http_auth_preferences.h" |
| 16 #include "net/http/http_auth_scheme.h" | 16 #include "net/http/http_auth_scheme.h" |
| 17 #include "net/http/http_response_info.h" |
| 17 | 18 |
| 18 #if defined(USE_KERBEROS) | 19 #if defined(USE_KERBEROS) |
| 19 #include "net/http/http_auth_handler_negotiate.h" | 20 #include "net/http/http_auth_handler_negotiate.h" |
| 20 #endif | 21 #endif |
| 21 | 22 |
| 22 namespace net { | 23 namespace net { |
| 23 | 24 |
| 24 int HttpAuthHandlerFactory::CreateAuthHandlerFromString( | 25 int HttpAuthHandlerFactory::CreateAuthHandlerFromString( |
| 25 const std::string& challenge, | 26 const std::string& challenge, |
| 26 HttpAuth::Target target, | 27 HttpAuth::Target target, |
| 28 const HttpResponseInfo& response_info, |
| 27 const GURL& origin, | 29 const GURL& origin, |
| 28 const BoundNetLog& net_log, | 30 const BoundNetLog& net_log, |
| 29 scoped_ptr<HttpAuthHandler>* handler) { | 31 scoped_ptr<HttpAuthHandler>* handler) { |
| 30 HttpAuthChallengeTokenizer props(challenge.begin(), challenge.end()); | 32 HttpAuthChallengeTokenizer props(challenge.begin(), challenge.end()); |
| 31 return CreateAuthHandler(&props, target, origin, CREATE_CHALLENGE, 1, | 33 return CreateAuthHandler(&props, target, response_info, origin, |
| 32 net_log, handler); | 34 CREATE_CHALLENGE, 1, net_log, handler); |
| 33 } | 35 } |
| 34 | 36 |
| 35 int HttpAuthHandlerFactory::CreatePreemptiveAuthHandlerFromString( | 37 int HttpAuthHandlerFactory::CreatePreemptiveAuthHandlerFromString( |
| 36 const std::string& challenge, | 38 const std::string& challenge, |
| 37 HttpAuth::Target target, | 39 HttpAuth::Target target, |
| 38 const GURL& origin, | 40 const GURL& origin, |
| 39 int digest_nonce_count, | 41 int digest_nonce_count, |
| 40 const BoundNetLog& net_log, | 42 const BoundNetLog& net_log, |
| 41 scoped_ptr<HttpAuthHandler>* handler) { | 43 scoped_ptr<HttpAuthHandler>* handler) { |
| 42 HttpAuthChallengeTokenizer props(challenge.begin(), challenge.end()); | 44 HttpAuthChallengeTokenizer props(challenge.begin(), challenge.end()); |
| 43 return CreateAuthHandler(&props, target, origin, CREATE_PREEMPTIVE, | 45 HttpResponseInfo null_response_info; |
| 44 digest_nonce_count, net_log, handler); | 46 return CreateAuthHandler(&props, target, null_response_info, origin, |
| 47 CREATE_PREEMPTIVE, digest_nonce_count, net_log, |
| 48 handler); |
| 45 } | 49 } |
| 46 | 50 |
| 47 namespace { | 51 namespace { |
| 48 | 52 |
| 49 const char* const kDefaultAuthSchemes[] = {kBasicAuthScheme, kDigestAuthScheme, | 53 const char* const kDefaultAuthSchemes[] = {kBasicAuthScheme, kDigestAuthScheme, |
| 50 #if defined(USE_KERBEROS) && !defined(OS_ANDROID) | 54 #if defined(USE_KERBEROS) && !defined(OS_ANDROID) |
| 51 kNegotiateAuthScheme, | 55 kNegotiateAuthScheme, |
| 52 #endif | 56 #endif |
| 53 kNtlmAuthScheme}; | 57 kNtlmAuthScheme}; |
| 54 | 58 |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 registry_factory->set_http_auth_preferences(prefs); | 158 registry_factory->set_http_auth_preferences(prefs); |
| 155 for (auto& factory_entry : registry_factory->factory_map_) { | 159 for (auto& factory_entry : registry_factory->factory_map_) { |
| 156 factory_entry.second->set_http_auth_preferences(prefs); | 160 factory_entry.second->set_http_auth_preferences(prefs); |
| 157 } | 161 } |
| 158 return registry_factory; | 162 return registry_factory; |
| 159 } | 163 } |
| 160 | 164 |
| 161 int HttpAuthHandlerRegistryFactory::CreateAuthHandler( | 165 int HttpAuthHandlerRegistryFactory::CreateAuthHandler( |
| 162 HttpAuthChallengeTokenizer* challenge, | 166 HttpAuthChallengeTokenizer* challenge, |
| 163 HttpAuth::Target target, | 167 HttpAuth::Target target, |
| 168 const HttpResponseInfo& response_info, |
| 164 const GURL& origin, | 169 const GURL& origin, |
| 165 CreateReason reason, | 170 CreateReason reason, |
| 166 int digest_nonce_count, | 171 int digest_nonce_count, |
| 167 const BoundNetLog& net_log, | 172 const BoundNetLog& net_log, |
| 168 scoped_ptr<HttpAuthHandler>* handler) { | 173 scoped_ptr<HttpAuthHandler>* handler) { |
| 169 std::string scheme = challenge->scheme(); | 174 std::string scheme = challenge->scheme(); |
| 170 if (scheme.empty()) { | 175 if (scheme.empty()) { |
| 171 handler->reset(); | 176 handler->reset(); |
| 172 return ERR_INVALID_RESPONSE; | 177 return ERR_INVALID_RESPONSE; |
| 173 } | 178 } |
| 174 std::string lower_scheme = base::ToLowerASCII(scheme); | 179 std::string lower_scheme = base::ToLowerASCII(scheme); |
| 175 FactoryMap::iterator it = factory_map_.find(lower_scheme); | 180 FactoryMap::iterator it = factory_map_.find(lower_scheme); |
| 176 if (it == factory_map_.end()) { | 181 if (it == factory_map_.end()) { |
| 177 handler->reset(); | 182 handler->reset(); |
| 178 return ERR_UNSUPPORTED_AUTH_SCHEME; | 183 return ERR_UNSUPPORTED_AUTH_SCHEME; |
| 179 } | 184 } |
| 180 DCHECK(it->second); | 185 DCHECK(it->second); |
| 181 return it->second->CreateAuthHandler(challenge, target, origin, reason, | 186 return it->second->CreateAuthHandler(challenge, target, response_info, origin, |
| 182 digest_nonce_count, net_log, handler); | 187 reason, digest_nonce_count, net_log, |
| 188 handler); |
| 183 } | 189 } |
| 184 | 190 |
| 185 } // namespace net | 191 } // namespace net |
| OLD | NEW |