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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « chromeos/login/auth/authpolicy_login_helper.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2017 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
5 #include "chromeos/login/auth/authpolicy_login_helper.h"
6
7 #include "base/files/file_util.h"
8 #include "base/task_scheduler/post_task.h"
9 #include "chromeos/dbus/auth_policy_client.h"
10 #include "chromeos/dbus/dbus_thread_manager.h"
11 #include "chromeos/dbus/upstart_client.h"
12
13 namespace chromeos {
14 namespace {
15
16 base::ScopedFD GetDataReadPipe(const std::string& data) {
17 int pipe_fds[2];
18 if (!base::CreateLocalNonBlockingPipe(pipe_fds)) {
19 DLOG(ERROR) << "Failed to create pipe";
20 return base::ScopedFD();
21 }
22 base::ScopedFD pipe_read_end(pipe_fds[0]);
23 base::ScopedFD pipe_write_end(pipe_fds[1]);
24
25 if (!base::WriteFileDescriptor(pipe_write_end.get(), data.c_str(),
26 data.size())) {
27 DLOG(ERROR) << "Failed to write to pipe";
28 return base::ScopedFD();
29 }
30 return pipe_read_end;
31 }
32
33 } // namespace
34
35 AuthPolicyLoginHelper::AuthPolicyLoginHelper() : weak_factory_(this) {}
36
37 void AuthPolicyLoginHelper::JoinAdDomain(const std::string& machine_name,
38 const std::string& username,
39 const std::string& password,
40 JoinCallback callback) {
41 DCHECK(!weak_factory_.HasWeakPtrs()) << "Another operation is in progress";
42 chromeos::DBusThreadManager::Get()->GetAuthPolicyClient()->JoinAdDomain(
43 machine_name, username, GetDataReadPipe(password).get(),
44 base::BindOnce(&AuthPolicyLoginHelper::OnJoinCallback,
45 weak_factory_.GetWeakPtr(), base::Passed(&callback)));
46 }
47
48 void AuthPolicyLoginHelper::AuthenticateUser(const std::string& username,
49 const std::string& password,
50 AuthCallback callback) {
51 DCHECK(!weak_factory_.HasWeakPtrs()) << "Another operation is in progress";
52 chromeos::DBusThreadManager::Get()->GetAuthPolicyClient()->AuthenticateUser(
53 username, GetDataReadPipe(password).get(),
54 base::BindOnce(&AuthPolicyLoginHelper::OnAuthCallback,
55 weak_factory_.GetWeakPtr(), base::Passed(&callback)));
56 }
57
58 void AuthPolicyLoginHelper::CancelRequestsAndRestart() {
59 weak_factory_.InvalidateWeakPtrs();
60 chromeos::DBusThreadManager::Get()
61 ->GetUpstartClient()
62 ->RestartAuthPolicyService();
63 }
64
65 void AuthPolicyLoginHelper::OnJoinCallback(JoinCallback callback,
66 authpolicy::ErrorType error) {
67 std::move(callback).Run(error);
68 }
69
70 void AuthPolicyLoginHelper::OnAuthCallback(
71 AuthCallback callback,
72 authpolicy::ErrorType error,
73 const authpolicy::ActiveDirectoryAccountData& account_data) {
74 std::move(callback).Run(error, account_data);
75 }
76
77 AuthPolicyLoginHelper::~AuthPolicyLoginHelper() {}
78
79 } // namespace chromeos
OLDNEW
« 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