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

Side by Side Diff: net/http/http_auth_controller.h

Issue 2808020: Create HttpAuthController. (Closed)
Patch Set: Fix mem leak Created 10 years, 6 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
« no previous file with comments | « net/http/http_auth.cc ('k') | net/http/http_auth_controller.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef NET_HTTP_HTTP_AUTH_CONTROLLER_H_
6 #define NET_HTTP_HTTP_AUTH_CONTROLLER_H_
7
8 #include <string>
9
10 #include "base/basictypes.h"
11 #include "base/ref_counted.h"
12 #include "base/scoped_ptr.h"
13 #include "googleurl/src/gurl.h"
14 #include "net/base/completion_callback.h"
15 #include "net/base/net_log.h"
16 #include "net/http/http_auth.h"
17
18 namespace net {
19
20 class AuthChallengeInfo;
21 class HostResolver;
22 class HttpNetworkSession;
23 class HttpRequestHeaders;
24 struct HttpRequestInfo;
25
26 class HttpAuthController {
27 public:
28 // The arguments are self explanatory except possibly for |auth_url|, which
29 // should be both the auth target and auth path in a single url argument.
30 HttpAuthController(HttpAuth::Target target, const GURL& auth_url,
31 scoped_refptr<HttpNetworkSession> session,
32 const BoundNetLog& net_log);
33
34 // Generate an authentication token for |target| if necessary. The return
35 // value is a net error code. |OK| will be returned both in the case that
36 // a token is correctly generated synchronously, as well as when no tokens
37 // were necessary.
38 int MaybeGenerateAuthToken(const HttpRequestInfo* request,
39 CompletionCallback* callback);
40
41 // Adds either the proxy auth header, or the origin server auth header,
42 // as specified by |target_|.
43 void AddAuthorizationHeader(HttpRequestHeaders* authorization_headers);
44
45 // Checks for and handles HTTP status code 401 or 407.
46 // |HandleAuthChallenge()| returns OK on success,
47 // ERR_AUTH_NEEDS_CANONICAL_NAME if the handler needs the canonical name
48 // resolved, or a network error code. It may also populate |auth_info_|.
49 int HandleAuthChallenge(scoped_refptr<HttpResponseHeaders> headers,
50 int load_flags, bool establishing_tunnel);
51
52 int ResolveCanonicalName(CompletionCallback* callback);
53
54 // Store the supplied credentials and prepare to restart the auth.
55 void ResetAuth(const std::wstring& username, const std::wstring& password);
56
57 bool HaveAuthHandler() const {
58 return handler_.get() != NULL;
59 }
60
61 bool HaveAuth() const {
62 return handler_.get() && !identity_.invalid;
63 }
64
65 scoped_refptr<AuthChallengeInfo> auth_info() {
66 return auth_info_;
67 }
68
69 private:
70 // Searches the auth cache for an entry that encompasses the request's path.
71 // If such an entry is found, updates |identity_| and |handler_| with the
72 // cache entry's data and returns true.
73 bool SelectPreemptiveAuth();
74
75 // Invalidates any auth cache entries after authentication has failed.
76 // The identity that was rejected is |identity_|.
77 void InvalidateRejectedAuthFromCache();
78
79 // Sets |identity_| to the next identity that the transaction should try. It
80 // chooses candidates by searching the auth cache and the URL for a
81 // username:password. Returns true if an identity was found.
82 bool SelectNextAuthIdentityToTry();
83
84 // Populates auth_info_ with the challenge information, so that
85 // URLRequestHttpJob can prompt for a username/password.
86 void PopulateAuthChallenge();
87
88 // Indicates if this handler is for Proxy auth or Server auth.
89 HttpAuth::Target target_;
90
91 // Holds the {scheme, host, path, port} for the authentication target.
92 const GURL auth_url_;
93
94 // Holds the {scheme, host, port} for the authentication target.
95 const GURL auth_origin_;
96
97 // The absolute path of the resource needing authentication.
98 // For proxy authentication the path is empty.
99 const std::string auth_path_;
100
101 // |handler_| encapsulates the logic for the particular auth-scheme.
102 // This includes the challenge's parameters. If NULL, then there is no
103 // associated auth handler.
104 scoped_ptr<HttpAuthHandler> handler_;
105
106 // |identity_| holds the (username/password) that should be used by
107 // the handler_ to generate credentials. This identity can come from
108 // a number of places (url, cache, prompt).
109 HttpAuth::Identity identity_;
110
111 // |auth_token_| contains the opaque string to pass to the proxy or
112 // server to authenticate the client.
113 std::string auth_token_;
114
115 // Contains information about the auth challenge.
116 scoped_refptr<AuthChallengeInfo> auth_info_;
117
118 // True if we've used the username/password embedded in the URL. This
119 // makes sure we use the embedded identity only once for the transaction,
120 // preventing an infinite auth restart loop.
121 bool embedded_identity_used_;
122
123 // True if default credentials have already been tried for this transaction
124 // in response to an HTTP authentication challenge.
125 bool default_credentials_used_;
126
127 scoped_refptr<HttpNetworkSession> session_;
128
129 BoundNetLog net_log_;
130 };
131
132 } // namespace net
133
134 #endif // NET_HTTP_HTTP_AUTH_CONTROLLER_H_
OLDNEW
« no previous file with comments | « net/http/http_auth.cc ('k') | net/http/http_auth_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698