| 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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "net/base/completion_callback.h" | 11 #include "net/base/completion_callback.h" |
| 12 #include "net/base/net_export.h" | 12 #include "net/base/net_export.h" |
| 13 #include "net/base/net_log.h" | 13 #include "net/base/net_log.h" |
| 14 #include "net/http/http_auth.h" | 14 #include "net/http/http_auth.h" |
| 15 | 15 |
| 16 namespace net { | 16 namespace net { |
| 17 | 17 |
| 18 struct HttpRequestInfo; | 18 struct HttpRequestInfo; |
| 19 | 19 |
| 20 // HttpAuthHandler is the interface for the authentication schemes | 20 // HttpAuthHandler is the interface for the authentication schemes |
| 21 // (basic, digest, NTLM, Negotiate). | 21 // (basic, digest, NTLM, Negotiate). |
| 22 // HttpAuthHandler objects are typically created by an HttpAuthHandlerFactory. | 22 // HttpAuthHandler objects are typically created by an HttpAuthHandlerFactory. |
| 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 occuring 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(HttpAuth::ChallengeTokenizer* challenge, | 33 bool InitFromChallenge(HttpAuth::ChallengeTokenizer* 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 occuring 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 HttpAuth::ChallengeTokenizer* challenge) = 0; | 52 HttpAuth::ChallengeTokenizer* 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 OldCompletionCallback* 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 HttpAuth::Scheme auth_scheme() const { | 80 HttpAuth::Scheme auth_scheme() const { |
| 81 return auth_scheme_; | 81 return auth_scheme_; |
| 82 } | 82 } |
| 83 | 83 |
| 84 // The realm, encoded as UTF-8. This may be empty. | 84 // The realm, encoded as UTF-8. This may be empty. |
| 85 const std::string& realm() const { | 85 const std::string& realm() const { |
| 86 return realm_; | 86 return realm_; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 virtual bool AllowsExplicitCredentials(); | 141 virtual bool AllowsExplicitCredentials(); |
| 142 | 142 |
| 143 protected: | 143 protected: |
| 144 enum Property { | 144 enum Property { |
| 145 ENCRYPTS_IDENTITY = 1 << 0, | 145 ENCRYPTS_IDENTITY = 1 << 0, |
| 146 IS_CONNECTION_BASED = 1 << 1, | 146 IS_CONNECTION_BASED = 1 << 1, |
| 147 }; | 147 }; |
| 148 | 148 |
| 149 // Initializes the handler using a challenge issued by a server. | 149 // Initializes the handler using a challenge issued by a server. |
| 150 // |challenge| must be non-NULL and have already tokenized the | 150 // |challenge| must be non-NULL and have already tokenized the |
| 151 // authentication scheme, but none of the tokens occuring after the | 151 // authentication scheme, but none of the tokens occurring after the |
| 152 // authentication scheme. | 152 // authentication scheme. |
| 153 // Implementations are expcted to initialize the following members: | 153 // Implementations are expected to initialize the following members: |
| 154 // scheme_, realm_, score_, properties_ | 154 // scheme_, realm_, score_, properties_ |
| 155 virtual bool Init(HttpAuth::ChallengeTokenizer* challenge) = 0; | 155 virtual bool Init(HttpAuth::ChallengeTokenizer* challenge) = 0; |
| 156 | 156 |
| 157 // |GenerateAuthTokenImpl()} is the auth-scheme specific implementation | 157 // |GenerateAuthTokenImpl()} is the auth-scheme specific implementation |
| 158 // of generating the next auth token. Callers sohuld use |GenerateAuthToken()| | 158 // of generating the next auth token. Callers should use |GenerateAuthToken()| |
| 159 // which will in turn call |GenerateAuthTokenImpl()| | 159 // which will in turn call |GenerateAuthTokenImpl()| |
| 160 virtual int GenerateAuthTokenImpl(const AuthCredentials* credentials, | 160 virtual int GenerateAuthTokenImpl(const AuthCredentials* credentials, |
| 161 const HttpRequestInfo* request, | 161 const HttpRequestInfo* request, |
| 162 OldCompletionCallback* callback, | 162 const CompletionCallback& callback, |
| 163 std::string* auth_token) = 0; | 163 std::string* auth_token) = 0; |
| 164 | 164 |
| 165 // The auth-scheme as an enumerated value. | 165 // The auth-scheme as an enumerated value. |
| 166 HttpAuth::Scheme auth_scheme_; | 166 HttpAuth::Scheme auth_scheme_; |
| 167 | 167 |
| 168 // The realm, encoded as UTF-8. Used by "basic" and "digest". | 168 // The realm, encoded as UTF-8. Used by "basic" and "digest". |
| 169 std::string realm_; | 169 std::string realm_; |
| 170 | 170 |
| 171 // The auth challenge. | 171 // The auth challenge. |
| 172 std::string auth_challenge_; | 172 std::string auth_challenge_; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 184 | 184 |
| 185 // A bitmask of the properties of the authentication scheme. | 185 // A bitmask of the properties of the authentication scheme. |
| 186 int properties_; | 186 int properties_; |
| 187 | 187 |
| 188 BoundNetLog net_log_; | 188 BoundNetLog net_log_; |
| 189 | 189 |
| 190 private: | 190 private: |
| 191 void OnGenerateAuthTokenComplete(int rv); | 191 void OnGenerateAuthTokenComplete(int rv); |
| 192 void FinishGenerateAuthToken(); | 192 void FinishGenerateAuthToken(); |
| 193 | 193 |
| 194 OldCompletionCallback* original_callback_; | 194 CompletionCallback callback_; |
| 195 OldCompletionCallbackImpl<HttpAuthHandler> wrapper_callback_; | |
| 196 }; | 195 }; |
| 197 | 196 |
| 198 } // namespace net | 197 } // namespace net |
| 199 | 198 |
| 200 #endif // NET_HTTP_HTTP_AUTH_HANDLER_H_ | 199 #endif // NET_HTTP_HTTP_AUTH_HANDLER_H_ |
| OLD | NEW |