| 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_FACTORY_H_ | 5 #ifndef NET_HTTP_HTTP_AUTH_HANDLER_FACTORY_H_ |
| 6 #define NET_HTTP_HTTP_AUTH_HANDLER_FACTORY_H_ | 6 #define NET_HTTP_HTTP_AUTH_HANDLER_FACTORY_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "net/base/net_export.h" | 13 #include "net/base/net_export.h" |
| 14 #include "net/http/http_auth.h" | 14 #include "net/http/http_auth.h" |
| 15 #include "net/http/http_auth_cache.h" |
| 15 #include "net/http/url_security_manager.h" | 16 #include "net/http/url_security_manager.h" |
| 16 | 17 |
| 17 class GURL; | 18 class GURL; |
| 18 | 19 |
| 19 namespace net { | 20 namespace net { |
| 20 | 21 |
| 21 class BoundNetLog; | 22 class BoundNetLog; |
| 22 class HostResolver; | 23 class HostResolver; |
| 23 class HttpAuthChallengeTokenizer; | 24 class HttpAuthChallengeTokenizer; |
| 24 class HttpAuthHandler; | 25 class HttpAuthHandler; |
| 25 class HttpAuthHandlerRegistryFactory; | 26 class HttpAuthHandlerRegistryFactory; |
| 26 | 27 |
| 27 // An HttpAuthHandlerFactory is used to create HttpAuthHandler objects. | 28 // An HttpAuthHandlerFactory is used to create HttpAuthHandler objects. |
| 28 // The HttpAuthHandlerFactory object _must_ outlive any of the HttpAuthHandler | 29 // The HttpAuthHandlerFactory object _must_ outlive any of the HttpAuthHandler |
| 29 // objects that it creates. | 30 // objects that it creates. |
| 30 class NET_EXPORT HttpAuthHandlerFactory { | 31 class NET_EXPORT HttpAuthHandlerFactory { |
| 31 public: | 32 public: |
| 32 enum CreateReason { | |
| 33 CREATE_CHALLENGE, // Create a handler in response to a challenge. | |
| 34 CREATE_PREEMPTIVE, // Create a handler preemptively. | |
| 35 }; | |
| 36 | |
| 37 HttpAuthHandlerFactory() : url_security_manager_(NULL) {} | 33 HttpAuthHandlerFactory() : url_security_manager_(NULL) {} |
| 38 virtual ~HttpAuthHandlerFactory() {} | 34 virtual ~HttpAuthHandlerFactory() {} |
| 39 | 35 |
| 40 // Sets an URL security manager. HttpAuthHandlerFactory doesn't own the URL | 36 // Sets an URL security manager. HttpAuthHandlerFactory doesn't own the URL |
| 41 // security manager, and the URL security manager should outlive this object. | 37 // security manager, and the URL security manager should outlive this object. |
| 42 void set_url_security_manager(URLSecurityManager* url_security_manager) { | 38 void set_url_security_manager(URLSecurityManager* url_security_manager) { |
| 43 url_security_manager_ = url_security_manager; | 39 url_security_manager_ = url_security_manager; |
| 44 } | 40 } |
| 45 | 41 |
| 46 // Retrieves the associated URL security manager. | 42 // Retrieves the associated URL security manager. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 67 // |digest_nonce_count| is specifically intended for the Digest authentication | 63 // |digest_nonce_count| is specifically intended for the Digest authentication |
| 68 // scheme, and indicates the number of handlers generated for a particular | 64 // scheme, and indicates the number of handlers generated for a particular |
| 69 // server nonce challenge. | 65 // server nonce challenge. |
| 70 // | 66 // |
| 71 // For the NTLM and Negotiate handlers: | 67 // For the NTLM and Negotiate handlers: |
| 72 // If |origin| does not match the authentication method's filters for | 68 // If |origin| does not match the authentication method's filters for |
| 73 // the specified |target|, ERR_INVALID_AUTH_CREDENTIALS is returned. | 69 // the specified |target|, ERR_INVALID_AUTH_CREDENTIALS is returned. |
| 74 // NOTE: This will apply to ALL |origin| values if the filters are empty. | 70 // NOTE: This will apply to ALL |origin| values if the filters are empty. |
| 75 // | 71 // |
| 76 // |*challenge| should not be reused after a call to |CreateAuthHandler()|, | 72 // |*challenge| should not be reused after a call to |CreateAuthHandler()|, |
| 77 virtual int CreateAuthHandler(const HttpAuthChallengeTokenizer& challenge, | 73 // TODO(asanka): Update comment. |
| 78 HttpAuth::Target target, | 74 virtual scoped_ptr<HttpAuthHandler> CreateAuthHandlerForScheme( |
| 79 const GURL& origin, | 75 const std::string& scheme) = 0; |
| 80 CreateReason create_reason, | |
| 81 int digest_nonce_count, | |
| 82 const BoundNetLog& net_log, | |
| 83 scoped_ptr<HttpAuthHandler>* handler) = 0; | |
| 84 | 76 |
| 85 // Creates an HTTP authentication handler based on the authentication | 77 // Creates an HTTP authentication handler based on the authentication |
| 86 // challenge string |challenge|. | 78 // challenge string |challenge|. |
| 87 // This is a convenience function which creates a ChallengeTokenizer for | 79 // This is a convenience function which creates a ChallengeTokenizer for |
| 88 // |challenge| and calls |CreateAuthHandler|. See |CreateAuthHandler| for | 80 // |challenge| and calls |CreateAuthHandler|. See |CreateAuthHandler| for |
| 89 // more details on return values. | 81 // more details on return values. |
| 90 int CreateAuthHandlerFromString(const std::string& challenge, | 82 // TODO(asanka): UPdate comment |
| 91 HttpAuth::Target target, | 83 virtual scoped_ptr<HttpAuthHandler> CreateAndInitPreemptiveAuthHandler( |
| 92 const GURL& origin, | 84 HttpAuthCache::Entry* cache_entry, |
| 93 const BoundNetLog& net_log, | 85 const HttpAuthChallengeTokenizer& tokenizer, |
| 94 scoped_ptr<HttpAuthHandler>* handler); | |
| 95 | |
| 96 // Creates an HTTP authentication handler based on the authentication | |
| 97 // challenge string |challenge|. | |
| 98 // This is a convenience function which creates a ChallengeTokenizer for | |
| 99 // |challenge| and calls |CreateAuthHandler|. See |CreateAuthHandler| for | |
| 100 // more details on return values. | |
| 101 int CreatePreemptiveAuthHandlerFromString( | |
| 102 const std::string& challenge, | |
| 103 HttpAuth::Target target, | 86 HttpAuth::Target target, |
| 104 const GURL& origin, | 87 const BoundNetLog& net_log) = 0; |
| 105 int digest_nonce_count, | |
| 106 const BoundNetLog& net_log, | |
| 107 scoped_ptr<HttpAuthHandler>* handler); | |
| 108 | 88 |
| 109 // Creates a standard HttpAuthHandlerRegistryFactory. The caller is | 89 // Creates a standard HttpAuthHandlerRegistryFactory. The caller is |
| 110 // responsible for deleting the factory. | 90 // responsible for deleting the factory. |
| 111 // The default factory supports Basic, Digest, NTLM, and Negotiate schemes. | 91 // The default factory supports Basic, Digest, NTLM, and Negotiate schemes. |
| 112 // | 92 // |
| 113 // |resolver| is used by the Negotiate authentication handler to perform | 93 // |resolver| is used by the Negotiate authentication handler to perform |
| 114 // CNAME lookups to generate a Kerberos SPN for the server. It must be | 94 // CNAME lookups to generate a Kerberos SPN for the server. It must be |
| 115 // non-NULL. |resolver| must remain valid for the lifetime of the | 95 // non-NULL. |resolver| must remain valid for the lifetime of the |
| 116 // HttpAuthHandlerRegistryFactory and any HttpAuthHandlers created by said | 96 // HttpAuthHandlerRegistryFactory and any HttpAuthHandlers created by said |
| 117 // factory. | 97 // factory. |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 // |gssapi_library_name| specifies the name of the GSSAPI library that will | 152 // |gssapi_library_name| specifies the name of the GSSAPI library that will |
| 173 // be loaded on Posix platforms other than Android. |gssapi_library_name| is | 153 // be loaded on Posix platforms other than Android. |gssapi_library_name| is |
| 174 // ignored on Android and Windows. | 154 // ignored on Android and Windows. |
| 175 // | 155 // |
| 176 // |auth_android_negotiate_account_type| is an Android account type, used to | 156 // |auth_android_negotiate_account_type| is an Android account type, used to |
| 177 // find the appropriate authenticator service on Android. It is ignored on | 157 // find the appropriate authenticator service on Android. It is ignored on |
| 178 // non-Android platforms. | 158 // non-Android platforms. |
| 179 // | 159 // |
| 180 // |negotiate_disable_cname_lookup| and |negotiate_enable_port| both control | 160 // |negotiate_disable_cname_lookup| and |negotiate_enable_port| both control |
| 181 // how Negotiate does SPN generation, by default these should be false. | 161 // how Negotiate does SPN generation, by default these should be false. |
| 162 // TODO(asanka): Update comment |
| 182 static HttpAuthHandlerRegistryFactory* Create( | 163 static HttpAuthHandlerRegistryFactory* Create( |
| 183 const std::vector<std::string>& supported_schemes, | 164 const std::vector<std::string>& supported_schemes, |
| 184 URLSecurityManager* security_manager, | 165 URLSecurityManager* security_manager, |
| 185 HostResolver* host_resolver, | 166 HostResolver* host_resolver, |
| 186 const std::string& gssapi_library_name, | 167 const std::string& gssapi_library_name, |
| 187 const std::string& auth_android_negotiate_account_type, | 168 const std::string& auth_android_negotiate_account_type, |
| 188 bool negotiate_disable_cname_lookup, | 169 bool negotiate_disable_cname_lookup, |
| 189 bool negotiate_enable_port); | 170 bool negotiate_enable_port); |
| 190 | 171 |
| 172 scoped_ptr<HttpAuthHandler> CreateAuthHandlerForScheme( |
| 173 const std::string& scheme) override; |
| 174 |
| 191 // Create an auth handler by dispatching the CreateAuthHandler() call to the | 175 // Create an auth handler by dispatching the CreateAuthHandler() call to the |
| 192 // factory registered to handle challenge->scheme(). | 176 // factory registered to handle challenge->scheme(). TODO(asanka): Update |
| 193 int CreateAuthHandler(const HttpAuthChallengeTokenizer& challenge, | 177 // comment |
| 194 HttpAuth::Target target, | 178 scoped_ptr<HttpAuthHandler> CreateAndInitPreemptiveAuthHandler( |
| 195 const GURL& origin, | 179 HttpAuthCache::Entry* cache_entry, |
| 196 CreateReason reason, | 180 const HttpAuthChallengeTokenizer& tokenizer, |
| 197 int digest_nonce_count, | 181 HttpAuth::Target target, |
| 198 const BoundNetLog& net_log, | 182 const BoundNetLog& net_log) override; |
| 199 scoped_ptr<HttpAuthHandler>* handler) override; | |
| 200 | 183 |
| 201 private: | 184 private: |
| 202 typedef std::map<std::string, HttpAuthHandlerFactory*> FactoryMap; | 185 typedef std::map<std::string, HttpAuthHandlerFactory*> FactoryMap; |
| 203 | 186 |
| 204 FactoryMap factory_map_; | 187 FactoryMap factory_map_; |
| 205 DISALLOW_COPY_AND_ASSIGN(HttpAuthHandlerRegistryFactory); | 188 DISALLOW_COPY_AND_ASSIGN(HttpAuthHandlerRegistryFactory); |
| 206 }; | 189 }; |
| 207 | 190 |
| 208 } // namespace net | 191 } // namespace net |
| 209 | 192 |
| 210 #endif // NET_HTTP_HTTP_AUTH_HANDLER_FACTORY_H_ | 193 #endif // NET_HTTP_HTTP_AUTH_HANDLER_FACTORY_H_ |
| OLD | NEW |