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_H_ | 5 #ifndef NET_HTTP_HTTP_AUTH_HANDLER_H_ |
6 #define NET_HTTP_HTTP_AUTH_HANDLER_H_ | 6 #define NET_HTTP_HTTP_AUTH_HANDLER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "net/base/completion_callback.h" | 10 #include "net/base/completion_callback.h" |
11 #include "net/base/net_export.h" | 11 #include "net/base/net_export.h" |
12 #include "net/http/http_auth.h" | 12 #include "net/http/http_auth.h" |
13 #include "net/log/net_log.h" | 13 #include "net/log/net_log.h" |
| 14 #include "url/origin.h" |
14 | 15 |
15 namespace net { | 16 namespace net { |
16 | 17 |
17 class HttpAuthChallengeTokenizer; | 18 class HttpAuthChallengeTokenizer; |
18 struct HttpRequestInfo; | 19 struct HttpRequestInfo; |
19 | 20 |
20 // HttpAuthHandler is the interface for the authentication schemes | 21 // HttpAuthHandler is the interface for the authentication schemes |
21 // (basic, digest, NTLM, Negotiate). | 22 // (basic, digest, NTLM, Negotiate). |
22 // HttpAuthHandler objects are typically created by an HttpAuthHandlerFactory. | 23 // HttpAuthHandler objects are typically created by an HttpAuthHandlerFactory. |
23 class NET_EXPORT_PRIVATE HttpAuthHandler { | 24 class NET_EXPORT_PRIVATE HttpAuthHandler { |
24 public: | 25 public: |
25 HttpAuthHandler(); | 26 HttpAuthHandler(); |
26 virtual ~HttpAuthHandler(); | 27 virtual ~HttpAuthHandler(); |
27 | 28 |
28 // Initializes the handler using a challenge issued by a server. | 29 // Initializes the handler using a challenge issued by a server. |
29 // |challenge| must be non-NULL and have already tokenized the | 30 // |challenge| must be non-NULL and have already tokenized the |
30 // authentication scheme, but none of the tokens occurring after the | 31 // authentication scheme, but none of the tokens occurring after the |
31 // authentication scheme. |target| and |origin| are both stored | 32 // authentication scheme. |target| and |origin| are both stored |
32 // for later use, and are not part of the initial challenge. | 33 // for later use, and are not part of the initial challenge. |
33 bool InitFromChallenge(HttpAuthChallengeTokenizer* challenge, | 34 bool InitFromChallenge(HttpAuthChallengeTokenizer* challenge, |
34 HttpAuth::Target target, | 35 HttpAuth::Target target, |
35 const GURL& origin, | 36 const url::Origin& origin, |
36 const BoundNetLog& net_log); | 37 const BoundNetLog& net_log); |
37 | 38 |
38 // Determines how the previous authorization attempt was received. | 39 // Determines how the previous authorization attempt was received. |
39 // | 40 // |
40 // This is called when the server/proxy responds with a 401/407 after an | 41 // This is called when the server/proxy responds with a 401/407 after an |
41 // earlier authorization attempt. Although this normally means that the | 42 // earlier authorization attempt. Although this normally means that the |
42 // previous attempt was rejected, in multi-round schemes such as | 43 // previous attempt was rejected, in multi-round schemes such as |
43 // NTLM+Negotiate it may indicate that another round of challenge+response | 44 // NTLM+Negotiate it may indicate that another round of challenge+response |
44 // is required. For Digest authentication it may also mean that the previous | 45 // is required. For Digest authentication it may also mean that the previous |
45 // attempt used a stale nonce (and nonce-count) and that a new attempt should | 46 // attempt used a stale nonce (and nonce-count) and that a new attempt should |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 return score_; | 96 return score_; |
96 } | 97 } |
97 | 98 |
98 HttpAuth::Target target() const { | 99 HttpAuth::Target target() const { |
99 return target_; | 100 return target_; |
100 } | 101 } |
101 | 102 |
102 // Returns the proxy or server which issued the authentication challenge | 103 // Returns the proxy or server which issued the authentication challenge |
103 // that this HttpAuthHandler is handling. The URL includes scheme, host, and | 104 // that this HttpAuthHandler is handling. The URL includes scheme, host, and |
104 // port, but does not include path. | 105 // port, but does not include path. |
105 const GURL& origin() const { | 106 const url::Origin& origin() const { return origin_; } |
106 return origin_; | |
107 } | |
108 | 107 |
109 // Returns true if the authentication scheme does not send the username and | 108 // Returns true if the authentication scheme does not send the username and |
110 // password in the clear. | 109 // password in the clear. |
111 bool encrypts_identity() const { | 110 bool encrypts_identity() const { |
112 return (properties_ & ENCRYPTS_IDENTITY) != 0; | 111 return (properties_ & ENCRYPTS_IDENTITY) != 0; |
113 } | 112 } |
114 | 113 |
115 // Returns true if the authentication scheme is connection-based, for | 114 // Returns true if the authentication scheme is connection-based, for |
116 // example, NTLM. A connection-based authentication scheme does not support | 115 // example, NTLM. A connection-based authentication scheme does not support |
117 // preemptive authentication, and must use the same handler object | 116 // preemptive authentication, and must use the same handler object |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 HttpAuth::Scheme auth_scheme_; | 163 HttpAuth::Scheme auth_scheme_; |
165 | 164 |
166 // The realm, encoded as UTF-8. Used by "basic" and "digest". | 165 // The realm, encoded as UTF-8. Used by "basic" and "digest". |
167 std::string realm_; | 166 std::string realm_; |
168 | 167 |
169 // The auth challenge. | 168 // The auth challenge. |
170 std::string auth_challenge_; | 169 std::string auth_challenge_; |
171 | 170 |
172 // The {scheme, host, port} for the authentication target. Used by "ntlm" | 171 // The {scheme, host, port} for the authentication target. Used by "ntlm" |
173 // and "negotiate" to construct the service principal name. | 172 // and "negotiate" to construct the service principal name. |
174 GURL origin_; | 173 url::Origin origin_; |
175 | 174 |
176 // The score for this challenge. Higher numbers are better. | 175 // The score for this challenge. Higher numbers are better. |
177 int score_; | 176 int score_; |
178 | 177 |
179 // Whether this authentication request is for a proxy server, or an | 178 // Whether this authentication request is for a proxy server, or an |
180 // origin server. | 179 // origin server. |
181 HttpAuth::Target target_; | 180 HttpAuth::Target target_; |
182 | 181 |
183 // A bitmask of the properties of the authentication scheme. | 182 // A bitmask of the properties of the authentication scheme. |
184 int properties_; | 183 int properties_; |
185 | 184 |
186 BoundNetLog net_log_; | 185 BoundNetLog net_log_; |
187 | 186 |
188 private: | 187 private: |
189 void OnGenerateAuthTokenComplete(int rv); | 188 void OnGenerateAuthTokenComplete(int rv); |
190 void FinishGenerateAuthToken(); | 189 void FinishGenerateAuthToken(); |
191 | 190 |
192 CompletionCallback callback_; | 191 CompletionCallback callback_; |
193 }; | 192 }; |
194 | 193 |
195 } // namespace net | 194 } // namespace net |
196 | 195 |
197 #endif // NET_HTTP_HTTP_AUTH_HANDLER_H_ | 196 #endif // NET_HTTP_HTTP_AUTH_HANDLER_H_ |
OLD | NEW |