Commit 01014b7c authored by rsorokin's avatar rsorokin Committed by Commit bot

Chromad: Add GetUserStatus call into AuthPolicyClient

Also s/ActiveDirectoryAccountData/ActiveDirectoryAccountInfo

BUG=662400
TBR=xiyuan@chromium.org

Review-Url: https://codereview.chromium.org/2841103002
Cr-Commit-Position: refs/heads/master@{#467967}
parent db08d35e
......@@ -540,15 +540,15 @@ void GaiaScreenHandler::DoAdAuth(
const std::string& username,
const Key& key,
authpolicy::ErrorType error,
const authpolicy::ActiveDirectoryAccountData& account_data) {
const authpolicy::ActiveDirectoryAccountInfo& account_info) {
switch (error) {
case authpolicy::ERROR_NONE: {
DCHECK(account_data.has_account_id() &&
!account_data.account_id().empty());
DCHECK(account_info.has_account_id() &&
!account_info.account_id().empty());
const AccountId account_id(GetAccountId(
username, account_data.account_id(), AccountType::ACTIVE_DIRECTORY));
Delegate()->SetDisplayAndGivenName(account_data.display_name(),
account_data.given_name());
username, account_info.account_id(), AccountType::ACTIVE_DIRECTORY));
Delegate()->SetDisplayAndGivenName(account_info.display_name(),
account_info.given_name());
UserContext user_context(account_id);
user_context.SetKey(key);
user_context.SetAuthFlow(UserContext::AUTH_FLOW_ACTIVE_DIRECTORY);
......
......@@ -21,7 +21,7 @@
class AccountId;
namespace authpolicy {
class ActiveDirectoryAccountData;
class ActiveDirectoryAccountInfo;
}
namespace chromeos {
......@@ -147,7 +147,7 @@ class GaiaScreenHandler : public BaseScreenHandler,
void DoAdAuth(const std::string& username,
const Key& key,
authpolicy::ErrorType error,
const authpolicy::ActiveDirectoryAccountData& account_data);
const authpolicy::ActiveDirectoryAccountInfo& account_info);
// Callback for writing password into pipe.
void OnPasswordPipeReady(const std::string& username,
......
......@@ -747,7 +747,7 @@ proto_library("cryptohome_signkey_proto") {
proto_library("authpolicy_proto") {
sources = [
"//third_party/cros_system_api/dbus/authpolicy/active_directory_account_data.proto",
"//third_party/cros_system_api/dbus/authpolicy/active_directory_info.proto",
]
proto_out_dir = "chromeos/dbus/authpolicy"
......
......@@ -33,6 +33,26 @@ authpolicy::ErrorType GetErrorFromReader(dbus::MessageReader* reader) {
return static_cast<authpolicy::ErrorType>(int_error);
}
authpolicy::ErrorType GetErrorAndProto(
dbus::Response* response,
google::protobuf::MessageLite* protobuf) {
if (!response) {
DLOG(ERROR) << "Auth: Failed to call to authpolicy";
return authpolicy::ERROR_DBUS_FAILURE;
}
dbus::MessageReader reader(response);
const authpolicy::ErrorType error(GetErrorFromReader(&reader));
if (error != authpolicy::ERROR_NONE)
return error;
if (!reader.PopArrayOfBytesAsProto(protobuf)) {
DLOG(ERROR) << "Failed to parse protobuf.";
return authpolicy::ERROR_DBUS_FAILURE;
}
return authpolicy::ERROR_NONE;
}
class AuthPolicyClientImpl : public AuthPolicyClient {
public:
AuthPolicyClientImpl() : weak_ptr_factory_(this) {}
......@@ -72,6 +92,18 @@ class AuthPolicyClientImpl : public AuthPolicyClient {
weak_ptr_factory_.GetWeakPtr(), base::Passed(&callback)));
}
void GetUserStatus(const std::string& object_guid,
GetUserStatusCallback callback) override {
dbus::MethodCall method_call(authpolicy::kAuthPolicyInterface,
authpolicy::kAuthPolicyGetUserStatus);
dbus::MessageWriter writer(&method_call);
writer.AppendString(object_guid);
proxy_->CallMethod(
&method_call, kSlowDbusTimeoutMilliseconds,
base::Bind(&AuthPolicyClientImpl::HandleGetUserStatusCallback,
weak_ptr_factory_.GetWeakPtr(), base::Passed(&callback)));
}
void RefreshDevicePolicy(RefreshPolicyCallback callback) override {
dbus::MethodCall method_call(authpolicy::kAuthPolicyInterface,
authpolicy::kAuthPolicyRefreshDevicePolicy);
......@@ -127,21 +159,16 @@ class AuthPolicyClientImpl : public AuthPolicyClient {
}
void HandleAuthCallback(AuthCallback callback, dbus::Response* response) {
authpolicy::ActiveDirectoryAccountData account_data;
if (!response) {
DLOG(ERROR) << "Auth: Failed to call to authpolicy";
std::move(callback).Run(authpolicy::ERROR_DBUS_FAILURE, account_data);
return;
}
dbus::MessageReader reader(response);
const authpolicy::ErrorType error(GetErrorFromReader(&reader));
if (!reader.PopArrayOfBytesAsProto(&account_data)) {
DLOG(ERROR) << "Failed to parse protobuf.";
std::move(callback).Run(authpolicy::ErrorType::ERROR_DBUS_FAILURE,
account_data);
return;
}
std::move(callback).Run(error, account_data);
authpolicy::ActiveDirectoryAccountInfo account_info;
authpolicy::ErrorType error(GetErrorAndProto(response, &account_info));
std::move(callback).Run(error, account_info);
}
void HandleGetUserStatusCallback(GetUserStatusCallback callback,
dbus::Response* response) {
authpolicy::ActiveDirectoryUserStatus user_status;
authpolicy::ErrorType error(GetErrorAndProto(response, &user_status));
std::move(callback).Run(error, user_status);
}
dbus::Bus* bus_ = nullptr;
......
......@@ -9,7 +9,7 @@
#include "base/callback.h"
#include "chromeos/chromeos_export.h"
#include "chromeos/dbus/authpolicy/active_directory_account_data.pb.h"
#include "chromeos/dbus/authpolicy/active_directory_info.pb.h"
#include "chromeos/dbus/dbus_client.h"
#include "third_party/cros_system_api/dbus/service_constants.h"
......@@ -22,11 +22,12 @@ namespace chromeos {
// initializes the DBusThreadManager instance.
class CHROMEOS_EXPORT AuthPolicyClient : public DBusClient {
public:
// |user_id| is a unique id for the users. Using objectGUID from Active
// Directory server.
using AuthCallback = base::OnceCallback<void(
authpolicy::ErrorType error,
const authpolicy::ActiveDirectoryAccountData& account_data)>;
const authpolicy::ActiveDirectoryAccountInfo& account_info)>;
using GetUserStatusCallback = base::OnceCallback<void(
authpolicy::ErrorType error,
const authpolicy::ActiveDirectoryUserStatus& user_status)>;
using JoinCallback = base::OnceCallback<void(authpolicy::ErrorType error)>;
using RefreshPolicyCallback = base::OnceCallback<void(bool success)>;
......@@ -59,6 +60,12 @@ class CHROMEOS_EXPORT AuthPolicyClient : public DBusClient {
int password_fd,
AuthCallback callback) = 0;
// Calls GetUserStatus. If Active Directory server is online it fetches
// ActiveDirectoryUserStatus for the user specified by |object_guid|.
// |callback| is called after getting (or failing to get) D-Bus response.
virtual void GetUserStatus(const std::string& object_guid,
GetUserStatusCallback callback) = 0;
// Calls RefreshDevicePolicy - handle policy for the device.
// Fetch GPO files from Active directory server, parse it, encode it into
// protobuf and send to SessionManager. Callback is called after that.
......
......@@ -109,20 +109,28 @@ void FakeAuthPolicyClient::AuthenticateUser(
int password_fd,
AuthCallback callback) {
authpolicy::ErrorType error = authpolicy::ERROR_NONE;
authpolicy::ActiveDirectoryAccountData account_data;
authpolicy::ActiveDirectoryAccountInfo account_info;
if (!started_) {
LOG(ERROR) << "authpolicyd not started";
error = authpolicy::ERROR_DBUS_FAILURE;
} else {
if (auth_error_ == authpolicy::ERROR_NONE) {
if (object_guid.empty())
account_data.set_account_id(base::MD5String(user_principal_name));
account_info.set_account_id(base::MD5String(user_principal_name));
else
account_data.set_account_id(object_guid);
account_info.set_account_id(object_guid);
}
error = auth_error_;
}
PostDelayedClosure(base::BindOnce(std::move(callback), error, account_data));
PostDelayedClosure(base::BindOnce(std::move(callback), error, account_info));
}
void FakeAuthPolicyClient::GetUserStatus(const std::string& object_guid,
GetUserStatusCallback callback) {
authpolicy::ActiveDirectoryUserStatus user_status;
user_status.mutable_account_info()->set_account_id(object_guid);
PostDelayedClosure(
base::BindOnce(std::move(callback), authpolicy::ERROR_NONE, user_status));
}
void FakeAuthPolicyClient::RefreshDevicePolicy(RefreshPolicyCallback callback) {
......
......@@ -31,6 +31,8 @@ class CHROMEOS_EXPORT FakeAuthPolicyClient : public AuthPolicyClient {
const std::string& object_guid,
int password_fd,
AuthCallback callback) override;
void GetUserStatus(const std::string& object_guid,
GetUserStatusCallback callback) override;
void RefreshDevicePolicy(RefreshPolicyCallback calllback) override;
void RefreshUserPolicy(const AccountId& account_id,
RefreshPolicyCallback callback) override;
......
......@@ -110,9 +110,9 @@ TEST_F(FakeAuthPolicyClientTest, AuthenticateUser_ByObjectGUID) {
kCorrectUserName, kObjectGUID, /* password_fd */ -1,
base::Bind(
[](authpolicy::ErrorType error,
const authpolicy::ActiveDirectoryAccountData& account_data) {
const authpolicy::ActiveDirectoryAccountInfo& account_info) {
EXPECT_EQ(authpolicy::ERROR_NONE, error);
EXPECT_EQ(kObjectGUID, account_data.account_id());
EXPECT_EQ(kObjectGUID, account_info.account_id());
}));
}
......@@ -126,7 +126,7 @@ TEST_F(FakeAuthPolicyClientTest, NotStartedAuthPolicyService) {
authpolicy_client()->AuthenticateUser(
kCorrectUserName, std::string() /* object_guid */, /* password_fd */ -1,
base::Bind([](authpolicy::ErrorType error,
const authpolicy::ActiveDirectoryAccountData&) {
const authpolicy::ActiveDirectoryAccountInfo&) {
EXPECT_EQ(authpolicy::ERROR_DBUS_FAILURE, error);
}));
authpolicy_client()->RefreshDevicePolicy(
......
......@@ -32,7 +32,7 @@ base::ScopedFD GetDataReadPipe(const std::string& data) {
void AuthCallbackDoNothing(
authpolicy::ErrorType /* error */,
const authpolicy::ActiveDirectoryAccountData& /* account_data */) {
const authpolicy::ActiveDirectoryAccountInfo& /* account_info */) {
// Do nothing.
}
......@@ -85,8 +85,8 @@ void AuthPolicyLoginHelper::OnJoinCallback(JoinCallback callback,
void AuthPolicyLoginHelper::OnAuthCallback(
AuthCallback callback,
authpolicy::ErrorType error,
const authpolicy::ActiveDirectoryAccountData& account_data) {
std::move(callback).Run(error, account_data);
const authpolicy::ActiveDirectoryAccountInfo& account_info) {
std::move(callback).Run(error, account_info);
}
AuthPolicyLoginHelper::~AuthPolicyLoginHelper() {}
......
......@@ -56,7 +56,7 @@ class CHROMEOS_EXPORT AuthPolicyLoginHelper {
void OnAuthCallback(
AuthCallback callback,
authpolicy::ErrorType error,
const authpolicy::ActiveDirectoryAccountData& account_data);
const authpolicy::ActiveDirectoryAccountInfo& account_info);
base::WeakPtrFactory<AuthPolicyLoginHelper> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(AuthPolicyLoginHelper);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment