| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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_HANDLER_H_ | 5 #ifndef NET_HTTP_HTTP_AUTH_HANDLER_H_ |
| 6 #define NET_HTTP_HTTP_AUTH_HANDLER_H_ | 6 #define NET_HTTP_HTTP_AUTH_HANDLER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/ref_counted.h" | 10 #include "base/ref_counted.h" |
| 11 #include "net/http/http_auth.h" | 11 #include "net/http/http_auth.h" |
| 12 | 12 |
| 13 namespace net { | 13 namespace net { |
| 14 | 14 |
| 15 class HttpRequestInfo; | 15 class HttpRequestInfo; |
| 16 class ProxyInfo; | 16 class ProxyInfo; |
| 17 | 17 |
| 18 // HttpAuthHandler is the interface for the authentication schemes | 18 // HttpAuthHandler is the interface for the authentication schemes |
| 19 // (basic, digest, ...) | 19 // (basic, digest, ...) |
| 20 // The registry mapping auth-schemes to implementations is hardcoded in | 20 // The registry mapping auth-schemes to implementations is hardcoded in |
| 21 // HttpAuth::CreateAuthHandler(). | 21 // HttpAuth::CreateAuthHandler(). |
| 22 class HttpAuthHandler : public base::RefCounted<HttpAuthHandler> { | 22 class HttpAuthHandler : public base::RefCounted<HttpAuthHandler> { |
| 23 public: | 23 public: |
| 24 virtual ~HttpAuthHandler() { } | 24 virtual ~HttpAuthHandler() { } |
| 25 | 25 |
| 26 // Initialize the handler by parsing a challenge string. | 26 // Initialize the handler by parsing a challenge string. |
| 27 bool InitFromChallenge(std::string::const_iterator begin, | 27 bool InitFromChallenge(std::string::const_iterator begin, |
| 28 std::string::const_iterator end, | 28 std::string::const_iterator end, |
| 29 HttpAuth::Target target); | 29 HttpAuth::Target target, |
| 30 const GURL& origin); |
| 30 | 31 |
| 31 // Lowercase name of the auth scheme | 32 // Lowercase name of the auth scheme |
| 32 const std::string& scheme() const { | 33 const std::string& scheme() const { |
| 33 return scheme_; | 34 return scheme_; |
| 34 } | 35 } |
| 35 | 36 |
| 36 // The realm value that was parsed during Init(). | 37 // The realm value that was parsed during Init(). |
| 37 const std::string& realm() const { | 38 const std::string& realm() const { |
| 38 return realm_; | 39 return realm_; |
| 39 } | 40 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 61 bool is_connection_based() const { | 62 bool is_connection_based() const { |
| 62 return (properties_ & IS_CONNECTION_BASED) != 0; | 63 return (properties_ & IS_CONNECTION_BASED) != 0; |
| 63 } | 64 } |
| 64 | 65 |
| 65 // Returns true if the response to the current authentication challenge | 66 // Returns true if the response to the current authentication challenge |
| 66 // requires an identity. | 67 // requires an identity. |
| 67 // TODO(wtc): Find a better way to handle a multi-round challenge-response | 68 // TODO(wtc): Find a better way to handle a multi-round challenge-response |
| 68 // sequence used by a connection-based authentication scheme. | 69 // sequence used by a connection-based authentication scheme. |
| 69 virtual bool NeedsIdentity() { return true; } | 70 virtual bool NeedsIdentity() { return true; } |
| 70 | 71 |
| 72 // Returns true if this is the final round of the authentication sequence. |
| 73 // For Basic and Digest, the method always returns true because they are |
| 74 // single-round schemes. |
| 75 virtual bool IsFinalRound() { return true; } |
| 76 |
| 71 // Generate the Authorization header value. | 77 // Generate the Authorization header value. |
| 72 virtual std::string GenerateCredentials(const std::wstring& username, | 78 virtual std::string GenerateCredentials(const std::wstring& username, |
| 73 const std::wstring& password, | 79 const std::wstring& password, |
| 74 const HttpRequestInfo* request, | 80 const HttpRequestInfo* request, |
| 75 const ProxyInfo* proxy) = 0; | 81 const ProxyInfo* proxy) = 0; |
| 76 | 82 |
| 77 protected: | 83 protected: |
| 78 enum Property { | 84 enum Property { |
| 79 ENCRYPTS_IDENTITY = 1 << 0, | 85 ENCRYPTS_IDENTITY = 1 << 0, |
| 80 IS_CONNECTION_BASED = 1 << 1, | 86 IS_CONNECTION_BASED = 1 << 1, |
| 81 }; | 87 }; |
| 82 | 88 |
| 83 // Initialize the handler by parsing a challenge string. | 89 // Initialize the handler by parsing a challenge string. |
| 84 // Implementations are expcted to initialize the following members: | 90 // Implementations are expcted to initialize the following members: |
| 85 // scheme_, realm_, score_, properties_ | 91 // scheme_, realm_, score_, properties_ |
| 86 virtual bool Init(std::string::const_iterator challenge_begin, | 92 virtual bool Init(std::string::const_iterator challenge_begin, |
| 87 std::string::const_iterator challenge_end) = 0; | 93 std::string::const_iterator challenge_end) = 0; |
| 88 | 94 |
| 89 // The lowercase auth-scheme {"basic", "digest", "ntlm", ...} | 95 // The lowercase auth-scheme {"basic", "digest", "ntlm", ...} |
| 90 std::string scheme_; | 96 std::string scheme_; |
| 91 | 97 |
| 92 // The realm. | 98 // The realm. Used by "basic" and "digest". |
| 93 std::string realm_; | 99 std::string realm_; |
| 94 | 100 |
| 101 // The {scheme, host, port} for the authentication target. Used by "ntlm" |
| 102 // to construct the service principal name. |
| 103 GURL origin_; |
| 104 |
| 95 // The score for this challenge. Higher numbers are better. | 105 // The score for this challenge. Higher numbers are better. |
| 96 int score_; | 106 int score_; |
| 97 | 107 |
| 98 // Whether this authentication request is for a proxy server, or an | 108 // Whether this authentication request is for a proxy server, or an |
| 99 // origin server. | 109 // origin server. |
| 100 HttpAuth::Target target_; | 110 HttpAuth::Target target_; |
| 101 | 111 |
| 102 // A bitmask of the properties of the authentication scheme. | 112 // A bitmask of the properties of the authentication scheme. |
| 103 int properties_; | 113 int properties_; |
| 104 }; | 114 }; |
| 105 | 115 |
| 106 } // namespace net | 116 } // namespace net |
| 107 | 117 |
| 108 #endif // NET_HTTP_HTTP_AUTH_HANDLER_H_ | 118 #endif // NET_HTTP_HTTP_AUTH_HANDLER_H_ |
| OLD | NEW |