Chromium Code Reviews| 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_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 <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <list> | 10 #include <list> |
| 11 #include <string> | 11 #include <string> |
| 12 | 12 |
| 13 #include "base/gtest_prod_util.h" | 13 #include "base/gtest_prod_util.h" |
| 14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 16 #include "net/base/net_export.h" | 16 #include "net/base/net_export.h" |
| 17 #include "net/http/http_auth.h" | 17 #include "net/http/http_auth.h" |
| 18 #include "url/gurl.h" | 18 #include "url/gurl.h" |
| 19 | 19 |
| 20 namespace net { | 20 namespace net { |
| 21 | 21 |
| 22 // HttpAuthCache stores HTTP authentication identities and challenge info. | 22 // HttpAuthCache stores HTTP authentication identities and challenge info. |
| 23 // For each (origin, realm, scheme) triple the cache stores a | 23 // For each (origin, realm, scheme) triple the cache stores a |
| 24 // HttpAuthCache::Entry, which holds: | 24 // HttpAuthCache::Entry, which holds: |
| 25 // - the origin server {protocol scheme, host, port} | 25 // - the origin server {protocol scheme, host, port} |
| 26 // - the last identity used (username/password) | 26 // - the last identity used (username/password) |
| 27 // - the last auth handler used (contains realm and authentication scheme) | 27 // - the last auth handler used (contains realm and authentication scheme) |
| 28 // - the list of paths which used this realm | 28 // - the list of paths which used this realm |
| 29 // Entries can be looked up by either (origin, realm, scheme) or (origin, path). | 29 // Entries can be looked up by either (origin, realm, scheme) or (origin, path). |
| 30 class NET_EXPORT_PRIVATE HttpAuthCache { | 30 class NET_EXPORT HttpAuthCache { |
| 31 public: | 31 public: |
| 32 class NET_EXPORT_PRIVATE Entry { | 32 class NET_EXPORT Entry { |
| 33 public: | 33 public: |
| 34 Entry(const Entry& other); | 34 Entry(const Entry& other); |
| 35 ~Entry(); | 35 ~Entry(); |
| 36 | 36 |
| 37 const GURL& origin() const { | 37 const GURL& origin() const { |
| 38 return origin_; | 38 return origin_; |
| 39 } | 39 } |
| 40 | 40 |
| 41 // The case-sensitive realm string of the challenge. | 41 // The case-sensitive realm string of the challenge. |
| 42 const std::string& realm() const { return realm_; } | 42 const std::string& realm() const { return realm_; } |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 57 int IncrementNonceCount() { | 57 int IncrementNonceCount() { |
| 58 return ++nonce_count_; | 58 return ++nonce_count_; |
| 59 } | 59 } |
| 60 | 60 |
| 61 void UpdateStaleChallenge(const std::string& auth_challenge); | 61 void UpdateStaleChallenge(const std::string& auth_challenge); |
| 62 | 62 |
| 63 private: | 63 private: |
| 64 friend class HttpAuthCache; | 64 friend class HttpAuthCache; |
| 65 FRIEND_TEST_ALL_PREFIXES(HttpAuthCacheTest, AddPath); | 65 FRIEND_TEST_ALL_PREFIXES(HttpAuthCacheTest, AddPath); |
| 66 FRIEND_TEST_ALL_PREFIXES(HttpAuthCacheTest, AddToExistingEntry); | 66 FRIEND_TEST_ALL_PREFIXES(HttpAuthCacheTest, AddToExistingEntry); |
| 67 FRIEND_TEST_ALL_PREFIXES(HttpAuthCacheTest, ClearEntriesAddedWithin); | |
|
mmenke
2016/08/31 14:48:32
Suggest a public method set_creation_time_for_test
Tomasz Moniuszko
2016/09/01 08:40:00
Done.
| |
| 67 | 68 |
| 68 typedef std::list<std::string> PathList; | 69 typedef std::list<std::string> PathList; |
| 69 | 70 |
| 70 Entry(); | 71 Entry(); |
| 71 | 72 |
| 72 // Adds a path defining the realm's protection space. If the path is | 73 // Adds a path defining the realm's protection space. If the path is |
| 73 // already contained in the protection space, is a no-op. | 74 // already contained in the protection space, is a no-op. |
| 74 void AddPath(const std::string& path); | 75 void AddPath(const std::string& path); |
| 75 | 76 |
| 76 // Returns true if |dir| is contained within the realm's protection | 77 // Returns true if |dir| is contained within the realm's protection |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 155 // |origin| - the {scheme, host, port} of the server. | 156 // |origin| - the {scheme, host, port} of the server. |
| 156 // |realm| - case sensitive realm string. | 157 // |realm| - case sensitive realm string. |
| 157 // |scheme| - the authentication scheme (i.e. basic, negotiate). | 158 // |scheme| - the authentication scheme (i.e. basic, negotiate). |
| 158 // |credentials| - the credentials to match. | 159 // |credentials| - the credentials to match. |
| 159 // returns - true if an entry was removed. | 160 // returns - true if an entry was removed. |
| 160 bool Remove(const GURL& origin, | 161 bool Remove(const GURL& origin, |
| 161 const std::string& realm, | 162 const std::string& realm, |
| 162 HttpAuth::Scheme scheme, | 163 HttpAuth::Scheme scheme, |
| 163 const AuthCredentials& credentials); | 164 const AuthCredentials& credentials); |
| 164 | 165 |
| 165 // Clears the cache. | 166 // Clears cache entries created within |duration| of base::TimeTicks::Now(). |
| 166 void Clear(); | 167 void ClearEntriesAddedWithin(base::TimeDelta duration); |
| 167 | 168 |
| 168 // Updates a stale digest entry on server |origin| for realm |realm| and | 169 // Updates a stale digest entry on server |origin| for realm |realm| and |
| 169 // scheme |scheme|. The cached auth challenge is replaced with | 170 // scheme |scheme|. The cached auth challenge is replaced with |
| 170 // |auth_challenge| and the nonce count is reset. | 171 // |auth_challenge| and the nonce count is reset. |
| 171 // |UpdateStaleChallenge()| returns true if a matching entry exists in the | 172 // |UpdateStaleChallenge()| returns true if a matching entry exists in the |
| 172 // cache, false otherwise. | 173 // cache, false otherwise. |
| 173 bool UpdateStaleChallenge(const GURL& origin, | 174 bool UpdateStaleChallenge(const GURL& origin, |
| 174 const std::string& realm, | 175 const std::string& realm, |
| 175 HttpAuth::Scheme scheme, | 176 HttpAuth::Scheme scheme, |
| 176 const std::string& auth_challenge); | 177 const std::string& auth_challenge); |
| 177 | 178 |
| 178 // Copies all entries from |other| cache. | 179 // Copies all entries from |other| cache. |
| 179 void UpdateAllFrom(const HttpAuthCache& other); | 180 void UpdateAllFrom(const HttpAuthCache& other); |
| 180 | 181 |
| 181 private: | 182 private: |
| 182 typedef std::list<Entry> EntryList; | 183 typedef std::list<Entry> EntryList; |
| 183 EntryList entries_; | 184 EntryList entries_; |
| 184 }; | 185 }; |
| 185 | 186 |
| 186 // An authentication realm entry. | 187 // An authentication realm entry. |
| 187 } // namespace net | 188 } // namespace net |
| 188 | 189 |
| 189 #endif // NET_HTTP_HTTP_AUTH_CACHE_H_ | 190 #endif // NET_HTTP_HTTP_AUTH_CACHE_H_ |
| OLD | NEW |