File: platform_auth_provider_manager.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (113 lines) | stat: -rw-r--r-- 4,349 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_ENTERPRISE_PLATFORM_AUTH_PLATFORM_AUTH_PROVIDER_MANAGER_H_
#define CHROME_BROWSER_ENTERPRISE_PLATFORM_AUTH_PLATFORM_AUTH_PROVIDER_MANAGER_H_

#include <stdint.h>

#include <array>
#include <memory>
#include <optional>
#include <string>
#include <vector>

#include "base/containers/flat_set.h"
#include "base/functional/callback.h"
#include "base/gtest_prod_util.h"
#include "base/memory/weak_ptr.h"
#include "base/sequence_checker.h"
#include "net/http/http_request_headers.h"
#include "url/origin.h"

class GURL;

namespace net {
class HttpRequestHeaders;
}  // namespace net

namespace enterprise_auth {

class PlatformAuthProvider;

// Provides a means by which a browser can enable and use platform-based
// authentication (for example Cloud AP SSO on Windows and Enterprise Extensible
// SSO on MacOS).
class PlatformAuthProviderManager {
 public:
  // Returns the process-wide instance owned by `BrowserMainLoop`.
  static PlatformAuthProviderManager& GetInstance();

  // Note: do not construct a new instance on demand; use the one returned by
  // `GetInstance()`.
  PlatformAuthProviderManager();
  PlatformAuthProviderManager(const PlatformAuthProviderManager&) = delete;
  PlatformAuthProviderManager& operator=(const PlatformAuthProviderManager&) =
      delete;
  ~PlatformAuthProviderManager();

  // Enables or disables platform-based auth asynchronously. `on_complete` will
  // be run (possibly synchronously) once processing is complete. Conversely,
  // `on_complete` will not be run if `SetEnabled()` is called again before a
  // previous call is fully processed.
  void SetEnabled(bool enabled, base::OnceClosure on_complete);

  // Returns true if platform-based authentication is enabled.
  bool IsEnabled() const;

  // Returns true if `url` corresponds to one of the origins `origins_`.
  bool IsEnabledFor(const GURL& url) const;

  using GetDataCallback = base::OnceCallback<void(net::HttpRequestHeaders)>;

  // Initiates an asynchronous fetch for proof of possession cookies and headers
  // to present to `url`. Data will only be fetched if platform-based auth is
  // enabled. `callback` will be run on the caller's sequence (possibly
  // synchronously) with the results.
  void GetData(const GURL& url, GetDataCallback callback) const;

  const base::flat_set<url::Origin>& GetOriginsForTesting() { return origins_; }

 private:
  friend class ScopedSetProviderForTesting;
  FRIEND_TEST_ALL_PREFIXES(PlatformAuthProviderManagerTest, DefaultDisabled);
  FRIEND_TEST_ALL_PREFIXES(PlatformAuthProviderManagerTest, DisableNoop);
  FRIEND_TEST_ALL_PREFIXES(PlatformAuthProviderManagerTest, NotSupported);
  FRIEND_TEST_ALL_PREFIXES(PlatformAuthProviderManagerTest,
                           SupportedWithEmptyOrigins);
  FRIEND_TEST_ALL_PREFIXES(PlatformAuthProviderManagerTest, OriginRemoval);
  FRIEND_TEST_ALL_PREFIXES(PlatformAuthProviderManagerMetricsTest, Success);
  FRIEND_TEST_ALL_PREFIXES(PlatformAuthProviderManagerNoOriginFilteringTest,
                           OriginFilteringNotSupported);
  FRIEND_TEST_ALL_PREFIXES(PlatformAuthNavigationThrottleTest, ManagerDisabled);
  FRIEND_TEST_ALL_PREFIXES(PlatformAuthNavigationThrottleTest, EmptyOrigins);
  FRIEND_TEST_ALL_PREFIXES(PlatformAuthNavigationThrottleTest, EmptyData);
  FRIEND_TEST_ALL_PREFIXES(PlatformAuthNavigationThrottleTest, DataReceived);

  explicit PlatformAuthProviderManager(
      std::unique_ptr<PlatformAuthProvider> provider);

  void StartFetchOrigins();
  void OnOrigins(std::unique_ptr<std::vector<url::Origin>> origins);

  // Returns the previously-configured instance.
  std::unique_ptr<PlatformAuthProvider> SetProviderForTesting(
      std::unique_ptr<PlatformAuthProvider> provider);

  std::unique_ptr<PlatformAuthProvider> provider_;
  bool supports_origin_filtering_;
  bool enabled_ = false;

  base::OnceClosure on_enable_complete_;

  // The collections of IdP/STS origins.
  base::flat_set<url::Origin> origins_;

  SEQUENCE_CHECKER(sequence_checker_);
  base::WeakPtrFactory<PlatformAuthProviderManager> weak_factory_{this};
};

}  // namespace enterprise_auth

#endif  // CHROME_BROWSER_ENTERPRISE_PLATFORM_AUTH_PLATFORM_AUTH_PROVIDER_MANAGER_H_