url_security_manager.h 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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
  3. // found in the LICENSE file.
  4. #ifndef NET_HTTP_URL_SECURITY_MANAGER_H_
  5. #define NET_HTTP_URL_SECURITY_MANAGER_H_
  6. #include <memory>
  7. #include "net/base/net_export.h"
  8. namespace url {
  9. class SchemeHostPort;
  10. }
  11. namespace net {
  12. class HttpAuthFilter;
  13. // The URL security manager controls the policies (allow, deny, prompt user)
  14. // regarding URL actions (e.g., sending the default credentials to a server).
  15. class NET_EXPORT_PRIVATE URLSecurityManager {
  16. public:
  17. URLSecurityManager() = default;
  18. URLSecurityManager(const URLSecurityManager&) = delete;
  19. URLSecurityManager& operator=(const URLSecurityManager&) = delete;
  20. virtual ~URLSecurityManager() = default;
  21. // Creates a platform-dependent instance of URLSecurityManager.
  22. //
  23. // A security manager has two allowlists, a "default allowlist" that is a
  24. // allowlist of servers with which default credentials can be used, and a
  25. // "delegate allowlist" that is the allowlist of servers that are allowed to
  26. // have delegated Kerberos tickets.
  27. //
  28. // On creation both allowlists are empty.
  29. //
  30. // If the default allowlist is empty and the platform is Windows, it indicates
  31. // that security zone mapping should be used to determine whether default
  32. // credentials should be used. If the default allowlist is empty and the
  33. // platform is non-Windows, it indicates that no servers should be
  34. // allowlisted.
  35. //
  36. // If the delegate allowlist is empty no servers can have delegated Kerberos
  37. // tickets.
  38. //
  39. static std::unique_ptr<URLSecurityManager> Create();
  40. // Returns true if we can send the default credentials to the server at
  41. // |auth_scheme_host_port| for HTTP NTLM or Negotiate authentication.
  42. virtual bool CanUseDefaultCredentials(
  43. const url::SchemeHostPort& auth_scheme_host_port) const = 0;
  44. // Returns true if Kerberos delegation is allowed for the server at
  45. // |auth_scheme_host_port| for HTTP Negotiate authentication.
  46. virtual bool CanDelegate(
  47. const url::SchemeHostPort& auth_scheme_host_port) const = 0;
  48. virtual void SetDefaultAllowlist(
  49. std::unique_ptr<HttpAuthFilter> allowlist_default) = 0;
  50. virtual void SetDelegateAllowlist(
  51. std::unique_ptr<HttpAuthFilter> allowlist_delegate) = 0;
  52. };
  53. class URLSecurityManagerAllowlist : public URLSecurityManager {
  54. public:
  55. URLSecurityManagerAllowlist();
  56. URLSecurityManagerAllowlist(const URLSecurityManagerAllowlist&) = delete;
  57. URLSecurityManagerAllowlist& operator=(const URLSecurityManagerAllowlist&) =
  58. delete;
  59. ~URLSecurityManagerAllowlist() override;
  60. // URLSecurityManager methods.
  61. bool CanUseDefaultCredentials(
  62. const url::SchemeHostPort& auth_scheme_host_port) const override;
  63. bool CanDelegate(
  64. const url::SchemeHostPort& auth_scheme_host_port) const override;
  65. void SetDefaultAllowlist(
  66. std::unique_ptr<HttpAuthFilter> allowlist_default) override;
  67. void SetDelegateAllowlist(
  68. std::unique_ptr<HttpAuthFilter> allowlist_delegate) override;
  69. protected:
  70. bool HasDefaultAllowlist() const;
  71. private:
  72. std::unique_ptr<const HttpAuthFilter> allowlist_default_;
  73. std::unique_ptr<const HttpAuthFilter> allowlist_delegate_;
  74. };
  75. } // namespace net
  76. #endif // NET_HTTP_URL_SECURITY_MANAGER_H_