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

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

Issue 1151843002: DO NOT LAND Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: More. Created 5 years, 7 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) 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_CACHE_H_ 5 #ifndef NET_HTTP_HTTP_AUTH_CACHE_H_
6 #define NET_HTTP_HTTP_AUTH_CACHE_H_ 6 #define NET_HTTP_HTTP_AUTH_CACHE_H_
7 7
8 #include <list> 8 #include <list>
9 #include <string> 9 #include <string>
10 10
11 #include "base/gtest_prod_util.h" 11 #include "base/gtest_prod_util.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/time/time.h" 13 #include "base/time/time.h"
14 #include "net/base/net_export.h" 14 #include "net/base/net_export.h"
15 #include "net/http/http_auth.h" 15 #include "net/http/http_auth.h"
16 #include "url/gurl.h" 16 #include "url/origin.h"
17 17
18 namespace net { 18 namespace net {
19 19
20 // HttpAuthCache stores HTTP authentication identities and challenge info. 20 // HttpAuthCache stores HTTP authentication identities and challenge info.
21 // For each (origin, realm, scheme) triple the cache stores a 21 // For each (origin, realm, scheme) triple the cache stores a
22 // HttpAuthCache::Entry, which holds: 22 // HttpAuthCache::Entry, which holds:
23 // - the origin server {protocol scheme, host, port} 23 // - the origin server {protocol scheme, host, port}
24 // - the last identity used (username/password) 24 // - the last identity used (username/password)
25 // - the last auth handler used (contains realm and authentication scheme) 25 // - the last auth handler used (contains realm and authentication scheme)
26 // - the list of paths which used this realm 26 // - the list of paths which used this realm
27 // Entries can be looked up by either (origin, realm, scheme) or (origin, path). 27 // Entries can be looked up by either (origin, realm, scheme) or (origin, path).
28 class NET_EXPORT_PRIVATE HttpAuthCache { 28 class NET_EXPORT_PRIVATE HttpAuthCache {
29 public: 29 public:
30 class NET_EXPORT_PRIVATE Entry { 30 class NET_EXPORT_PRIVATE Entry {
31 public: 31 public:
32 ~Entry(); 32 ~Entry();
33 33
34 const GURL& origin() const { 34 const url::Origin& origin() const { return origin_; }
35 return origin_;
36 }
37 35
38 // The case-sensitive realm string of the challenge. 36 // The case-sensitive realm string of the challenge.
39 const std::string& realm() const { return realm_; } 37 const std::string& realm() const { return realm_; }
40 38
41 // The authentication scheme of the challenge. 39 // The authentication scheme of the challenge.
42 HttpAuth::Scheme scheme() const { 40 HttpAuth::Scheme scheme() const {
43 return scheme_; 41 return scheme_;
44 } 42 }
45 43
46 // The authentication challenge. 44 // The authentication challenge.
(...skipping 27 matching lines...) Expand all
74 // space. |*path_len| is set to the length of the enclosing path if 72 // space. |*path_len| is set to the length of the enclosing path if
75 // such a path exists and |path_len| is non-NULL. If no enclosing 73 // such a path exists and |path_len| is non-NULL. If no enclosing
76 // path is found, |*path_len| is left unmodified. 74 // path is found, |*path_len| is left unmodified.
77 // 75 //
78 // Note that proxy auth cache entries are associated with empty 76 // Note that proxy auth cache entries are associated with empty
79 // paths. Therefore it is possible for HasEnclosingPath() to return 77 // paths. Therefore it is possible for HasEnclosingPath() to return
80 // true and set |*path_len| to 0. 78 // true and set |*path_len| to 0.
81 bool HasEnclosingPath(const std::string& dir, size_t* path_len); 79 bool HasEnclosingPath(const std::string& dir, size_t* path_len);
82 80
83 // |origin_| contains the {protocol, host, port} of the server. 81 // |origin_| contains the {protocol, host, port} of the server.
84 GURL origin_; 82 url::Origin origin_;
85 std::string realm_; 83 std::string realm_;
86 HttpAuth::Scheme scheme_; 84 HttpAuth::Scheme scheme_;
87 85
88 // Identity. 86 // Identity.
89 std::string auth_challenge_; 87 std::string auth_challenge_;
90 AuthCredentials credentials_; 88 AuthCredentials credentials_;
91 89
92 int nonce_count_; 90 int nonce_count_;
93 91
94 // List of paths that define the realm's protection space. 92 // List of paths that define the realm's protection space.
(...skipping 14 matching lines...) Expand all
109 107
110 HttpAuthCache(); 108 HttpAuthCache();
111 ~HttpAuthCache(); 109 ~HttpAuthCache();
112 110
113 // Find the realm entry on server |origin| for realm |realm| and 111 // Find the realm entry on server |origin| for realm |realm| and
114 // scheme |scheme|. 112 // scheme |scheme|.
115 // |origin| - the {scheme, host, port} of the server. 113 // |origin| - the {scheme, host, port} of the server.
116 // |realm| - case sensitive realm string. 114 // |realm| - case sensitive realm string.
117 // |scheme| - the authentication scheme (i.e. basic, negotiate). 115 // |scheme| - the authentication scheme (i.e. basic, negotiate).
118 // returns - the matched entry or NULL. 116 // returns - the matched entry or NULL.
119 Entry* Lookup(const GURL& origin, 117 Entry* Lookup(const url::Origin& origin,
120 const std::string& realm, 118 const std::string& realm,
121 HttpAuth::Scheme scheme); 119 HttpAuth::Scheme scheme);
122 120
123 // Find the entry on server |origin| whose protection space includes 121 // Find the entry on server |origin| whose protection space includes
124 // |path|. This uses the assumption in RFC 2617 section 2 that deeper 122 // |path|. This uses the assumption in RFC 2617 section 2 that deeper
125 // paths lie in the same protection space. 123 // paths lie in the same protection space.
126 // |origin| - the {scheme, host, port} of the server. 124 // |origin| - the {scheme, host, port} of the server.
127 // |path| - absolute path of the resource, or empty string in case of 125 // |path| - absolute path of the resource, or empty string in case of
128 // proxy auth (which does not use the concept of paths). 126 // proxy auth (which does not use the concept of paths).
129 // returns - the matched entry or NULL. 127 // returns - the matched entry or NULL.
130 Entry* LookupByPath(const GURL& origin, const std::string& path); 128 Entry* LookupByPath(const url::Origin& origin, const std::string& path);
131 129
132 // Add an entry on server |origin| for realm |handler->realm()| and 130 // Add an entry on server |origin| for realm |handler->realm()| and
133 // scheme |handler->scheme()|. If an entry for this (realm,scheme) 131 // scheme |handler->scheme()|. If an entry for this (realm,scheme)
134 // already exists, update it rather than replace it -- this preserves the 132 // already exists, update it rather than replace it -- this preserves the
135 // paths list. 133 // paths list.
136 // |origin| - the {scheme, host, port} of the server. 134 // |origin| - the {scheme, host, port} of the server.
137 // |realm| - the auth realm for the challenge. 135 // |realm| - the auth realm for the challenge.
138 // |scheme| - the authentication scheme (i.e. basic, negotiate). 136 // |scheme| - the authentication scheme (i.e. basic, negotiate).
139 // |credentials| - login information for the realm. 137 // |credentials| - login information for the realm.
140 // |path| - absolute path for a resource contained in the protection 138 // |path| - absolute path for a resource contained in the protection
141 // space; this will be added to the list of known paths. 139 // space; this will be added to the list of known paths.
142 // returns - the entry that was just added/updated. 140 // returns - the entry that was just added/updated.
143 Entry* Add(const GURL& origin, 141 Entry* Add(const url::Origin& origin,
144 const std::string& realm, 142 const std::string& realm,
145 HttpAuth::Scheme scheme, 143 HttpAuth::Scheme scheme,
146 const std::string& auth_challenge, 144 const std::string& auth_challenge,
147 const AuthCredentials& credentials, 145 const AuthCredentials& credentials,
148 const std::string& path); 146 const std::string& path);
149 147
150 // Remove entry on server |origin| for realm |realm| and scheme |scheme| 148 // Remove entry on server |origin| for realm |realm| and scheme |scheme|
151 // if one exists AND if the cached credentials matches |credentials|. 149 // if one exists AND if the cached credentials matches |credentials|.
152 // |origin| - the {scheme, host, port} of the server. 150 // |origin| - the {scheme, host, port} of the server.
153 // |realm| - case sensitive realm string. 151 // |realm| - case sensitive realm string.
154 // |scheme| - the authentication scheme (i.e. basic, negotiate). 152 // |scheme| - the authentication scheme (i.e. basic, negotiate).
155 // |credentials| - the credentials to match. 153 // |credentials| - the credentials to match.
156 // returns - true if an entry was removed. 154 // returns - true if an entry was removed.
157 bool Remove(const GURL& origin, 155 bool Remove(const url::Origin& origin,
158 const std::string& realm, 156 const std::string& realm,
159 HttpAuth::Scheme scheme, 157 HttpAuth::Scheme scheme,
160 const AuthCredentials& credentials); 158 const AuthCredentials& credentials);
161 159
162 // Clears the cache. 160 // Clears the cache.
163 void Clear(); 161 void Clear();
164 162
165 // Updates a stale digest entry on server |origin| for realm |realm| and 163 // Updates a stale digest entry on server |origin| for realm |realm| and
166 // scheme |scheme|. The cached auth challenge is replaced with 164 // scheme |scheme|. The cached auth challenge is replaced with
167 // |auth_challenge| and the nonce count is reset. 165 // |auth_challenge| and the nonce count is reset.
168 // |UpdateStaleChallenge()| returns true if a matching entry exists in the 166 // |UpdateStaleChallenge()| returns true if a matching entry exists in the
169 // cache, false otherwise. 167 // cache, false otherwise.
170 bool UpdateStaleChallenge(const GURL& origin, 168 bool UpdateStaleChallenge(const url::Origin& origin,
171 const std::string& realm, 169 const std::string& realm,
172 HttpAuth::Scheme scheme, 170 HttpAuth::Scheme scheme,
173 const std::string& auth_challenge); 171 const std::string& auth_challenge);
174 172
175 // Copies all entries from |other| cache. 173 // Copies all entries from |other| cache.
176 void UpdateAllFrom(const HttpAuthCache& other); 174 void UpdateAllFrom(const HttpAuthCache& other);
177 175
178 private: 176 private:
179 typedef std::list<Entry> EntryList; 177 typedef std::list<Entry> EntryList;
180 EntryList entries_; 178 EntryList entries_;
181 }; 179 };
182 180
183 // An authentication realm entry. 181 // An authentication realm entry.
184 } // namespace net 182 } // namespace net
185 183
186 #endif // NET_HTTP_HTTP_AUTH_CACHE_H_ 184 #endif // NET_HTTP_HTTP_AUTH_CACHE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698