OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef NET_HTTP_HTTP_AUTH_HANDLER_FACTORY_H_ | 5 #ifndef NET_HTTP_HTTP_AUTH_HANDLER_FACTORY_H_ |
6 #define NET_HTTP_HTTP_AUTH_HANDLER_FACTORY_H_ | 6 #define NET_HTTP_HTTP_AUTH_HANDLER_FACTORY_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "net/base/net_export.h" | 13 #include "net/base/net_export.h" |
14 #include "net/http/http_auth.h" | 14 #include "net/http/http_auth.h" |
15 #include "net/http/url_security_manager.h" | 15 #include "net/http/url_security_manager.h" |
16 | 16 |
17 class GURL; | 17 class GURL; |
18 | 18 |
19 namespace net { | 19 namespace net { |
20 | 20 |
21 class BoundNetLog; | 21 class BoundNetLog; |
| 22 class HttpAuthPreferences; |
22 class HostResolver; | 23 class HostResolver; |
23 class HttpAuthChallengeTokenizer; | 24 class HttpAuthChallengeTokenizer; |
24 class HttpAuthHandler; | 25 class HttpAuthHandler; |
25 class HttpAuthHandlerRegistryFactory; | 26 class HttpAuthHandlerRegistryFactory; |
26 | 27 |
27 // An HttpAuthHandlerFactory is used to create HttpAuthHandler objects. | 28 // An HttpAuthHandlerFactory is used to create HttpAuthHandler objects. |
28 // The HttpAuthHandlerFactory object _must_ outlive any of the HttpAuthHandler | 29 // The HttpAuthHandlerFactory object _must_ outlive any of the HttpAuthHandler |
29 // objects that it creates. | 30 // objects that it creates. |
30 class NET_EXPORT HttpAuthHandlerFactory { | 31 class NET_EXPORT HttpAuthHandlerFactory { |
31 public: | 32 public: |
32 enum CreateReason { | 33 enum CreateReason { |
33 CREATE_CHALLENGE, // Create a handler in response to a challenge. | 34 CREATE_CHALLENGE, // Create a handler in response to a challenge. |
34 CREATE_PREEMPTIVE, // Create a handler preemptively. | 35 CREATE_PREEMPTIVE, // Create a handler preemptively. |
35 }; | 36 }; |
36 | 37 |
37 HttpAuthHandlerFactory() : url_security_manager_(NULL) {} | 38 HttpAuthHandlerFactory() : http_auth_preferences_(NULL) {} |
38 virtual ~HttpAuthHandlerFactory() {} | 39 virtual ~HttpAuthHandlerFactory() {} |
39 | 40 |
40 // Sets an URL security manager. HttpAuthHandlerFactory doesn't own the URL | 41 // Sets the source of the HTTP authentication preferences. |
41 // security manager, and the URL security manager should outlive this object. | 42 // HttpAuthHandlerFactory doesn't own the preferences, and the |
42 void set_url_security_manager(URLSecurityManager* url_security_manager) { | 43 // HttpAuthPreferences object should outlive the factory and any handlers it |
43 url_security_manager_ = url_security_manager; | 44 // creates. |
| 45 void set_http_auth_preferences( |
| 46 const HttpAuthPreferences* http_auth_preferences) { |
| 47 http_auth_preferences_ = http_auth_preferences; |
44 } | 48 } |
45 | 49 |
46 // Retrieves the associated URL security manager. | 50 // Retrieves the associated URL security manager. |
47 URLSecurityManager* url_security_manager() { | 51 const HttpAuthPreferences* http_auth_preferences() { |
48 return url_security_manager_; | 52 return http_auth_preferences_; |
49 } | 53 } |
50 | 54 |
51 // Creates an HttpAuthHandler object based on the authentication | 55 // Creates an HttpAuthHandler object based on the authentication |
52 // challenge specified by |*challenge|. |challenge| must point to a valid | 56 // challenge specified by |*challenge|. |challenge| must point to a valid |
53 // non-NULL tokenizer. | 57 // non-NULL tokenizer. |
54 // | 58 // |
55 // If an HttpAuthHandler object is successfully created it is passed back to | 59 // If an HttpAuthHandler object is successfully created it is passed back to |
56 // the caller through |*handler| and OK is returned. | 60 // the caller through |*handler| and OK is returned. |
57 // | 61 // |
58 // If |*challenge| specifies an unsupported authentication scheme, |*handler| | 62 // If |*challenge| specifies an unsupported authentication scheme, |*handler| |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 // | 116 // |
113 // |resolver| is used by the Negotiate authentication handler to perform | 117 // |resolver| is used by the Negotiate authentication handler to perform |
114 // CNAME lookups to generate a Kerberos SPN for the server. It must be | 118 // CNAME lookups to generate a Kerberos SPN for the server. It must be |
115 // non-NULL. |resolver| must remain valid for the lifetime of the | 119 // non-NULL. |resolver| must remain valid for the lifetime of the |
116 // HttpAuthHandlerRegistryFactory and any HttpAuthHandlers created by said | 120 // HttpAuthHandlerRegistryFactory and any HttpAuthHandlers created by said |
117 // factory. | 121 // factory. |
118 static scoped_ptr<HttpAuthHandlerRegistryFactory> CreateDefault( | 122 static scoped_ptr<HttpAuthHandlerRegistryFactory> CreateDefault( |
119 HostResolver* resolver); | 123 HostResolver* resolver); |
120 | 124 |
121 private: | 125 private: |
122 // The URL security manager | 126 // The preferences for HTTP authentication. |
123 URLSecurityManager* url_security_manager_; | 127 const HttpAuthPreferences* http_auth_preferences_; |
124 | 128 |
125 DISALLOW_COPY_AND_ASSIGN(HttpAuthHandlerFactory); | 129 DISALLOW_COPY_AND_ASSIGN(HttpAuthHandlerFactory); |
126 }; | 130 }; |
127 | 131 |
128 // The HttpAuthHandlerRegistryFactory dispatches create requests out | 132 // The HttpAuthHandlerRegistryFactory dispatches create requests out |
129 // to other factories based on the auth scheme. | 133 // to other factories based on the auth scheme. |
130 class NET_EXPORT HttpAuthHandlerRegistryFactory | 134 class NET_EXPORT HttpAuthHandlerRegistryFactory |
131 : public HttpAuthHandlerFactory { | 135 : public HttpAuthHandlerFactory { |
132 public: | 136 public: |
133 HttpAuthHandlerRegistryFactory(); | 137 HttpAuthHandlerRegistryFactory(); |
134 ~HttpAuthHandlerRegistryFactory() override; | 138 ~HttpAuthHandlerRegistryFactory() override; |
135 | 139 |
136 // Sets an URL security manager into the factory associated with |scheme|. | 140 // Sets the preferences into the factory associated with |scheme|. |
137 void SetURLSecurityManager(const std::string& scheme, | 141 void SetHttpAuthPreferences(const std::string& scheme, |
138 URLSecurityManager* url_security_manager); | 142 const HttpAuthPreferences* prefs); |
139 | 143 |
140 // Registers a |factory| that will be used for a particular HTTP | 144 // Registers a |factory| that will be used for a particular HTTP |
141 // authentication scheme such as Basic, Digest, or Negotiate. | 145 // authentication scheme such as Basic, Digest, or Negotiate. |
142 // The |*factory| object is assumed to be new-allocated, and its lifetime | 146 // The |*factory| object is assumed to be new-allocated, and its lifetime |
143 // will be managed by this HttpAuthHandlerRegistryFactory object (including | 147 // will be managed by this HttpAuthHandlerRegistryFactory object (including |
144 // deleting it when it is no longer used. | 148 // deleting it when it is no longer used. |
145 // A NULL |factory| value means that HttpAuthHandlers's will not be created | 149 // A NULL |factory| value means that HttpAuthHandlers's will not be created |
146 // for |scheme|. If a factory object used to exist for |scheme|, it will be | 150 // for |scheme|. If a factory object used to exist for |scheme|, it will be |
147 // deleted. | 151 // deleted. |
148 void RegisterSchemeFactory(const std::string& scheme, | 152 void RegisterSchemeFactory(const std::string& scheme, |
149 HttpAuthHandlerFactory* factory); | 153 HttpAuthHandlerFactory* factory); |
150 | 154 |
151 // Retrieve the factory for the specified |scheme|. If no factory exists | 155 // Retrieve the factory for the specified |scheme|. If no factory exists |
152 // for the |scheme|, NULL is returned. The returned factory must not be | 156 // for the |scheme|, NULL is returned. The returned factory must not be |
153 // deleted by the caller, and it is guaranteed to be valid until either | 157 // deleted by the caller, and it is guaranteed to be valid until either |
154 // a new factory is registered for the same scheme, or until this | 158 // a new factory is registered for the same scheme, or until this |
155 // registry factory is destroyed. | 159 // registry factory is destroyed. |
156 HttpAuthHandlerFactory* GetSchemeFactory(const std::string& scheme) const; | 160 HttpAuthHandlerFactory* GetSchemeFactory(const std::string& scheme) const; |
157 | 161 |
158 // Creates an HttpAuthHandlerRegistryFactory. | 162 // Creates an HttpAuthHandlerRegistryFactory. |
159 // | 163 // |
160 // |supported_schemes| is a list of authentication schemes. Valid values | 164 // |prefs| is a pointer to the (single) authentication preferences object. |
161 // include "basic", "digest", "ntlm", and "negotiate", where case matters. | 165 // That object tracks preference, and hence policy, updates relevant to HTTP |
162 // | 166 // authentication, and provides the current values of the preferences. |
163 // |security_manager| is used by the NTLM and Negotiate authenticators | |
164 // to determine which servers Integrated Authentication can be used with. If | |
165 // NULL, Integrated Authentication will not be used with any server. | |
166 // | 167 // |
167 // |host_resolver| is used by the Negotiate authentication handler to perform | 168 // |host_resolver| is used by the Negotiate authentication handler to perform |
168 // CNAME lookups to generate a Kerberos SPN for the server. If the "negotiate" | 169 // CNAME lookups to generate a Kerberos SPN for the server. If the "negotiate" |
169 // scheme is used and |negotiate_disable_cname_lookup| is false, | 170 // scheme is used and |negotiate_disable_cname_lookup| is false, |
170 // |host_resolver| must not be NULL. | 171 // |host_resolver| must not be NULL. |
171 // | 172 static scoped_ptr<HttpAuthHandlerRegistryFactory> Create( |
172 // |gssapi_library_name| specifies the name of the GSSAPI library that will | 173 const HttpAuthPreferences* prefs, |
173 // be loaded on Posix platforms other than Android. |gssapi_library_name| is | 174 HostResolver* host_resolver); |
174 // ignored on Android and Windows. | |
175 // | |
176 // |auth_android_negotiate_account_type| is an Android account type, used to | |
177 // find the appropriate authenticator service on Android. It is ignored on | |
178 // non-Android platforms. | |
179 // | |
180 // |negotiate_disable_cname_lookup| and |negotiate_enable_port| both control | |
181 // how Negotiate does SPN generation, by default these should be false. | |
182 static HttpAuthHandlerRegistryFactory* Create( | |
183 const std::vector<std::string>& supported_schemes, | |
184 URLSecurityManager* security_manager, | |
185 HostResolver* host_resolver, | |
186 const std::string& gssapi_library_name, | |
187 const std::string& auth_android_negotiate_account_type, | |
188 bool negotiate_disable_cname_lookup, | |
189 bool negotiate_enable_port); | |
190 | |
191 // Creates an auth handler by dispatching out to the registered factories | 175 // Creates an auth handler by dispatching out to the registered factories |
192 // based on the first token in |challenge|. | 176 // based on the first token in |challenge|. |
193 int CreateAuthHandler(HttpAuthChallengeTokenizer* challenge, | 177 int CreateAuthHandler(HttpAuthChallengeTokenizer* challenge, |
194 HttpAuth::Target target, | 178 HttpAuth::Target target, |
195 const GURL& origin, | 179 const GURL& origin, |
196 CreateReason reason, | 180 CreateReason reason, |
197 int digest_nonce_count, | 181 int digest_nonce_count, |
198 const BoundNetLog& net_log, | 182 const BoundNetLog& net_log, |
199 scoped_ptr<HttpAuthHandler>* handler) override; | 183 scoped_ptr<HttpAuthHandler>* handler) override; |
200 | 184 |
201 private: | 185 private: |
202 typedef std::map<std::string, HttpAuthHandlerFactory*> FactoryMap; | 186 typedef std::map<std::string, HttpAuthHandlerFactory*> FactoryMap; |
203 | 187 |
204 FactoryMap factory_map_; | 188 FactoryMap factory_map_; |
205 DISALLOW_COPY_AND_ASSIGN(HttpAuthHandlerRegistryFactory); | 189 DISALLOW_COPY_AND_ASSIGN(HttpAuthHandlerRegistryFactory); |
206 }; | 190 }; |
207 | 191 |
208 } // namespace net | 192 } // namespace net |
209 | 193 |
210 #endif // NET_HTTP_HTTP_AUTH_HANDLER_FACTORY_H_ | 194 #endif // NET_HTTP_HTTP_AUTH_HANDLER_FACTORY_H_ |
OLD | NEW |