Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(135)

Unified Diff: chromeos/login/auth/authpolicy_login_helper.cc

Issue 2794493002: Add AuthPolicyLoginHelper (Closed)
Patch Set: Fix test + Update on Lutz's comments Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chromeos/login/auth/authpolicy_login_helper.cc
diff --git a/chromeos/login/auth/authpolicy_login_helper.cc b/chromeos/login/auth/authpolicy_login_helper.cc
new file mode 100644
index 0000000000000000000000000000000000000000..b118cea72982a7092764192ae1a46201bb64093d
--- /dev/null
+++ b/chromeos/login/auth/authpolicy_login_helper.cc
@@ -0,0 +1,79 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chromeos/login/auth/authpolicy_login_helper.h"
+
+#include "base/files/file_util.h"
+#include "base/task_scheduler/post_task.h"
+#include "chromeos/dbus/auth_policy_client.h"
+#include "chromeos/dbus/dbus_thread_manager.h"
+#include "chromeos/dbus/upstart_client.h"
+
+namespace chromeos {
+namespace {
+
+base::ScopedFD GetDataReadPipe(const std::string& data) {
+ int pipe_fds[2];
+ if (!base::CreateLocalNonBlockingPipe(pipe_fds)) {
+ DLOG(ERROR) << "Failed to create pipe";
+ return base::ScopedFD();
+ }
+ base::ScopedFD pipe_read_end(pipe_fds[0]);
+ base::ScopedFD pipe_write_end(pipe_fds[1]);
+
+ if (!base::WriteFileDescriptor(pipe_write_end.get(), data.c_str(),
+ data.size())) {
+ DLOG(ERROR) << "Failed to write to pipe";
+ return base::ScopedFD();
+ }
+ return pipe_read_end;
+}
+
+} // namespace
+
+AuthPolicyLoginHelper::AuthPolicyLoginHelper() : weak_factory_(this) {}
+
+void AuthPolicyLoginHelper::JoinAdDomain(const std::string& machine_name,
+ const std::string& username,
+ const std::string& password,
+ const JoinCallback& callback) {
+ DCHECK(!weak_factory_.HasWeakPtrs()) << "Another operation is in progress";
+ chromeos::DBusThreadManager::Get()->GetAuthPolicyClient()->JoinAdDomain(
+ machine_name, username, GetDataReadPipe(password).get(),
+ base::Bind(&AuthPolicyLoginHelper::OnJoinCallback,
+ weak_factory_.GetWeakPtr(), callback));
+}
+
+void AuthPolicyLoginHelper::AuthenticateUser(const std::string& username,
+ const std::string& password,
+ const AuthCallback& callback) {
+ DCHECK(!weak_factory_.HasWeakPtrs()) << "Another operation is in progress";
+ chromeos::DBusThreadManager::Get()->GetAuthPolicyClient()->AuthenticateUser(
+ username, GetDataReadPipe(password).get(),
ljusten (tachyonic) 2017/04/04 12:51:32 I was a bit concerned about this, but seems like i
Roman Sorokin (ftl) 2017/04/06 15:00:32 Acknowledged.
+ base::Bind(&AuthPolicyLoginHelper::OnAuthCallback,
+ weak_factory_.GetWeakPtr(), callback));
+}
+
+void AuthPolicyLoginHelper::CancelRequestsAndRestart() {
ljusten (tachyonic) 2017/04/04 12:51:32 Are you aware of https://cs.chromium.org/chromium/
Roman Sorokin (ftl) 2017/04/06 15:00:32 I think it would be more complicated.
+ weak_factory_.InvalidateWeakPtrs();
+ chromeos::DBusThreadManager::Get()
+ ->GetUpstartClient()
+ ->RestartAuthPolicyService();
+}
+
+void AuthPolicyLoginHelper::OnJoinCallback(const JoinCallback& callback,
+ authpolicy::ErrorType error) {
+ callback.Run(error);
+}
+
+void AuthPolicyLoginHelper::OnAuthCallback(
+ const AuthCallback& callback,
+ authpolicy::ErrorType error,
+ const authpolicy::ActiveDirectoryAccountData& account_data) {
+ callback.Run(error, account_data);
+}
+
+AuthPolicyLoginHelper::~AuthPolicyLoginHelper() {}
+
+} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698