| OLD | NEW |
| 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_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 "base/string16.h" | 11 #include "base/string16.h" |
| 12 #include "net/base/completion_callback.h" | 12 #include "net/base/completion_callback.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 HttpAuthHandler { | 23 class HttpAuthHandler { |
| 24 public: | 24 public: |
| 25 enum AuthScheme { | |
| 26 AUTH_SCHEME_BASIC = 0, | |
| 27 AUTH_SCHEME_DIGEST, | |
| 28 AUTH_SCHEME_NTLM, | |
| 29 AUTH_SCHEME_NEGOTIATE, | |
| 30 AUTH_SCHEME_MAX, | |
| 31 }; | |
| 32 | |
| 33 HttpAuthHandler(); | 25 HttpAuthHandler(); |
| 34 virtual ~HttpAuthHandler(); | 26 virtual ~HttpAuthHandler(); |
| 35 | 27 |
| 36 // Initializes the handler using a challenge issued by a server. | 28 // Initializes the handler using a challenge issued by a server. |
| 37 // |challenge| must be non-NULL and have already tokenized the | 29 // |challenge| must be non-NULL and have already tokenized the |
| 38 // authentication scheme, but none of the tokens occuring after the | 30 // authentication scheme, but none of the tokens occuring after the |
| 39 // authentication scheme. |target| and |origin| are both stored | 31 // authentication scheme. |target| and |origin| are both stored |
| 40 // for later use, and are not part of the initial challenge. | 32 // for later use, and are not part of the initial challenge. |
| 41 bool InitFromChallenge(HttpAuth::ChallengeTokenizer* challenge, | 33 bool InitFromChallenge(HttpAuth::ChallengeTokenizer* challenge, |
| 42 HttpAuth::Target target, | 34 HttpAuth::Target target, |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 // call. | 69 // call. |
| 78 // Otherwise, there was a problem generating a token synchronously, and the | 70 // Otherwise, there was a problem generating a token synchronously, and the |
| 79 // value of |*auth_token| is unspecified. | 71 // value of |*auth_token| is unspecified. |
| 80 int GenerateAuthToken(const string16* username, | 72 int GenerateAuthToken(const string16* username, |
| 81 const string16* password, | 73 const string16* password, |
| 82 const HttpRequestInfo* request, | 74 const HttpRequestInfo* request, |
| 83 CompletionCallback* callback, | 75 CompletionCallback* callback, |
| 84 std::string* auth_token); | 76 std::string* auth_token); |
| 85 | 77 |
| 86 // The authentication scheme as an enumerated value. | 78 // The authentication scheme as an enumerated value. |
| 87 AuthScheme auth_scheme() const { | 79 HttpAuth::Scheme auth_scheme() const { |
| 88 return auth_scheme_; | 80 return auth_scheme_; |
| 89 } | 81 } |
| 90 | 82 |
| 91 // Lowercase name of the auth scheme | |
| 92 const std::string& scheme() const { | |
| 93 return scheme_; | |
| 94 } | |
| 95 | |
| 96 // The realm value that was parsed during Init(). | 83 // The realm value that was parsed during Init(). |
| 97 const std::string& realm() const { | 84 const std::string& realm() const { |
| 98 return realm_; | 85 return realm_; |
| 99 } | 86 } |
| 100 | 87 |
| 101 // The challenge which was issued when creating the handler. | 88 // The challenge which was issued when creating the handler. |
| 102 const std::string challenge() const { | 89 const std::string challenge() const { |
| 103 return auth_challenge_; | 90 return auth_challenge_; |
| 104 } | 91 } |
| 105 | 92 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 // |GenerateAuthTokenImpl()} is the auth-scheme specific implementation | 151 // |GenerateAuthTokenImpl()} is the auth-scheme specific implementation |
| 165 // of generating the next auth token. Callers sohuld use |GenerateAuthToken()| | 152 // of generating the next auth token. Callers sohuld use |GenerateAuthToken()| |
| 166 // which will in turn call |GenerateAuthTokenImpl()| | 153 // which will in turn call |GenerateAuthTokenImpl()| |
| 167 virtual int GenerateAuthTokenImpl(const string16* username, | 154 virtual int GenerateAuthTokenImpl(const string16* username, |
| 168 const string16* password, | 155 const string16* password, |
| 169 const HttpRequestInfo* request, | 156 const HttpRequestInfo* request, |
| 170 CompletionCallback* callback, | 157 CompletionCallback* callback, |
| 171 std::string* auth_token) = 0; | 158 std::string* auth_token) = 0; |
| 172 | 159 |
| 173 // The auth-scheme as an enumerated value. | 160 // The auth-scheme as an enumerated value. |
| 174 AuthScheme auth_scheme_; | 161 HttpAuth::Scheme auth_scheme_; |
| 175 | |
| 176 // The lowercase auth-scheme {"basic", "digest", "ntlm", "negotiate"} | |
| 177 std::string scheme_; | |
| 178 | 162 |
| 179 // The realm. Used by "basic" and "digest". | 163 // The realm. Used by "basic" and "digest". |
| 180 std::string realm_; | 164 std::string realm_; |
| 181 | 165 |
| 182 // The auth challenge. | 166 // The auth challenge. |
| 183 std::string auth_challenge_; | 167 std::string auth_challenge_; |
| 184 | 168 |
| 185 // The {scheme, host, port} for the authentication target. Used by "ntlm" | 169 // The {scheme, host, port} for the authentication target. Used by "ntlm" |
| 186 // and "negotiate" to construct the service principal name. | 170 // and "negotiate" to construct the service principal name. |
| 187 GURL origin_; | 171 GURL origin_; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 202 void OnGenerateAuthTokenComplete(int rv); | 186 void OnGenerateAuthTokenComplete(int rv); |
| 203 void FinishGenerateAuthToken(); | 187 void FinishGenerateAuthToken(); |
| 204 | 188 |
| 205 CompletionCallback* original_callback_; | 189 CompletionCallback* original_callback_; |
| 206 CompletionCallbackImpl<HttpAuthHandler> wrapper_callback_; | 190 CompletionCallbackImpl<HttpAuthHandler> wrapper_callback_; |
| 207 }; | 191 }; |
| 208 | 192 |
| 209 } // namespace net | 193 } // namespace net |
| 210 | 194 |
| 211 #endif // NET_HTTP_HTTP_AUTH_HANDLER_H_ | 195 #endif // NET_HTTP_HTTP_AUTH_HANDLER_H_ |
| OLD | NEW |