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

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

Issue 2519823006: Chromad: Add authentication flow (Closed)
Patch Set: Rename HandleAdAuth. Use system_api enums Created 3 years, 12 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/dbus/auth_policy_client.h ('k') | chromeos/dbus/fake_auth_policy_client.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 13 matching lines...) Expand all
62 bus_ = bus; 75 bus_ = bus;
63 proxy_ = bus_->GetObjectProxy( 76 proxy_ = bus_->GetObjectProxy(
64 authpolicy::kAuthPolicyServiceName, 77 authpolicy::kAuthPolicyServiceName,
65 dbus::ObjectPath(authpolicy::kAuthPolicyServicePath)); 78 dbus::ObjectPath(authpolicy::kAuthPolicyServicePath));
66 } 79 }
67 80
68 private: 81 private:
69 void HandleRefreshPolicyCallback(const RefreshPolicyCallback& callback, 82 void HandleRefreshPolicyCallback(const RefreshPolicyCallback& callback,
70 dbus::Response* response) { 83 dbus::Response* response) {
71 if (!response) { 84 if (!response) {
72 LOG(ERROR) << "RefreshDevicePolicy: failed to call to authpolicy"; 85 DLOG(ERROR) << "RefreshDevicePolicy: failed to call to authpolicy";
73 callback.Run(false); 86 callback.Run(false);
74 return; 87 return;
75 } 88 }
76 callback.Run(true); 89 callback.Run(true);
77 } 90 }
78 91
79 void HandleJoinCallback(const JoinCallback& callback, 92 void HandleJoinCallback(const JoinCallback& callback,
80 dbus::Response* response) { 93 dbus::Response* response) {
81 if (!response) { 94 if (!response) {
82 LOG(ERROR) << "Join: Couldn't call to authpolicy"; 95 DLOG(ERROR) << "Join: Couldn't call to authpolicy";
83 // TODO(rsorokin): make proper call, after defining possible errors codes. 96 // TODO(rsorokin): make proper call, after defining possible errors codes.
84 callback.Run(authpolicy::types::AD_JOIN_ERROR_UNKNOWN); 97 callback.Run(authpolicy::types::AD_JOIN_ERROR_UNKNOWN);
85 return; 98 return;
86 } 99 }
87 100
88 dbus::MessageReader reader(response); 101 dbus::MessageReader reader(response);
89 int res = authpolicy::types::AD_JOIN_ERROR_UNKNOWN; 102 int res = authpolicy::types::AD_JOIN_ERROR_UNKNOWN;
90 if (!reader.PopInt32(&res)) { 103 if (!reader.PopInt32(&res)) {
91 LOG(ERROR) << "Join: Couldn't get an error from the response"; 104 DLOG(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::types::AD_JOIN_ERROR_DBUS_FAIL); 106 callback.Run(authpolicy::types::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 int32_t res = static_cast<int32_t>(authpolicy::AUTH_USER_ERROR_UNKNOWN);
117 if (!response) {
118 DLOG(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 DLOG(ERROR) << "Auth: Failed to get an error from the response";
126 // TODO(rsorokin): make proper call, after defining possible errors codes.
127 callback.Run(static_cast<authpolicy::AuthUserErrorType>(res), user_id);
128 return;
129 }
130 if (res < 0 || res >= authpolicy::AUTH_USER_ERROR_COUNT)
131 res = static_cast<int32_t>(authpolicy::AUTH_USER_ERROR_UNKNOWN);
132 if (!reader.PopString(&user_id))
133 DLOG(ERROR) << "Auth: Failed to get user_id from the response";
134 callback.Run(static_cast<authpolicy::AuthUserErrorType>(res), user_id);
135 }
136
100 dbus::Bus* bus_ = nullptr; 137 dbus::Bus* bus_ = nullptr;
101 dbus::ObjectProxy* proxy_ = nullptr; 138 dbus::ObjectProxy* proxy_ = nullptr;
102 139
103 // Note: This should remain the last member so it'll be destroyed and 140 // Note: This should remain the last member so it'll be destroyed and
104 // invalidate its weak pointers before any other members are destroyed. 141 // invalidate its weak pointers before any other members are destroyed.
105 base::WeakPtrFactory<AuthPolicyClientImpl> weak_ptr_factory_; 142 base::WeakPtrFactory<AuthPolicyClientImpl> weak_ptr_factory_;
106 143
107 DISALLOW_COPY_AND_ASSIGN(AuthPolicyClientImpl); 144 DISALLOW_COPY_AND_ASSIGN(AuthPolicyClientImpl);
108 }; 145 };
109 146
110 } // namespace 147 } // namespace
111 148
112 AuthPolicyClient::AuthPolicyClient() {} 149 AuthPolicyClient::AuthPolicyClient() {}
113 150
114 AuthPolicyClient::~AuthPolicyClient() {} 151 AuthPolicyClient::~AuthPolicyClient() {}
115 152
116 // static 153 // static
117 AuthPolicyClient* AuthPolicyClient::Create() { 154 AuthPolicyClient* AuthPolicyClient::Create() {
118 return new AuthPolicyClientImpl(); 155 return new AuthPolicyClientImpl();
119 } 156 }
120 157
121 } // namespace chromeos 158 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/dbus/auth_policy_client.h ('k') | chromeos/dbus/fake_auth_policy_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698