Commit a49cf47b authored by Yicheng Li's avatar Yicheng Li Committed by Commit Bot

ash: Let UserAuthenticationServiceProvider start auth dialog

This enables UserAuthenticationServiceProvider to call
AuthDialogController to start the dialog. Currently the dialog
only has a dev view which will only show when a command line
switch is enabled.

TEST=Used u2fd to call UserAuthenticationServiceProvider while
     having --show-auth-dialog-dev-overlap. Observed that the debug
     view shows up.

Bug: b:156258540
Change-Id: Ibe4437c628fb5aed91b63e7905518112ce97a4b5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2298544
Commit-Queue: Yicheng Li <yichengli@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#797929}
parent e52c47fb
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "ash/dbus/user_authentication_service_provider.h" #include "ash/dbus/user_authentication_service_provider.h"
#include "ash/public/cpp/in_session_auth_dialog_controller.h"
#include "base/bind.h" #include "base/bind.h"
#include "base/logging.h" #include "base/logging.h"
#include "dbus/bus.h" #include "dbus/bus.h"
...@@ -41,8 +42,23 @@ void UserAuthenticationServiceProvider::OnExported( ...@@ -41,8 +42,23 @@ void UserAuthenticationServiceProvider::OnExported(
void UserAuthenticationServiceProvider::ShowAuthDialog( void UserAuthenticationServiceProvider::ShowAuthDialog(
dbus::MethodCall* method_call, dbus::MethodCall* method_call,
dbus::ExportedObject::ResponseSender response_sender) { dbus::ExportedObject::ResponseSender response_sender) {
// TODO(yichengli): Call AuthDialogController to start authentication flow. auto* auth_dialog_controller = InSessionAuthDialogController::Get();
std::move(response_sender).Run(dbus::Response::FromMethodCall(method_call)); auth_dialog_controller->ShowAuthenticationDialog(base::BindOnce(
&UserAuthenticationServiceProvider::OnAuthFlowComplete,
weak_ptr_factory_.GetWeakPtr(), method_call, std::move(response_sender)));
}
void UserAuthenticationServiceProvider::OnAuthFlowComplete(
dbus::MethodCall* method_call,
dbus::ExportedObject::ResponseSender response_sender,
bool success) {
DCHECK(method_call && !response_sender.is_null());
std::unique_ptr<dbus::Response> response =
dbus::Response::FromMethodCall(method_call);
dbus::MessageWriter writer(response.get());
writer.AppendBool(success);
std::move(response_sender).Run(std::move(response));
} }
} // namespace ash } // namespace ash
...@@ -41,6 +41,11 @@ class UserAuthenticationServiceProvider ...@@ -41,6 +41,11 @@ class UserAuthenticationServiceProvider
void ShowAuthDialog(dbus::MethodCall* method_call, void ShowAuthDialog(dbus::MethodCall* method_call,
dbus::ExportedObject::ResponseSender response_sender); dbus::ExportedObject::ResponseSender response_sender);
// Called when the user authentication flow completes.
void OnAuthFlowComplete(dbus::MethodCall* method_call,
dbus::ExportedObject::ResponseSender response_sender,
bool success);
// Keep this last so that all weak pointers will be invalidated at the // Keep this last so that all weak pointers will be invalidated at the
// beginning of destruction. // beginning of destruction.
base::WeakPtrFactory<UserAuthenticationServiceProvider> weak_ptr_factory_{ base::WeakPtrFactory<UserAuthenticationServiceProvider> weak_ptr_factory_{
......
...@@ -234,8 +234,8 @@ void AuthDialogDebugView::AddActionButtonsView() { ...@@ -234,8 +234,8 @@ void AuthDialogDebugView::AddActionButtonsView() {
void AuthDialogDebugView::ButtonPressed(views::Button* sender, void AuthDialogDebugView::ButtonPressed(views::Button* sender,
const ui::Event& event) { const ui::Event& event) {
if (sender == cancel_button_) { if (sender == cancel_button_) {
// DestroyAuthenticationDialog deletes |this|. // Cancel() deletes |this|.
InSessionAuthDialogController::Get()->DestroyAuthenticationDialog(); InSessionAuthDialogController::Get()->Cancel();
} }
// TODO(b/156258540): Enable more options button when we have both fingerprint // TODO(b/156258540): Enable more options button when we have both fingerprint
......
...@@ -25,8 +25,13 @@ void InSessionAuthDialogControllerImpl::SetClient( ...@@ -25,8 +25,13 @@ void InSessionAuthDialogControllerImpl::SetClient(
client_ = client; client_ = client;
} }
void InSessionAuthDialogControllerImpl::ShowAuthenticationDialog() { void InSessionAuthDialogControllerImpl::ShowAuthenticationDialog(
FinishCallback finish_callback) {
DCHECK(client_); DCHECK(client_);
// Concurrent requests are not supported.
DCHECK(!dialog_);
finish_callback_ = std::move(finish_callback);
AccountId account_id = AccountId account_id =
Shell::Get()->session_controller()->GetActiveAccountId(); Shell::Get()->session_controller()->GetActiveAccountId();
...@@ -73,9 +78,16 @@ void InSessionAuthDialogControllerImpl::OnAuthenticateComplete( ...@@ -73,9 +78,16 @@ void InSessionAuthDialogControllerImpl::OnAuthenticateComplete(
OnAuthenticateCallback callback, OnAuthenticateCallback callback,
bool success) { bool success) {
std::move(callback).Run(success); std::move(callback).Run(success);
// TODO(b/156258540): send status to UserAuthenticationServiceProvider for // TODO(b/156258540): Manage retry instead of closing directly.
// dbus response. DestroyAuthenticationDialog();
if (finish_callback_)
std::move(finish_callback_).Run(success);
}
void InSessionAuthDialogControllerImpl::Cancel() {
DestroyAuthenticationDialog(); DestroyAuthenticationDialog();
if (finish_callback_)
std::move(finish_callback_).Run(false);
} }
} // namespace ash } // namespace ash
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#include "ash/in_session_auth/in_session_auth_dialog.h" #include "ash/in_session_auth/in_session_auth_dialog.h"
#include "ash/public/cpp/in_session_auth_dialog_controller.h" #include "ash/public/cpp/in_session_auth_dialog_controller.h"
#include "base/callback_forward.h" #include "base/callback.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/optional.h" #include "base/optional.h"
...@@ -22,12 +22,6 @@ class InSessionAuthDialogClient; ...@@ -22,12 +22,6 @@ class InSessionAuthDialogClient;
// InSessionAuthDialogControllerImpl persists as long as UI is running. // InSessionAuthDialogControllerImpl persists as long as UI is running.
class InSessionAuthDialogControllerImpl : public InSessionAuthDialogController { class InSessionAuthDialogControllerImpl : public InSessionAuthDialogController {
public: public:
// Callback for authentication checks. |success| is nullopt if an
// authentication check did not run, otherwise it is true/false if auth
// succeeded/failed.
using OnAuthenticateCallback =
base::OnceCallback<void(base::Optional<bool> success)>;
InSessionAuthDialogControllerImpl(); InSessionAuthDialogControllerImpl();
InSessionAuthDialogControllerImpl(const InSessionAuthDialogControllerImpl&) = InSessionAuthDialogControllerImpl(const InSessionAuthDialogControllerImpl&) =
delete; delete;
...@@ -37,11 +31,12 @@ class InSessionAuthDialogControllerImpl : public InSessionAuthDialogController { ...@@ -37,11 +31,12 @@ class InSessionAuthDialogControllerImpl : public InSessionAuthDialogController {
// InSessionAuthDialogController overrides // InSessionAuthDialogController overrides
void SetClient(InSessionAuthDialogClient* client) override; void SetClient(InSessionAuthDialogClient* client) override;
void ShowAuthenticationDialog() override; void ShowAuthenticationDialog(FinishCallback finish_callback) override;
void DestroyAuthenticationDialog() override; void DestroyAuthenticationDialog() override;
void AuthenticateUserWithPasswordOrPin( void AuthenticateUserWithPasswordOrPin(
const std::string& password, const std::string& password,
OnAuthenticateCallback callback) override; OnAuthenticateCallback callback) override;
void Cancel() override;
private: private:
bool IsFingerprintAvailable(const AccountId& account_id); bool IsFingerprintAvailable(const AccountId& account_id);
...@@ -52,6 +47,10 @@ class InSessionAuthDialogControllerImpl : public InSessionAuthDialogController { ...@@ -52,6 +47,10 @@ class InSessionAuthDialogControllerImpl : public InSessionAuthDialogController {
InSessionAuthDialogClient* client_ = nullptr; InSessionAuthDialogClient* client_ = nullptr;
// Callback to provide result of the entire authentication flow to
// UserAuthenticationServiceProvider.
FinishCallback finish_callback_;
std::unique_ptr<InSessionAuthDialog> dialog_; std::unique_ptr<InSessionAuthDialog> dialog_;
base::WeakPtrFactory<InSessionAuthDialogControllerImpl> weak_factory_{this}; base::WeakPtrFactory<InSessionAuthDialogControllerImpl> weak_factory_{this};
......
...@@ -19,6 +19,8 @@ class ASH_PUBLIC_EXPORT InSessionAuthDialogController { ...@@ -19,6 +19,8 @@ class ASH_PUBLIC_EXPORT InSessionAuthDialogController {
// succeeded/failed. // succeeded/failed.
using OnAuthenticateCallback = using OnAuthenticateCallback =
base::OnceCallback<void(base::Optional<bool> success)>; base::OnceCallback<void(base::Optional<bool> success)>;
// Callback for overall authentication flow result.
using FinishCallback = base::OnceCallback<void(bool success)>;
// Return the singleton instance. // Return the singleton instance.
static InSessionAuthDialogController* Get(); static InSessionAuthDialogController* Get();
...@@ -27,7 +29,7 @@ class ASH_PUBLIC_EXPORT InSessionAuthDialogController { ...@@ -27,7 +29,7 @@ class ASH_PUBLIC_EXPORT InSessionAuthDialogController {
virtual void SetClient(InSessionAuthDialogClient* client) = 0; virtual void SetClient(InSessionAuthDialogClient* client) = 0;
// Displays the authentication dialog. // Displays the authentication dialog.
virtual void ShowAuthenticationDialog() = 0; virtual void ShowAuthenticationDialog(FinishCallback finish_callback) = 0;
// Destroys the authentication dialog. // Destroys the authentication dialog.
virtual void DestroyAuthenticationDialog() = 0; virtual void DestroyAuthenticationDialog() = 0;
...@@ -39,6 +41,9 @@ class ASH_PUBLIC_EXPORT InSessionAuthDialogController { ...@@ -39,6 +41,9 @@ class ASH_PUBLIC_EXPORT InSessionAuthDialogController {
const std::string& password, const std::string& password,
OnAuthenticateCallback callback) = 0; OnAuthenticateCallback callback) = 0;
// Cancels all operations and destroys the dialog.
virtual void Cancel() = 0;
protected: protected:
InSessionAuthDialogController(); InSessionAuthDialogController();
virtual ~InSessionAuthDialogController(); virtual ~InSessionAuthDialogController();
......
...@@ -35,19 +35,17 @@ const AccountId kAccountId = AccountId::FromUserEmail("testemail@example.com"); ...@@ -35,19 +35,17 @@ const AccountId kAccountId = AccountId::FromUserEmail("testemail@example.com");
class FakeInSessionAuthDialogController class FakeInSessionAuthDialogController
: public ash::InSessionAuthDialogController { : public ash::InSessionAuthDialogController {
public: public:
using OnAuthenticateCallback =
base::OnceCallback<void(base::Optional<bool> success)>;
FakeInSessionAuthDialogController() = default; FakeInSessionAuthDialogController() = default;
~FakeInSessionAuthDialogController() override = default; ~FakeInSessionAuthDialogController() override = default;
// ash::InSessionAuthDialogController: // ash::InSessionAuthDialogController:
void SetClient(ash::InSessionAuthDialogClient* client) override {} void SetClient(ash::InSessionAuthDialogClient* client) override {}
void ShowAuthenticationDialog() override {} void ShowAuthenticationDialog(FinishCallback callback) override {}
void DestroyAuthenticationDialog() override {} void DestroyAuthenticationDialog() override {}
void AuthenticateUserWithPasswordOrPin( void AuthenticateUserWithPasswordOrPin(
const std::string& password, const std::string& password,
OnAuthenticateCallback callback) override {} OnAuthenticateCallback callback) override {}
void Cancel() override {}
}; };
class InSessionAuthDialogClientTest : public testing::Test { class InSessionAuthDialogClientTest : public testing::Test {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment