| 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_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 "net/base/completion_callback.h" | 10 #include "net/base/completion_callback.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 class NET_EXPORT_PRIVATE HttpAuthHandler { | 23 class NET_EXPORT_PRIVATE HttpAuthHandler { |
| 24 public: | 24 public: |
| 25 HttpAuthHandler(); | 25 HttpAuthHandler(); |
| 26 virtual ~HttpAuthHandler(); | 26 virtual ~HttpAuthHandler(); |
| 27 | 27 |
| 28 // Initializes the handler using a challenge issued by a server. | 28 // Initializes the handler using a challenge issued by a server. |
| 29 // |challenge| must be non-NULL and have already tokenized the | 29 // |challenge| must be non-NULL and have already tokenized the |
| 30 // authentication scheme, but none of the tokens occurring after the | 30 // authentication scheme, but none of the tokens occurring after the |
| 31 // authentication scheme. |target| and |origin| are both stored | 31 // authentication scheme. |target| and |origin| are both stored |
| 32 // for later use, and are not part of the initial challenge. | 32 // for later use, and are not part of the initial challenge. |
| 33 bool InitFromChallenge(HttpAuthChallengeTokenizer* challenge, | 33 int HandleInitialChallenge(const HttpAuthChallengeTokenizer& challenge, |
| 34 HttpAuth::Target target, | 34 HttpAuth::Target target, |
| 35 const GURL& origin, | 35 const GURL& origin, |
| 36 const BoundNetLog& net_log); | 36 const BoundNetLog& net_log); |
| 37 | 37 |
| 38 // Determines how the previous authorization attempt was received. | 38 // Determines how the previous authorization attempt was received. |
| 39 // | 39 // |
| 40 // This is called when the server/proxy responds with a 401/407 after an | 40 // This is called when the server/proxy responds with a 401/407 after an |
| 41 // earlier authorization attempt. Although this normally means that the | 41 // earlier authorization attempt. Although this normally means that the |
| 42 // previous attempt was rejected, in multi-round schemes such as | 42 // previous attempt was rejected, in multi-round schemes such as |
| 43 // NTLM+Negotiate it may indicate that another round of challenge+response | 43 // NTLM+Negotiate it may indicate that another round of challenge+response |
| 44 // is required. For Digest authentication it may also mean that the previous | 44 // is required. For Digest authentication it may also mean that the previous |
| 45 // attempt used a stale nonce (and nonce-count) and that a new attempt should | 45 // attempt used a stale nonce (and nonce-count) and that a new attempt should |
| 46 // be made with a different nonce provided in the challenge. | 46 // be made with a different nonce provided in the challenge. |
| 47 // | 47 // |
| 48 // |challenge| must be non-NULL and have already tokenized the | 48 // |challenge| must be non-NULL and have already tokenized the |
| 49 // authentication scheme, but none of the tokens occurring after the | 49 // authentication scheme, but none of the tokens occurring after the |
| 50 // authentication scheme. | 50 // authentication scheme. |
| 51 virtual HttpAuth::AuthorizationResult HandleAnotherChallenge( | 51 virtual HttpAuth::AuthorizationResult HandleAnotherChallenge( |
| 52 HttpAuthChallengeTokenizer* challenge) = 0; | 52 const HttpAuthChallengeTokenizer& challenge) = 0; |
| 53 | 53 |
| 54 // Generates an authentication token, potentially asynchronously. | 54 // Generates an authentication token, potentially asynchronously. |
| 55 // | 55 // |
| 56 // When |credentials| is NULL, the default credentials for the currently | 56 // When |credentials| is NULL, the default credentials for the currently |
| 57 // logged in user are used. |AllowsDefaultCredentials()| MUST be true in this | 57 // logged in user are used. |AllowsDefaultCredentials()| MUST be true in this |
| 58 // case. | 58 // case. |
| 59 // | 59 // |
| 60 // |request|, |callback|, and |auth_token| must be non-NULL. | 60 // |request|, |callback|, and |auth_token| must be non-NULL. |
| 61 // | 61 // |
| 62 // The return value is a net error code. | 62 // The return value is a net error code. |
| 63 // | 63 // |
| 64 // If |OK| is returned, |*auth_token| is filled in with an authentication | 64 // If |OK| is returned, |*auth_token| is filled in with an authentication |
| 65 // token which can be inserted in the HTTP request. | 65 // token which can be inserted in the HTTP request. |
| 66 // | 66 // |
| 67 // If |ERR_IO_PENDING| is returned, |*auth_token| will be filled in | 67 // If |ERR_IO_PENDING| is returned, |*auth_token| will be filled in |
| 68 // asynchronously and |callback| will be invoked. The lifetime of | 68 // asynchronously and |callback| will be invoked. The lifetime of |
| 69 // |request|, |callback|, and |auth_token| must last until |callback| is | 69 // |request|, |callback|, and |auth_token| must last until |callback| is |
| 70 // invoked, but |credentials| is only used during the initial call. | 70 // invoked, but |credentials| is only used during the initial call. |
| 71 // | 71 // |
| 72 // All other return codes indicate that there was a problem generating a | 72 // All other return codes indicate that there was a problem generating a |
| 73 // token, and the value of |*auth_token| is unspecified. | 73 // token, and the value of |*auth_token| is unspecified. |
| 74 int GenerateAuthToken(const AuthCredentials* credentials, | 74 int GenerateAuthToken(const AuthCredentials* credentials, |
| 75 const HttpRequestInfo* request, | 75 const HttpRequestInfo& request, |
| 76 const CompletionCallback& callback, | 76 const CompletionCallback& callback, |
| 77 std::string* auth_token); | 77 std::string* auth_token); |
| 78 | 78 |
| 79 // The authentication scheme as an enumerated value. | 79 // The authentication scheme as an enumerated value. |
| 80 const std::string& auth_scheme() const { return auth_scheme_; } | 80 const std::string& auth_scheme() const { return auth_scheme_; } |
| 81 | 81 |
| 82 // The realm, encoded as UTF-8. This may be empty. | 82 // The realm, encoded as UTF-8. This may be empty. |
| 83 const std::string& realm() const { | 83 const std::string& realm() const { |
| 84 return realm_; | 84 return realm_; |
| 85 } | 85 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 98 return origin_; | 98 return origin_; |
| 99 } | 99 } |
| 100 | 100 |
| 101 // Returns true if the response to the current authentication challenge | 101 // Returns true if the response to the current authentication challenge |
| 102 // requires an identity. | 102 // requires an identity. |
| 103 // TODO(wtc): Find a better way to handle a multi-round challenge-response | 103 // TODO(wtc): Find a better way to handle a multi-round challenge-response |
| 104 // sequence used by a connection-based authentication scheme. | 104 // sequence used by a connection-based authentication scheme. |
| 105 virtual bool NeedsIdentity(); | 105 virtual bool NeedsIdentity(); |
| 106 | 106 |
| 107 // Returns whether the default credentials may be used for the |origin| passed | 107 // Returns whether the default credentials may be used for the |origin| passed |
| 108 // into |InitFromChallenge|. If true, the user does not need to be prompted | 108 // into |HandleInitialChallenge|. If true, the user does not need to be |
| 109 // for username and password to establish credentials. | 109 // prompted for username and password to establish credentials. NOTE: SSO is |
| 110 // NOTE: SSO is a potential security risk. | 110 // a potential security risk. |
| 111 // TODO(cbentzel): Add a pointer to Firefox documentation about risk. | 111 // TODO(cbentzel): Add a pointer to Firefox documentation about risk. |
| 112 virtual bool AllowsDefaultCredentials(); | 112 virtual bool AllowsDefaultCredentials(); |
| 113 | 113 |
| 114 // Returns whether explicit credentials can be used with this handler. If | 114 // Returns whether explicit credentials can be used with this handler. If |
| 115 // true the user may be prompted for credentials if an implicit identity | 115 // true the user may be prompted for credentials if an implicit identity |
| 116 // cannot be determined. | 116 // cannot be determined. |
| 117 virtual bool AllowsExplicitCredentials(); | 117 virtual bool AllowsExplicitCredentials(); |
| 118 | 118 |
| 119 protected: | 119 protected: |
| 120 // Initializes the handler using a challenge issued by a server. | 120 // Initializes the handler using a challenge issued by a server. |challenge| |
| 121 // |challenge| must be non-NULL and have already tokenized the | 121 // must be non-NULL and have already tokenized the authentication scheme, but |
| 122 // authentication scheme, but none of the tokens occurring after the | 122 // none of the tokens occurring after the authentication scheme. |
| 123 // authentication scheme. | 123 // Implementations are expected to initialize the following members: scheme_, |
| 124 // Implementations are expected to initialize the following members: | 124 // realm_ |
| 125 // scheme_, realm_ | 125 virtual int Init(const HttpAuthChallengeTokenizer& challenge) = 0; |
| 126 virtual bool Init(HttpAuthChallengeTokenizer* challenge) = 0; | |
| 127 | 126 |
| 128 // |GenerateAuthTokenImpl()} is the auth-scheme specific implementation | 127 // |GenerateAuthTokenImpl()} is the auth-scheme specific implementation |
| 129 // of generating the next auth token. Callers should use |GenerateAuthToken()| | 128 // of generating the next auth token. Callers should use |GenerateAuthToken()| |
| 130 // which will in turn call |GenerateAuthTokenImpl()| | 129 // which will in turn call |GenerateAuthTokenImpl()| |
| 131 virtual int GenerateAuthTokenImpl(const AuthCredentials* credentials, | 130 virtual int GenerateAuthTokenImpl(const AuthCredentials* credentials, |
| 132 const HttpRequestInfo* request, | 131 const HttpRequestInfo& request, |
| 133 const CompletionCallback& callback, | 132 const CompletionCallback& callback, |
| 134 std::string* auth_token) = 0; | 133 std::string* auth_token) = 0; |
| 135 | 134 |
| 136 // The auth-scheme as a lowercase ASCII RFC 2616 2.2 token. | 135 // The auth-scheme as a lowercase ASCII RFC 2616 2.2 token. |
| 137 std::string auth_scheme_; | 136 std::string auth_scheme_; |
| 138 | 137 |
| 139 // The realm, encoded as UTF-8. Used by "basic" and "digest". | 138 // The realm, encoded as UTF-8. Used by "basic" and "digest". |
| 140 std::string realm_; | 139 std::string realm_; |
| 141 | 140 |
| 142 // The auth challenge. | 141 // The auth challenge. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 155 private: | 154 private: |
| 156 void OnGenerateAuthTokenComplete(int rv); | 155 void OnGenerateAuthTokenComplete(int rv); |
| 157 void FinishGenerateAuthToken(); | 156 void FinishGenerateAuthToken(); |
| 158 | 157 |
| 159 CompletionCallback callback_; | 158 CompletionCallback callback_; |
| 160 }; | 159 }; |
| 161 | 160 |
| 162 } // namespace net | 161 } // namespace net |
| 163 | 162 |
| 164 #endif // NET_HTTP_HTTP_AUTH_HANDLER_H_ | 163 #endif // NET_HTTP_HTTP_AUTH_HANDLER_H_ |
| OLD | NEW |