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

Side by Side Diff: chromeos/dbus/auth_policy_client.cc

Issue 2519823006: Chromad: Add authentication flow (Closed)
Patch Set: Created 4 years 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
OLDNEW
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 #include "chromeos/dbus/auth_policy_client.h" 4 #include "chromeos/dbus/auth_policy_client.h"
5 5
6 #include "base/bind.h" 6 #include "base/bind.h"
7 #include "base/memory/weak_ptr.h" 7 #include "base/memory/weak_ptr.h"
8 #include "dbus/bus.h" 8 #include "dbus/bus.h"
9 #include "dbus/message.h" 9 #include "dbus/message.h"
10 #include "dbus/object_proxy.h" 10 #include "dbus/object_proxy.h"
11 #include "third_party/cros_system_api/dbus/service_constants.h" 11 #include "third_party/cros_system_api/dbus/service_constants.h"
12 12
13 namespace chromeos { 13 namespace chromeos {
14 14
15 namespace { 15 namespace {
16 16
17 class AuthPolicyClientImpl : public AuthPolicyClient { 17 class AuthPolicyClientImpl : public AuthPolicyClient {
18 public: 18 public:
19 AuthPolicyClientImpl() : weak_ptr_factory_(this) {} 19 AuthPolicyClientImpl() : weak_ptr_factory_(this) {}
20 20
21 ~AuthPolicyClientImpl() override {} 21 ~AuthPolicyClientImpl() override {}
22 22
23 // AuthPolicyClient override. 23 // AuthPolicyClient override.
24 void JoinAdDomain(const std::string& machine_name, 24 void JoinAdDomain(const std::string& machine_name,
25 const std::string& user, 25 const std::string& user_principal_name,
26 int password_fd, 26 int password_fd,
27 const JoinCallback& callback) override { 27 const JoinCallback& callback) override {
28 dbus::MethodCall method_call(authpolicy::kAuthPolicyInterface, 28 dbus::MethodCall method_call(authpolicy::kAuthPolicyInterface,
29 authpolicy::kAuthPolicyJoinADDomain); 29 authpolicy::kAuthPolicyJoinADDomain);
30 dbus::MessageWriter writer(&method_call); 30 dbus::MessageWriter writer(&method_call);
31 writer.AppendString(machine_name); 31 writer.AppendString(machine_name);
32 writer.AppendString(user); 32 writer.AppendString(user_principal_name);
33 writer.AppendFileDescriptor(password_fd); 33 writer.AppendFileDescriptor(password_fd);
34 proxy_->CallMethod(&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, 34 proxy_->CallMethod(&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
35 base::Bind(&AuthPolicyClientImpl::HandleJoinCallback, 35 base::Bind(&AuthPolicyClientImpl::HandleJoinCallback,
36 weak_ptr_factory_.GetWeakPtr(), callback)); 36 weak_ptr_factory_.GetWeakPtr(), callback));
37 } 37 }
38 38
39 void AuthenticateUser(const std::string& user_principal_name,
40 int password_fd,
41 const AuthCallback& callback) override {
42 dbus::MethodCall method_call(authpolicy::kAuthPolicyInterface,
43 authpolicy::kAuthPolicyAuthenticateUser);
44 dbus::MessageWriter writer(&method_call);
45 writer.AppendString(user_principal_name);
46 writer.AppendFileDescriptor(password_fd);
47 proxy_->CallMethod(&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
48 base::Bind(&AuthPolicyClientImpl::HandleAuthCallback,
49 weak_ptr_factory_.GetWeakPtr(), callback));
50 }
51
39 void RefreshDevicePolicy(const RefreshPolicyCallback& callback) override { 52 void RefreshDevicePolicy(const RefreshPolicyCallback& callback) override {
40 dbus::MethodCall method_call(authpolicy::kAuthPolicyInterface, 53 dbus::MethodCall method_call(authpolicy::kAuthPolicyInterface,
41 authpolicy::kAuthPolicyRefreshDevicePolicy); 54 authpolicy::kAuthPolicyRefreshDevicePolicy);
42 proxy_->CallMethod( 55 proxy_->CallMethod(
43 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, 56 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
44 base::Bind(&AuthPolicyClientImpl::HandleRefreshPolicyCallback, 57 base::Bind(&AuthPolicyClientImpl::HandleRefreshPolicyCallback,
45 weak_ptr_factory_.GetWeakPtr(), callback)); 58 weak_ptr_factory_.GetWeakPtr(), callback));
46 } 59 }
47 60
48 void RefreshUserPolicy(const std::string& account_id, 61 void RefreshUserPolicy(const std::string& account_id,
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 if (!reader.PopInt32(&res)) { 103 if (!reader.PopInt32(&res)) {
91 LOG(ERROR) << "Join: Couldn't get an error from the response"; 104 LOG(ERROR) << "Join: Couldn't get an error from the response";
92 // TODO(rsorokin): make proper call, after defining possible errors codes. 105 // TODO(rsorokin): make proper call, after defining possible errors codes.
93 callback.Run(authpolicy::AD_JOIN_ERROR_DBUS_FAIL); 106 callback.Run(authpolicy::AD_JOIN_ERROR_DBUS_FAIL);
94 return; 107 return;
95 } 108 }
96 109
97 callback.Run(res); 110 callback.Run(res);
98 } 111 }
99 112
113 void HandleAuthCallback(const AuthCallback& callback,
114 dbus::Response* response) {
115 std::string user_id;
116 int res = authpolicy::AUTH_USER_ERROR_DBUS_FAILURE;
117 if (!response) {
118 LOG(ERROR) << "Auth: Failed to call to authpolicy";
119 // TODO(rsorokin): make proper call, after defining possible errors codes.
120 callback.Run(authpolicy::AUTH_USER_ERROR_DBUS_FAILURE, user_id);
121 return;
122 }
123 dbus::MessageReader reader(response);
124 if (!reader.PopInt32(&res)) {
125 LOG(ERROR) << "Auth: Failed to get an error from the response";
126 // TODO(rsorokin): make proper call, after defining possible errors codes.
127 callback.Run(res, user_id);
128 return;
129 }
130 if (!reader.PopString(&user_id)) {
131 LOG(ERROR) << "Auth: Failed to get user_id from the response";
132 callback.Run(res, user_id);
133 return;
134 }
135 callback.Run(res, user_id);
136 }
137
100 dbus::Bus* bus_ = nullptr; 138 dbus::Bus* bus_ = nullptr;
101 dbus::ObjectProxy* proxy_ = nullptr; 139 dbus::ObjectProxy* proxy_ = nullptr;
102 140
103 // Note: This should remain the last member so it'll be destroyed and 141 // Note: This should remain the last member so it'll be destroyed and
104 // invalidate its weak pointers before any other members are destroyed. 142 // invalidate its weak pointers before any other members are destroyed.
105 base::WeakPtrFactory<AuthPolicyClientImpl> weak_ptr_factory_; 143 base::WeakPtrFactory<AuthPolicyClientImpl> weak_ptr_factory_;
106 144
107 DISALLOW_COPY_AND_ASSIGN(AuthPolicyClientImpl); 145 DISALLOW_COPY_AND_ASSIGN(AuthPolicyClientImpl);
108 }; 146 };
109 147
110 } // namespace 148 } // namespace
111 149
112 AuthPolicyClient::AuthPolicyClient() {} 150 AuthPolicyClient::AuthPolicyClient() {}
113 151
114 AuthPolicyClient::~AuthPolicyClient() {} 152 AuthPolicyClient::~AuthPolicyClient() {}
115 153
116 // static 154 // static
117 AuthPolicyClient* AuthPolicyClient::Create() { 155 AuthPolicyClient* AuthPolicyClient::Create() {
118 return new AuthPolicyClientImpl(); 156 return new AuthPolicyClientImpl();
119 } 157 }
120 158
121 } // namespace chromeos 159 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698