Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(272)

Side by Side Diff: net/http/http_auth_handler_negotiate.cc

Issue 1393693002: [net/http auth] Split HttpAuthHandler creation from initialization. Base URL: https://chromium.googlesource.com/chromium/src.git@rename-auth-handler-methods
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_negotiate.h" 5 #include "net/http/http_auth_handler_negotiate.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
11 #include "base/strings/stringprintf.h" 11 #include "base/strings/stringprintf.h"
12 #include "net/base/address_family.h" 12 #include "net/base/address_family.h"
13 #include "net/base/net_errors.h" 13 #include "net/base/net_errors.h"
14 #include "net/dns/host_resolver.h" 14 #include "net/dns/host_resolver.h"
15 #include "net/dns/single_request_host_resolver.h" 15 #include "net/dns/single_request_host_resolver.h"
16 #include "net/http/http_auth_challenge_tokenizer.h" 16 #include "net/http/http_auth_challenge_tokenizer.h"
17 #include "net/http/http_auth_filter.h" 17 #include "net/http/http_auth_filter.h"
18 #include "net/http/url_security_manager.h" 18 #include "net/http/url_security_manager.h"
19 19
20 // TODO(asanka): This file is a mess of platform dependent code. We should break
21 // it up.
20 namespace net { 22 namespace net {
21 23
22 HttpAuthHandlerNegotiate::Factory::Factory() 24 HttpAuthHandlerNegotiate::Factory::Factory()
23 : disable_cname_lookup_(false), 25 : disable_cname_lookup_(false),
24 use_port_(false), 26 use_port_(false),
25 resolver_(NULL), 27 resolver_(NULL),
26 #if defined(OS_WIN) 28 #if defined(OS_WIN)
27 max_token_length_(0), 29 max_token_length_(0),
28 #endif 30 #endif
29 is_unsupported_(false) { 31 is_unsupported_(false) {
30 } 32 }
31 33
32 HttpAuthHandlerNegotiate::Factory::~Factory() { 34 HttpAuthHandlerNegotiate::Factory::~Factory() {
33 } 35 }
34 36
35 void HttpAuthHandlerNegotiate::Factory::set_host_resolver( 37 void HttpAuthHandlerNegotiate::Factory::set_host_resolver(
36 HostResolver* resolver) { 38 HostResolver* resolver) {
37 resolver_ = resolver; 39 resolver_ = resolver;
38 } 40 }
39 41
40 int HttpAuthHandlerNegotiate::Factory::CreateAuthHandler( 42 scoped_ptr<HttpAuthHandler>
41 const HttpAuthChallengeTokenizer& challenge, 43 HttpAuthHandlerNegotiate::Factory::CreateAndInitPreemptiveAuthHandler(
44 HttpAuthCache::Entry* cache_entry,
45 const HttpAuthChallengeTokenizer& tokenizer,
42 HttpAuth::Target target, 46 HttpAuth::Target target,
43 const GURL& origin, 47 const BoundNetLog& net_log) {
44 CreateReason reason, 48 return scoped_ptr<HttpAuthHandler>();
45 int digest_nonce_count, 49 }
46 const BoundNetLog& net_log, 50
47 scoped_ptr<HttpAuthHandler>* handler) { 51 scoped_ptr<HttpAuthHandler>
52 HttpAuthHandlerNegotiate::Factory::CreateAuthHandlerForScheme(
53 const std::string& scheme) {
54 DCHECK(HttpAuth::IsValidNormalizedScheme(scheme));
55 if (scheme != "negotiate")
56 return scoped_ptr<HttpAuthHandler>();
48 #if defined(OS_WIN) 57 #if defined(OS_WIN)
49 if (is_unsupported_ || reason == CREATE_PREEMPTIVE) 58 if (is_unsupported_)
50 return ERR_UNSUPPORTED_AUTH_SCHEME; 59 return scoped_ptr<HttpAuthHandler>();
51 if (max_token_length_ == 0) { 60 if (max_token_length_ == 0) {
52 int rv = DetermineMaxTokenLength(auth_library_.get(), NEGOSSP_NAME, 61 int rv = DetermineMaxTokenLength(auth_library_.get(), NEGOSSP_NAME,
53 &max_token_length_); 62 &max_token_length_);
54 if (rv == ERR_UNSUPPORTED_AUTH_SCHEME) 63 if (rv == ERR_UNSUPPORTED_AUTH_SCHEME)
55 is_unsupported_ = true; 64 is_unsupported_ = true;
56 if (rv != OK) 65 if (rv != OK)
57 return rv; 66 return scoped_ptr<HttpAuthHandler>();
58 } 67 }
59 // TODO(cbentzel): Move towards model of parsing in the factory 68 // TODO(cbentzel): Move towards model of parsing in the factory
60 // method and only constructing when valid. 69 // method and only constructing when valid.
61 scoped_ptr<HttpAuthHandler> tmp_handler( 70 return make_scoped_ptr(new HttpAuthHandlerNegotiate(
62 new HttpAuthHandlerNegotiate(auth_library_.get(), max_token_length_, 71 auth_library_.get(), max_token_length_, url_security_manager(), resolver_,
63 url_security_manager(), resolver_, 72 disable_cname_lookup_, use_port_));
64 disable_cname_lookup_, use_port_));
65 #elif defined(OS_ANDROID) 73 #elif defined(OS_ANDROID)
66 if (is_unsupported_ || auth_library_->empty() || reason == CREATE_PREEMPTIVE) 74 if (is_unsupported_ || auth_library_->empty())
67 return ERR_UNSUPPORTED_AUTH_SCHEME; 75 return scoped_ptr<HttpAuthHandler>();
68 // TODO(cbentzel): Move towards model of parsing in the factory 76 // TODO(cbentzel): Move towards model of parsing in the factory
69 // method and only constructing when valid. 77 // method and only constructing when valid.
70 scoped_ptr<HttpAuthHandler> tmp_handler(new HttpAuthHandlerNegotiate( 78 return make_scoped_ptr(new HttpAuthHandlerNegotiate(
71 auth_library_.get(), url_security_manager(), resolver_, 79 auth_library_.get(), url_security_manager(), resolver_,
72 disable_cname_lookup_, use_port_)); 80 disable_cname_lookup_, use_port_));
73 #elif defined(OS_POSIX) 81 #elif defined(OS_POSIX)
74 if (is_unsupported_) 82 if (is_unsupported_)
75 return ERR_UNSUPPORTED_AUTH_SCHEME; 83 return scoped_ptr<HttpAuthHandler>();
76 if (!auth_library_->Init()) { 84 if (!auth_library_->Init()) {
77 is_unsupported_ = true; 85 is_unsupported_ = true;
78 return ERR_UNSUPPORTED_AUTH_SCHEME; 86 return scoped_ptr<HttpAuthHandler>();
79 } 87 }
80 // TODO(ahendrickson): Move towards model of parsing in the factory 88 // TODO(ahendrickson): Move towards model of parsing in the factory
81 // method and only constructing when valid. 89 // method and only constructing when valid.
82 scoped_ptr<HttpAuthHandler> tmp_handler( 90 return make_scoped_ptr(new HttpAuthHandlerNegotiate(
83 new HttpAuthHandlerNegotiate(auth_library_.get(), url_security_manager(), 91 auth_library_.get(), url_security_manager(), resolver_,
84 resolver_, disable_cname_lookup_, 92 disable_cname_lookup_, use_port_));
85 use_port_));
86 #endif 93 #endif
87 int result =
88 tmp_handler->HandleInitialChallenge(challenge, target, origin, net_log);
89 if (result == OK)
90 handler->swap(tmp_handler);
91 return result;
92 } 94 }
93 95
94 HttpAuthHandlerNegotiate::HttpAuthHandlerNegotiate( 96 HttpAuthHandlerNegotiate::HttpAuthHandlerNegotiate(
95 AuthLibrary* auth_library, 97 AuthLibrary* auth_library,
96 #if defined(OS_WIN) 98 #if defined(OS_WIN)
97 ULONG max_token_length, 99 ULONG max_token_length,
98 #endif 100 #endif
99 URLSecurityManager* url_security_manager, 101 URLSecurityManager* url_security_manager,
100 HostResolver* resolver, 102 HostResolver* resolver,
101 bool disable_cname_lookup, 103 bool disable_cname_lookup,
102 bool use_port) 104 bool use_port)
105 : HttpAuthHandler("negotiate"),
103 #if defined(OS_ANDROID) 106 #if defined(OS_ANDROID)
104 : auth_system_(*auth_library), 107 auth_system_(*auth_library),
105 #elif defined(OS_WIN) 108 #elif defined(OS_WIN)
106 : auth_system_(auth_library, "Negotiate", NEGOSSP_NAME, max_token_length), 109 auth_system_(auth_library, "Negotiate", NEGOSSP_NAME, max_token_length),
107 #elif defined(OS_POSIX) 110 #elif defined(OS_POSIX)
108 : auth_system_(auth_library, "Negotiate", CHROME_GSS_SPNEGO_MECH_OID_DESC), 111 auth_system_(auth_library, "Negotiate", CHROME_GSS_SPNEGO_MECH_OID_DESC),
109 #endif 112 #endif
110 disable_cname_lookup_(disable_cname_lookup), 113 disable_cname_lookup_(disable_cname_lookup),
111 use_port_(use_port), 114 use_port_(use_port),
112 resolver_(resolver), 115 resolver_(resolver),
113 already_called_(false), 116 already_called_(false),
114 has_credentials_(false), 117 has_credentials_(false),
115 auth_token_(NULL), 118 auth_token_(NULL),
116 next_state_(STATE_NONE), 119 next_state_(STATE_NONE),
117 url_security_manager_(url_security_manager) { 120 url_security_manager_(url_security_manager) {
118 } 121 }
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 bool HttpAuthHandlerNegotiate::CanDelegate() const { 344 bool HttpAuthHandlerNegotiate::CanDelegate() const {
342 // TODO(cbentzel): Should delegation be allowed on proxies? 345 // TODO(cbentzel): Should delegation be allowed on proxies?
343 if (target_ == HttpAuth::AUTH_PROXY) 346 if (target_ == HttpAuth::AUTH_PROXY)
344 return false; 347 return false;
345 if (!url_security_manager_) 348 if (!url_security_manager_)
346 return false; 349 return false;
347 return url_security_manager_->CanDelegate(origin_); 350 return url_security_manager_->CanDelegate(origin_);
348 } 351 }
349 352
350 } // namespace net 353 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_auth_handler_negotiate.h ('k') | net/http/http_auth_handler_negotiate_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698