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

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

Issue 2794493002: Add AuthPolicyLoginHelper (Closed)
Patch Set: Update after review 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
« no previous file with comments | « chromeos/login/auth/authpolicy_login_helper.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..263cb96c6c97a07f29168302f693f0c003ccb949
--- /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,
+ JoinCallback callback) {
+ DCHECK(!weak_factory_.HasWeakPtrs()) << "Another operation is in progress";
+ chromeos::DBusThreadManager::Get()->GetAuthPolicyClient()->JoinAdDomain(
+ machine_name, username, GetDataReadPipe(password).get(),
+ base::BindOnce(&AuthPolicyLoginHelper::OnJoinCallback,
+ weak_factory_.GetWeakPtr(), base::Passed(&callback)));
+}
+
+void AuthPolicyLoginHelper::AuthenticateUser(const std::string& username,
+ const std::string& password,
+ AuthCallback callback) {
+ DCHECK(!weak_factory_.HasWeakPtrs()) << "Another operation is in progress";
+ chromeos::DBusThreadManager::Get()->GetAuthPolicyClient()->AuthenticateUser(
+ username, GetDataReadPipe(password).get(),
+ base::BindOnce(&AuthPolicyLoginHelper::OnAuthCallback,
+ weak_factory_.GetWeakPtr(), base::Passed(&callback)));
+}
+
+void AuthPolicyLoginHelper::CancelRequestsAndRestart() {
+ weak_factory_.InvalidateWeakPtrs();
+ chromeos::DBusThreadManager::Get()
+ ->GetUpstartClient()
+ ->RestartAuthPolicyService();
+}
+
+void AuthPolicyLoginHelper::OnJoinCallback(JoinCallback callback,
+ authpolicy::ErrorType error) {
+ std::move(callback).Run(error);
+}
+
+void AuthPolicyLoginHelper::OnAuthCallback(
+ AuthCallback callback,
+ authpolicy::ErrorType error,
+ const authpolicy::ActiveDirectoryAccountData& account_data) {
+ std::move(callback).Run(error, account_data);
+}
+
+AuthPolicyLoginHelper::~AuthPolicyLoginHelper() {}
+
+} // namespace chromeos
« no previous file with comments | « chromeos/login/auth/authpolicy_login_helper.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698