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_CONTROLLER_H_ | 5 #ifndef NET_HTTP_HTTP_AUTH_CONTROLLER_H_ |
6 #define NET_HTTP_HTTP_AUTH_CONTROLLER_H_ | 6 #define NET_HTTP_HTTP_AUTH_CONTROLLER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "base/string16.h" | |
16 #include "base/threading/non_thread_safe.h" | 15 #include "base/threading/non_thread_safe.h" |
17 #include "googleurl/src/gurl.h" | 16 #include "googleurl/src/gurl.h" |
18 #include "net/base/completion_callback.h" | 17 #include "net/base/completion_callback.h" |
19 #include "net/base/net_export.h" | 18 #include "net/base/net_export.h" |
20 #include "net/base/net_log.h" | 19 #include "net/base/net_log.h" |
21 #include "net/http/http_auth.h" | 20 #include "net/http/http_auth.h" |
22 | 21 |
23 namespace net { | 22 namespace net { |
24 | 23 |
25 class AuthChallengeInfo; | 24 class AuthChallengeInfo; |
| 25 class AuthCredentials; |
26 class HttpAuthHandler; | 26 class HttpAuthHandler; |
27 class HttpAuthHandlerFactory; | 27 class HttpAuthHandlerFactory; |
28 class HttpAuthCache; | 28 class HttpAuthCache; |
29 class HttpRequestHeaders; | 29 class HttpRequestHeaders; |
30 struct HttpRequestInfo; | 30 struct HttpRequestInfo; |
31 | 31 |
32 class NET_EXPORT_PRIVATE HttpAuthController | 32 class NET_EXPORT_PRIVATE HttpAuthController |
33 : public base::RefCounted<HttpAuthController>, | 33 : public base::RefCounted<HttpAuthController>, |
34 NON_EXPORTED_BASE(public base::NonThreadSafe) { | 34 NON_EXPORTED_BASE(public base::NonThreadSafe) { |
35 public: | 35 public: |
(...skipping 19 matching lines...) Expand all Loading... |
55 | 55 |
56 // Checks for and handles HTTP status code 401 or 407. | 56 // Checks for and handles HTTP status code 401 or 407. |
57 // |HandleAuthChallenge()| returns OK on success, or a network error code | 57 // |HandleAuthChallenge()| returns OK on success, or a network error code |
58 // otherwise. It may also populate |auth_info_|. | 58 // otherwise. It may also populate |auth_info_|. |
59 virtual int HandleAuthChallenge(scoped_refptr<HttpResponseHeaders> headers, | 59 virtual int HandleAuthChallenge(scoped_refptr<HttpResponseHeaders> headers, |
60 bool do_not_send_server_auth, | 60 bool do_not_send_server_auth, |
61 bool establishing_tunnel, | 61 bool establishing_tunnel, |
62 const BoundNetLog& net_log); | 62 const BoundNetLog& net_log); |
63 | 63 |
64 // Store the supplied credentials and prepare to restart the auth. | 64 // Store the supplied credentials and prepare to restart the auth. |
65 virtual void ResetAuth(const string16& username, | 65 virtual void ResetAuth(const AuthCredentials& credentials); |
66 const string16& password); | |
67 | 66 |
68 virtual bool HaveAuthHandler() const; | 67 virtual bool HaveAuthHandler() const; |
69 | 68 |
70 virtual bool HaveAuth() const; | 69 virtual bool HaveAuth() const; |
71 | 70 |
72 virtual scoped_refptr<AuthChallengeInfo> auth_info(); | 71 virtual scoped_refptr<AuthChallengeInfo> auth_info(); |
73 | 72 |
74 virtual bool IsAuthSchemeDisabled(HttpAuth::Scheme scheme) const; | 73 virtual bool IsAuthSchemeDisabled(HttpAuth::Scheme scheme) const; |
75 virtual void DisableAuthScheme(HttpAuth::Scheme scheme); | 74 virtual void DisableAuthScheme(HttpAuth::Scheme scheme); |
76 | 75 |
(...skipping 23 matching lines...) Expand all Loading... |
100 // Invalidates any auth cache entries after authentication has failed. | 99 // Invalidates any auth cache entries after authentication has failed. |
101 // The identity that was rejected is |identity_|. | 100 // The identity that was rejected is |identity_|. |
102 void InvalidateRejectedAuthFromCache(); | 101 void InvalidateRejectedAuthFromCache(); |
103 | 102 |
104 // Sets |identity_| to the next identity that the transaction should try. It | 103 // Sets |identity_| to the next identity that the transaction should try. It |
105 // chooses candidates by searching the auth cache and the URL for a | 104 // chooses candidates by searching the auth cache and the URL for a |
106 // username:password. Returns true if an identity was found. | 105 // username:password. Returns true if an identity was found. |
107 bool SelectNextAuthIdentityToTry(); | 106 bool SelectNextAuthIdentityToTry(); |
108 | 107 |
109 // Populates auth_info_ with the challenge information, so that | 108 // Populates auth_info_ with the challenge information, so that |
110 // URLRequestHttpJob can prompt for a username/password. | 109 // URLRequestHttpJob can prompt for credentials. |
111 void PopulateAuthChallenge(); | 110 void PopulateAuthChallenge(); |
112 | 111 |
113 // If |result| indicates a permanent failure, disables the current | 112 // If |result| indicates a permanent failure, disables the current |
114 // auth scheme for this controller and returns true. Returns false | 113 // auth scheme for this controller and returns true. Returns false |
115 // otherwise. | 114 // otherwise. |
116 bool DisableOnAuthHandlerResult(int result); | 115 bool DisableOnAuthHandlerResult(int result); |
117 | 116 |
118 void OnIOComplete(int result); | 117 void OnIOComplete(int result); |
119 | 118 |
120 // Indicates if this handler is for Proxy auth or Server auth. | 119 // Indicates if this handler is for Proxy auth or Server auth. |
121 HttpAuth::Target target_; | 120 HttpAuth::Target target_; |
122 | 121 |
123 // Holds the {scheme, host, path, port} for the authentication target. | 122 // Holds the {scheme, host, path, port} for the authentication target. |
124 const GURL auth_url_; | 123 const GURL auth_url_; |
125 | 124 |
126 // Holds the {scheme, host, port} for the authentication target. | 125 // Holds the {scheme, host, port} for the authentication target. |
127 const GURL auth_origin_; | 126 const GURL auth_origin_; |
128 | 127 |
129 // The absolute path of the resource needing authentication. | 128 // The absolute path of the resource needing authentication. |
130 // For proxy authentication the path is empty. | 129 // For proxy authentication the path is empty. |
131 const std::string auth_path_; | 130 const std::string auth_path_; |
132 | 131 |
133 // |handler_| encapsulates the logic for the particular auth-scheme. | 132 // |handler_| encapsulates the logic for the particular auth-scheme. |
134 // This includes the challenge's parameters. If NULL, then there is no | 133 // This includes the challenge's parameters. If NULL, then there is no |
135 // associated auth handler. | 134 // associated auth handler. |
136 scoped_ptr<HttpAuthHandler> handler_; | 135 scoped_ptr<HttpAuthHandler> handler_; |
137 | 136 |
138 // |identity_| holds the (username/password) that should be used by | 137 // |identity_| holds the credentials that should be used by |
139 // the handler_ to generate credentials. This identity can come from | 138 // the handler_ to generate challenge responses. This identity can come from |
140 // a number of places (url, cache, prompt). | 139 // a number of places (url, cache, prompt). |
141 HttpAuth::Identity identity_; | 140 HttpAuth::Identity identity_; |
142 | 141 |
143 // |auth_token_| contains the opaque string to pass to the proxy or | 142 // |auth_token_| contains the opaque string to pass to the proxy or |
144 // server to authenticate the client. | 143 // server to authenticate the client. |
145 std::string auth_token_; | 144 std::string auth_token_; |
146 | 145 |
147 // Contains information about the auth challenge. | 146 // Contains information about the auth challenge. |
148 scoped_refptr<AuthChallengeInfo> auth_info_; | 147 scoped_refptr<AuthChallengeInfo> auth_info_; |
149 | 148 |
150 // True if we've used the username/password embedded in the URL. This | 149 // True if we've used the username:password embedded in the URL. This |
151 // makes sure we use the embedded identity only once for the transaction, | 150 // makes sure we use the embedded identity only once for the transaction, |
152 // preventing an infinite auth restart loop. | 151 // preventing an infinite auth restart loop. |
153 bool embedded_identity_used_; | 152 bool embedded_identity_used_; |
154 | 153 |
155 // True if default credentials have already been tried for this transaction | 154 // True if default credentials have already been tried for this transaction |
156 // in response to an HTTP authentication challenge. | 155 // in response to an HTTP authentication challenge. |
157 bool default_credentials_used_; | 156 bool default_credentials_used_; |
158 | 157 |
159 // These two are owned by the HttpNetworkSession/IOThread, which own the | 158 // These two are owned by the HttpNetworkSession/IOThread, which own the |
160 // objects which reference |this|. Therefore, these raw pointers are valid | 159 // objects which reference |this|. Therefore, these raw pointers are valid |
161 // for the lifetime of this object. | 160 // for the lifetime of this object. |
162 HttpAuthCache* const http_auth_cache_; | 161 HttpAuthCache* const http_auth_cache_; |
163 HttpAuthHandlerFactory* const http_auth_handler_factory_; | 162 HttpAuthHandlerFactory* const http_auth_handler_factory_; |
164 | 163 |
165 std::set<HttpAuth::Scheme> disabled_schemes_; | 164 std::set<HttpAuth::Scheme> disabled_schemes_; |
166 | 165 |
167 OldCompletionCallbackImpl<HttpAuthController> io_callback_; | 166 OldCompletionCallbackImpl<HttpAuthController> io_callback_; |
168 OldCompletionCallback* user_callback_; | 167 OldCompletionCallback* user_callback_; |
169 }; | 168 }; |
170 | 169 |
171 } // namespace net | 170 } // namespace net |
172 | 171 |
173 #endif // NET_HTTP_HTTP_AUTH_CONTROLLER_H_ | 172 #endif // NET_HTTP_HTTP_AUTH_CONTROLLER_H_ |
OLD | NEW |