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

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

Issue 6191001: Cleanup: Use AUTH_SCHEME enum instead of a string. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Added AUTH_SCHEME_MOCK Created 9 years, 11 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 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 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 #pragma once 7 #pragma once
8 8
9 #include <list> 9 #include <list>
10 #include <string> 10 #include <string>
11 11
12 #include "base/gtest_prod_util.h" 12 #include "base/gtest_prod_util.h"
13 #include "base/ref_counted.h" 13 #include "base/ref_counted.h"
14 #include "base/string16.h" 14 #include "base/string16.h"
15 #include "googleurl/src/gurl.h" 15 #include "googleurl/src/gurl.h"
16 #include "net/http/http_auth.h"
16 17
17 namespace net { 18 namespace net {
18 19
19 // HttpAuthCache stores HTTP authentication identities and challenge info. 20 // HttpAuthCache stores HTTP authentication identities and challenge info.
20 // For each (origin, realm, scheme) triple the cache stores a 21 // For each (origin, realm, scheme) triple the cache stores a
21 // HttpAuthCache::Entry, which holds: 22 // HttpAuthCache::Entry, which holds:
22 // - the origin server {protocol scheme, host, port} 23 // - the origin server {protocol scheme, host, port}
23 // - the last identity used (username/password) 24 // - the last identity used (username/password)
24 // - the last auth handler used (contains realm and authentication scheme) 25 // - the last auth handler used (contains realm and authentication scheme)
25 // - the list of paths which used this realm 26 // - the list of paths which used this realm
26 // 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).
27 class HttpAuthCache { 28 class HttpAuthCache {
28 public: 29 public:
29 class Entry; 30 class Entry;
30 31
31 HttpAuthCache(); 32 HttpAuthCache();
32 ~HttpAuthCache(); 33 ~HttpAuthCache();
33 34
34 // Find the realm entry on server |origin| for realm |realm| and 35 // Find the realm entry on server |origin| for realm |realm| and
35 // scheme |scheme|. 36 // scheme |scheme|.
36 // |origin| - the {scheme, host, port} of the server. 37 // |origin| - the {scheme, host, port} of the server.
37 // |realm| - case sensitive realm string. 38 // |realm| - case sensitive realm string.
38 // |scheme| - case sensitive authentication scheme, should be lower-case. 39 // |scheme| - the authentication scheme (i.e. basic, negotiate).
39 // returns - the matched entry or NULL. 40 // returns - the matched entry or NULL.
40 Entry* Lookup(const GURL& origin, const std::string& realm, 41 Entry* Lookup(const GURL& origin,
41 const std::string& scheme); 42 const std::string& realm,
43 HttpAuth::Scheme scheme);
42 44
43 // Find the entry on server |origin| whose protection space includes 45 // Find the entry on server |origin| whose protection space includes
44 // |path|. This uses the assumption in RFC 2617 section 2 that deeper 46 // |path|. This uses the assumption in RFC 2617 section 2 that deeper
45 // paths lie in the same protection space. 47 // paths lie in the same protection space.
46 // |origin| - the {scheme, host, port} of the server. 48 // |origin| - the {scheme, host, port} of the server.
47 // |path| - absolute path of the resource, or empty string in case of 49 // |path| - absolute path of the resource, or empty string in case of
48 // proxy auth (which does not use the concept of paths). 50 // proxy auth (which does not use the concept of paths).
49 // returns - the matched entry or NULL. 51 // returns - the matched entry or NULL.
50 Entry* LookupByPath(const GURL& origin, const std::string& path); 52 Entry* LookupByPath(const GURL& origin, const std::string& path);
51 53
52 // Add an entry on server |origin| for realm |handler->realm()| and 54 // Add an entry on server |origin| for realm |handler->realm()| and
53 // scheme |handler->scheme()|. If an entry for this (realm,scheme) 55 // scheme |handler->scheme()|. If an entry for this (realm,scheme)
54 // already exists, update it rather than replace it -- this preserves the 56 // already exists, update it rather than replace it -- this preserves the
55 // paths list. 57 // paths list.
56 // |origin| - the {scheme, host, port} of the server. 58 // |origin| - the {scheme, host, port} of the server.
57 // |realm| - the auth realm for the challenge. 59 // |realm| - the auth realm for the challenge.
58 // |scheme| - the authentication scheme for the challenge. 60 // |scheme| - the authentication scheme (i.e. basic, negotiate).
59 // |username| - login information for the realm. 61 // |username| - login information for the realm.
60 // |password| - login information for the realm. 62 // |password| - login information for the realm.
61 // |path| - absolute path for a resource contained in the protection 63 // |path| - absolute path for a resource contained in the protection
62 // space; this will be added to the list of known paths. 64 // space; this will be added to the list of known paths.
63 // returns - the entry that was just added/updated. 65 // returns - the entry that was just added/updated.
64 Entry* Add(const GURL& origin, 66 Entry* Add(const GURL& origin,
65 const std::string& realm, 67 const std::string& realm,
66 const std::string& scheme, 68 HttpAuth::Scheme scheme,
67 const std::string& auth_challenge, 69 const std::string& auth_challenge,
68 const string16& username, 70 const string16& username,
69 const string16& password, 71 const string16& password,
70 const std::string& path); 72 const std::string& path);
71 73
72 // Remove entry on server |origin| for realm |realm| and scheme |scheme| 74 // Remove entry on server |origin| for realm |realm| and scheme |scheme|
73 // if one exists AND if the cached identity matches (|username|, |password|). 75 // if one exists AND if the cached identity matches (|username|, |password|).
74 // |origin| - the {scheme, host, port} of the server. 76 // |origin| - the {scheme, host, port} of the server.
75 // |realm| - case sensitive realm string. 77 // |realm| - case sensitive realm string.
76 // |scheme| - authentication scheme 78 // |scheme| - the authentication scheme (i.e. basic, negotiate).
77 // |username| - condition to match. 79 // |username| - condition to match.
78 // |password| - condition to match. 80 // |password| - condition to match.
79 // returns - true if an entry was removed. 81 // returns - true if an entry was removed.
80 bool Remove(const GURL& origin, 82 bool Remove(const GURL& origin,
81 const std::string& realm, 83 const std::string& realm,
82 const std::string& scheme, 84 HttpAuth::Scheme scheme,
83 const string16& username, 85 const string16& username,
84 const string16& password); 86 const string16& password);
85 87
86 // Updates a stale digest entry on server |origin| for realm |realm| and 88 // Updates a stale digest entry on server |origin| for realm |realm| and
87 // scheme |scheme|. The cached auth challenge is replaced with 89 // scheme |scheme|. The cached auth challenge is replaced with
88 // |auth_challenge| and the nonce count is reset. 90 // |auth_challenge| and the nonce count is reset.
89 // |UpdateStaleChallenge()| returns true if a matching entry exists in the 91 // |UpdateStaleChallenge()| returns true if a matching entry exists in the
90 // cache, false otherwise. 92 // cache, false otherwise.
91 bool UpdateStaleChallenge(const GURL& origin, 93 bool UpdateStaleChallenge(const GURL& origin,
92 const std::string& realm, 94 const std::string& realm,
93 const std::string& scheme, 95 HttpAuth::Scheme scheme,
94 const std::string& auth_challenge); 96 const std::string& auth_challenge);
95 97
96 // Prevent unbounded memory growth. These are safeguards for abuse; it is 98 // Prevent unbounded memory growth. These are safeguards for abuse; it is
97 // not expected that the limits will be reached in ordinary usage. 99 // not expected that the limits will be reached in ordinary usage.
98 // This also defines the worst-case lookup times (which grow linearly 100 // This also defines the worst-case lookup times (which grow linearly
99 // with number of elements in the cache). 101 // with number of elements in the cache).
100 enum { kMaxNumPathsPerRealmEntry = 10 }; 102 enum { kMaxNumPathsPerRealmEntry = 10 };
101 enum { kMaxNumRealmEntries = 10 }; 103 enum { kMaxNumRealmEntries = 10 };
102 104
103 private: 105 private:
104 typedef std::list<Entry> EntryList; 106 typedef std::list<Entry> EntryList;
105 EntryList entries_; 107 EntryList entries_;
106 }; 108 };
107 109
108 // An authentication realm entry. 110 // An authentication realm entry.
109 class HttpAuthCache::Entry { 111 class HttpAuthCache::Entry {
110 public: 112 public:
111 const GURL& origin() const { 113 const GURL& origin() const {
112 return origin_; 114 return origin_;
113 } 115 }
114 116
115 // The case-sensitive realm string of the challenge. 117 // The case-sensitive realm string of the challenge.
116 const std::string realm() const { 118 const std::string realm() const {
117 return realm_; 119 return realm_;
118 } 120 }
119 121
120 // The authentication scheme string of the challenge 122 // The authentication scheme string of the challenge
eroman 2011/01/10 19:32:39 "string" -- no longer applicable.
cbentzel 2011/01/11 16:54:18 Done.
121 const std::string scheme() const { 123 const HttpAuth::Scheme scheme() const {
122 return scheme_; 124 return scheme_;
123 } 125 }
124 126
125 // The authentication challenge. 127 // The authentication challenge.
126 const std::string auth_challenge() const { 128 const std::string auth_challenge() const {
127 return auth_challenge_; 129 return auth_challenge_;
128 } 130 }
129 131
130 // The login username. 132 // The login username.
131 const string16 username() const { 133 const string16 username() const {
(...skipping 20 matching lines...) Expand all
152 154
153 Entry(); 155 Entry();
154 156
155 // Adds a path defining the realm's protection space. If the path is 157 // Adds a path defining the realm's protection space. If the path is
156 // already contained in the protection space, is a no-op. 158 // already contained in the protection space, is a no-op.
157 void AddPath(const std::string& path); 159 void AddPath(const std::string& path);
158 160
159 // Returns true if |dir| is contained within the realm's protection space. 161 // Returns true if |dir| is contained within the realm's protection space.
160 bool HasEnclosingPath(const std::string& dir); 162 bool HasEnclosingPath(const std::string& dir);
161 163
162 // |origin_| contains the {scheme, host, port} of the server. 164 // |origin_| contains the {protocol, host, port} of the server.
163 GURL origin_; 165 GURL origin_;
164 std::string realm_; 166 std::string realm_;
165 std::string scheme_; 167 HttpAuth::Scheme scheme_;
166 168
167 // Identity. 169 // Identity.
168 std::string auth_challenge_; 170 std::string auth_challenge_;
169 string16 username_; 171 string16 username_;
170 string16 password_; 172 string16 password_;
171 173
172 int nonce_count_; 174 int nonce_count_;
173 175
174 // List of paths that define the realm's protection space. 176 // List of paths that define the realm's protection space.
175 typedef std::list<std::string> PathList; 177 typedef std::list<std::string> PathList;
176 PathList paths_; 178 PathList paths_;
177 }; 179 };
178 180
179 } // namespace net 181 } // namespace net
180 182
181 #endif // NET_HTTP_HTTP_AUTH_CACHE_H_ 183 #endif // NET_HTTP_HTTP_AUTH_CACHE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698